Search in sources :

Example 1 with SpdxCreator

use of com.synopsys.integration.bdio.model.SpdxCreator 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 2 with SpdxCreator

use of com.synopsys.integration.bdio.model.SpdxCreator in project hub-detect by blackducksoftware.

the class DetectBdioWriter method writeBdioFile.

public void writeBdioFile(final File outputFile, final SimpleBdioDocument simpleBdioDocument) throws DetectUserFriendlyException {
    if (outputFile.exists()) {
        final boolean deleteSuccess = outputFile.delete();
        logger.debug(String.format("%s deleted: %b", outputFile.getAbsolutePath(), deleteSuccess));
    }
    try {
        final String hubDetectVersion = detectInfo.getDetectVersion();
        final SpdxCreator hubDetectCreator = SpdxCreator.createToolSpdxCreator("Detect", hubDetectVersion);
        simpleBdioDocument.billOfMaterials.creationInfo.setPrimarySpdxCreator(hubDetectCreator);
        simpleBdioFactory.writeSimpleBdioDocumentToFile(outputFile, simpleBdioDocument);
        logger.info(String.format("BDIO Generated: %s", outputFile.getAbsolutePath()));
    } catch (final IOException e) {
        throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IOException(java.io.IOException) SpdxCreator(com.synopsys.integration.bdio.model.SpdxCreator)

Example 3 with SpdxCreator

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

the class CreateAggregateBdio2FileOperation method writeAggregateBdio2File.

public void writeAggregateBdio2File(AggregateCodeLocation aggregateCodeLocation) throws DetectUserFriendlyException {
    String detectVersion = detectInfo.getDetectVersion();
    SpdxCreator detectCreator = SpdxCreator.createToolSpdxCreator("Detect", detectVersion);
    ExternalId projectExternalId = aggregateCodeLocation.getAggregateDependencyGraph().getProjectDependency().getExternalId();
    String group = StringUtils.defaultIfBlank(projectExternalId.getGroup(), null);
    ProjectInfo projectInfo = ProjectInfo.nameVersionGroup(aggregateCodeLocation.getProjectNameVersion(), group);
    BdioMetadata bdioMetadata = bdio2Factory.createBdioMetadata(aggregateCodeLocation.getCodeLocationName(), projectInfo, ZonedDateTime.now(), new Product.Builder().name(detectCreator.getIdentifier()).build());
    bdioMetadata.scanType(Bdio.ScanType.PACKAGE_MANAGER);
    Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdioMetadata, aggregateCodeLocation.getAggregateDependencyGraph());
    writeDocument(aggregateCodeLocation.getAggregateFile(), bdio2Document);
}
Also used : BdioMetadata(com.blackducksoftware.bdio2.BdioMetadata) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ProjectInfo(com.synopsys.integration.blackduck.bdio2.model.ProjectInfo) Product(com.blackducksoftware.common.value.Product) SpdxCreator(com.synopsys.integration.bdio.model.SpdxCreator)

Example 4 with SpdxCreator

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

the class DetectBdioWriter method writeBdioFile.

public void writeBdioFile(File outputFile, SimpleBdioDocument simpleBdioDocument) throws DetectUserFriendlyException {
    if (outputFile.exists()) {
        boolean deleteSuccess = outputFile.delete();
        logger.debug(String.format("%s deleted: %b", outputFile.getAbsolutePath(), deleteSuccess));
    }
    try {
        String detectVersion = detectInfo.getDetectVersion();
        SpdxCreator detectCreator = SpdxCreator.createToolSpdxCreator("Detect", detectVersion);
        simpleBdioDocument.getBillOfMaterials().creationInfo.setPrimarySpdxCreator(detectCreator);
        simpleBdioFactory.writeSimpleBdioDocumentToFile(outputFile, simpleBdioDocument);
        logger.debug(String.format("BDIO Generated: %s", outputFile.getAbsolutePath()));
    } catch (IOException e) {
        throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IOException(java.io.IOException) SpdxCreator(com.synopsys.integration.bdio.model.SpdxCreator)

Aggregations

SpdxCreator (com.synopsys.integration.bdio.model.SpdxCreator)4 IOException (java.io.IOException)3 BdioMetadata (com.blackducksoftware.bdio2.BdioMetadata)2 Product (com.blackducksoftware.common.value.Product)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 Bdio2Document (com.synopsys.integration.blackduck.bdio2.model.Bdio2Document)2 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)2 Project (com.blackducksoftware.bdio2.model.Project)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 ProjectInfo (com.synopsys.integration.blackduck.bdio2.model.ProjectInfo)1 Bdio2Writer (com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer)1 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)1 BdioCodeLocation (com.synopsys.integration.detect.workflow.codelocation.BdioCodeLocation)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1