Search in sources :

Example 1 with UploadTarget

use of com.synopsys.integration.blackduck.codelocation.upload.UploadTarget in project synopsys-detect by blackducksoftware.

the class CreateBdio1FilesOperation method createBdioFiles.

public List<UploadTarget> createBdioFiles(BdioCodeLocationResult bdioCodeLocationResult, File outputDirectory, NameVersion projectNameVersion) throws DetectUserFriendlyException {
    logger.debug("Creating BDIO files from code locations.");
    List<UploadTarget> uploadTargets = new ArrayList<>();
    for (BdioCodeLocation bdioCodeLocation : bdioCodeLocationResult.getBdioCodeLocations()) {
        String codeLocationName = bdioCodeLocation.getCodeLocationName();
        ExternalId externalId = bdioCodeLocation.getDetectCodeLocation().getExternalId();
        DependencyGraph dependencyGraph = bdioCodeLocation.getDetectCodeLocation().getDependencyGraph();
        File bdioOutputFile = new File(outputDirectory, bdioCodeLocation.getBdioName() + ".jsonld");
        SimpleBdioDocument simpleBdioDocument = simpleBdioFactory.createSimpleBdioDocument(codeLocationName, projectNameVersion.getName(), projectNameVersion.getVersion(), externalId, dependencyGraph);
        detectBdioWriter.writeBdioFile(bdioOutputFile, simpleBdioDocument);
        uploadTargets.add(UploadTarget.createDefault(projectNameVersion, codeLocationName, bdioOutputFile));
    }
    return uploadTargets;
}
Also used : BdioCodeLocation(com.synopsys.integration.detect.workflow.codelocation.BdioCodeLocation) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) File(java.io.File) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument)

Example 2 with UploadTarget

use of com.synopsys.integration.blackduck.codelocation.upload.UploadTarget 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 3 with UploadTarget

use of com.synopsys.integration.blackduck.codelocation.upload.UploadTarget in project synopsys-detect by blackducksoftware.

the class UniversalStepRunner method generateAggregateBdio.

private BdioResult generateAggregateBdio(AggregateDecision aggregateDecision, UniversalToolsResult universalToolsResult, NameVersion projectNameVersion, String aggregateName) throws OperationException, DetectUserFriendlyException {
    DependencyGraph aggregateDependencyGraph;
    if (aggregateDecision.getAggregateMode() == AggregateMode.DIRECT) {
        aggregateDependencyGraph = operationFactory.aggregateDirect(universalToolsResult.getDetectCodeLocations());
    } else if (aggregateDecision.getAggregateMode() == AggregateMode.TRANSITIVE) {
        aggregateDependencyGraph = operationFactory.aggregateTransitive(universalToolsResult.getDetectCodeLocations());
    } else if (aggregateDecision.getAggregateMode() == AggregateMode.SUBPROJECT) {
        aggregateDependencyGraph = operationFactory.aggregateSubProject(universalToolsResult.getDetectCodeLocations());
    } else {
        throw new DetectUserFriendlyException(String.format("The %s property was set to an unsupported aggregation mode, will not aggregate at this time.", DetectProperties.DETECT_BOM_AGGREGATE_REMEDIATION_MODE.getKey()), ExitCodeType.FAILURE_GENERAL_ERROR);
    }
    boolean isBdio2 = operationFactory.calculateBdioOptions().isBdio2Enabled();
    String aggregateExtension = isBdio2 ? ".bdio" : ".jsonld";
    AggregateCodeLocation aggregateCodeLocation = operationFactory.createAggregateCodeLocation(aggregateDependencyGraph, projectNameVersion, aggregateName, aggregateExtension);
    if (isBdio2) {
        operationFactory.createAggregateBdio2File(aggregateCodeLocation);
    } else {
        operationFactory.createAggregateBdio1File(aggregateCodeLocation);
    }
    List<UploadTarget> uploadTargets = new ArrayList<>();
    Map<DetectCodeLocation, String> codeLocationNamesResult = new HashMap<>();
    universalToolsResult.getDetectCodeLocations().forEach(cl -> codeLocationNamesResult.put(cl, aggregateCodeLocation.getCodeLocationName()));
    // TODO: This doesn't seem right, it should just be the aggregate CL name right?
    if (aggregateCodeLocation.getAggregateDependencyGraph().getRootDependencies().size() > 0 || aggregateDecision.shouldUploadEmptyAggregate()) {
        uploadTargets.add(UploadTarget.createDefault(projectNameVersion, aggregateCodeLocation.getCodeLocationName(), aggregateCodeLocation.getAggregateFile()));
    } else {
        logger.warn("The aggregate contained no dependencies, will not upload aggregate at this time.");
    }
    return new BdioResult(uploadTargets, new DetectCodeLocationNamesResult(codeLocationNamesResult), isBdio2);
}
Also used : AggregateCodeLocation(com.synopsys.integration.detect.workflow.bdio.AggregateCodeLocation) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BdioResult(com.synopsys.integration.detect.workflow.bdio.BdioResult) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) DetectCodeLocationNamesResult(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocationNamesResult) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)

