Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Loubyansky committed Nov 20, 2024
1 parent f212555 commit 1657bc2
Showing 1 changed file with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver

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

visitRuntimeDependencies(root.getChildren());
visitRuntimeDependencies(root.getChildren(), -1);

List<ConditionalDependency> activatedConditionalDeps = List.of();

Expand Down Expand Up @@ -424,13 +424,13 @@ private boolean isRuntimeArtifact(ArtifactKey key) {
return dep != null && dep.isFlagSet(DependencyFlags.RUNTIME_CP);
}

private void visitRuntimeDependencies(List<DependencyNode> list) {
private void visitRuntimeDependencies(List<DependencyNode> list, int topLevelExtensionDistance) {
for (DependencyNode n : list) {
visitRuntimeDependency(n);
visitRuntimeDependency(n, topLevelExtensionDistance);
}
}

private void visitRuntimeDependency(DependencyNode node) {
private void visitRuntimeDependency(DependencyNode node, int topLevelExtensionDistance) {

final byte prevWalkingFlags = walkingFlags;
final ExtensionDependency prevLastVisitedRtExtNode = lastVisitedRuntimeExtNode;
Expand All @@ -448,7 +448,7 @@ private void visitRuntimeDependency(DependencyNode node) {
}

try {
final ExtensionDependency extDep = getExtensionDependencyOrNull(node, artifact);
final ExtensionDependency extDep = getExtensionDependencyOrNull(node, artifact, topLevelExtensionDistance);

if (dep == null) {
// in case it was relocated it might not survive conflict resolution in the deployment graph
Expand All @@ -473,6 +473,7 @@ private void visitRuntimeDependency(DependencyNode node) {
dep.setRuntimeExtensionArtifact();
if (isWalkingFlagOn(COLLECT_TOP_EXTENSION_RUNTIME_NODES)) {
dep.setFlags(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
topLevelExtensionDistance = extDep.topLevelExtensionDistance;
}
}
if (isWalkingFlagOn(COLLECT_RELOADABLE_MODULES)) {
Expand All @@ -491,7 +492,8 @@ private void visitRuntimeDependency(DependencyNode node) {
extDep.info.ensureActivated(appBuilder);
visitExtensionDependency(extDep);
}
visitRuntimeDependencies(node.getChildren());
visitRuntimeDependencies(node.getChildren(),
topLevelExtensionDistance < 0 ? topLevelExtensionDistance : topLevelExtensionDistance + 1);
} catch (DeploymentInjectionException e) {
throw e;
} catch (Exception t) {
Expand All @@ -505,7 +507,8 @@ private void visitRuntimeDependency(DependencyNode node) {
lastVisitedRuntimeExtNode = prevLastVisitedRtExtNode;
}

private ExtensionDependency getExtensionDependencyOrNull(DependencyNode node, Artifact artifact)
private ExtensionDependency getExtensionDependencyOrNull(DependencyNode node, Artifact artifact,
int topLevelExtensionDistance)
throws BootstrapDependencyProcessingException {
ExtensionDependency extDep = ExtensionDependency.get(node);
if (extDep != null) {
Expand All @@ -524,7 +527,7 @@ private ExtensionDependency getExtensionDependencyOrNull(DependencyNode node, Ar
exclusions.addAll(set);
}
}
return new ExtensionDependency(extInfo, node, exclusions);
return new ExtensionDependency(extInfo, node, exclusions, Math.max(topLevelExtensionDistance, 0));
}
return null;
}
Expand Down Expand Up @@ -623,7 +626,9 @@ private void injectDeploymentDependencies(ExtensionDependency extDep)
}

var deploymentVisitor = new OrderedDependencyVisitor(deploymentNode);
while (deploymentVisitor.hasNext() && !extDep.presentInTargetGraph) {
// skip the root node
deploymentVisitor.next();
while (deploymentVisitor.hasNext()) {
deploymentVisitor.next();
extDep.replaceRuntimeNodes(deploymentVisitor);
}
Expand All @@ -634,15 +639,6 @@ private void injectDeploymentDependencies(ExtensionDependency extDep)
+ " does not appear to depend on the corresponding runtime artifact "
+ extDep.info.runtimeArtifact);
}
/* @formatter:off
final List<DependencyNode> deploymentDeps = deploymentNode.getChildren();
if (!replaceDirectDepBranch(extDep, deploymentDeps)) {
throw new BootstrapDependencyProcessingException(
"Quarkus extension deployment artifact " + deploymentNode.getArtifact()
+ " does not appear to depend on the corresponding runtime artifact "
+ extDep.info.runtimeArtifact);
}
@formatter:on */

final DependencyNode runtimeNode = extDep.runtimeNode;
runtimeNode.setData(QUARKUS_RUNTIME_ARTIFACT, runtimeNode.getArtifact());
Expand Down Expand Up @@ -810,14 +806,17 @@ static ExtensionDependency get(DependencyNode node) {
final ExtensionInfo info;
final DependencyNode runtimeNode;
final Collection<Exclusion> exclusions;
private final int topLevelExtensionDistance;
boolean conditionalDepsQueued;
private List<ExtensionDependency> runtimeExtensionDeps;
private boolean presentInTargetGraph;

ExtensionDependency(ExtensionInfo info, DependencyNode node, Collection<Exclusion> exclusions) {
ExtensionDependency(ExtensionInfo info, DependencyNode node, Collection<Exclusion> exclusions,
int topLevelExtensionDistance) {
this.runtimeNode = node;
this.info = info;
this.exclusions = exclusions;
this.topLevelExtensionDistance = topLevelExtensionDistance;

@SuppressWarnings("unchecked")
final Map<Object, Object> data = (Map<Object, Object>) node.getData();
Expand All @@ -837,10 +836,21 @@ void addExtensionDependency(ExtensionDependency dep) {
}

void replaceRuntimeNodes(OrderedDependencyVisitor depVisitor) {
if (presentInTargetGraph) {
return;
}
if (isSameKey(runtimeNode.getArtifact(), depVisitor.getCurrent().getArtifact())) {

var deploymentDistance = topLevelExtensionDistance + 1;
//if(presentInTargetGraph && depVisitor.getCurrentDistance() > deploymentDistance) {
// return;
//}

/* @formatter:off
var sb = new StringBuilder();
sb.append(depVisitor.getCurrentDistance()).append("/").append(deploymentDistance).append(" ")
.append(depVisitor.getCurrent().getArtifact())
.append(runtimeNode.getArtifact()).append(" ").append(presentInTargetGraph);
System.out.println(sb);
@formatter:on */

if (!presentInTargetGraph && isSameKey(runtimeNode.getArtifact(), depVisitor.getCurrent().getArtifact())) {
// we are not comparing the version in the above condition because the runtime version
// may appear to be different from the deployment one and that's ok
// e.g. the version of the runtime artifact could be managed by a BOM
Expand All @@ -850,6 +860,7 @@ void replaceRuntimeNodes(OrderedDependencyVisitor depVisitor) {
inserted.setChildren(runtimeNode.getChildren());
depVisitor.replaceCurrent(inserted);
presentInTargetGraph = true;
//stem.out.println(" replace");
return;
}
if (runtimeExtensionDeps != null) {
Expand Down Expand Up @@ -880,7 +891,7 @@ ExtensionDependency getExtensionDependency() {
rtNode.setVersionConstraint(new BootstrapArtifactVersionConstraint(
new BootstrapArtifactVersion(info.runtimeArtifact.getVersion())));
rtNode.setRepositories(dependent.runtimeNode.getRepositories());
dependency = new ExtensionDependency(info, rtNode, dependent.exclusions);
dependency = new ExtensionDependency(info, rtNode, dependent.exclusions, 0);
}
return dependency;
}
Expand All @@ -904,7 +915,7 @@ void activate() {
} else {
currentChildren.addAll(originalNode.getChildren());
}
visitRuntimeDependency(rtNode);
visitRuntimeDependency(rtNode, 0);
dependent.runtimeNode.getChildren().add(rtNode);
}

Expand Down

0 comments on commit 1657bc2

Please sign in to comment.