forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Loubyansky
committed
Nov 20, 2024
1 parent
c872c3b
commit 81e34a8
Showing
5 changed files
with
219 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...r/test/ConditionalDependenciesDirectDependencyOnTransitiveDeploymentArtifactTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkus.bootstrap.resolver.test; | ||
|
||
import org.junit.jupiter.api.Disabled; | ||
|
||
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver; | ||
import io.quarkus.bootstrap.resolver.CollectDependenciesBase; | ||
import io.quarkus.bootstrap.resolver.TsArtifact; | ||
import io.quarkus.bootstrap.resolver.TsQuarkusExt; | ||
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject; | ||
import io.quarkus.maven.dependency.DependencyFlags; | ||
|
||
@Disabled | ||
public class ConditionalDependenciesDirectDependencyOnTransitiveDeploymentArtifactTestCase extends CollectDependenciesBase { | ||
|
||
@Override | ||
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception { | ||
var resolver = super.newAppModelResolver(currentProject); | ||
resolver.setIncubatingModelResolver(false); | ||
return resolver; | ||
} | ||
|
||
@Override | ||
protected void setupDependencies() { | ||
|
||
TsArtifact nettyNioClient = TsArtifact.jar("netty-nio-client"); | ||
installAsDep(nettyNioClient); | ||
|
||
final TsQuarkusExt nettyClientInternalExt = new TsQuarkusExt("netty-client-internal"); | ||
nettyClientInternalExt.getRuntime().addDependency(nettyNioClient, true); | ||
nettyClientInternalExt.setDependencyCondition(nettyNioClient); | ||
install(nettyClientInternalExt, false); | ||
addCollectedDep(nettyClientInternalExt.getRuntime(), | ||
DependencyFlags.RUNTIME_CP | DependencyFlags.DEPLOYMENT_CP | DependencyFlags.RUNTIME_EXTENSION_ARTIFACT); | ||
addCollectedDeploymentDep(nettyClientInternalExt.getDeployment()); | ||
|
||
final TsQuarkusExt commonExt = new TsQuarkusExt("common"); | ||
commonExt.getRuntime().addDependency(nettyNioClient, true); | ||
commonExt.getRuntime().addDependency(nettyClientInternalExt, true); | ||
commonExt.setConditionalDeps(nettyClientInternalExt); | ||
install(commonExt, false); | ||
addCollectedDep(commonExt.getRuntime(), | ||
DependencyFlags.RUNTIME_CP | DependencyFlags.DEPLOYMENT_CP | DependencyFlags.RUNTIME_EXTENSION_ARTIFACT); | ||
addCollectedDeploymentDep(commonExt.getDeployment()); | ||
|
||
final TsQuarkusExt sqsExt = new TsQuarkusExt("sqs"); | ||
sqsExt.addDependency(commonExt); | ||
sqsExt.getRuntime().addDependency(nettyNioClient, true); | ||
addCollectedDep(sqsExt.getRuntime(), | ||
DependencyFlags.RUNTIME_CP | DependencyFlags.DEPLOYMENT_CP | DependencyFlags.RUNTIME_EXTENSION_ARTIFACT); | ||
addCollectedDeploymentDep(sqsExt.getDeployment()); | ||
|
||
final TsQuarkusExt messagingSqsExt = new TsQuarkusExt("messaging-sqs"); | ||
messagingSqsExt.getDeployment().addDependency(commonExt.getDeployment()); // this line breaks it | ||
messagingSqsExt.addDependency(sqsExt); | ||
|
||
installAsDep(messagingSqsExt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/OrderedDependencyVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package io.quarkus.bootstrap.resolver.maven; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
import org.eclipse.aether.graph.DependencyNode; | ||
|
||
/** | ||
* Walks a dependency tree by visiting dependencies in the order of their priorities | ||
* from the perspective of version conflict resolution. | ||
*/ | ||
class OrderedDependencyVisitor { | ||
|
||
private final Deque<List<DependencyNode>> stack = new ArrayDeque<>(); | ||
private List<DependencyNode> currentList; | ||
private int currentIndex = -1; | ||
private int currentDistance; | ||
private int totalOnCurrentDistance = 1; | ||
private int totalOnNextDistance; | ||
|
||
/** | ||
* The root of the dependency tree | ||
* | ||
* @param root the root of the dependency tree | ||
*/ | ||
OrderedDependencyVisitor(DependencyNode root) { | ||
currentList = List.of(root); | ||
} | ||
|
||
/** | ||
* Current dependency. | ||
* | ||
* @return current dependency | ||
*/ | ||
DependencyNode getCurrent() { | ||
ensureNonNegativeIndex(); | ||
return currentList.get(currentIndex); | ||
} | ||
|
||
/** | ||
* Returns the current distance (depth) from the root to the level on which the current node is. | ||
* | ||
* @return current depth | ||
*/ | ||
int getCurrentDistance() { | ||
ensureNonNegativeIndex(); | ||
return currentDistance; | ||
} | ||
|
||
private void ensureNonNegativeIndex() { | ||
if (currentIndex < 0) { | ||
throw new RuntimeException("The visitor has not been positioned on the first dependency node yet"); | ||
} | ||
} | ||
|
||
/** | ||
* Whether there are still not visited dependencies. | ||
* | ||
* @return true if there are still not visited dependencies, otherwise - false | ||
*/ | ||
boolean hasNext() { | ||
return !stack.isEmpty() | ||
|| currentIndex + 1 < currentList.size() | ||
|| !currentList.get(currentIndex).getChildren().isEmpty(); | ||
} | ||
|
||
/** | ||
* Returns the next dependency. | ||
* | ||
* @return the next dependency | ||
*/ | ||
DependencyNode next() { | ||
if (!hasNext()) { | ||
throw new NoSuchElementException(); | ||
} | ||
if (currentIndex >= 0) { | ||
var children = currentList.get(currentIndex).getChildren(); | ||
if (!children.isEmpty()) { | ||
stack.addLast(children); | ||
totalOnNextDistance += children.size(); | ||
} | ||
if (--totalOnCurrentDistance == 0) { | ||
++currentDistance; | ||
totalOnCurrentDistance = totalOnNextDistance; | ||
totalOnNextDistance = 0; | ||
} | ||
} | ||
if (++currentIndex == currentList.size()) { | ||
currentList = stack.removeFirst(); | ||
currentIndex = 0; | ||
} | ||
return currentList.get(currentIndex); | ||
} | ||
|
||
/** | ||
* Replaces the current dependency in the tree with the argument. | ||
* | ||
* @param newNode dependency node that should replace the current one in the tree | ||
*/ | ||
void replaceCurrent(DependencyNode newNode) { | ||
currentList.set(currentIndex, newNode); | ||
} | ||
} |