From b930d292e2c3140c1fc03be7f5bc1eef92ce54af Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Thu, 30 Jun 2022 17:38:46 +0100 Subject: [PATCH 1/3] Use Maven's RepositoryUtils to convert Artifact types --- .../maven/MojoImplementation.scala | 11 +--- .../src/test/resources/test_jars/pom.xml | 57 +++++++++++++++++++ .../maven/MavenConfigGenerationSuite.scala | 25 ++++++++ 3 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 integrations/maven-bloop/src/test/resources/test_jars/pom.xml diff --git a/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala b/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala index b8817f68fc..2bb5f982be 100644 --- a/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala +++ b/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala @@ -10,6 +10,7 @@ import scala.util.Success import scala.util.Try import bloop.config.Config import bloop.config.Tag +import org.apache.maven.RepositoryUtils import org.apache.maven.artifact.Artifact import org.apache.maven.artifact.ArtifactUtils import org.apache.maven.execution.MavenSession @@ -84,15 +85,7 @@ object MojoImplementation { val suffix = if (classifier.nonEmpty) s":$classifier" else "" log.info("Resolving artifact: " + artifact + suffix) val request = new ArtifactRequest() - request.setArtifact( - new DefaultArtifact( - artifact.getGroupId(), - artifact.getArtifactId(), - classifier, - artifact.getType(), - artifact.getVersion() - ) - ) + request.setArtifact(RepositoryUtils.toArtifact(artifact)) request.setRepositories(mojo.getRemoteRepositories()) val result = mojo.getRepoSystem().resolveArtifact(session.getRepositorySession(), request) log.info("SUCCESS " + artifact) diff --git a/integrations/maven-bloop/src/test/resources/test_jars/pom.xml b/integrations/maven-bloop/src/test/resources/test_jars/pom.xml new file mode 100644 index 0000000000..a236a0c0b6 --- /dev/null +++ b/integrations/maven-bloop/src/test/resources/test_jars/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + com.example + test_jars + 1.0-SNAPSHOT + test_jars + A minimal Scala project using the Maven build tool. + + + 1.8 + 1.8 + UTF-8 + 2.13.6 + + + + + org.scala-lang + scala-library + 2.13.6 + + + + + org.apache.spark + spark-tags_2.13 + test-jar + test + 3.3.0 + + + + + src/main/scala + src/test/scala + + + + net.alchim31.maven + scala-maven-plugin + 3.3.2 + + + + + compile + testCompile + + + + + + + + + + diff --git a/integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala b/integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala index 40ad25942d..91ed5731c3 100644 --- a/integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala +++ b/integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala @@ -173,6 +173,31 @@ class MavenConfigGenerationSuite extends BaseConfigSuite { } } + @Test + def dependencyTestJars() = { + check("test_jars/pom.xml") { (configFile, projectName, subprojects) => + assert(subprojects.isEmpty) + assert(configFile.project.`scala`.isDefined) + assertEquals("2.13.6", configFile.project.`scala`.get.version) + assertEquals("org.scala-lang", configFile.project.`scala`.get.organization) + assert( + !configFile.project.`scala`.get.jars.exists(_.toString.contains("scala3-compiler_3")), + "No Scala 3 jar should be present." + ) + assert(!hasCompileClasspathEntryName(configFile, "scala3-library_3")) + assert(hasCompileClasspathEntryName(configFile, "scala-library")) + + assert(hasTag(configFile, Tag.Library)) + val testJar = configFile.project.resolution.get.modules.find(_.name == "spark-tags_2.13") + assert(testJar.exists { m => + m.artifacts.exists(_.path.toString().endsWith("spark-tags_2.13-3.3.0-tests.jar")) + }) + + assertNoConfigsHaveAnyJars(List(configFile), List(s"$projectName", s"$projectName-test")) + assertAllConfigsMatchJarNames(List(configFile), List("scala-library", "spark-tags")) + } + } + @Test def multiModuleTestJar() = { check( From 3a1d935f9c37bc8ad26ffdeb79ad367f6302971a Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Thu, 30 Jun 2022 18:01:02 +0100 Subject: [PATCH 2/3] Resolve test-jar dependencies --- .../scala/bloop/integrations/maven/MojoImplementation.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala b/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala index 2bb5f982be..ceaea99c9b 100644 --- a/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala +++ b/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala @@ -185,9 +185,10 @@ object MojoImplementation { case a: Artifact => a.getArtifactId() == "scala-library" } val allArtifacts = if (hasScalaLibrary) artifacts else artifacts ++ libraryAndDependencies + val isJar = Set("jar", "test-jar") val modules = allArtifacts.collect { - case art: Artifact if art.getType() == "jar" && isNotReactorProjectArtifact(art) => + case art: Artifact if isJar(art.getType()) && isNotReactorProjectArtifact(art) => if (art.getArtifactId() == "scala-library") scalaContext match { case Some(context) => From 8a606df7d3d157d8b3864cca81f54121e164a491 Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Thu, 30 Jun 2022 18:48:38 +0100 Subject: [PATCH 3/3] Remove RepositoryUtils --- .../maven/MojoImplementation.scala | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala b/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala index ceaea99c9b..8f6404be48 100644 --- a/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala +++ b/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala @@ -10,7 +10,6 @@ import scala.util.Success import scala.util.Try import bloop.config.Config import bloop.config.Tag -import org.apache.maven.RepositoryUtils import org.apache.maven.artifact.Artifact import org.apache.maven.artifact.ArtifactUtils import org.apache.maven.execution.MavenSession @@ -22,6 +21,7 @@ import org.apache.maven.plugin.logging.Log import org.apache.maven.project.MavenProject import org.codehaus.plexus.util.xml.Xpp3Dom import org.eclipse.aether.artifact.DefaultArtifact +import org.eclipse.aether.artifact.DefaultArtifactType import org.eclipse.aether.resolution.ArtifactRequest import scala_maven.AppLauncher @@ -85,7 +85,26 @@ object MojoImplementation { val suffix = if (classifier.nonEmpty) s":$classifier" else "" log.info("Resolving artifact: " + artifact + suffix) val request = new ArtifactRequest() - request.setArtifact(RepositoryUtils.toArtifact(artifact)) + val handler = artifact.getArtifactHandler() + val artifactType = new DefaultArtifactType( + artifact.getType(), + handler.getExtension(), + handler.getClassifier(), + handler.getLanguage(), + handler.isAddedToClasspath(), + handler.isIncludesDependencies() + ) + request.setArtifact( + new DefaultArtifact( + artifact.getGroupId(), + artifact.getArtifactId(), + classifier, + handler.getExtension(), + artifact.getVersion(), + null, + artifactType + ) + ) request.setRepositories(mojo.getRemoteRepositories()) val result = mojo.getRepoSystem().resolveArtifact(session.getRepositorySession(), request) log.info("SUCCESS " + artifact)