Search in sources :

Example 6 with ProjectDependency

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);
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Test(org.junit.jupiter.api.Test)

Example 7 with 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);
}
Also used : ArrayList(java.util.ArrayList) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Project(com.blackducksoftware.bdio2.model.Project) ProductList(com.blackducksoftware.common.value.ProductList) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.blackducksoftware.bdio2.model.Component)

Aggregations

ProjectDependency (com.synopsys.integration.bdio.model.dependency.ProjectDependency)7 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)5 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)4 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)4 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Project (com.blackducksoftware.bdio2.model.Project)2 BdioReader (com.synopsys.integration.bdio.BdioReader)2 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)2 DetectCodeLocation (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)2 NameVersion (com.synopsys.integration.util.NameVersion)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Component (com.blackducksoftware.bdio2.model.Component)1 ProductList (com.blackducksoftware.common.value.ProductList)1 Gson (com.google.gson.Gson)1 BdioTransformer (com.synopsys.integration.bdio.BdioTransformer)1 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)1