Search in sources :

Example 1 with Bdio2Document

use of com.synopsys.integration.blackduck.bdio2.model.Bdio2Document in project blackduck-common by blackducksoftware.

the class Bdio2Factory method createLegacyBdio2Document.

/**
 * @deprecated (Use createBdio2Document instead when the ProjectDependencyGraph has an accurate ProjectDependency)
 */
@Deprecated
public Bdio2Document createLegacyBdio2Document(BdioMetadata bdioMetadata, DependencyGraph dependencyGraph, ProjectInfo projectInfo, ExternalId projectExternalId) {
    Project project = createProject(projectInfo.getNameVersion(), projectExternalId, true);
    Pair<List<Project>, List<Component>> subprojectsAndComponents = createAndLinkComponents(dependencyGraph, project);
    return new Bdio2Document(bdioMetadata, project, subprojectsAndComponents.getLeft(), subprojectsAndComponents.getRight());
}
Also used : Project(com.blackducksoftware.bdio2.model.Project) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) ProductList(com.blackducksoftware.common.value.ProductList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Bdio2Document

use of com.synopsys.integration.blackduck.bdio2.model.Bdio2Document in project blackduck-common by blackducksoftware.

the class Bdio2Factory method createBdio2Document.

public Bdio2Document createBdio2Document(BdioMetadata bdioMetadata, ProjectDependencyGraph dependencyGraph) {
    Project project = createProject(dependencyGraph.getProjectDependency().getExternalId(), true);
    Pair<List<Project>, List<Component>> subprojectsAndComponents = createAndLinkComponents(dependencyGraph, project);
    return new Bdio2Document(bdioMetadata, project, subprojectsAndComponents.getLeft(), subprojectsAndComponents.getRight());
}
Also used : Project(com.blackducksoftware.bdio2.model.Project) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) ProductList(com.blackducksoftware.common.value.ProductList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Bdio2Document

use of com.synopsys.integration.blackduck.bdio2.model.Bdio2Document in project blackduck-common by blackducksoftware.

the class IntelligentPersistenceRecipeTest method uploadBdio2.

@Test
void uploadBdio2() throws IOException, IntegrationException, InterruptedException {
    Bdio2Factory bdio2Factory = new Bdio2Factory();
    // create the bdio2 metadata
    ZonedDateTime now = Instant.now().atZone(ZoneId.of("EST5EDT"));
    ProjectInfo projectInfo = ProjectInfo.nameVersion(PROJECT);
    BdioMetadata bdio2Metadata = bdio2Factory.createBdioMetadata(CODE_LOCATION_NAME, projectInfo, now);
    // create the bdio2 project
    Dependency projectDependency = Dependency.FACTORY.createMavenDependency("com.synopsys.integration", PROJECT.getName(), PROJECT.getVersion());
    // create a graph of one dependency
    Dependency dependency = Dependency.FACTORY.createMavenDependency("org.apache.commons", "commons-lang3", "3.11");
    ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraph(projectDependency);
    dependencyGraph.addDirectDependency(dependency);
    // now, with metadata, a project, and a graph, we can create a bdio2 document and write out the file
    Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdio2Metadata, dependencyGraph);
    File bdio2File = File.createTempFile("test_bdio2", ".bdio");
    bdio2File.createNewFile();
    bdio2File.deleteOnExit();
    Bdio2Writer bdio2Writer = new Bdio2Writer();
    bdio2Writer.writeBdioDocument(new FileOutputStream(bdio2File), bdio2Document);
    // using the file and the previously set values, we create the UploadBatch for uploading to Black Duck
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(UploadTarget.createDefault(PROJECT, CODE_LOCATION_NAME, bdio2File));
    // now all the setup is done, we can upload the bdio2 file
    IntelligentPersistenceService intelligentPersistenceService = blackDuckServicesFactory.createIntelligentPersistenceService();
    UploadBatchOutput uploadBatchOutput = intelligentPersistenceService.uploadBdioAndWait(uploadBatch, 120);
    assertFalse(uploadBatchOutput.hasAnyFailures());
    // verify that we now have a bom with 1 component
    Optional<ProjectVersionWrapper> projectVersionWrapper = projectService.getProjectVersion(PROJECT);
    assertTrue(projectVersionWrapper.isPresent());
    List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.get().getProjectVersionView());
    assertEquals(1, bomComponents.size());
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BdioMetadata(com.blackducksoftware.bdio2.BdioMetadata) Bdio2Writer(com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Bdio2Factory(com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory) IntelligentPersistenceService(com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceService) ZonedDateTime(java.time.ZonedDateTime) FileOutputStream(java.io.FileOutputStream) ProjectInfo(com.synopsys.integration.blackduck.bdio2.model.ProjectInfo) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) File(java.io.File) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 4 with Bdio2Document

