Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Feb 2, 2024
1 parent c6e2517 commit fe05bee
Showing 1 changed file with 92 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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));
Expand All @@ -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<CompletableFuture<?>>();
var errors = new ConcurrentLinkedDeque<Throwable>();
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<ConditionalDependency> activatedConditionalDeps) {
var futures = new CompletableFuture<?>[topExtensionDeps.size() + activatedConditionalDeps.size()];
int i = 0;
Expand Down Expand Up @@ -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) {
Expand All @@ -374,7 +389,7 @@ private void processRuntimeDeps(DependencyNode root) {

var futures = new ArrayList<CompletableFuture<?>>();
var errors = new ConcurrentLinkedDeque<Throwable>();
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:");
Expand All @@ -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 {
Expand All @@ -408,25 +423,74 @@ private class AppDep {
this.children = new ArrayList<>(node.getChildren().size());
}

void init(List<CompletableFuture<?>> futures, ConcurrentLinkedDeque<Throwable> 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<CompletableFuture<?>> futures, ConcurrentLinkedDeque<Throwable> errors) {
futures.add(CompletableFuture.runAsync(() -> {
try {
initDeployment();
} catch (Throwable e) {
errors.add(e);
}
}));
initChildren(futures, errors);
initDeploymentChildren(futures, errors);
}

void initChildren(List<CompletableFuture<?>> futures, ConcurrentLinkedDeque<Throwable> errors) {
void initDeploymentChildren(List<CompletableFuture<?>> futures, ConcurrentLinkedDeque<Throwable> 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<ArtifactKey>(node.getChildren().size());
for (var child : node.getChildren()) {
deps.add(getKey(child.getArtifact()));
}
resolvedDep.setDependencies(deps);
}
}

void initRuntime(List<CompletableFuture<?>> futures, ConcurrentLinkedDeque<Throwable> errors) {
futures.add(CompletableFuture.runAsync(() -> {
try {
initRuntime();
} catch (Throwable t) {
errors.add(t);
}
}));
initRuntimeChildren(futures, errors);
}

void initRuntimeChildren(List<CompletableFuture<?>> futures, ConcurrentLinkedDeque<Throwable> 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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -482,7 +545,7 @@ private Collection<Exclusion> collectExclusions() {
return exclusions == null ? List.of() : exclusions;
}

void init() {
void initRuntime() {
Artifact artifact = node.getArtifact();
final ArtifactKey key = getKey(artifact);
if (resolvedDep == null) {
Expand Down Expand Up @@ -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;

Expand All @@ -548,7 +614,7 @@ void setFlags(byte walkingFlags) {

clearWalkingFlag(COLLECT_DIRECT_DEPS);

passFlags();
setFlags();
}

private boolean isWalkingFlagOn(byte flag) {
Expand Down Expand Up @@ -635,10 +701,6 @@ private void injectDeploymentDependencies(ExtensionDependency extDep)
+ extDep.info.runtimeArtifact + " is expected");
}

if (resolver.getProjectModuleResolver() != null && collectReloadableModules) {
clearReloadable(deploymentNode);
}

final List<DependencyNode> deploymentDeps = deploymentNode.getChildren();
if (!replaceDirectDepBranch(extDep, deploymentDeps)) {
throw new BootstrapDependencyProcessingException(
Expand All @@ -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<DependencyNode> deploymentDeps)
throws BootstrapDependencyProcessingException {
int i = 0;
Expand Down Expand Up @@ -934,7 +984,7 @@ void activate() {
}
var futures = new ArrayList<CompletableFuture<?>>();
var errors = new ConcurrentLinkedDeque<Throwable>();
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:");
Expand Down

0 comments on commit fe05bee

Please sign in to comment.