Skip to content

Commit

Permalink
Merge pull request #300 from aloubyansky/break-cyclic-deps
Browse files Browse the repository at this point in the history
Break cyclic dependencies when manifesting
  • Loading branch information
aloubyansky authored Nov 17, 2023
2 parents 09d1add + 35741ea commit 18dd86e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 61 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ List<VisitedComponent> 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
Expand Down Expand Up @@ -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<Long, VisitedComponentImpl, VisitedComponentImpl> newTreeProcessor() {
Expand Down Expand Up @@ -246,21 +246,32 @@ private void linkParent(VisitedComponentImpl parent) {

private void resolveLinkedDependencies(Map<ArtifactCoords, VisitedComponentImpl> 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);
}
linkedDeps = null;
}
}

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);
Expand Down Expand Up @@ -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<String, String> qualifiers = new TreeMap<>();
qualifiers.put("type", coords.getType());
Expand Down

0 comments on commit 18dd86e

Please sign in to comment.