Skip to content

Commit

Permalink
Tune api a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Dec 19, 2024
1 parent 8d4d134 commit 538a274
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ default Stream<P> problems() {
ProblemCollector<P> createChild();

/**
* Attaches a child collector. Parent (this) instance will accumulate values for itself and all of its children.
* May attach a child collector (if not present already). Parent (this) instance will accumulate values for
* itself and all of its children.
*
* @return {@code true} if child attached, or {@code false} if child already present.
*/
void addChild(ProblemCollector<P> child);
boolean mayAddChild(ProblemCollector<P> child);

/**
* Returns true if collector is present in passed in collector or its children.
Expand Down Expand Up @@ -178,8 +181,8 @@ public ProblemCollector<P> createChild() {
}

@Override
public void addChild(ProblemCollector<P> child) {
throw new IllegalStateException("empty problem collector");
public boolean mayAddChild(ProblemCollector<P> child) {
return false;
}

@Override
Expand Down Expand Up @@ -294,15 +297,13 @@ public ProblemCollector<P> createChild() {
}

@Override
public void addChild(ProblemCollector<P> child) {
public boolean mayAddChild(ProblemCollector<P> child) {
requireNonNull(child, "child");
if (child == this) {
throw new IllegalArgumentException("child cannot be attached to itself");
}
if (presentCollector(child)) {
throw new IllegalArgumentException("child already present");
if (!presentCollector(child)) {
childCollectors.add(child);
return true;
}
childCollectors.add(child);
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public List<MavenProject> selectProjects(List<File> files, MavenExecutionRequest
(problemsCount == 1) ? "problem was" : "problems were",
result.getProject().getId());

if (request.isShowErrors()) { // this means -e or -X (as -X turns on this one)
if (request.isShowErrors()) { // this means -e or -X (as -X enables -e as well)
for (ModelProblem problem : result.getProblems()) {
String loc = ModelProblemUtils.formatLocation(problem, result.getProjectId());
LOGGER.warn("{}{}", problem.getMessage(), ((loc != null && !loc.isEmpty()) ? " @ " + loc : ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,7 @@ private void loadFilePom(
// gathered with problem collector
add(Severity.ERROR, Version.V40, "Failed to load project " + pom, e);
}
if (!result.getProblemCollector().presentCollector(r.getProblemCollector())) {
result.getProblemCollector().addChild(r.getProblemCollector());
}
result.getProblemCollector().mayAddChild(r.getProblemCollector());
}

static <T> Set<T> concat(Set<T> a, T b) {
Expand Down Expand Up @@ -1721,12 +1719,12 @@ private Model doLoadDependencyManagement(
modelBuilderSession.buildEffectiveModel(importIds);
importResult = modelBuilderSession.result;
} catch (ModelBuilderException e) {
if (!result.getProblemCollector().presentCollector(e.getProblemCollector())) {
result.getProblemCollector().addChild(e.getProblemCollector());
}
result.getProblemCollector().mayAddChild(e.getProblemCollector());
return null;
}

result.getProblemCollector().mayAddChild(importResult.getProblemCollector());

importModel = importResult.getEffectiveModel();

return importModel;
Expand Down

0 comments on commit 538a274

Please sign in to comment.