use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project synopsys-detect by blackducksoftware.
the class BdioAggregationTest method testSubProjectMode.
@Test
void testSubProjectMode() {
FullAggregateGraphCreator fullAggregateGraphCreator = new FullAggregateGraphCreator();
DependencyGraph aggregatedGraph = fullAggregateGraphCreator.aggregateCodeLocations(sourceDir, new NameVersion("aggregate-test", "test"), inputCodelocations);
assertEquals(3, aggregatedGraph.getDirectDependencies().size());
assertTrue(aggregatedGraph.getDirectDependencies().contains(genProjectDependency("com.synopsys.integration", "basic-multiproject", "0.0.0-SNAPSHOT")));
assertTrue(aggregatedGraph.getDirectDependencies().contains(genProjectDependency("basic-multiproject", "subprojectone", "unspecified")));
assertTrue(aggregatedGraph.getDirectDependencies().contains(genProjectDependency("basic-multiproject", "subprojecttwo", "unspecified")));
Dependency subProjectOne = aggregatedGraph.getDependency(genProjectExternalId("basic-multiproject", "subprojectone", "unspecified"));
Set<Dependency> subProjectOneDependencies = aggregatedGraph.getChildrenForParent(subProjectOne);
assertTrue(subProjectOneDependencies.contains(Dependency.FACTORY.createMavenDependency("junit", "junit", "4.12")));
assertTrue(subProjectOneDependencies.contains(Dependency.FACTORY.createMavenDependency("joda-time", "joda-time", "2.2")));
assertTrue(subProjectOne instanceof ProjectDependency);
}
use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project blackduck-common by blackducksoftware.
the class Bdio2Factory method createAndLinkComponentsFromGraph.
private Pair<List<Project>, List<Component>> createAndLinkComponentsFromGraph(DependencyGraph dependencyGraph, @Nullable SubProjectFunction linkProjectDependency, DependencyFunction linkComponentDependency, Set<Dependency> dependencies, Map<ExternalId, Project> existingSubprojects, Map<ExternalId, Component> existingComponents) {
List<Project> addedSubprojects = new ArrayList<>();
List<Component> addedComponents = new ArrayList<>();
for (Dependency dependency : dependencies) {
if (dependency instanceof ProjectDependency) {
if (linkProjectDependency == null) {
// Subprojects cannot be dependencies of components
// TODO is there a better way to handle this?
// passing subProjectFunction: component::dependency on line 124 might look better (but be more nonsensical?)
String subprojectExternalId = dependency.getExternalId().toString();
logger.warn("Sipping subproject {}. Failed to add the subproject to the graph because subprojects cannot be dependencies of components. Please contact Synopsys support.", subprojectExternalId);
continue;
// Jake's maybe better way for now? Exposed a few issues with graph building. See IDETECT-3243
// throw new UnsupportedOperationException("Subprojects cannot be dependencies of components. The graph was incorrectly built.");
}
Project subproject = projectFromDependency(dependency);
linkProjectDependency.subProject(new Project(subproject.id()).subproject(subproject));
if (!existingSubprojects.containsKey(dependency.getExternalId())) {
addedSubprojects.add(subproject);
existingSubprojects.put(dependency.getExternalId(), subproject);
Pair<List<Project>, List<Component>> children = createAndLinkComponentsFromGraph(dependencyGraph, subproject::subproject, subproject::dependency, dependencyGraph.getChildrenForParent(dependency), existingSubprojects, existingComponents);
addedSubprojects.addAll(children.getLeft());
addedComponents.addAll(children.getRight());
}
} else {
Component component = componentFromDependency(dependency);
linkComponentDependency.dependency(new com.blackducksoftware.bdio2.model.Dependency().dependsOn(component));
if (!existingComponents.containsKey(dependency.getExternalId())) {
addedComponents.add(component);
existingComponents.put(dependency.getExternalId(), component);
Pair<List<Project>, List<Component>> children = createAndLinkComponentsFromGraph(dependencyGraph, null, component::dependency, dependencyGraph.getChildrenForParent(dependency), existingSubprojects, existingComponents);
addedSubprojects.addAll(children.getLeft());
addedComponents.addAll(children.getRight());
}
}
}
return Pair.of(addedSubprojects, addedComponents);
}
Aggregations