Example 4 with UploadTarget

use of com.synopsys.integration.blackduck.codelocation.upload.UploadTarget in project synopsys-detect by blackducksoftware.

the class BdioUploadOperation method createBatch.

private UploadBatch createBatch(BdioResult bdioResult) {
    UploadBatch uploadBatch = new UploadBatch();
    for (UploadTarget uploadTarget : bdioResult.getUploadTargets()) {
        logger.debug(String.format("Uploading %s", uploadTarget.getUploadFile().getName()));
        uploadBatch.addUploadTarget(uploadTarget);
    }
    return uploadBatch;
}
Also used : UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)

Example 5 with UploadTarget

use of com.synopsys.integration.blackduck.codelocation.upload.UploadTarget in project synopsys-detect by blackducksoftware.

the class UniversalStepRunner method generateBdio.

public BdioResult generateBdio(UniversalToolsResult universalToolsResult, NameVersion projectNameVersion) throws OperationException {
    ProjectDependencyGraph aggregateDependencyGraph = operationFactory.aggregateSubProject(projectNameVersion, universalToolsResult.getDetectCodeLocations());
    AggregateCodeLocation aggregateCodeLocation = operationFactory.createAggregateCodeLocation(aggregateDependencyGraph, projectNameVersion);
    operationFactory.createAggregateBdio2File(aggregateCodeLocation);
    List<UploadTarget> uploadTargets = new ArrayList<>();
    Map<DetectCodeLocation, String> codeLocationNamesResult = new HashMap<>();
    universalToolsResult.getDetectCodeLocations().forEach(cl -> codeLocationNamesResult.put(cl, aggregateCodeLocation.getCodeLocationName()));
    // TODO: This doesn't seem right, it should just be the aggregate CL name right?
    uploadTargets.add(UploadTarget.createDefault(projectNameVersion, aggregateCodeLocation.getCodeLocationName(), aggregateCodeLocation.getAggregateFile()));
    return new BdioResult(uploadTargets, new DetectCodeLocationNamesResult(codeLocationNamesResult));
}
Also used : AggregateCodeLocation(com.synopsys.integration.detect.workflow.bdio.AggregateCodeLocation) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) HashMap(java.util.HashMap) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) ArrayList(java.util.ArrayList) BdioResult(com.synopsys.integration.detect.workflow.bdio.BdioResult) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) DetectCodeLocationNamesResult(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocationNamesResult)

Aggregations

UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)10 HttpUrl (com.synopsys.integration.rest.HttpUrl)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)3 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)3 HashMap (java.util.HashMap)3 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 BdioUploadService (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)2 AggregateCodeLocation (com.synopsys.integration.detect.workflow.bdio.AggregateCodeLocation)2 BdioResult (com.synopsys.integration.detect.workflow.bdio.BdioResult)2 BdioCodeLocation (com.synopsys.integration.detect.workflow.codelocation.BdioCodeLocation)2 DetectCodeLocation (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)2 DetectCodeLocationNamesResult (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocationNamesResult)2 NameVersion (com.synopsys.integration.util.NameVersion)2 IOException (java.io.IOException)2 BdioMetadata (com.blackducksoftware.bdio2.BdioMetadata)1 Project (com.blackducksoftware.bdio2.model.Project)1