From 31482d05f8c958c4cf16519511e6c777bbd25c46 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Fri, 17 Nov 2023 23:43:18 +0100 Subject: [PATCH 1/3] Break cyclic dependencies when manifesting --- .../PurgingDependencyTreeVisitor.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/domino/api/src/main/java/io/quarkus/domino/manifest/PurgingDependencyTreeVisitor.java b/domino/api/src/main/java/io/quarkus/domino/manifest/PurgingDependencyTreeVisitor.java index 740729dd..48daafcc 100644 --- a/domino/api/src/main/java/io/quarkus/domino/manifest/PurgingDependencyTreeVisitor.java +++ b/domino/api/src/main/java/io/quarkus/domino/manifest/PurgingDependencyTreeVisitor.java @@ -246,14 +246,21 @@ private void linkParent(VisitedComponentImpl parent) { private void resolveLinkedDependencies(Map treeComponents) { if (linkedDeps != null) { - log.debugf("Resolving linked dependencies of %s", coords.toCompactCoords()); + log.debugf("Resolving linked dependencies of %s", coords); + // check for circular dependencies + for (var linked : linkedDeps) { + if (isCyclicDependency(linked)) { + log.debugf("- %s skipped to avoid a circular dependency", linked); + return; + } + } for (var linked : linkedDeps) { var c = treeComponents.get(linked); if (c == null) { throw new IllegalStateException("Failed to resolve linked dependency " + linked.toCompactCoords() + " of " + this.coords.toCompactCoords() + " among " + treeComponents.keySet()); } - log.debugf("- %s", c.coords.toCompactCoords()); + log.debugf("- %s", c.coords); addChild(c); c.linkParent(this); } @@ -261,6 +268,10 @@ private void resolveLinkedDependencies(Map } } + private boolean isCyclicDependency(ArtifactCoords coords) { + return isSameGav(this.coords, coords) || parent != null && parent.isCyclicDependency(coords); + } + private void swap(VisitedComponentImpl other) { if (!coords.equals(other.coords)) { throw new IllegalArgumentException("Expected " + coords + " but got " + other.coords); @@ -377,6 +388,12 @@ public String toString() { } } + private static boolean isSameGav(ArtifactCoords c1, ArtifactCoords c2) { + return c1.getArtifactId().equals(c2.getArtifactId()) + && c1.getVersion().equals(c2.getVersion()) + && c1.getGroupId().equals(c2.getGroupId()); + } + static PackageURL getPurl(ArtifactCoords coords) { final TreeMap qualifiers = new TreeMap<>(); qualifiers.put("type", coords.getType()); From f8659ab765a49ea2a079422ee5089e935dfaed6e Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Fri, 17 Nov 2023 23:45:51 +0100 Subject: [PATCH 2/3] Removed a playground class committed by accident --- .../quarkus/domino/manifest/Playground.java | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 domino/api/src/main/java/io/quarkus/domino/manifest/Playground.java diff --git a/domino/api/src/main/java/io/quarkus/domino/manifest/Playground.java b/domino/api/src/main/java/io/quarkus/domino/manifest/Playground.java deleted file mode 100644 index 948cb58b..00000000 --- a/domino/api/src/main/java/io/quarkus/domino/manifest/Playground.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.quarkus.domino.manifest; - -import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext; -import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; -import io.quarkus.domino.ProjectDependencyConfig; -import io.quarkus.domino.ProjectDependencyResolver; -import io.quarkus.maven.dependency.ArtifactCoords; -import java.util.List; -import java.util.Set; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; -import org.eclipse.aether.util.graph.transformer.ConflictResolver; - -public class Playground { - - public static void main(String[] args) throws Exception { - - var mvnCtx = new BootstrapMavenContext(BootstrapMavenContext.config().setWorkspaceDiscovery(false)); - var session = new DefaultRepositorySystemSession(mvnCtx.getRepositorySystemSession()); - if (true) { - session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true); - session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); - } - - mvnCtx = new BootstrapMavenContext(BootstrapMavenContext.config() - .setRepositorySystem(mvnCtx.getRepositorySystem()) - .setRepositorySystemSession(session) - .setRemoteRepositoryManager(mvnCtx.getRemoteRepositoryManager()) - .setRemoteRepositories(mvnCtx.getRemoteRepositories())); - - var resolver = new MavenArtifactResolver(mvnCtx); - - ProjectDependencyResolver.builder() - .setArtifactResolver(resolver) - .setDependencyConfig(ProjectDependencyConfig.builder() - /* @formatter:off - .setProjectArtifacts(List.of( - ArtifactCoords.jar("org.acme", "acme-lib-b", "1.0.0-SNAPSHOT"), - ArtifactCoords.jar("org.acme", "acme-lib-a", "1.0.0-SNAPSHOT"))) - @formatter:on */ - .setProjectArtifacts(List.of( - ArtifactCoords.jar("io.quarkus", "quarkus-core-deployment", "3.2.6.Final"), - ArtifactCoords.jar("io.quarkus", "quarkus-core", "3.2.6.Final"))) - //.setIncludeOptionalDeps(true) - .setLegacyScmLocator(true) - .setExcludeScopes(Set.of("test")) - .build()) - //.addDependencyTreeVisitor(new LoggingDependencyTreeVisitor(MessageWriter.info(), false, null)) - .addDependencyTreeVisitor(new SbomGeneratingDependencyVisitor( - SbomGenerator.builder() - .setArtifactResolver(resolver))) - .build() - .resolveDependencies(); - } -} From 35741eaa84ff2f85d0d6ec783db6c9ccbbc1cded Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Fri, 17 Nov 2023 23:49:47 +0100 Subject: [PATCH 3/3] Remove unnecessary logging uring dependency graph aggregation --- .../domino/manifest/PurgingDependencyTreeVisitor.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/domino/api/src/main/java/io/quarkus/domino/manifest/PurgingDependencyTreeVisitor.java b/domino/api/src/main/java/io/quarkus/domino/manifest/PurgingDependencyTreeVisitor.java index 48daafcc..6f07988f 100644 --- a/domino/api/src/main/java/io/quarkus/domino/manifest/PurgingDependencyTreeVisitor.java +++ b/domino/api/src/main/java/io/quarkus/domino/manifest/PurgingDependencyTreeVisitor.java @@ -50,8 +50,8 @@ List getRoots() { } private void purge() { - log.infof("Roots total: %s", roots.size()); - log.infof("Nodes total: %s", nodesTotal); + //log.infof("Roots total: %s", roots.size()); + //log.infof("Nodes total: %s", nodesTotal); for (VisitedComponentImpl root : roots) { // we want to process each tree separately due to possible variations across different trees @@ -84,8 +84,8 @@ private void purge() { } } } - log.infof("Unique roots total: %s", roots.size()); - log.infof("Unique nodes total: %s", uniqueNodesTotal); + //log.infof("Unique roots total: %s", roots.size()); + //log.infof("Unique nodes total: %s", uniqueNodesTotal); } private ParallelTreeProcessor newTreeProcessor() {