From fe05bee19af331b194dfd941dfe252afd1cb6333 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Fri, 2 Feb 2024 17:42:29 +0100 Subject: [PATCH] more --- .../ApplicationDependencyModelResolver.java | 134 ++++++++++++------ 1 file changed, 92 insertions(+), 42 deletions(-) diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyModelResolver.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyModelResolver.java index 6067f7213080f..5bf0e8315f0cb 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyModelResolver.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyModelResolver.java @@ -55,7 +55,6 @@ import io.quarkus.bootstrap.resolver.AppModelResolverException; import io.quarkus.bootstrap.util.BootstrapUtils; import io.quarkus.bootstrap.util.DependencyUtils; -import io.quarkus.bootstrap.util.PropertyUtils; import io.quarkus.bootstrap.workspace.WorkspaceModule; import io.quarkus.maven.dependency.ArtifactCoords; import io.quarkus.maven.dependency.ArtifactKey; @@ -76,9 +75,6 @@ public class ApplicationDependencyModelResolver { private static final byte COLLECT_RELOADABLE_MODULES = 0b100; /* @formatter:on */ - // this is a temporary option, to enable the previous way of initializing runtime classpath dependencies - private static final boolean CONVERGED_TREE_ONLY = PropertyUtils.getBoolean("quarkus.bootstrap.converged-tree-only", false); - private static final Artifact[] NO_ARTIFACTS = new Artifact[0]; public static ApplicationDependencyModelResolver newInstance() { @@ -182,6 +178,9 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver root = normalize(resolver.getSession(), root); // add deployment dependencies current = System.currentTimeMillis(); + + processDeploymentDeps(root); + new BuildDependencyGraphVisitor(resolver, appBuilder, buildTreeConsumer).visit(root); if (doLog) System.out.println("Added deployment " + (System.currentTimeMillis() - current)); @@ -207,6 +206,26 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver System.out.println("TOTAL: " + (System.currentTimeMillis() - start)); } + private void processDeploymentDeps(DependencyNode root) { + var app = new AppDep(root); + var futures = new ArrayList>(); + var errors = new ConcurrentLinkedDeque(); + app.initDeploymentChildren(futures, errors); + CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); + if (!errors.isEmpty()) { + log.error("The following errors were encountered while processing application dependencies:"); + var i = 1; + for (var error : errors) { + log.error(i++ + ")", error); + error.printStackTrace(); + } + throw new RuntimeException("Failed to process application dependencies, please see the errors logged above"); + } + for (var d : app.children) { + d.addToModel(); + } + } + private void injectDeployment(List activatedConditionalDeps) { var futures = new CompletableFuture[topExtensionDeps.size() + activatedConditionalDeps.size()]; int i = 0; @@ -343,14 +362,10 @@ private DependencyNode normalize(RepositorySystemSession session, DependencyNode private DependencyNode resolveRuntimeDeps(CollectRequest request) throws AppModelResolverException { var session = resolver.getSession(); - if (!CONVERGED_TREE_ONLY - && collectReloadableModules - && !Boolean.TRUE.equals(session.getConfigProperties().get(ConflictResolver.CONFIG_PROP_VERBOSE))) { - final DefaultRepositorySystemSession mutableSession = new DefaultRepositorySystemSession(resolver.getSession()); - mutableSession.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true); - mutableSession.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); - session = mutableSession; - } + final DefaultRepositorySystemSession mutableSession = new DefaultRepositorySystemSession(resolver.getSession()); + mutableSession.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true); + mutableSession.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); + session = mutableSession; try { return resolver.getSystem().collectDependencies(session, request).getRoot(); } catch (DependencyCollectionException e) { @@ -374,7 +389,7 @@ private void processRuntimeDeps(DependencyNode root) { var futures = new ArrayList>(); var errors = new ConcurrentLinkedDeque(); - app.initChildren(futures, errors); + app.initRuntimeChildren(futures, errors); CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); if (!errors.isEmpty()) { log.error("The following errors were encountered while processing application dependencies:"); @@ -385,7 +400,7 @@ private void processRuntimeDeps(DependencyNode root) { } throw new RuntimeException("Failed to process application dependencies, please see the errors logged above"); } - app.passFlags(); + app.setFlags(); } private class AppDep { @@ -408,25 +423,74 @@ private class AppDep { this.children = new ArrayList<>(node.getChildren().size()); } - void init(List> futures, ConcurrentLinkedDeque errors) { - futures.add(CompletableFuture.runAsync(this::init).exceptionally(t -> { - errors.add(t.getCause()); - return null; + void addToModel() { + if (resolvedDep != null) { + appBuilder.addDependency(resolvedDep); + } + for (var child : children) { + child.addToModel(); + } + } + + void initDeployment(List> futures, ConcurrentLinkedDeque errors) { + futures.add(CompletableFuture.runAsync(() -> { + try { + initDeployment(); + } catch (Throwable e) { + errors.add(e); + } })); - initChildren(futures, errors); + initDeploymentChildren(futures, errors); } - void initChildren(List> futures, ConcurrentLinkedDeque errors) { + void initDeploymentChildren(List> futures, ConcurrentLinkedDeque errors) { for (var childNode : node.getChildren()) { if (!hasWinner(childNode)) { var child = new AppDep(this, childNode); children.add(child); - child.init(futures, errors); + child.initDeployment(futures, errors); } } } - void passFlags() { + void initDeployment() { + var dep = appBuilder.getDependency(getKey(node.getArtifact())); + if (dep == null) { + try { + resolvedDep = newDependencyBuilder(node, resolver).setFlags(DependencyFlags.DEPLOYMENT_CP); + } catch (BootstrapMavenException e) { + throw new RuntimeException(e); + } + var deps = new ArrayList(node.getChildren().size()); + for (var child : node.getChildren()) { + deps.add(getKey(child.getArtifact())); + } + resolvedDep.setDependencies(deps); + } + } + + void initRuntime(List> futures, ConcurrentLinkedDeque errors) { + futures.add(CompletableFuture.runAsync(() -> { + try { + initRuntime(); + } catch (Throwable t) { + errors.add(t); + } + })); + initRuntimeChildren(futures, errors); + } + + void initRuntimeChildren(List> futures, ConcurrentLinkedDeque errors) { + for (var childNode : node.getChildren()) { + if (!hasWinner(childNode)) { + var child = new AppDep(this, childNode); + children.add(child); + child.initRuntime(futures, errors); + } + } + } + + void setFlags() { for (var c : children) { c.setFlags(walkingFlags); } @@ -451,7 +515,6 @@ private ExtensionDependency getExtensionDependencyOrNull(Artifact artifact) parentExtDep = parentExtDep.parent; } ext.info.ensureActivated(); - managedDeps.add(new Dependency(ext.info.deploymentArtifact, JavaScopes.COMPILE)); } } return ext; @@ -482,7 +545,7 @@ private Collection collectExclusions() { return exclusions == null ? List.of() : exclusions; } - void init() { + void initRuntime() { Artifact artifact = node.getArtifact(); final ArtifactKey key = getKey(artifact); if (resolvedDep == null) { @@ -528,6 +591,9 @@ void init() { void setFlags(byte walkingFlags) { if (appBuilder.getDependency(resolvedDep.getKey()) == null) { appBuilder.addDependency(resolvedDep); + if (ext != null) { + managedDeps.add(new Dependency(ext.info.deploymentArtifact, JavaScopes.COMPILE)); + } } this.walkingFlags = walkingFlags; @@ -548,7 +614,7 @@ void setFlags(byte walkingFlags) { clearWalkingFlag(COLLECT_DIRECT_DEPS); - passFlags(); + setFlags(); } private boolean isWalkingFlagOn(byte flag) { @@ -635,10 +701,6 @@ private void injectDeploymentDependencies(ExtensionDependency extDep) + extDep.info.runtimeArtifact + " is expected"); } - if (resolver.getProjectModuleResolver() != null && collectReloadableModules) { - clearReloadable(deploymentNode); - } - final List deploymentDeps = deploymentNode.getChildren(); if (!replaceDirectDepBranch(extDep, deploymentDeps)) { throw new BootstrapDependencyProcessingException( @@ -654,18 +716,6 @@ private void injectDeploymentDependencies(ExtensionDependency extDep) runtimeNode.setChildren(deploymentDeps); } - private void clearReloadable(DependencyNode node) { - for (DependencyNode child : node.getChildren()) { - if (!hasWinner(child)) { - clearReloadable(child); - } - } - final ResolvedDependencyBuilder dep = appBuilder.getDependency(getKey(node.getArtifact())); - if (dep != null) { - dep.clearFlag(DependencyFlags.RELOADABLE); - } - } - private boolean replaceDirectDepBranch(ExtensionDependency extDep, List deploymentDeps) throws BootstrapDependencyProcessingException { int i = 0; @@ -934,7 +984,7 @@ void activate() { } var futures = new ArrayList>(); var errors = new ConcurrentLinkedDeque(); - app.init(futures, errors); + app.initRuntime(futures, errors); CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); if (!errors.isEmpty()) { log.error("The following errors were encountered while processing application dependencies:");