From 05049a235d238020d9d5a0bbddbd6874b1cad2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Mickevi=C4=8Dius?= Date: Tue, 17 Apr 2018 11:30:42 +0300 Subject: [PATCH] Use vendor-id when discovering main classes (#839) (#841) --- .../main/scala-2.12/coursier/cli/Helper.scala | 2 +- .../cli/CliFetchIntegrationTest.scala | 44 +++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/cli/src/main/scala-2.12/coursier/cli/Helper.scala b/cli/src/main/scala-2.12/coursier/cli/Helper.scala index 566dcebf1..a8b7baaa5 100644 --- a/cli/src/main/scala-2.12/coursier/cli/Helper.scala +++ b/cli/src/main/scala-2.12/coursier/cli/Helper.scala @@ -43,7 +43,7 @@ object Helper { def attributeOpt(name: String) = Option(attributes.getValue(name)) - val vendor = attributeOpt("Specification-Vendor").getOrElse("") + val vendor = attributeOpt("Implementation-Vendor-Id").getOrElse("") val title = attributeOpt("Specification-Title").getOrElse("") val mainClass = attributeOpt("Main-Class") diff --git a/cli/src/test/scala-2.12/coursier/cli/CliFetchIntegrationTest.scala b/cli/src/test/scala-2.12/coursier/cli/CliFetchIntegrationTest.scala index 9bba0e78d..279c670e2 100644 --- a/cli/src/test/scala-2.12/coursier/cli/CliFetchIntegrationTest.scala +++ b/cli/src/test/scala-2.12/coursier/cli/CliFetchIntegrationTest.scala @@ -1,8 +1,8 @@ package coursier.cli import java.io._ - import java.net.URLEncoder.encode + import argonaut.Argonaut._ import caseapp.core.RemainingArgs import coursier.cli.options._ @@ -13,12 +13,13 @@ import java.nio.charset.StandardCharsets.UTF_8 import java.nio.file.{Files, Paths} import org.junit.runner.RunWith -import org.scalatest.FlatSpec +import org.scalatest.{FlatSpec, Matchers} import org.scalatest.junit.JUnitRunner + import scala.io.Source @RunWith(classOf[JUnitRunner]) -class CliFetchIntegrationTest extends FlatSpec with CliTestLib { +class CliFetchIntegrationTest extends FlatSpec with CliTestLib with Matchers { def getReportFromJson(f: File): ReportNode = { // Parse back the output json file @@ -35,11 +36,46 @@ class CliFetchIntegrationTest extends FlatSpec with CliTestLib { private val fileNameLength: DepNode => Int = _.file.getOrElse("").length "Normal fetch" should "get all files" in { - val fetchOpt = FetchOptions(common = CommonOptions()) val fetch = Fetch(fetchOpt, RemainingArgs(Seq("junit:junit:4.12"), Seq())) assert(fetch.files0.map(_.getName).toSet.equals(Set("junit-4.12.jar", "hamcrest-core-1.3.jar"))) + } + "scalafmt-cli fetch" should "discover all main classes" in { + val fetchOpt = FetchOptions(common = CommonOptions()) + val fetch = Fetch(fetchOpt, RemainingArgs(Seq("com.geirsson:scalafmt-cli_2.12:1.4.0"), Seq())) + Helper.mainClasses(fetch.helper.loader) should contain theSameElementsAs Map ( + ("", "") -> "com.martiansoftware.nailgun.NGServer", + ("com.geirsson", "cli") -> "org.scalafmt.cli.Cli" + ) + } + + "scalafix-cli fetch" should "discover all main classes" in { + val fetchOpt = FetchOptions(common = CommonOptions()) + val fetch = Fetch(fetchOpt, RemainingArgs(Seq("ch.epfl.scala:scalafix-cli_2.12.4:0.5.10"), Seq())) + Helper.mainClasses(fetch.helper.loader) should contain theSameElementsAs Map( + ("", "") -> "com.martiansoftware.nailgun.NGServer", + ("ch.epfl.scala", "cli") -> "scalafix.cli.Cli" + ) + } + + "ammonite fetch" should "discover all main classes" in { + val fetchOpt = FetchOptions(common = CommonOptions()) + val fetch = Fetch(fetchOpt, RemainingArgs(Seq("com.lihaoyi:ammonite_2.12.4:1.1.0"), Seq())) + Helper.mainClasses(fetch.helper.loader) should contain theSameElementsAs Map( + ("", "Javassist") -> "javassist.CtClass", + ("" ,"Java Native Access (JNA)") -> "com.sun.jna.Native", + ("com.lihaoyi", "ammonite") -> "ammonite.Main" + ) + } + + "sssio fetch" should "discover all main classes" in { + val fetchOpt = FetchOptions(common = CommonOptions()) + val fetch = Fetch(fetchOpt, RemainingArgs(Seq("lt.dvim.sssio:sssio_2.12:0.0.1"), Seq())) + Helper.mainClasses(fetch.helper.loader) should contain theSameElementsAs Map( + ("", "") -> "com.kenai.jffi.Main", + ("lt.dvim.sssio", "sssio") -> "lt.dvim.sssio.Sssio" + ) } "Module level" should "exclude correctly" in withFile(