diff --git a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeInspector.java b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeInspector.java index c5386d00..7ab14335 100644 --- a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeInspector.java +++ b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeInspector.java @@ -26,19 +26,15 @@ public static DependencyTreeInspector configure() { private MavenArtifactResolver resolver; private boolean resolveDependencies; private DependencyTreeBuilder treeBuilder; - private DependencyTreeVisitor treeVisitor; + private DependencyTreeVisitor visitor; private boolean parallelProcessing; private MessageWriter log; private List roots = new ArrayList<>(); + private String progressTrackerPrefix; private DependencyTreeInspector() { } - public DependencyTreeInspector setTreeBuilder(DependencyTreeBuilder treeBuilder) { - this.treeBuilder = treeBuilder; - return this; - } - public DependencyTreeInspector setArtifactResolver(MavenArtifactResolver resolver) { this.resolver = resolver; return this; @@ -49,8 +45,13 @@ public DependencyTreeInspector setResolveDependencies(boolean resolveDependencie return this; } + public DependencyTreeInspector setTreeBuilder(DependencyTreeBuilder treeBuilder) { + this.treeBuilder = treeBuilder; + return this; + } + public DependencyTreeInspector setTreeVisitor(DependencyTreeVisitor treeVisitor) { - this.treeVisitor = treeVisitor; + this.visitor = treeVisitor; return this; } @@ -95,6 +96,11 @@ public DependencyTreeInspector inspect(DependencyTreeRequest request) { return this; } + public DependencyTreeInspector setProgressTrackerPrefix(String progressTrackerPrefix) { + this.progressTrackerPrefix = progressTrackerPrefix; + return this; + } + public void complete() { if (resolver == null) { @@ -131,8 +137,8 @@ public void complete() { log = MessageWriter.info(); } - if (treeVisitor == null) { - treeVisitor = new DependencyTreeVisitor<>() { + if (visitor == null) { + visitor = new DependencyTreeVisitor<>() { @Override public void visit(DependencyTreeVisit ctx) { } @@ -148,15 +154,19 @@ public void handleResolutionFailures(Collection requests) { } var scheduler = parallelProcessing - ? DependencyTreeVisitScheduler.parallel(treeBuilder, treeVisitor, log, roots.size()) - : DependencyTreeVisitScheduler.sequential(treeBuilder, treeVisitor, log, roots.size()); + ? new ParallelTreeVisitScheduler<>( + new DependencyTreeVisitContext<>(visitor, log), + roots.size(), treeBuilder, progressTrackerPrefix) + : new SequentialTreeVisitScheduler<>( + new DependencyTreeVisitContext<>(visitor, log), + roots.size(), treeBuilder, progressTrackerPrefix); for (var r : roots) { scheduler.process(r); } scheduler.waitForCompletion(); if (!scheduler.getResolutionFailures().isEmpty()) { - treeVisitor.handleResolutionFailures(scheduler.getResolutionFailures()); + visitor.handleResolutionFailures(scheduler.getResolutionFailures()); } } } diff --git a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeRequest.java b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeRequest.java index cfb0ab3c..ea79ef48 100644 --- a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeRequest.java +++ b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeRequest.java @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.graph.Dependency; import org.eclipse.aether.graph.Exclusion; @@ -32,6 +33,10 @@ public static DependencyTreeRequest ofPlugin(Artifact artifact, Collection constraints; private final Collection exclusions; @@ -42,10 +47,11 @@ private DependencyTreeRequest(Artifact root, List constraints, Colle this.constraints = constraints; this.exclusions = exclusions; this.type = type; + id = counter.incrementAndGet(); } - String getId() { - return root.toString(); + Integer getId() { + return id; } public Artifact getArtifact() { diff --git a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitContext.java b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitContext.java index 864fd6b4..63357229 100644 --- a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitContext.java +++ b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitContext.java @@ -6,8 +6,8 @@ class DependencyTreeVisitContext implements DependencyTreeVisitor.DependencyTreeVisit { - private final DependencyTreeVisitor visitor; - private final MessageWriter log; + final DependencyTreeVisitor visitor; + final MessageWriter log; DependencyNode root; DependencyTreeVisitContext(DependencyTreeVisitor visitor, MessageWriter log) { diff --git a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitScheduler.java b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitScheduler.java index 4c97b3bf..adf68f3a 100644 --- a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitScheduler.java +++ b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitScheduler.java @@ -1,24 +1,9 @@ package io.quarkus.domino.inspect; -import io.quarkus.devtools.messagewriter.MessageWriter; import java.util.Collection; public interface DependencyTreeVisitScheduler { - static DependencyTreeVisitScheduler sequential(DependencyTreeBuilder treeBuilder, - DependencyTreeVisitor visitor, - MessageWriter log, - int treesTotal) { - return new SequentialTreeVisitScheduler<>(visitor, log, treesTotal, treeBuilder); - } - - static DependencyTreeVisitScheduler parallel(DependencyTreeBuilder treeBuilder, - DependencyTreeVisitor visitor, - MessageWriter log, - int treesTotal) { - return new ParallelTreeVisitScheduler<>(visitor, log, treesTotal, treeBuilder); - } - void process(DependencyTreeRequest root); void waitForCompletion(); diff --git a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitSchedulerBase.java b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitSchedulerBase.java index 3d3f7f42..2bed62bd 100644 --- a/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitSchedulerBase.java +++ b/domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitSchedulerBase.java @@ -1,6 +1,5 @@ package io.quarkus.domino.inspect; -import io.quarkus.devtools.messagewriter.MessageWriter; import java.util.ArrayList; import java.util.Formatter; import java.util.List; @@ -15,10 +14,12 @@ abstract class DependencyTreeVisitSchedulerBase implements DependencyTreeVisi protected final DependencyTreeVisitContext ctx; protected final AtomicInteger counter = new AtomicInteger(); protected final int rootsTotal; + private final String progressTrackerPrefix; - DependencyTreeVisitSchedulerBase(DependencyTreeVisitor visitor, MessageWriter log, int rootsTotal) { - ctx = new DependencyTreeVisitContext<>(visitor, log); + DependencyTreeVisitSchedulerBase(DependencyTreeVisitContext ctx, int rootsTotal, String progressTrackerPrefix) { + this.ctx = ctx; this.rootsTotal = rootsTotal; + this.progressTrackerPrefix = progressTrackerPrefix; } @Override @@ -27,12 +28,15 @@ public List getResolutionFailures() { } protected String getResolvedTreeMessage(Artifact a) { - var sb = new StringBuilder(160); + var sb = new StringBuilder(180); var formatter = new Formatter(sb); var treeIndex = counter.incrementAndGet(); final double percents = ((double) treeIndex * 100) / rootsTotal; formatter.format(FORMAT_BASE, treeIndex, rootsTotal, percents); + if (progressTrackerPrefix != null) { + sb.append(progressTrackerPrefix); + } sb.append(a.getGroupId()).append(':').append(a.getArtifactId()).append(':'); if (!a.getClassifier().isEmpty()) { @@ -47,10 +51,14 @@ protected String getResolvedTreeMessage(Artifact a) { return sb.append(a.getVersion()).toString(); } - protected String formatErrorMessage(DependencyTreeRequest request, Exception e) { + protected String formatErrorMessage(DependencyTreeRequest request, Throwable e) { var sb = new StringBuilder(); sb.append("Failed to process dependencies of ").append(request.getArtifact()); if (e != null) { + if (e.getCause() != null) { + // the outer one is most probably a tree processing wrapper of the actual one thrown by the resolver + e = e.getCause(); + } var error = e.getLocalizedMessage(); sb.append(" because ").append(Character.toLowerCase(error.charAt(0))).append(error.substring(1)); } diff --git a/domino/api/src/main/java/io/quarkus/domino/inspect/ParallelTreeVisitScheduler.java b/domino/api/src/main/java/io/quarkus/domino/inspect/ParallelTreeVisitScheduler.java index 379930af..04a31280 100644 --- a/domino/api/src/main/java/io/quarkus/domino/inspect/ParallelTreeVisitScheduler.java +++ b/domino/api/src/main/java/io/quarkus/domino/inspect/ParallelTreeVisitScheduler.java @@ -1,6 +1,5 @@ package io.quarkus.domino.inspect; -import io.quarkus.devtools.messagewriter.MessageWriter; import io.quarkus.domino.processor.ExecutionContext; import io.quarkus.domino.processor.NodeProcessor; import io.quarkus.domino.processor.ParallelTreeProcessor; @@ -9,26 +8,22 @@ import java.util.function.Function; import org.eclipse.aether.graph.DependencyNode; -public class ParallelTreeVisitScheduler extends DependencyTreeVisitSchedulerBase { +class ParallelTreeVisitScheduler extends DependencyTreeVisitSchedulerBase { - final ParallelTreeProcessor treeProcessor; - private final DependencyTreeVisitor visitor; - private final MessageWriter log; + final ParallelTreeProcessor treeProcessor; - public ParallelTreeVisitScheduler(DependencyTreeVisitor visitor, MessageWriter log, int treesTotal, - DependencyTreeBuilder treeBuilder) { - super(visitor, log, treesTotal); - this.visitor = visitor; - this.log = log; + ParallelTreeVisitScheduler(DependencyTreeVisitContext ctx, int treesTotal, + DependencyTreeBuilder treeBuilder, String progressTrackerPrefix) { + super(ctx, treesTotal, progressTrackerPrefix); treeProcessor = ParallelTreeProcessor .with(new NodeProcessor<>() { - private TaskResult apply( - ExecutionContext execution) { + private TaskResult apply( + ExecutionContext execution) { var request = execution.getNode(); try { var node = treeBuilder.buildTree(request); - log.info(getResolvedTreeMessage(request.getArtifact())); + ctx.log.info(getResolvedTreeMessage(request.getArtifact())); return execution.success(node); } catch (Exception e) { return execution.failure(e); @@ -36,7 +31,7 @@ private TaskResult apply( } @Override - public String getNodeId(DependencyTreeRequest request) { + public Integer getNodeId(DependencyTreeRequest request) { return request.getId(); } @@ -46,7 +41,7 @@ public Iterable getChildren(DependencyTreeRequest node) { } @Override - public Function, TaskResult> createFunction() { + public Function, TaskResult> createFunction() { return this::apply; } }); @@ -63,10 +58,10 @@ public void waitForCompletion() { for (var r : results) { if (r.isFailure()) { errors.add(new DependencyTreeError(r.getNode(), r.getException())); - log.error(formatErrorMessage(r.getNode(), r.getException())); + ctx.getLog().error(formatErrorMessage(r.getNode(), r.getException())); } else { ctx.root = r.getOutcome(); - visitor.visit(ctx); + ctx.visitor.visit(ctx); } } } diff --git a/domino/api/src/main/java/io/quarkus/domino/inspect/SequentialTreeVisitScheduler.java b/domino/api/src/main/java/io/quarkus/domino/inspect/SequentialTreeVisitScheduler.java index 9b0ff2fc..f0479160 100644 --- a/domino/api/src/main/java/io/quarkus/domino/inspect/SequentialTreeVisitScheduler.java +++ b/domino/api/src/main/java/io/quarkus/domino/inspect/SequentialTreeVisitScheduler.java @@ -1,19 +1,14 @@ package io.quarkus.domino.inspect; -import io.quarkus.devtools.messagewriter.MessageWriter; import org.eclipse.aether.graph.DependencyNode; -public class SequentialTreeVisitScheduler extends DependencyTreeVisitSchedulerBase { +class SequentialTreeVisitScheduler extends DependencyTreeVisitSchedulerBase { - private final DependencyTreeVisitor visitor; - private final MessageWriter log; private final DependencyTreeBuilder treeBuilder; - public SequentialTreeVisitScheduler(DependencyTreeVisitor visitor, MessageWriter log, int treesTotal, - DependencyTreeBuilder treeBuilder) { - super(visitor, log, treesTotal); - this.visitor = visitor; - this.log = log; + SequentialTreeVisitScheduler(DependencyTreeVisitContext ctx, int treesTotal, + DependencyTreeBuilder treeBuilder, String progressTrackerPrefix) { + super(ctx, treesTotal, progressTrackerPrefix); this.treeBuilder = treeBuilder; } @@ -22,14 +17,14 @@ public void process(DependencyTreeRequest req) { final DependencyNode rootNode; try { rootNode = treeBuilder.buildTree(req); - log.info(getResolvedTreeMessage(rootNode.getArtifact())); + ctx.log.info(getResolvedTreeMessage(rootNode.getArtifact())); } catch (Exception e) { errors.add(new DependencyTreeError(req, e)); - log.error(formatErrorMessage(req, e)); + ctx.log.error(formatErrorMessage(req, e)); return; } ctx.root = rootNode; - visitor.visit(ctx); + ctx.visitor.visit(ctx); } @Override