Skip to content

Commit

Permalink
incubating
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Loubyansky committed Nov 21, 2024
1 parent 2acabd6 commit 401c502
Showing 1 changed file with 84 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -615,18 +615,8 @@ void setChildFlags() {

void setFlags(byte walkingFlags) {

this.walkingFlags = walkingFlags;
resolvedDep.addDependencies(allDeps);
if (ext != null) {
var parentExtDep = parent;
while (parentExtDep != null) {
if (parentExtDep.ext != null) {
parentExtDep.ext.addExtensionDependency(ext);
break;
}
parentExtDep = parentExtDep.parent;
}
ext.info.ensureActivated(appBuilder);
}

var existingDep = appBuilder.getDependency(resolvedDep.getKey());
if (existingDep == null) {
@@ -637,13 +627,26 @@ void setFlags(byte walkingFlags) {
} else if (existingDep != resolvedDep) {
throw new IllegalStateException(node.getArtifact() + " is already in the model");
}
this.walkingFlags = walkingFlags;

resolvedDep.setDirect(isWalkingFlagOn(COLLECT_DIRECT_DEPS));
if (ext != null && isWalkingFlagOn(COLLECT_TOP_EXTENSION_RUNTIME_NODES)) {
resolvedDep.setFlags(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
clearWalkingFlag(COLLECT_TOP_EXTENSION_RUNTIME_NODES);
topExtensionDeps.add(ext);
if (ext != null) {
ext.info.ensureActivated(appBuilder);
if (isWalkingFlagOn(COLLECT_TOP_EXTENSION_RUNTIME_NODES)) {
resolvedDep.setFlags(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
clearWalkingFlag(COLLECT_TOP_EXTENSION_RUNTIME_NODES);
topExtensionDeps.add(ext);
} else {
var parentExtDep = parent;
while (parentExtDep != null) {
if (parentExtDep.ext != null
&& parentExtDep.resolvedDep.isFlagSet(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT)) {
parentExtDep.ext.addExtensionDependency(ext);
break;
}
parentExtDep = parentExtDep.parent;
}
}
ext.info.ensureActivated(appBuilder);
}
if (isWalkingFlagOn(COLLECT_RELOADABLE_MODULES)) {
if (resolvedDep.getWorkspaceModule() != null
@@ -849,6 +852,7 @@ static ExtensionDependency get(DependencyNode node) {
private List<ExtensionDependency> extDeps;
private DependencyNode deploymentNode;
private DependencyNode parentNode;
private boolean presentInTargetGraph;

ExtensionDependency(ExtensionInfo info, DependencyNode node, Collection<Exclusion> exclusions) {
this.runtimeNode = node;
@@ -894,12 +898,32 @@ private void collectDeploymentDeps()
+ "or the artifact does not have any dependencies while at least a dependency on the runtime artifact "
+ info.runtimeArtifact + " is expected");
}

/* @formatter:off
System.out.println("injectDeploymentNode " + this.runtimeNode.getArtifact());
if (extDeps != null) {
for (var e : extDeps) {
System.out.println("- " + e.runtimeNode.getArtifact());
}
}
replaceRuntimeExtensionNodes(deploymentNode);
if (!presentInTargetGraph) {
throw new BootstrapDependencyProcessingException(
"Quarkus extension deployment artifact " + deploymentNode.getArtifact()
+ " does not appear to depend on the corresponding runtime artifact "
+ info.runtimeArtifact);
}
@formatter:on
*/

if (!replaceDirectDepBranch(deploymentNode, true)) {
throw new BootstrapDependencyProcessingException(
"Quarkus extension deployment artifact " + deploymentNode.getArtifact()
+ " does not appear to depend on the corresponding runtime artifact "
+ info.runtimeArtifact);
}

}

private void injectDeploymentNode(DependencyNode parentDeploymentNode) {
@@ -912,6 +936,50 @@ private void injectDeploymentNode(DependencyNode parentDeploymentNode) {
}
}

void replaceRuntimeExtensionNodes(DependencyNode deploymentNode) {
var deploymentVisitor = new OrderedDependencyVisitor(deploymentNode);
// skip the root node
deploymentVisitor.next();
int nodesToReplace = extDeps == null ? 1 : extDeps.size() + 1;
while (deploymentVisitor.hasNext() && nodesToReplace > 0) {
var node = deploymentVisitor.next();
if (hasWinner(node)) {
continue;
}
if (replaceRuntimeNode(deploymentVisitor)) {
--nodesToReplace;
} else if (extDeps != null) {
for (int i = 0; i < extDeps.size(); ++i) {
if (extDeps.get(i).replaceRuntimeNode(deploymentVisitor)) {
--nodesToReplace;
break;
}
}
}
}
}

private boolean replaceRuntimeNode(OrderedDependencyVisitor depVisitor) {
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
// but overridden by the user in the project config. The way the deployment deps
// are resolved here, the deployment version of the runtime artifact will be the one from the BOM.
var inserted = new DefaultDependencyNode(runtimeNode);
inserted.setChildren(runtimeNode.getChildren());
depVisitor.replaceCurrent(inserted);
presentInTargetGraph = true;

if (this.deploymentNode == null && this.parentNode == null) {
this.parentNode = depVisitor.getCurrent();
}

return true;
}
return false;
}

private boolean replaceDirectDepBranch(DependencyNode parentNode, boolean replaceRuntimeNode) {
int i = 0;
DependencyNode inserted = null;

0 comments on commit 401c502

Please sign in to comment.