From 5f5eb78da61011405ea9a1646d734ad93e0838ab Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Tue, 5 Mar 2024 08:22:40 +0100 Subject: [PATCH] more --- .../resolver/maven/GraphLevelVisitor.java | 95 ++++++++++++++----- 1 file changed, 71 insertions(+), 24 deletions(-) diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/GraphLevelVisitor.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/GraphLevelVisitor.java index b7987833efab89..ecc3b2ebd1f294 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/GraphLevelVisitor.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/GraphLevelVisitor.java @@ -28,6 +28,7 @@ import org.eclipse.aether.graph.DependencyNode; import org.eclipse.aether.util.artifact.JavaScopes; import org.eclipse.aether.util.graph.transformer.ConflictResolver; +import org.eclipse.aether.util.graph.visitor.DependencyGraphDumper; import com.google.common.util.concurrent.AtomicDouble; @@ -73,9 +74,9 @@ private static void processLocalMavenRepo() throws IOException { log("Resolver2: " + time2.get()); if (!errors.isEmpty()) { - log("Errors:"); + System.err.println("ERRORS:"); for (var e : errors) { - e.printStackTrace(); + System.err.println(e.getLocalizedMessage()); } } } @@ -109,6 +110,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO private static void compare(Artifact a) { inProgress.incrementAndGet(); try { + if (!errors.isEmpty()) { + return; + } var sb = new StringBuilder(180); var formatter = new Formatter(sb); var artifacts = artifactsTotal.incrementAndGet(); @@ -163,10 +167,11 @@ private static void compare() throws Exception { //var artifact = new DefaultArtifact("io.quarkus", "quarkus-core", "jar", "3.8.0"); //var artifact = new DefaultArtifact("io.quarkus", "quarkus-hibernate-reactive-deployment", "jar", "3.7.3"); //var artifact = new DefaultArtifact("io.quarkus", "quarkus-opentelemetry-deployment", "jar", "3.7.3"); - //var artifact = new DefaultArtifact("jotm", "jotm", "pom", "2.0.10"); - //var artifact = new DefaultArtifact("commons-beanutils", "commons-beanutils", "pom", "1.7.0"); - //var artifact = new DefaultArtifact("com.google.oauth-client", "google-oauth-client-appengine", "pom", "1.34.1"); - var artifact = new DefaultArtifact("com.datastax.oss.simulacron", "simulacron-native-server", "pom", "0.11.0"); + //var artifact = new DefaultArtifact("com.datastax.oss.simulacron", "simulacron-native-server", "pom", "0.11.0"); + //var artifact = new DefaultArtifact("be.cm.apps.subpersub", "subpersub-integration", "pom", "0.0.16-SNAPSHOT"); + //var artifact = new DefaultArtifact("com.cloudhopper.proxool", "proxool", "pom", "0.9.1"); + var artifact = new DefaultArtifact("com.microsoft.azure", "msal4j", "pom", "1.13.1.redhat-00001"); + //var artifact = new DefaultArtifact("com.microsoft.azure", "msal4j", "pom", "1.13.1"); var start = System.currentTimeMillis(); @@ -180,6 +185,8 @@ private static void compare() throws Exception { log("Time " + (System.currentTimeMillis() - start)); logDep(root1); + root1.accept(new DependencyGraphDumper(System.out::println)); + start = System.currentTimeMillis(); var root2 = resolver2.getSystem().collectDependencies( resolver2.getSession(), @@ -217,15 +224,18 @@ private static void assertIdentical(DependencyNode root, DependencyNode n1, Depe } else if (d2 == null) { throw new IllegalStateException(root + " has a missing dependency for " + d1); } else { - if (d1.isOptional() != d2.isOptional()) { - throw new IllegalStateException(root + " has a dependency with not matching optionality " + d1 + " optional " - + d1.isOptional() + " vs " + d2.isOptional()); - } + /* + * if (d1.isOptional() != d2.isOptional()) { + * throw new IllegalStateException(root + " has a dependency with not matching optionality " + d1 + " optional " + * + d1.isOptional() + " vs " + d2.isOptional()); + * } + */ /* * if (!Objects.equals(d1.getScope(), d2.getScope())) { * throw new IllegalStateException(root + " has a dependency with not matching scope " + d1 + " vs " + d2); * } */ + if (!d1.getExclusions().equals(d2.getExclusions())) { throw new IllegalStateException(root + " has a dependency with not matching exclusions " + d1 + " vs " + d2); } @@ -293,7 +303,7 @@ private static void logDep(DependencyNode node, int depth) { } log(sb.append(")")); for (var c : node.getChildren()) { - if (c.getData().containsKey(ConflictResolver.NODE_DATA_WINNER)) { + if (c.getData().get(ConflictResolver.NODE_DATA_WINNER) != null) { continue; } logDep(c, depth + 1); @@ -303,6 +313,7 @@ private static void logDep(DependencyNode node, int depth) { private static MavenArtifactResolver getResolver() throws BootstrapMavenException { var resolver = getDefaultResolver(); var session = new DefaultRepositorySystemSession(resolver.getSession()); + //session.setOffline(true); //session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true); //session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); session.setDependencyGraphTransformer((node, ctx) -> { @@ -331,6 +342,7 @@ private static MavenArtifactResolver getDefaultResolver() throws BootstrapMavenE .build(); var session = new DefaultRepositorySystemSession(resolver.getSession()); session.setCache(null); + //session.setOffline(true); resolver = MavenArtifactResolver.builder() .setRepositorySystem(resolver.getSystem()) .setRepositorySystemSession(session) @@ -367,14 +379,14 @@ public void rewire() { if (nextLevel == null) { nextLevel = new DependencyLevel(); } - boolean optional = false; - String scope = null; + boolean parentOptional = false; + String parentScope = null; if (rewiredParent != null) { var d = rewiredParent.getDependency(); - optional = d.isOptional(); - scope = d.getScope(); + parentOptional = d.isOptional(); + parentScope = d.getScope(); } - var rewired = getRewired(node, optional, scope); + var rewired = getRewired(node, parentOptional, parentScope); if (rewiredParent != null) { rewiredParent.getChildren().add(rewired); } @@ -401,10 +413,29 @@ public static DependencyNode visit(DependencyNode node, DependencyNodeVisitor vi visit.nextLevel = null; for (var entry : level.parentNodes) { visit.rewiredParent = entry.getValue(); + log("Parent " + visit.rewiredParent.getDependency()); + DependencyNode prevNode = null; for (var n : entry.getKey().getChildren()) { - var pc = new ParentChild(entry.getKey(), n); + log(" " + n.getDependency()); + if (prevNode == null + || prevNode.getArtifact().getArtifactId().equals(n.getArtifact().getArtifactId()) + && prevNode.getArtifact().getGroupId().equals(n.getArtifact().getGroupId()) + && prevNode.getArtifact().getClassifier().equals(n.getArtifact().getClassifier()) + && prevNode.getArtifact().getExtension().equals(n.getArtifact().getExtension())) { + prevNode = n; + continue; + } + var pc = new ParentChild(entry.getKey(), prevNode); if (visited.put(pc, pc) == null) { - visit.node = n; + visit.node = prevNode; + visitor.visit(visit); + } + prevNode = n; + } + if (prevNode != null) { + var pc = new ParentChild(entry.getKey(), prevNode); + if (visited.put(pc, pc) == null) { + visit.node = prevNode; visitor.visit(visit); } } @@ -416,17 +447,15 @@ public static DependencyNode visit(DependencyNode node, DependencyNodeVisitor vi } } - private static DependencyNode getRewired(DependencyNode node, boolean optional, String scope) { + private static DependencyNode getRewired(DependencyNode node, boolean parentOptional, String parentScope) { var tmp = node.getDependency() == null ? new DefaultDependencyNode(node.getArtifact()) : new DefaultDependencyNode(node.getDependency()); - if (optional) { + if (parentOptional) { tmp.setOptional(true); } - if (scope != null && !scope.isEmpty() - && !scope.equals(tmp.getDependency().getScope()) - && !tmp.getDependency().getScope().equals("system")) { - tmp.setScope(scope); + if (parentScope != null && !parentScope.isEmpty()) { + tmp.setScope(getDerivedScope(parentScope, tmp.getDependency().getScope())); } tmp.setAliases(node.getAliases()); tmp.setRequestContext(node.getRequestContext()); @@ -438,6 +467,24 @@ private static DependencyNode getRewired(DependencyNode node, boolean optional, return tmp; } + private static String getDerivedScope(String parentScope, String childScope) { + String derivedScope; + + if (JavaScopes.SYSTEM.equals(childScope) || JavaScopes.TEST.equals(childScope)) { + derivedScope = childScope; + } else if (parentScope == null || parentScope.isEmpty() || JavaScopes.COMPILE.equals(parentScope)) { + derivedScope = childScope; + } else if (JavaScopes.TEST.equals(parentScope) || JavaScopes.RUNTIME.equals(parentScope)) { + derivedScope = parentScope; + } else if (JavaScopes.SYSTEM.equals(parentScope) || JavaScopes.PROVIDED.equals(parentScope)) { + derivedScope = JavaScopes.PROVIDED; + } else { + derivedScope = JavaScopes.RUNTIME; + } + + return derivedScope; + } + private static void log(Object o) { System.out.println(o); }