Skip to content

Commit

Permalink
bug fix for overriding dependencies while storing version data (#395)
Browse files Browse the repository at this point in the history
* bug fix for overriding dependencies while storing project data

bug fix for overriding dependencies while storing project data

* bug fix for overriding dependencies for storing version data

bug fix for overriding dependencies for storing version data
  • Loading branch information
gs-gunjan authored Sep 22, 2023
1 parent 718aaf5 commit 0eeefa9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ else if (!projectData.get().getTransitiveDependenciesReport().isValid())
throw new IllegalStateException(String.format("Cannot calculate dependencies for project version: %s", deps.getGav()));
}
projectDependencies.addAll(projectData.get().getVersionData().getDependencies());
projectDependencies.addAll(this.dependencyUtil.overrideDependencies(directDependencies, projectData.get().getTransitiveDependenciesReport().getTransitiveDependencies(), this::getCalculatedTransitiveDependencies));
projectDependencies.addAll(projectData.get().getTransitiveDependenciesReport().getTransitiveDependencies());
}
else
{
Expand All @@ -116,7 +116,8 @@ else if (!projectData.get().getTransitiveDependenciesReport().isValid())
return new VersionDependencyReport(new ArrayList<>(), false);
}
LOGGER.info("Completed finding dependencies");
return new VersionDependencyReport(projectDependencies.stream().collect(Collectors.toList()), true);
List<ProjectVersion> finalDependencies = this.dependencyUtil.overrideDependencies(directDependencies, projectDependencies.stream().collect(Collectors.toList()), this::getCalculatedTransitiveDependencies);
return new VersionDependencyReport(finalDependencies, true);
}

private Set<ProjectVersion> getCalculatedTransitiveDependencies(List<ProjectVersion> directDependencies, boolean transitive)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public void canUpdateTransitiveDependenciesForRevision()
public void canOverrideDependencies1()
{
StoreProjectVersionData project1 = new StoreProjectVersionData(GROUPID, "art102", "2.0.0");
ProjectVersion dependency = new ProjectVersion(GROUPID, "art103", "1.0.0");
ProjectVersion dependency = new ProjectVersion(GROUPID, "test", "1.0.0");
project1.getVersionData().setDependencies(Collections.singletonList(dependency));
projectsService.createOrUpdate(project1);
project1 = manageDependenciesService.updateTransitiveDependencies(GROUPID, "art102", "2.0.0");
Assert.assertTrue(project1.getTransitiveDependenciesReport().isValid());
Assert.assertEquals(Collections.singletonList(dependency), project1.getTransitiveDependenciesReport().getTransitiveDependencies());

//overriding art102:1.0.0 dependency with art102:2.0.0
//overriding test:1.0.0 dependency with test:3.0.0
StoreProjectVersionData project2 = new StoreProjectVersionData(GROUPID, "test-master", "3.0.0");
ProjectVersion dependency1 = new ProjectVersion(GROUPID, "test", "3.0.0");
ProjectVersion dependency2 = new ProjectVersion(GROUPID, "art102", "2.0.0");
Expand All @@ -134,7 +134,7 @@ public void canOverrideDependencies1()

project2 = manageDependenciesService.updateTransitiveDependencies(GROUPID, "test-master", "3.0.0");
Assert.assertTrue(project2.getTransitiveDependenciesReport().isValid());
Assert.assertEquals(Arrays.asList(dependency1, dependency2, new ProjectVersion(GROUPID, "test-dependencies", "2.0.0"), new ProjectVersion(GROUPID, "art101", "1.0.0"), dependency), project2.getTransitiveDependenciesReport().getTransitiveDependencies());
Assert.assertEquals(Arrays.asList(dependency1, dependency2, new ProjectVersion(GROUPID, "test-dependencies", "2.0.0"), new ProjectVersion(GROUPID, "art101", "1.0.0")), project2.getTransitiveDependenciesReport().getTransitiveDependencies());
}

@Test
Expand Down Expand Up @@ -162,4 +162,50 @@ public void canOverrideDependencies2()
Assert.assertEquals(Arrays.asList(dependency1, dependency, dependency2, new ProjectVersion(GROUPID, "test-dependencies", "2.0.0"), new ProjectVersion(GROUPID, "art101", "1.0.0")), project2.getTransitiveDependenciesReport().getTransitiveDependencies());
}

// Example : A -> B_V1 -> C_V1
// B_V2->C_V2
// C depends on A and B_V2
// Result: C depends on A and B_V2 and C_V2
@Test
public void canOverrideDependencies3()
{
projectsService.createOrUpdate(new StoreProjectVersionData(GROUPID, "art104", "1.0.0"));

StoreProjectVersionData project1 = new StoreProjectVersionData(GROUPID, "art102", "1.0.0");
ProjectVersion dependency = new ProjectVersion(GROUPID, "art104", "1.0.0");
project1.getVersionData().setDependencies(Collections.singletonList(dependency));
projectsService.createOrUpdate(project1);
project1 = manageDependenciesService.updateTransitiveDependencies(GROUPID, "art102", "1.0.0");
Assert.assertTrue(project1.getTransitiveDependenciesReport().isValid());
Assert.assertEquals(Collections.singletonList(dependency), project1.getTransitiveDependenciesReport().getTransitiveDependencies());

projectsService.createOrUpdate(new StoreProjectVersionData(GROUPID, "art104", "2.0.0"));

StoreProjectVersionData project2 = new StoreProjectVersionData(GROUPID, "art102", "2.0.0");
ProjectVersion dependency1 = new ProjectVersion(GROUPID, "art104", "2.0.0");
project2.getVersionData().setDependencies(Collections.singletonList(dependency1));
projectsService.createOrUpdate(project2);
project2 = manageDependenciesService.updateTransitiveDependencies(GROUPID, "art102", "2.0.0");
Assert.assertTrue(project2.getTransitiveDependenciesReport().isValid());
Assert.assertEquals(Collections.singletonList(dependency1), project2.getTransitiveDependenciesReport().getTransitiveDependencies());

StoreProjectVersionData project3 = new StoreProjectVersionData(GROUPID, "test", "5.0.0");
ProjectVersion dependency2 = new ProjectVersion(GROUPID, "art102", "1.0.0");
project3.getVersionData().setDependencies(Collections.singletonList(dependency2));
projectsService.createOrUpdate(project3);
project3 = manageDependenciesService.updateTransitiveDependencies(GROUPID, "test", "5.0.0");
Assert.assertTrue(project3.getTransitiveDependenciesReport().isValid());
Assert.assertEquals(Arrays.asList(dependency, dependency2), project3.getTransitiveDependenciesReport().getTransitiveDependencies());

//overriding art102:1.0.0 dependency with art102:2.0.0 with a different underlying dependency
StoreProjectVersionData project4 = new StoreProjectVersionData(GROUPID, "test-master", "3.0.0");
ProjectVersion dependency3 = new ProjectVersion(GROUPID, "test", "5.0.0");
ProjectVersion dependency4 = new ProjectVersion(GROUPID, "art102", "2.0.0");
project4.getVersionData().setDependencies(Arrays.asList(dependency3, dependency4));
projectsService.createOrUpdate(project4);

project4 = manageDependenciesService.updateTransitiveDependencies(GROUPID, "test-master", "3.0.0");
Assert.assertTrue(project4.getTransitiveDependenciesReport().isValid());
Assert.assertEquals(Arrays.asList(dependency3, dependency4, dependency1), project4.getTransitiveDependenciesReport().getTransitiveDependencies());
}
}

0 comments on commit 0eeefa9

Please sign in to comment.