From 5ae6c3b6d6c0118c42b380f848458c1865bb9a3f Mon Sep 17 00:00:00 2001 From: Tiago Bento Date: Tue, 17 Sep 2024 12:38:14 -0400 Subject: [PATCH] Use ChainedLocalRepositoryManager --- .../resolver/maven/BootstrapMavenContext.java | 57 ++++- .../maven/BootstrapMavenContextConfig.java | 26 +++ .../test/BootstrapMavenContextTestBase.java | 11 +- .../ChainedLocalRepositoryManagerTest.java | 206 ++++++++++++++++++ .../test/PreferPomsFromWorkspaceTest.java | 10 +- .../org/acme/foo/0.0.1/_remote.repositories | 3 + .../org/acme/foo/0.0.1/foo-0.0.1.jar | 0 .../org/acme/foo/0.0.1/foo-0.0.1.pom | 10 + .../org/acme/foo/0.0.1/foo-0.0.1.jar | 0 .../org/acme/foo/0.0.1/foo-0.0.1.pom | 10 + .../org/acme/bar/0.0.2/bar-0.0.2.jar | 0 .../org/acme/bar/0.0.2/bar-0.0.2.pom | 10 + .../org/acme/foo/0.0.1/foo-0.0.1.jar | 0 .../org/acme/foo/0.0.1/foo-0.0.1.pom | 10 + .../workspace-with-local-repo-tail/pom.xml | 17 ++ 15 files changed, 355 insertions(+), 15 deletions(-) create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/ChainedLocalRepositoryManagerTest.java create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/_remote.repositories create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/foo-0.0.1.jar create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/foo-0.0.1.pom create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-1/repository/org/acme/foo/0.0.1/foo-0.0.1.jar create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-1/repository/org/acme/foo/0.0.1/foo-0.0.1.pom create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/bar/0.0.2/bar-0.0.2.jar create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/bar/0.0.2/bar-0.0.2.pom create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/foo/0.0.1/foo-0.0.1.jar create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/foo/0.0.1/foo-0.0.1.pom create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/pom.xml diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java index eb6f577c0410a..3eb1af3732511 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java @@ -61,6 +61,7 @@ import org.eclipse.aether.repository.ArtifactRepository; import org.eclipse.aether.repository.Authentication; import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.Proxy; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RepositoryPolicy; @@ -68,6 +69,7 @@ import org.eclipse.aether.resolution.ArtifactDescriptorRequest; import org.eclipse.aether.transfer.TransferListener; import org.eclipse.aether.util.repository.AuthenticationBuilder; +import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager; import org.eclipse.aether.util.repository.DefaultAuthenticationSelector; import org.eclipse.aether.util.repository.DefaultMirrorSelector; import org.eclipse.aether.util.repository.DefaultProxySelector; @@ -128,6 +130,8 @@ public class BootstrapMavenContext { private List remotePluginRepos; private RemoteRepositoryManager remoteRepoManager; private String localRepo; + private String[] localRepoTail; + private Boolean localRepoTailIgnoreAvailability; private Path currentPom; private Boolean currentProjectExists; private String alternatePomName; @@ -157,6 +161,8 @@ public BootstrapMavenContext(BootstrapMavenContextConfig config) this.alternatePomName = config.alternatePomName; this.artifactTransferLogging = config.artifactTransferLogging; this.localRepo = config.localRepo; + this.localRepoTail = config.localRepoTail; + this.localRepoTailIgnoreAvailability = config.localRepoTailIgnoreAvailability; this.offline = config.offline; this.warnOnFailingWorkspaceModules = config.warnOnFailedWorkspaceModules; this.repoSystem = config.repoSystem; @@ -363,6 +369,16 @@ public String getLocalRepo() throws BootstrapMavenException { return localRepo == null ? localRepo = resolveLocalRepo(getEffectiveSettings()) : localRepo; } + private String[] getLocalRepoTail() { + return localRepoTail == null ? localRepoTail = resolveLocalRepoTail() : localRepoTail; + } + + private boolean getLocalRepoTailIgnoreAvailability() { + return localRepoTailIgnoreAvailability == null + ? localRepoTailIgnoreAvailability = resolveLocalRepoTailIgnoreAvailability() + : localRepoTailIgnoreAvailability; + } + private LocalProject resolveCurrentProject(Function modelProvider) throws BootstrapMavenException { try { return LocalProject.loadWorkspace(this, modelProvider); @@ -384,6 +400,29 @@ private String resolveLocalRepo(Settings settings) { return localRepo == null ? new File(getUserMavenConfigurationHome(), "repository").getAbsolutePath() : localRepo; } + private String[] resolveLocalRepoTail() { + final String localRepoTail = getProperty("maven.repo.local.tail"); + if (localRepoTail == null) { + return new String[] {}; + } + if (localRepoTail.trim().isEmpty()) { + return new String[] {}; + } + return localRepoTail.split(","); + } + + private boolean resolveLocalRepoTailIgnoreAvailability() { + final String ignoreAvailability = getProperty("maven.repo.local.tail.ignoreAvailability"); + + // The only "falsy" value is `false` itself + if ("false".equalsIgnoreCase(ignoreAvailability)) { + return false; + } + + //All other strings are interpreted as `true`. + return true; + } + private File resolveSettingsFile(String settingsArg, Supplier supplier) { File userSettings; if (settingsArg != null) { @@ -460,9 +499,23 @@ private DefaultRepositorySystemSession newRepositorySystemSession() throws Boots } session.setMirrorSelector(ms); } + final String localRepoPath = getLocalRepo(); - session.setLocalRepositoryManager( - getRepositorySystem().newLocalRepositoryManager(session, new LocalRepository(localRepoPath))); + final String[] localRepoTailPaths = getLocalRepoTail(); + + final LocalRepositoryManager head = getRepositorySystem().newLocalRepositoryManager(session, + new LocalRepository(localRepoPath)); + + if (localRepoTailPaths.length == 0) { + session.setLocalRepositoryManager(head); + } else { + final List tail = new ArrayList<>(localRepoTailPaths.length); + for (final String tailPath : localRepoTailPaths) { + tail.add(getRepositorySystem().newLocalRepositoryManager(session, new LocalRepository(tailPath))); + } + session.setLocalRepositoryManager( + new ChainedLocalRepositoryManager(head, tail, getLocalRepoTailIgnoreAvailability())); + } session.setOffline(isOffline()); diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java index 487f94dba7ab0..df226da3caded 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java @@ -21,6 +21,8 @@ public class BootstrapMavenContextConfig> { protected String localRepo; + protected String[] localRepoTail; + protected Boolean localRepoTailIgnoreAvailability; protected Boolean offline; protected LocalProject currentProject; protected boolean workspaceDiscovery = true; @@ -92,6 +94,30 @@ public T setLocalRepository(String localRepo) { return (T) this; } + /** + * Local repository tail locations (comma-separated) + * + * @param localRepoTail local repository tail locations (comma-separated) + * @return this instance + */ + @SuppressWarnings("unchecked") + public T setLocalRepositoryTail(String[] localRepoTail) { + this.localRepoTail = localRepoTail; + return (T) this; + } + + /** + * Wheter to ignore availability on local repository tail (default: true) + * + * @param localRepoTailIgnoreAvailability whether to ignore availability on local repository tail + * @return this instance + */ + @SuppressWarnings("unchecked") + public T setLocalRepositoryTailIgnoreAvailability(boolean localRepoTailIgnoreAvailability) { + this.localRepoTailIgnoreAvailability = localRepoTailIgnoreAvailability; + return (T) this; + } + /** * Whether to operate offline * diff --git a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/BootstrapMavenContextTestBase.java b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/BootstrapMavenContextTestBase.java index dbc11c5fb97b6..c624e51c476aa 100644 --- a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/BootstrapMavenContextTestBase.java +++ b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/BootstrapMavenContextTestBase.java @@ -42,10 +42,12 @@ protected RemoteRepository newRepo(String id, String url) { } protected BootstrapMavenContext bootstrapMavenContextForProject(String projectOnCp) throws Exception { - final BootstrapMavenContextConfig config = BootstrapMavenContext.config(); - initBootstrapMavenContextConfig(config); + return bootstrapMavenContextForProject(projectOnCp, config); + } + protected BootstrapMavenContext bootstrapMavenContextForProject(String projectOnCp, BootstrapMavenContextConfig config) + throws Exception { final Path projectLocation = getProjectLocation(projectOnCp); config.setCurrentProject(projectLocation.toString()); @@ -56,9 +58,6 @@ protected BootstrapMavenContext bootstrapMavenContextForProject(String projectOn return new BootstrapMavenContext(config); } - protected void initBootstrapMavenContextConfig(BootstrapMavenContextConfig config) throws Exception { - } - protected BootstrapMavenContext bootstrapMavenContextWithSettings(String configDirOnCp) throws Exception { final BootstrapMavenContextConfig config = initBootstrapMavenContextConfig(); @@ -75,7 +74,7 @@ protected BootstrapMavenContextConfig initBootstrapMavenContextConfig() throw return BootstrapMavenContext.config().setWorkspaceDiscovery(false); } - protected Path getProjectLocation(String projectOnCp) throws URISyntaxException { + protected static Path getProjectLocation(String projectOnCp) throws URISyntaxException { final URL basedirUrl = Thread.currentThread().getContextClassLoader().getResource(projectOnCp); assertNotNull(basedirUrl); return Paths.get(basedirUrl.toURI()); diff --git a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/ChainedLocalRepositoryManagerTest.java b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/ChainedLocalRepositoryManagerTest.java new file mode 100644 index 0000000000000..56ae3be0e30d1 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/ChainedLocalRepositoryManagerTest.java @@ -0,0 +1,206 @@ +package io.quarkus.bootstrap.resolver.maven.test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrowsExactly; + +import java.net.URISyntaxException; +import java.nio.file.Paths; + +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.junit.jupiter.api.Test; + +import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext; +import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException; +import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; + +public class ChainedLocalRepositoryManagerTest extends BootstrapMavenContextTestBase { + + private static final String M2_LOCAL_1; + private static final String M2_LOCAL_2; + private static final String M2_FROM_REMOTE; + + static { + final String projectLocation; + try { + projectLocation = getProjectLocation("workspace-with-local-repo-tail").toString(); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + + M2_LOCAL_1 = Paths.get(projectLocation, ".m2-local-1", "repository").toAbsolutePath().toString(); + M2_LOCAL_2 = Paths.get(projectLocation, ".m2-local-2", "repository").toAbsolutePath().toString(); + M2_FROM_REMOTE = Paths.get(projectLocation, ".m2-from-remote", "repository").toAbsolutePath().toString(); + } + + // Tail configuration tests + + @Test + public void testNoTail() throws Exception { + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail"); + assertThrowsExactly(BootstrapMavenException.class, () -> resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testTailConfiguredButEmptyString() throws Exception { + setSystemProp("maven.repo.local.tail", ""); + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail"); + assertThrowsExactly(BootstrapMavenException.class, () -> resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testTailConfiguredButBlank() throws Exception { + setSystemProp("maven.repo.local.tail", " "); + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail"); + assertThrowsExactly(BootstrapMavenException.class, () -> resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testTailConfiguredButNonExistent() throws Exception { + setSystemProp("maven.repo.local.tail", "/tmp/this-dir-does-not-exist"); + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail"); + assertThrowsExactly(BootstrapMavenException.class, () -> resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailViaSystemProp() throws Exception { + setSystemProp("maven.repo.local.tail", M2_LOCAL_1); + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail"); + assertNotNull(resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailViaConfig() throws Exception { + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTail(new String[] { M2_LOCAL_1 })); + + assertNotNull(resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailResolutionOrder() throws Exception { + final BootstrapMavenContext mvnLocal1first = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTail(new String[] { M2_LOCAL_1, M2_LOCAL_2 })); + + final BootstrapMavenContext mvnLocal2first = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTail(new String[] { M2_LOCAL_2, M2_LOCAL_1 })); + + assertEquals(resolveOrgAcmeFooJar001(mvnLocal1first).getFile().getAbsolutePath(), + Paths.get(M2_LOCAL_1, "org", "acme", "foo", "0.0.1", "foo-0.0.1.jar").toAbsolutePath().toString()); + assertEquals(resolveOrgAcmeFooJar001(mvnLocal2first).getFile().getAbsolutePath(), + Paths.get(M2_LOCAL_2, "org", "acme", "foo", "0.0.1", "foo-0.0.1.jar").toAbsolutePath().toString()); + } + + @Test + public void testValidTailMultiplicity() throws Exception { + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTail(new String[] { M2_LOCAL_1, M2_LOCAL_2 })); + + final Artifact foo = resolveOrgAcmeFooJar001(mvn); + assertNotNull(foo); + assertEquals(foo.getFile().getAbsolutePath(), + Paths.get(M2_LOCAL_1, "org", "acme", "foo", "0.0.1", "foo-0.0.1.jar").toAbsolutePath().toString()); + + final Artifact bar = resolveOrgAcmeBarJar002(mvn); + assertNotNull(bar); + assertEquals(bar.getFile().getAbsolutePath(), + Paths.get(M2_LOCAL_2, "org", "acme", "bar", "0.0.2", "bar-0.0.2.jar").toAbsolutePath().toString()); + } + + // ignoreAvailability tests + + @Test + public void testValidTailLocalCheckingForAvailabilityViaConfig() throws Exception { + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTailIgnoreAvailability(false) + .setLocalRepositoryTail(new String[] { M2_LOCAL_1 })); + + assertNotNull(resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailFromRemoteCheckingForAvailabilityViaConfig() throws Exception { + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTailIgnoreAvailability(false) + .setLocalRepositoryTail(new String[] { M2_FROM_REMOTE })); + + assertThrowsExactly(BootstrapMavenException.class, () -> resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailFromRemoteCheckingForAvailabilityViaSystemProp() throws Exception { + setSystemProp("maven.repo.local.tail.ignoreAvailability", "false"); + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTail(new String[] { M2_FROM_REMOTE })); + + assertThrowsExactly(BootstrapMavenException.class, () -> resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailFromRemoteIgnoringAvailabilityViaSystemPropEmpty() throws Exception { + setSystemProp("maven.repo.local.tail.ignoreAvailability", ""); // will become `true` + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTail(new String[] { M2_FROM_REMOTE })); + + assertNotNull(resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailFromRemoteIgnoringAvailabilityViaSystemPropBlank() throws Exception { + setSystemProp("maven.repo.local.tail.ignoreAvailability", " "); // will become `true` + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTail(new String[] { M2_FROM_REMOTE })); + + assertNotNull(resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailFromRemoteIgnoringAvailabilityViaSystemPropTruthy() throws Exception { + setSystemProp("maven.repo.local.tail.ignoreAvailability", "fals"); // will become `true` + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTail(new String[] { M2_FROM_REMOTE })); + + assertNotNull(resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailLocalIgnoringAvailabilityViaConfig() throws Exception { + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTailIgnoreAvailability(true) + .setLocalRepositoryTail(new String[] { M2_LOCAL_1 })); + + assertNotNull(resolveOrgAcmeFooJar001(mvn)); + } + + @Test + public void testValidTailFromRemoteIgnoringAvailabilityViaConfig() throws Exception { + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-with-local-repo-tail", + BootstrapMavenContext.config() + .setLocalRepositoryTailIgnoreAvailability(true) + .setLocalRepositoryTail(new String[] { M2_FROM_REMOTE })); + + assertNotNull(resolveOrgAcmeFooJar001(mvn)); + } + + private Artifact resolveOrgAcmeFooJar001(BootstrapMavenContext ctx) throws BootstrapMavenException { + final MavenArtifactResolver resolver = new MavenArtifactResolver(ctx); + return resolver.resolve(new DefaultArtifact("org.acme", "foo", "", "jar", "0.0.1")).getArtifact(); + } + + private Artifact resolveOrgAcmeBarJar002(BootstrapMavenContext ctx) throws BootstrapMavenException { + final MavenArtifactResolver resolver = new MavenArtifactResolver(ctx); + return resolver.resolve(new DefaultArtifact("org.acme", "bar", "", "jar", "0.0.2")).getArtifact(); + } +} diff --git a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/PreferPomsFromWorkspaceTest.java b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/PreferPomsFromWorkspaceTest.java index 4ef51e928c22e..8d6aeddb5b661 100644 --- a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/PreferPomsFromWorkspaceTest.java +++ b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/resolver/maven/test/PreferPomsFromWorkspaceTest.java @@ -12,18 +12,14 @@ import org.junit.jupiter.api.Test; import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext; -import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContextConfig; public class PreferPomsFromWorkspaceTest extends BootstrapMavenContextTestBase { - @Override - protected void initBootstrapMavenContextConfig(BootstrapMavenContextConfig config) { - config.setPreferPomsFromWorkspace(true); - } - @Test public void preferPomsFromWorkspace() throws Exception { - final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-alternate-pom/root/module2"); + final BootstrapMavenContext mvn = bootstrapMavenContextForProject("workspace-alternate-pom/root/module2", + BootstrapMavenContext.config().setPreferPomsFromWorkspace(true)); + final Artifact artifact = new DefaultArtifact(mvn.getCurrentProject().getGroupId(), mvn.getCurrentProject().getArtifactId(), null, "pom", mvn.getCurrentProject().getVersion()); final ArtifactDescriptorResult descriptor = mvn.getRepositorySystem().readArtifactDescriptor( diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/_remote.repositories b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/_remote.repositories new file mode 100644 index 0000000000000..66812c3554f97 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/_remote.repositories @@ -0,0 +1,3 @@ +#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice. +#Tue Sep 17 14:44:24 EDT 2024 +foo-0.0.1.jar>some-repo-id= \ No newline at end of file diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/foo-0.0.1.jar b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/foo-0.0.1.jar new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/foo-0.0.1.pom b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/foo-0.0.1.pom new file mode 100644 index 0000000000000..72edbfc4cb9b9 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-from-remote/repository/org/acme/foo/0.0.1/foo-0.0.1.pom @@ -0,0 +1,10 @@ + + + 4.0.0 + + org.acme + foo + 0.0.1 + jar + + diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-1/repository/org/acme/foo/0.0.1/foo-0.0.1.jar b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-1/repository/org/acme/foo/0.0.1/foo-0.0.1.jar new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-1/repository/org/acme/foo/0.0.1/foo-0.0.1.pom b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-1/repository/org/acme/foo/0.0.1/foo-0.0.1.pom new file mode 100644 index 0000000000000..72edbfc4cb9b9 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-1/repository/org/acme/foo/0.0.1/foo-0.0.1.pom @@ -0,0 +1,10 @@ + + + 4.0.0 + + org.acme + foo + 0.0.1 + jar + + diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/bar/0.0.2/bar-0.0.2.jar b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/bar/0.0.2/bar-0.0.2.jar new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/bar/0.0.2/bar-0.0.2.pom b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/bar/0.0.2/bar-0.0.2.pom new file mode 100644 index 0000000000000..a8bb3b37d03c8 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/bar/0.0.2/bar-0.0.2.pom @@ -0,0 +1,10 @@ + + + 4.0.0 + + org.acme + bar + 0.0.2 + jar + + diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/foo/0.0.1/foo-0.0.1.jar b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/foo/0.0.1/foo-0.0.1.jar new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/foo/0.0.1/foo-0.0.1.pom b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/foo/0.0.1/foo-0.0.1.pom new file mode 100644 index 0000000000000..72edbfc4cb9b9 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/.m2-local-2/repository/org/acme/foo/0.0.1/foo-0.0.1.pom @@ -0,0 +1,10 @@ + + + 4.0.0 + + org.acme + foo + 0.0.1 + jar + + diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/pom.xml b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/pom.xml new file mode 100644 index 0000000000000..0c43d46ee4b6f --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-with-local-repo-tail/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.acme + local-repo-tail + 0.0.1-SNAPSHOT + pom + + + + org.acme + foo + 0.0.1 + + +