-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancements, fixes and refactoring of dependency tree processing API
- Loading branch information
1 parent
46fdb09
commit f731407
Showing
20 changed files
with
441 additions
and
411 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.quarkus.domino.inspect; | ||
|
||
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException; | ||
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.eclipse.aether.collection.CollectRequest; | ||
import org.eclipse.aether.graph.Dependency; | ||
import org.eclipse.aether.graph.DependencyNode; | ||
import org.eclipse.aether.util.artifact.JavaScopes; | ||
|
||
public abstract class DependencyTreeBuilder { | ||
|
||
private static final Artifact root = new DefaultArtifact("io.domino", "domino-tree-builder", "pom", "1"); | ||
|
||
public static DependencyTreeBuilder resolvingTreeBuilder(MavenArtifactResolver resolver) { | ||
return new ResolvingDependencyTreeBuilder(resolver); | ||
} | ||
|
||
public static DependencyTreeBuilder nonResolvingTreeBuilder(MavenArtifactResolver resolver) { | ||
return new NonResolvingDependencyTreeBuilder(resolver); | ||
} | ||
|
||
protected final MavenArtifactResolver resolver; | ||
|
||
DependencyTreeBuilder(MavenArtifactResolver resolver) { | ||
this.resolver = Objects.requireNonNull(resolver); | ||
} | ||
|
||
public DependencyNode buildTree(DependencyTreeRequest root) { | ||
var rootNode = doBuildTree(root); | ||
if (root.isDependency()) { | ||
if (rootNode.getChildren().size() != 1) { | ||
throw new RuntimeException("Expected a single child node but got " + rootNode.getChildren()); | ||
} | ||
return rootNode.getChildren().get(0); | ||
} | ||
return rootNode; | ||
} | ||
|
||
public abstract DependencyNode doBuildTree(DependencyTreeRequest root); | ||
|
||
protected CollectRequest createCollectRequest(DependencyTreeRequest root) { | ||
var req = new CollectRequest().setManagedDependencies(root.getConstraints()); | ||
if (root.isPlugin()) { | ||
try { | ||
req.setRepositories(resolver.getMavenContext().getRemotePluginRepositories()); | ||
} catch (BootstrapMavenException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} else { | ||
req.setRepositories(resolver.getRepositories()); | ||
} | ||
var dep = new Dependency( | ||
root.getArtifact(), | ||
JavaScopes.RUNTIME, | ||
false, | ||
root.getExclusions()); | ||
if (root.isDependency()) { | ||
req.setRootArtifact(DependencyTreeBuilder.root) | ||
.setDependencies(List.of(dep)); | ||
} else { | ||
req.setRoot(dep); | ||
} | ||
return req; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.domino.inspect; | ||
|
||
public class DependencyTreeError { | ||
|
||
private final DependencyTreeRequest request; | ||
private final Throwable error; | ||
|
||
public DependencyTreeError(DependencyTreeRequest request, Throwable error) { | ||
this.request = request; | ||
this.error = error; | ||
} | ||
|
||
public DependencyTreeRequest getRequest() { | ||
return request; | ||
} | ||
|
||
public Throwable getError() { | ||
return error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.quarkus.domino.inspect; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.graph.Dependency; | ||
import org.eclipse.aether.graph.Exclusion; | ||
|
||
public class DependencyTreeRequest { | ||
|
||
/* @formatter:off */ | ||
private static final byte ROOT = 0b001; | ||
private static final byte DEPENDENCY = 0b010; | ||
private static final byte PLUGIN = 0b100; | ||
/* @formatter:on */ | ||
|
||
public static DependencyTreeRequest ofRoot(Artifact artifact, List<Dependency> constraints, | ||
Collection<Exclusion> exclusions) { | ||
return new DependencyTreeRequest(artifact, constraints, exclusions, ROOT); | ||
} | ||
|
||
public static DependencyTreeRequest ofDependency(Artifact artifact, List<Dependency> constraints, | ||
Collection<Exclusion> exclusions) { | ||
return new DependencyTreeRequest(artifact, constraints, exclusions, DEPENDENCY); | ||
} | ||
|
||
public static DependencyTreeRequest ofPlugin(Artifact artifact) { | ||
return ofPlugin(artifact, List.of()); | ||
} | ||
|
||
public static DependencyTreeRequest ofPlugin(Artifact artifact, Collection<Exclusion> exclusions) { | ||
return new DependencyTreeRequest(artifact, List.of(), exclusions, PLUGIN); | ||
} | ||
|
||
private final Artifact root; | ||
private final List<Dependency> constraints; | ||
private final Collection<Exclusion> exclusions; | ||
private final byte type; | ||
|
||
private DependencyTreeRequest(Artifact root, List<Dependency> constraints, Collection<Exclusion> exclusions, byte type) { | ||
this.root = root; | ||
this.constraints = constraints; | ||
this.exclusions = exclusions; | ||
this.type = type; | ||
} | ||
|
||
String getId() { | ||
return root.toString(); | ||
} | ||
|
||
public Artifact getArtifact() { | ||
return root; | ||
} | ||
|
||
public List<Dependency> getConstraints() { | ||
return constraints; | ||
} | ||
|
||
public Collection<Exclusion> getExclusions() { | ||
return exclusions; | ||
} | ||
|
||
boolean isRoot() { | ||
return type == ROOT; | ||
} | ||
|
||
boolean isDependency() { | ||
return type == DEPENDENCY; | ||
} | ||
|
||
boolean isPlugin() { | ||
return type == PLUGIN; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
domino/api/src/main/java/io/quarkus/domino/inspect/DependencyTreeVisitScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.domino.inspect; | ||
|
||
import io.quarkus.devtools.messagewriter.MessageWriter; | ||
import java.util.Collection; | ||
|
||
public interface DependencyTreeVisitScheduler { | ||
|
||
static <E> DependencyTreeVisitScheduler sequential(DependencyTreeBuilder treeBuilder, | ||
DependencyTreeVisitor<E> visitor, | ||
MessageWriter log, | ||
int treesTotal) { | ||
return new SequentialTreeVisitScheduler<>(visitor, log, treesTotal, treeBuilder); | ||
} | ||
|
||
static <E> DependencyTreeVisitScheduler parallel(DependencyTreeBuilder treeBuilder, | ||
DependencyTreeVisitor<E> visitor, | ||
MessageWriter log, | ||
int treesTotal) { | ||
return new ParallelTreeVisitScheduler<>(visitor, log, treesTotal, treeBuilder); | ||
} | ||
|
||
void process(DependencyTreeRequest root); | ||
|
||
void waitForCompletion(); | ||
|
||
Collection<DependencyTreeError> getResolutionFailures(); | ||
|
||
} |
Oops, something went wrong.