Skip to content

Commit

Permalink
Ensure that MavenPomDownloader's behavior around adding default repos…
Browse files Browse the repository at this point in the history
…itories can be controlled from the execution context
  • Loading branch information
sambsnyd committed Mar 27, 2024
1 parent 12d0670 commit 152606f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MavenExecutionContextView extends DelegatingExecutionContext {
private static final String MAVEN_POM_CACHE = "org.openrewrite.maven.pomCache";
private static final String MAVEN_RESOLUTION_LISTENER = "org.openrewrite.maven.resolutionListener";
private static final String MAVEN_RESOLUTION_TIME = "org.openrewrite.maven.resolutionTime";
private static final String IS_ENABLE_DEFAULT_REPOSITORIES = "org.openrewrite.maven.isEnableDefaultRepositories";

public MavenExecutionContextView(ExecutionContext delegate) {
super(delegate);
Expand Down Expand Up @@ -211,6 +212,16 @@ public MavenSettings getSettings() {
return getMessage(MAVEN_SETTINGS, null);
}

@Nullable
public Boolean isEnableDefaultRepositories() {
return getMessage(IS_ENABLE_DEFAULT_REPOSITORIES, null);
}

public MavenExecutionContextView setEnableDefaultRepositories(@Nullable Boolean enableDefaultRepositories) {
putMessage(IS_ENABLE_DEFAULT_REPOSITORIES, enableDefaultRepositories);
return this;
}

private static List<String> mapActiveProfiles(MavenSettings settings, String... activeProfiles) {
if(settings.getActiveProfiles() == null) {
return Arrays.asList(activeProfiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public MavenPomDownloader(Map<Path, Pom> projectPoms, ExecutionContext ctx,
this(projectPoms, HttpSenderExecutionContextView.view(ctx).getHttpSender(), ctx);
this.mavenSettings = mavenSettings;
this.activeProfiles = activeProfiles;
Boolean enableDefaultRepositories = MavenExecutionContextView.view(ctx).isEnableDefaultRepositories();
this.addDefaultRepositories = enableDefaultRepositories == null || enableDefaultRepositories;
}

/**
Expand All @@ -108,7 +110,8 @@ public MavenPomDownloader(Map<Path, Pom> projectPoms, ExecutionContext ctx,
*/
public MavenPomDownloader(ExecutionContext ctx) {
this(emptyMap(), HttpSenderExecutionContextView.view(ctx).getHttpSender(), ctx);
this.addDefaultRepositories = false;
Boolean enableDefaultRepositories = MavenExecutionContextView.view(ctx).isEnableDefaultRepositories();
this.addDefaultRepositories = enableDefaultRepositories != null && enableDefaultRepositories;
}

/**
Expand Down Expand Up @@ -249,7 +252,7 @@ public MavenMetadata downloadMetadata(GroupArtifactVersion gav, @Nullable Resolv
try {
String scheme = URI.create(repo.getUri()).getScheme();
String uri = repo.getUri() + (repo.getUri().endsWith("/") ? "" : "/") +
gav.getGroupId().replace('.', '/') + '/' +
requireNonNull(gav.getGroupId()).replace('.', '/') + '/' +
gav.getArtifactId() + '/' +
(gav.getVersion() == null ? "" : gav.getVersion() + '/') +
"maven-metadata.xml";
Expand Down

0 comments on commit 152606f

Please sign in to comment.