use of com.synopsys.integration.blackduck.bdio2.model.Bdio2Document in project synopsys-detect by blackducksoftware.

the class CreateBdio2FilesOperation method createBdioFiles.

public List<UploadTarget> createBdioFiles(BdioCodeLocationResult bdioCodeLocationResult, File outputDirectory, NameVersion projectNameVersion) throws DetectUserFriendlyException {
    List<UploadTarget> uploadTargets = new ArrayList<>();
    for (BdioCodeLocation bdioCodeLocation : bdioCodeLocationResult.getBdioCodeLocations()) {
        String codeLocationName = bdioCodeLocation.getCodeLocationName();
        ExternalId externalId = bdioCodeLocation.getDetectCodeLocation().getExternalId();
        DependencyGraph dependencyGraph = bdioCodeLocation.getDetectCodeLocation().getDependencyGraph();
        // Bdio 2
        String detectVersion = detectInfo.getDetectVersion();
        SpdxCreator detectCreator = SpdxCreator.createToolSpdxCreator("Detect", detectVersion);
        BdioMetadata bdioMetadata = bdio2Factory.createBdioMetadata(codeLocationName, ZonedDateTime.now(), new Product.Builder().name(detectCreator.getIdentifier()).build());
        bdioMetadata.scanType(Bdio.ScanType.PACKAGE_MANAGER);
        Project bdio2Project = bdio2Factory.createProject(externalId, projectNameVersion.getName(), projectNameVersion.getVersion(), true);
        Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdioMetadata, bdio2Project, dependencyGraph);
        Bdio2Writer bdio2Writer = new Bdio2Writer();
        File bdio2OutputFile = new File(outputDirectory, bdioCodeLocation.getBdioName() + ".bdio");
        try {
            OutputStream outputStream = new FileOutputStream(bdio2OutputFile);
            bdio2Writer.writeBdioDocument(outputStream, bdio2Document);
            logger.debug(String.format("BDIO Generated: %s", bdio2OutputFile.getAbsolutePath()));
            uploadTargets.add(UploadTarget.createDefault(projectNameVersion, codeLocationName, bdio2OutputFile));
        } catch (IOException e) {
            throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
        }
    }
    return uploadTargets;
}
Also used : BdioMetadata(com.blackducksoftware.bdio2.BdioMetadata) Bdio2Writer(com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Product(com.blackducksoftware.common.value.Product) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException) SpdxCreator(com.synopsys.integration.bdio.model.SpdxCreator) BdioCodeLocation(com.synopsys.integration.detect.workflow.codelocation.BdioCodeLocation) Project(com.blackducksoftware.bdio2.model.Project) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 5 with Bdio2Document

use of com.synopsys.integration.blackduck.bdio2.model.Bdio2Document in project synopsys-detect by blackducksoftware.

the class CreateAggregateBdio2FileOperation method writeDocument.

private void writeDocument(File aggregateFile, Bdio2Document bdio2Document) throws DetectUserFriendlyException {
    Bdio2Writer bdio2Writer = new Bdio2Writer();
    try {
        OutputStream outputStream = new FileOutputStream(aggregateFile);
        bdio2Writer.writeBdioDocument(outputStream, bdio2Document);
        logger.debug(String.format("BDIO Generated: %s", aggregateFile.getAbsolutePath()));
    } catch (IOException e) {
        throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : Bdio2Writer(com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Aggregations

Bdio2Document (com.synopsys.integration.blackduck.bdio2.model.Bdio2Document)6 BdioMetadata (com.blackducksoftware.bdio2.BdioMetadata)4 Bdio2Writer (com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer)4 FileOutputStream (java.io.FileOutputStream)4 Project (com.blackducksoftware.bdio2.model.Project)3 ProjectInfo (com.synopsys.integration.blackduck.bdio2.model.ProjectInfo)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Product (com.blackducksoftware.common.value.Product)2 ProductList (com.blackducksoftware.common.value.ProductList)2 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)2 SpdxCreator (com.synopsys.integration.bdio.model.SpdxCreator)2 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)2 Bdio2Factory (com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory)2 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)2 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)2