Search in sources :

Example 1 with ProjectDependency

use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project blackduck-common by blackducksoftware.

the class Bdio2FactoryTest method testCreateAndLinkComponents.

@Test
void testCreateAndLinkComponents() {
    ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    String rootProjectGroup = "testRootProjectGroup";
    String rootProjectName = "testRootProjectName";
    String rootProjectVersion = "testRootProjectVersion";
    String subProjectGroup = "testSubProjectGroup";
    String subProjectName = "testSubProjectName";
    String subProjectVersion = "testSubProjectVersion";
    String compGroup = "testCompGroup";
    String compName = "testCompName";
    String compVersion = "testCompVersion";
    ExternalId rootProjectExternalId = externalIdFactory.createMavenExternalId(rootProjectGroup, rootProjectName, rootProjectVersion);
    ExternalId subProjectExternalId = externalIdFactory.createMavenExternalId(subProjectGroup, subProjectName, subProjectVersion);
    ExternalId componentExternalId = externalIdFactory.createMavenExternalId(compGroup, compName, compVersion);
    Bdio2Factory bdio2Factory = new Bdio2Factory();
    Project rootProject = bdio2Factory.createProject(rootProjectExternalId, true);
    DependencyGraph dependencyGraph = Mockito.mock(DependencyGraph.class);
    Set<Dependency> dependencies = new HashSet<>();
    ProjectDependency subProjectDependency = new ProjectDependency(subProjectName, subProjectVersion, subProjectExternalId);
    Dependency componentDependency = new Dependency(componentExternalId);
    dependencies.add(subProjectDependency);
    dependencies.add(componentDependency);
    Mockito.when(dependencyGraph.getDirectDependencies()).thenReturn(dependencies);
    Pair<List<Project>, List<Component>> results = bdio2Factory.createAndLinkComponents(dependencyGraph, rootProject);
    assertEquals(1, results.getLeft().size());
    assertEquals("http:maven/" + subProjectGroup + "/" + subProjectName + "/" + subProjectVersion, results.getLeft().get(0).id());
    assertEquals(1, results.getRight().size());
    assertEquals("http:maven/" + compGroup + "/" + compName + "/" + compVersion, results.getRight().get(0).id());
}
Also used : Project(com.blackducksoftware.bdio2.model.Project) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) List(java.util.List) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with ProjectDependency

use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project synopsys-detect by blackducksoftware.

the class DockerExtractor method findCodeLocations.

private Extraction.Builder findCodeLocations(File directoryToSearch, File directory, @Nullable String dockerInspectorMessage) {
    File bdioFile = fileFinder.findFile(directoryToSearch, DEPENDENCIES_PATTERN);
    if (bdioFile != null) {
        SimpleBdioDocument simpleBdioDocument = null;
        try (InputStream dockerOutputInputStream = new FileInputStream(bdioFile);
            BdioReader bdioReader = new BdioReader(gson, dockerOutputInputStream)) {
            simpleBdioDocument = bdioReader.readSimpleBdioDocument();
        } catch (Exception e) {
            return new Extraction.Builder().exception(e);
        }
        if (simpleBdioDocument != null) {
            String projectName = simpleBdioDocument.getProject().name;
            String projectVersionName = simpleBdioDocument.getProject().version;
            // TODO ejk - update this when project external id is not req'd anymore
            Forge dockerForge = new Forge(BdioId.BDIO_ID_SEPARATOR, simpleBdioDocument.getProject().bdioExternalIdentifier.forge);
            String externalIdPath = simpleBdioDocument.getProject().bdioExternalIdentifier.externalId;
            ExternalId projectExternalId = externalIdFactory.createPathExternalId(dockerForge, externalIdPath);
            ProjectDependency projectDependency = new ProjectDependency(projectName, projectVersionName, projectExternalId);
            DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(projectDependency, simpleBdioDocument.getProject(), simpleBdioDocument.getComponents());
            CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, projectExternalId);
            return new Extraction.Builder().success(detectCodeLocation).projectName(projectName).projectVersion(projectVersionName);
        }
    }
    logger.error("Docker Inspector returned no BDIO files");
    String dockerInspectorMsgSuffix = Optional.ofNullable(dockerInspectorMessage).filter(StringUtils::isNotBlank).map(s -> "; Docker Inspector message: " + s).orElse("");
    return new Extraction.Builder().failure("No files found matching pattern [" + DEPENDENCIES_PATTERN + "]. Expected docker-inspector to produce file in " + directory.toString() + dockerInspectorMsgSuffix);
}
Also used : Arrays(java.util.Arrays) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IntegrationException(com.synopsys.integration.exception.IntegrationException) Forge(com.synopsys.integration.bdio.model.Forge) Extraction(com.synopsys.integration.detectable.extraction.Extraction) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) ArrayList(java.util.ArrayList) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) DockerInspectorResultsFileParser(com.synopsys.integration.detectable.detectables.docker.parser.DockerInspectorResultsFileParser) DockerInspectorResults(com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults) Gson(com.google.gson.Gson) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) Map(java.util.Map) BdioReader(com.synopsys.integration.bdio.BdioReader) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BdioTransformer(com.synopsys.integration.bdio.BdioTransformer) Logger(org.slf4j.Logger) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BdioId(com.synopsys.integration.bdio.model.BdioId) Nullable(org.jetbrains.annotations.Nullable) Executable(com.synopsys.integration.executable.Executable) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) Optional(java.util.Optional) ExecutableUtils(com.synopsys.integration.detectable.ExecutableUtils) ExtractionMetadata(com.synopsys.integration.detectable.extraction.ExtractionMetadata) InputStream(java.io.InputStream) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BdioReader(com.synopsys.integration.bdio.BdioReader) Forge(com.synopsys.integration.bdio.model.Forge) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) FileInputStream(java.io.FileInputStream) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) IOException(java.io.IOException) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) StringUtils(org.apache.commons.lang3.StringUtils) Extraction(com.synopsys.integration.detectable.extraction.Extraction) File(java.io.File)

