Skip to content

Commit

Permalink
feat: introuduce itr option
Browse files Browse the repository at this point in the history
Updates MIMA and introduces new (Resolver) feature
to ignore remote repositories introduced by transitive POMs.

In certain environments this may become essential.

Read more here https://issues.apache.org/jira/browse/MNG-7980

This option is present in Maven 3.9.7 and 4.0.0 as "-itr" CLI.
  • Loading branch information
cstamas committed Jul 6, 2024
1 parent ccdae1d commit b8cb881
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 8 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ dependencies {
implementation "org.slf4j:jcl-over-slf4j:1.7.30"
implementation "org.jboss:jandex:2.2.3.Final"

implementation "eu.maveniverse.maven.mima:context:2.4.12"
runtimeOnly "eu.maveniverse.maven.mima.runtime:standalone-static:2.4.12"
implementation "eu.maveniverse.maven.mima:context:2.4.15"
runtimeOnly "eu.maveniverse.maven.mima.runtime:standalone-static:2.4.15"

testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.1"
testImplementation "org.junit.jupiter:junit-jupiter:5.10.1"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.3"
testImplementation "org.junit.jupiter:junit-jupiter:5.10.3"
testImplementation "com.github.stefanbirkner:system-rules:1.17.2"
testImplementation "org.hamcrest:hamcrest-library:2.2"
testImplementation "com.github.tomakehurst:wiremock-jre8:2.32.0"
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/jbang/cli/JBang.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ void setPreview(boolean preview) {
Util.setPreview(preview);
}

@CommandLine.Option(names = {
"--ignore-transitive-repositories" }, description = "Resolver should ignore transitive POM introduced remote repositories")
void setIgnoreTransitiveRepositories(boolean ignoreTransitiveRepositories) {
Util.setIgnoreTransitiveRepositories(ignoreTransitiveRepositories);
}

@CommandLine.ArgGroup(exclusive = true)
VerboseQuietExclusive verboseQuietExclusive = new VerboseQuietExclusive();

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/dev/jbang/dependencies/ArtifactResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class Builder {
private List<MavenRepo> repositories;
private int timeout;
private boolean offline;
private boolean ignoreTransitiveRepositories;
private boolean withUserSettings;
private Path localFolder;
private Path settingsXml;
Expand Down Expand Up @@ -98,6 +99,11 @@ public Builder offline(boolean offline) {
return this;
}

public Builder ignoreTransitiveRepositories(boolean ignoreTransitiveRepositories) {
this.ignoreTransitiveRepositories = ignoreTransitiveRepositories;
return this;
}

public Builder logging(boolean logging) {
this.loggingEnabled = logging;
return this;
Expand Down Expand Up @@ -132,6 +138,8 @@ private ArtifactResolver(Builder builder) {
ContextOverrides.Builder overridesBuilder = ContextOverrides.create()
.userProperties(userProperties)
.offline(builder.offline)
.ignoreArtifactDescriptorRepositories(
builder.ignoreTransitiveRepositories)
.withUserSettings(builder.withUserSettings)
.withUserSettingsXmlOverride(builder.settingsXml)
.withLocalRepositoryOverride(builder.localFolder)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dev/jbang/dependencies/DependencyResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public DependencyResolver addClassPaths(List<String> classPaths) {
public ModularClassPath resolve() {
ModularClassPath mcp = DependencyUtil.resolveDependencies(
new ArrayList<>(dependencies), new ArrayList<>(repositories),
Util.isOffline(), Util.isFresh(), !Util.isQuiet(), Util.downloadSources());
Util.isOffline(), Util.isIgnoreTransitiveRepositories(), Util.isFresh(), !Util.isQuiet(),
Util.downloadSources());
if (classPaths.isEmpty()) {
return mcp;
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/dev/jbang/dependencies/DependencyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private DependencyUtil() {
}

public static ModularClassPath resolveDependencies(List<String> deps, List<MavenRepo> repos,
boolean offline, boolean updateCache, boolean loggingEnabled, boolean downloadSources) {
boolean offline, boolean ignoreTransitiveRepositories, boolean updateCache, boolean loggingEnabled,
boolean downloadSources) {

// if no dependencies were provided we stop here
if (deps.isEmpty()) {
Expand Down Expand Up @@ -102,6 +103,8 @@ public static ModularClassPath resolveDependencies(List<String> deps, List<Maven
.withUserSettings(true)
.localFolder(getJBangLocalMavenRepoOverride())
.offline(offline)
.ignoreTransitiveRepositories(
ignoreTransitiveRepositories)
.forceCacheUpdate(updateCache)
.logging(loggingEnabled)
.downloadSources(downloadSources)
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/dev/jbang/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class Util {
private static boolean quiet;
private static boolean offline;
private static boolean fresh;
private static boolean ignoreTransitiveRepositories;
private static boolean preview;

private static Path cwd;
Expand Down Expand Up @@ -136,6 +137,10 @@ public static void setOffline(boolean offline) {
}
}

public static void setIgnoreTransitiveRepositories(boolean ignoreTransitiveRepositories) {
Util.ignoreTransitiveRepositories = ignoreTransitiveRepositories;
}

public static void setDownloadSources(boolean flag) {
downloadSources = flag;
}
Expand All @@ -151,6 +156,10 @@ public static boolean isOffline() {
return offline;
}

public static boolean isIgnoreTransitiveRepositories() {
return ignoreTransitiveRepositories;
}

public static void setFresh(boolean fresh) {
Util.fresh = fresh;
if (fresh) {
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/dev/jbang/dependencies/DependencyResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void testResolveDependencies() {
List<String> deps = Arrays.asList("com.offbytwo:docopt:0.6.0.20150202", "log4j:log4j:1.2+");

ModularClassPath classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false,
false,
true, false);

// if returns 5 its because optional deps are included which they shouldn't
Expand All @@ -151,6 +152,7 @@ void testResolveDependenciesNoDuplicates() {
"org.apache.commons:commons-text:1.8");

ModularClassPath classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false,
false,
true, false);

// if returns with duplicates its because some dependencies are multiple times
Expand All @@ -172,6 +174,7 @@ void testResolveNativeDependencies() {
List<String> deps = Collections.singletonList("com.github.docker-java:docker-java:3.1.5");

ModularClassPath classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false,
false,
true, false);

assertEquals(46, classpath.getClassPaths().size());
Expand All @@ -183,7 +186,7 @@ void testResolveJavaModules() throws IOException {
List<String> deps = Arrays.asList("org.openjfx:javafx-graphics:11.0.2:mac", "com.offbytwo:docopt:0.6+");

ModularClassPath cp = new ModularClassPath(
DependencyUtil .resolveDependencies(deps, Collections.emptyList(), false, false, true, false)
DependencyUtil .resolveDependencies(deps, Collections.emptyList(), false, false, false, true, false)
.getArtifacts()) {
@Override
protected boolean supportsModules(JdkProvider.Jdk jdk) {
Expand All @@ -205,6 +208,7 @@ void testImportPOM() {
List<String> deps = Arrays.asList("com.microsoft.azure:azure-bom:1.0.0.M1@pom", "com.microsoft.azure:azure");

ModularClassPath classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false,
false,
true, false);

assertEquals(62, classpath.getArtifacts().size());
Expand All @@ -221,6 +225,7 @@ void testImportMultipleBoms() {
"org.slf4j:slf4j-simple:1.7.30");

ModularClassPath classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false,
false,
true, false);

Optional<ArtifactInfo> coord = classpath.getArtifacts()
Expand Down Expand Up @@ -253,7 +258,7 @@ void testImportMultipleBoms() {
"org.apache.camel:camel-core",
"org.apache.camel:camel-vertx",
"org.slf4j:slf4j-simple:1.7.30");
classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false, true, false);
classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false, false, true, false);

coord = classpath .getArtifacts()
.stream()
Expand All @@ -268,6 +273,7 @@ void testResolveTestJar() {
List<String> deps = Arrays.asList("org.infinispan:infinispan-commons:13.0.5.Final@test-jar");

ModularClassPath classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false,
false,
true, false);

assertThat(classpath.getArtifacts(), hasSize(7));
Expand Down
1 change: 1 addition & 0 deletions src/test/java/dev/jbang/dependencies/TestArtifactInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void testDependencyCache() {
"org.apache.commons:commons-text:1.8");

ModularClassPath classpath = DependencyUtil.resolveDependencies(deps, Collections.emptyList(), false, false,
false,
true, false);

DependencyCache.cache("wonka", classpath.getArtifacts());
Expand Down

0 comments on commit b8cb881

Please sign in to comment.