Skip to content

Commit

Permalink
Dont directly set context, but use defaults for the gradle/non gradle…
Browse files Browse the repository at this point in the history
… constructor (#4112)

* Dont directly set context, but use defaults for the gradle/non gradle constructor

* use equals
  • Loading branch information
pstreef authored Mar 28, 2024
1 parent be71765 commit bd9ec56
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public class MavenPomDownloader {
@Nullable
private List<String> activeProfiles;

private boolean addCentralRepository;
private boolean addLocalRepository;

/**
* @param projectPoms Other POMs in this project.
* @param ctx The execution context, which potentially contain Maven settings customization
Expand All @@ -106,8 +109,8 @@ public MavenPomDownloader(Map<Path, Pom> projectPoms, ExecutionContext ctx,
*/
public MavenPomDownloader(ExecutionContext ctx) {
this(emptyMap(), HttpSenderExecutionContextView.view(ctx).getHttpSender(), ctx);
MavenExecutionContextView.view(ctx).setAddCentralRepository(false);
MavenExecutionContextView.view(ctx).setAddLocalRepository(false);
this.addCentralRepository = Boolean.TRUE.equals(MavenExecutionContextView.view(ctx).getAddCentralRepository());
this.addLocalRepository = Boolean.TRUE.equals(MavenExecutionContextView.view(ctx).getAddLocalRepository());
}

/**
Expand All @@ -132,6 +135,8 @@ public MavenPomDownloader(Map<Path, Pom> projectPoms, HttpSender httpSender, Exe
this.httpSender = httpSender;
this.ctx = MavenExecutionContextView.view(ctx);
this.mavenCache = this.ctx.getPomCache();
this.addCentralRepository = !Boolean.FALSE.equals(MavenExecutionContextView.view(ctx).getAddCentralRepository());
this.addLocalRepository = !Boolean.FALSE.equals(MavenExecutionContextView.view(ctx).getAddLocalRepository());
}

byte[] sendRequest(HttpSender.Request request) throws IOException, HttpSenderResponseException {
Expand Down Expand Up @@ -661,7 +666,7 @@ Collection<MavenRepository> distinctNormalizedRepositories(
@Nullable ResolvedPom containingPom,
@Nullable String acceptsVersion) {
LinkedHashMap<String, MavenRepository> normalizedRepositories = new LinkedHashMap<>();
if (ctx.getAddLocalRepository()) {
if (addLocalRepository) {
normalizedRepositories.put(ctx.getLocalRepository().getId(), ctx.getLocalRepository());
}

Expand All @@ -679,7 +684,7 @@ Collection<MavenRepository> distinctNormalizedRepositories(
normalizedRepositories.put(normalizedRepo.getId(), normalizedRepo);
}
}
if (!normalizedRepositories.containsKey(MavenRepository.MAVEN_CENTRAL.getId()) && ctx.getAddCentralRepository()) {
if (!normalizedRepositories.containsKey(MavenRepository.MAVEN_CENTRAL.getId()) && addCentralRepository) {
MavenRepository normalizedRepo = normalizeRepository(MavenRepository.MAVEN_CENTRAL, ctx, containingPom);
if (normalizedRepo != null) {
normalizedRepositories.put(normalizedRepo.getId(), normalizedRepo);
Expand Down

0 comments on commit bd9ec56

Please sign in to comment.