diff --git a/pom.xml b/pom.xml index 0e5d1ebe..6df39949 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ 21 - 3.6.3 + 3.9.8 2.0.13 snapshot @@ -81,7 +81,7 @@ org.apache.maven.shared maven-filtering - 3.2.0 + 3.3.2 @@ -134,17 +134,17 @@ 2.17.2 - org.apache.httpcomponents - httpclient - 4.5.14 - compile - - - org.apache.httpcomponents - httpmime - 4.5.14 - compile - + org.apache.httpcomponents + httpclient + 4.5.14 + compile + + + org.apache.httpcomponents + httpmime + 4.5.14 + compile + diff --git a/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractEngineInstanceMojo.java b/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractEngineInstanceMojo.java index de450974..cdc25d10 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractEngineInstanceMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractEngineInstanceMojo.java @@ -18,13 +18,13 @@ import java.io.File; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; import ch.ivyteam.ivy.maven.AbstractEngineMojo; import ch.ivyteam.ivy.maven.engine.EngineClassLoaderFactory; @@ -53,8 +53,8 @@ public abstract class AbstractEngineInstanceMojo extends AbstractEngineMojo { @Component private RepositorySystem repository; - @Parameter(defaultValue = "${localRepository}") - public ArtifactRepository localRepository; + @Parameter( defaultValue = "${repositorySystemSession}", readonly = true, required = true ) + protected RepositorySystemSession repoSession; private static MavenProjectBuilderProxy builder; @@ -97,8 +97,7 @@ protected MavenProjectBuilderProxy getMavenProjectBuilder() throws Exception { } public final EngineClassLoaderFactory getEngineClassloaderFactory() { - MavenContext context = new EngineClassLoaderFactory.MavenContext( - repository, localRepository, project, getLog()); + MavenContext context = new EngineClassLoaderFactory.MavenContext(repository, project, getLog()); return new EngineClassLoaderFactory(context); } diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java index 246540cf..4e172150 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java @@ -30,7 +30,7 @@ import org.apache.commons.io.filefilter.SuffixFileFilter; import org.apache.commons.io.filefilter.WildcardFileFilter; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; @@ -141,25 +141,27 @@ private static URL[] toUrls(List ivyEngineClassPathFiles) throws Malformed public static class MavenContext { private final RepositorySystem repoSystem; - private final ArtifactRepository localRepository; private final MavenProject project; private final Log log; - public MavenContext(RepositorySystem repoSystem, ArtifactRepository localRepository, MavenProject project, + public MavenContext(RepositorySystem repoSystem, MavenProject project, Log log) { this.repoSystem = repoSystem; - this.localRepository = localRepository; this.project = project; this.log = log; } public File getJar(String groupId, String artifactId, String version) { Artifact artifact = repoSystem.createArtifact(groupId, artifactId, version, "jar"); - File jar = new File(localRepository.getBasedir(), localRepository.pathOf(artifact)); - if (!jar.exists()) { - log.warn("Failed to resolve '" + artifactId + "' from local repository in '" + jar + "'."); + var request = new ArtifactResolutionRequest(); + request.setArtifact(artifact); + var response = repoSystem.resolve(request); + if (response.isSuccess()) { + return response.getArtifacts().iterator().next().getFile(); + } else { + log.warn("Failed to resolve '" + artifactId + "' from local repository."); } - return jar; + return null; } } diff --git a/src/test/java/ch/ivyteam/ivy/maven/compile/CompileMojoRule.java b/src/test/java/ch/ivyteam/ivy/maven/compile/CompileMojoRule.java index ef2a4acf..c75eeaff 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/compile/CompileMojoRule.java +++ b/src/test/java/ch/ivyteam/ivy/maven/compile/CompileMojoRule.java @@ -16,14 +16,6 @@ package ch.ivyteam.ivy.maven.compile; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; -import org.apache.maven.plugin.LegacySupport; -import org.apache.maven.plugin.internal.DefaultLegacySupport; - -import ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest; import ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest.EngineMojoRule; public class CompileMojoRule extends EngineMojoRule { @@ -36,30 +28,4 @@ protected void before() throws Throwable { super.before(); configureMojo(getMojo()); } - - public void configureMojo(AbstractEngineInstanceMojo newMojo) throws IllegalAccessException { - newMojo.localRepository = provideLocalRepository(); - } - - /** - * maven-plugin-testing-harness can not inject local repositories (though the - * real runtime supports it). and the default stubs have no sufficient - * implementation of getPath(): - * @see "http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/examples/repositories.html" - */ - private ArtifactRepository provideLocalRepository() throws IllegalAccessException { - DefaultArtifactRepositoryFactory factory = new DefaultArtifactRepositoryFactory(); - setVariableValueToObject(factory, "factory", - new org.apache.maven.repository.legacy.repository.DefaultArtifactRepositoryFactory()); - - LegacySupport legacySupport = new DefaultLegacySupport(); - setVariableValueToObject(factory, "legacySupport", legacySupport); - - ArtifactRepository localRepository = factory.createArtifactRepository("local", "http://localhost", - new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy()); - - setVariableValueToObject(localRepository, "basedir", BaseEngineProjectMojoTest.LOCAL_REPOSITORY); - - return localRepository; - } -} \ No newline at end of file +}