Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Feb 16, 2024
1 parent 4b6fd23 commit 0303e6e
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.quarkus.bootstrap.workspace.WorkspaceModule;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.DependencyFlags;
import io.quarkus.maven.dependency.ResolvableDependency;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.maven.dependency.ResolvedDependencyBuilder;
Expand Down Expand Up @@ -327,7 +328,7 @@ private ApplicationModel buildAppModel(ResolvedDependency appArtifact,
}
directDeps = filtered;
}
var parallel = true; //Boolean.getBoolean("parallel");
var parallel = Boolean.getBoolean("parallel");
var collectRtDepsRequest = MavenArtifactResolver.newCollectRequest(artifact, directDeps, managedDeps, List.of(), repos);
try {
if (parallel) {
Expand All @@ -352,7 +353,11 @@ private ApplicationModel buildAppModel(ResolvedDependency appArtifact,
"Failed to inject extension deployment dependencies for " + appArtifact.toCompactCoords(), e);
}

return appBuilder.build();
var model = appBuilder.build();
for (var d : model.getDependenciesWithAnyFlag(DependencyFlags.DIRECT)) {
System.out.println("- " + d.toCompactCoords());
}
return model;
}

private io.quarkus.maven.dependency.ResolvedDependency resolve(ArtifactCoords appArtifact, Artifact mvnArtifact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
this.managedDeps = collectRtDepsRequest.getManagedDependencies();
DependencyNode root = resolveRuntimeDeps(collectRtDepsRequest);
boolean doLog = false;
if (doLog)
if (doLog) {
System.out.println("Resolve runtime " + (System.currentTimeMillis() - start));

}
this.managedDeps = managedDeps.isEmpty() ? new ArrayList<>() : managedDeps;

var current = System.currentTimeMillis();
Expand Down Expand Up @@ -181,9 +181,10 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver

processDeploymentDeps(root);

new BuildDependencyGraphVisitor(resolver, appBuilder, buildTreeConsumer).visit(root);
if (doLog)
//new BuildDependencyGraphVisitor(resolver, appBuilder, buildTreeConsumer).visit(root);
if (doLog) {
System.out.println("Added deployment " + (System.currentTimeMillis() - current));
}

for (var d : appBuilder.getDependencies()) {
if (!d.isFlagSet(DependencyFlags.RELOADABLE) && !d.isFlagSet(DependencyFlags.VISITED)) {
Expand All @@ -202,8 +203,9 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
collectPlatformProperties();
collectCompileOnly(collectRtDepsRequest, root);

if (doLog)
if (doLog) {
System.out.println("TOTAL: " + (System.currentTimeMillis() - start));
}
}

private void processDeploymentDeps(DependencyNode root) {
Expand All @@ -224,26 +226,44 @@ private void processDeploymentDeps(DependencyNode root) {
for (var d : app.children) {
d.addToModel();
}

if (buildTreeConsumer != null) {
new AppDepLogger(buildTreeConsumer).process(app);
}
}

private void injectDeployment(List<ConditionalDependency> activatedConditionalDeps) {
var futures = new CompletableFuture<?>[topExtensionDeps.size() + activatedConditionalDeps.size()];
int i = 0;
for (ExtensionDependency extDep : topExtensionDeps) {
futures[i++] = CompletableFuture.runAsync(() -> {
try {
injectDeploymentDependencies(extDep);
} catch (BootstrapDependencyProcessingException e) {
throw new RuntimeException(e);
var resolvedDep = appBuilder.getDependency(getKey(extDep.info.deploymentArtifact));
if (resolvedDep == null) {
try {
injectDeploymentDependencies(extDep);
} catch (BootstrapDependencyProcessingException e) {
throw new RuntimeException(e);
}
} else {
// if resolvedDep isn't null, it means the deployment artifact is on the runtime classpath
// in which case we also clear the reloadable flag on it, in case it's coming from the workspace
resolvedDep.clearFlag(DependencyFlags.RELOADABLE);
}
});
}
for (ConditionalDependency cd : activatedConditionalDeps) {
futures[i++] = CompletableFuture.runAsync(() -> {
try {
injectDeploymentDependencies(cd.getExtensionDependency());
} catch (BootstrapDependencyProcessingException e) {
throw new RuntimeException(e);
var resolvedDep = appBuilder.getDependency(getKey(cd.getExtensionDependency().info.deploymentArtifact));
if (resolvedDep == null) {
try {
injectDeploymentDependencies(cd.getExtensionDependency());
} catch (BootstrapDependencyProcessingException e) {
throw new RuntimeException(e);
}
} else {
// if resolvedDep isn't null, it means the deployment artifact is on the runtime classpath
// in which case we also clear the reloadable flag on it, in case it's coming from the workspace
resolvedDep.clearFlag(DependencyFlags.RELOADABLE);
}
});
}
Expand Down Expand Up @@ -366,6 +386,15 @@ private DependencyNode resolveRuntimeDeps(CollectRequest request)
mutableSession.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true);
mutableSession.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
session = mutableSession;

var ctx = new BootstrapMavenContext(BootstrapMavenContext.config()
.setRepositorySystem(resolver.getSystem())
.setRepositorySystemSession(session)
.setRemoteRepositories(resolver.getRepositories())
.setRemoteRepositoryManager(resolver.getRemoteRepositoryManager())
.setCurrentProject(resolver.getMavenContext().getCurrentProject()));
resolver = new MavenArtifactResolver(ctx);

try {
return resolver.getSystem().collectDependencies(session, request).getRoot();
} catch (DependencyCollectionException e) {
Expand Down Expand Up @@ -1032,4 +1061,66 @@ private static String toCompactCoords(Artifact a) {
b.append(a.getVersion());
return b.toString();
}

private static class AppDepLogger {

private final Consumer<String> consumer;
final List<Boolean> depth = new ArrayList<>();

private AppDepLogger(Consumer<String> consumer) {
this.consumer = consumer;
}

public void process(AppDep dep) {
consume(dep);

final int childrenTotal = dep.children.size();
if (childrenTotal > 0) {
if (childrenTotal == 1) {
depth.add(false);
process(dep.children.get(0));
} else {
depth.add(true);
int i = 0;
while (i < childrenTotal) {
process(dep.children.get(i++));
if (i == childrenTotal - 1) {
depth.set(depth.size() - 1, false);
}
}
}
depth.remove(depth.size() - 1);
}
}

private void consume(AppDep dep) {
var buf = new StringBuilder();
if (!depth.isEmpty()) {
for (int i = 0; i < depth.size() - 1; ++i) {
if (depth.get(i)) {
//buf.append("| ");
buf.append('\u2502').append(" ");
} else {
buf.append(" ");
}
}
if (depth.get(depth.size() - 1)) {
//buf.append("|- ");
buf.append('\u251c').append('\u2500').append(' ');
} else {
//buf.append("\\- ");
buf.append('\u2514').append('\u2500').append(' ');
}
}
buf.append(dep.node.getArtifact());
if (!depth.isEmpty()) {
buf.append(" (").append(dep.node.getDependency().getScope());
if (dep.node.getDependency().isOptional()) {
buf.append(" optional");
}
buf.append(')');
}
consumer.accept(buf.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
* @throws BootstrapMavenException in case of a failure
*/
private void collectCompileOnly(CollectRequest collectRtDepsRequest, DependencyNode root) throws BootstrapMavenException {
System.out.println("ApplicationDependencyTreeResolver.collectCompileOnly " + collectCompileOnly);
if (collectCompileOnly.isEmpty()) {
return;
}
Expand Down
Loading

0 comments on commit 0303e6e

Please sign in to comment.