-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ChainedLocalRepositoryManager
to support -Dmaven.repo.local.tail
#43352
Merged
+355
−15
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
...test/java/io/quarkus/bootstrap/resolver/maven/test/ChainedLocalRepositoryManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tiagobento could you please explain this one.
ignoreAvailability
istrue
. Is it availability of artifacts that should be ignored?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. So maybe the
ignoreAvailability
name kind of gives the wrong idea of what it actually does, and maybe a more explicit, albeit verbose, name would beignoreRemoteAvailability
? cc @cstamasThis flag is only applicable for dependencies that have been downloaded from a remote repository prior to being consumed as part of a
tail
local repository ("tracked", in Maven Resolver's terminology) . See the_remote.repositories
file.This particular test succeeds because
maven.repo.local.tail.ignoreAvailability
ends up beingtrue
, so even though org.acme:foo:jar:0.0.1 was supposedly initially resolved from a remote repository with id =some-repo-id
, this fact is ignored, and it being available in the local repository suffices. Whenmaven.repo.local.tail.ignoreAvailability
is false, it fails. That case is exactly what is covered bytestValidTailFromRemoteCheckingForAvailabilityViaSystemProp
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. The property name is indeed very confusing. It sounds like the meaning is "trust any remote repo" that provided an artifact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"availability" in resolver means that tracked remote repository (by repoID) is available in the context artifact is asked for. So "remote" may come in as "remote repo ID is available in current context asking for artifact" :)