Example 3 with ProjectDependency

use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project synopsys-detect by blackducksoftware.

the class FullAggregateGraphCreator method aggregateCodeLocations.

public ProjectDependencyGraph aggregateCodeLocations(File sourcePath, NameVersion projectNameVersion, List<DetectCodeLocation> codeLocations) {
    ExternalId projectExternalId = ExternalId.FACTORY.createNameVersionExternalId(DETECT_FORGE, projectNameVersion.getName(), projectNameVersion.getVersion());
    ProjectDependency projectDependency = new ProjectDependency(projectExternalId);
    ProjectDependencyGraph aggregateDependencyGraph = new ProjectDependencyGraph(projectDependency);
    for (DetectCodeLocation detectCodeLocation : codeLocations) {
        Dependency codeLocationDependency = createAggregateNode(sourcePath, detectCodeLocation);
        aggregateDependencyGraph.addDirectDependency(codeLocationDependency);
        DependencyGraphUtil.copyDirectDependenciesToParent(aggregateDependencyGraph, codeLocationDependency, detectCodeLocation.getDependencyGraph());
    }
    return aggregateDependencyGraph;
}
Also used : DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency)

Example 4 with ProjectDependency

use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project synopsys-detect by blackducksoftware.

the class FullAggregateGraphCreator method createAggregateNode.

private Dependency createAggregateNode(File sourcePath, DetectCodeLocation codeLocation) {
    ExternalId original = codeLocation.getExternalId();
    List<String> externalIdPieces = new ArrayList<>(Arrays.asList(original.getExternalIdPieces()));
    NameVersion projectNameVersion = createProjectNameVersion(codeLocation);
    createRelativePath(sourcePath, projectNameVersion, codeLocation).ifPresent(externalIdPieces::add);
    String bomToolType = createBomToolType(codeLocation);
    externalIdPieces.add(bomToolType);
    String[] pieces = externalIdPieces.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
    return new ProjectDependency(projectNameVersion.getName(), projectNameVersion.getVersion(), new ExternalIdFactory().createModuleNamesExternalId(original.getForge(), pieces));
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ArrayList(java.util.ArrayList) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency)

Example 5 with ProjectDependency

use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project synopsys-detect by blackducksoftware.

the class BdioAggregationTest method readInputCodeLocations.

@NotNull
private static List<DetectCodeLocation> readInputCodeLocations(List<String> inputBdioFilenames, File sourceDir) throws IOException {
    File inputBdioDir = new File("src/test/resources/workflow/bdio/aggregation/input");
    List<DetectCodeLocation> inputCodelocations = new LinkedList<>();
    for (String inputBdioFilename : inputBdioFilenames) {
        File bdioFile = new File(inputBdioDir, inputBdioFilename);
        SimpleBdioDocument simpleBdioDocument;
        try (InputStream bdioInputStream = new FileInputStream(bdioFile);
            BdioReader bdioReader = new BdioReader(gson, bdioInputStream)) {
            simpleBdioDocument = bdioReader.readSimpleBdioDocument();
        }
        ExternalId externalId = simpleBdioDocument.getProject().bdioExternalIdentifier.externalIdMetaData;
        ProjectDependency projectDependency = new ProjectDependency(externalId);
        DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(projectDependency, simpleBdioDocument.getProject(), simpleBdioDocument.getComponents());
        DetectCodeLocation detectCodeLocation = DetectCodeLocation.forCreator(dependencyGraph, sourceDir, externalId, "testcreator");
        inputCodelocations.add(detectCodeLocation);
    }
    return inputCodelocations;
}
Also used : DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BdioReader(com.synopsys.integration.bdio.BdioReader) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) File(java.io.File) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) NotNull(org.jetbrains.annotations.NotNull)

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