Search in sources :

Example 1 with UploadTarget

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

the class DetectBdioUploadService method uploadBdioFiles.

public CodeLocationCreationData<UploadBatchOutput> uploadBdioFiles(List<UploadTarget> uploadTargets) throws IntegrationException, DetectUserFriendlyException {
    UploadBatch uploadBatch = new UploadBatch();
    for (UploadTarget uploadTarget : uploadTargets) {
        logger.info(String.format("uploading %s to %s", uploadTarget.getUploadFile().getName(), detectConfiguration.getProperty(DetectProperty.BLACKDUCK_URL, PropertyAuthority.None)));
        uploadBatch.addUploadTarget(uploadTarget);
    }
    BdioUploadCodeLocationCreationRequest uploadRequest = bdioUploadService.createUploadRequest(uploadBatch);
    CodeLocationCreationData<UploadBatchOutput> response = bdioUploadService.uploadBdio(uploadRequest);
    for (UploadOutput uploadOutput : response.getOutput()) {
        if (uploadOutput.getResult() == Result.FAILURE) {
            logger.error("Failed to upload code location: " + uploadOutput.getCodeLocationName());
            logger.error("Reason: " + uploadOutput.getErrorMessage().orElse("Unknown reason."));
            throw new DetectUserFriendlyException("An error occurred uploading a bdio file.", uploadOutput.getException().orElse(null), ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
        }
    }
    return response;
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.bdioupload.UploadBatchOutput) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) UploadTarget(com.synopsys.integration.blackduck.codelocation.bdioupload.UploadTarget) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdioupload.BdioUploadCodeLocationCreationRequest) UploadBatch(com.synopsys.integration.blackduck.codelocation.bdioupload.UploadBatch) UploadOutput(com.synopsys.integration.blackduck.codelocation.bdioupload.UploadOutput)

Example 2 with UploadTarget

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

the class CodeLocationBdioCreator method createBdioFiles.

public List<UploadTarget> createBdioFiles(File bdioOutput, final List<BdioCodeLocation> bdioCodeLocations, NameVersion projectNameVersion) throws DetectUserFriendlyException {
    final List<UploadTarget> uploadTargets = new ArrayList<>();
    for (final BdioCodeLocation bdioCodeLocation : bdioCodeLocations) {
        String codeLocationName = bdioCodeLocation.codeLocationName;
        ExternalId externalId = bdioCodeLocation.codeLocation.getExternalId();
        DependencyGraph dependencyGraph = bdioCodeLocation.codeLocation.getDependencyGraph();
        final SimpleBdioDocument simpleBdioDocument = simpleBdioFactory.createSimpleBdioDocument(codeLocationName, projectNameVersion.getName(), projectNameVersion.getVersion(), externalId, dependencyGraph);
        final File outputFile = new File(bdioOutput, bdioCodeLocation.bdioName);
        detectBdioWriter.writeBdioFile(outputFile, simpleBdioDocument);
        uploadTargets.add(UploadTarget.createDefault(codeLocationName, outputFile));
    }
    return uploadTargets;
}
Also used : BdioCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.BdioCodeLocation) UploadTarget(com.synopsys.integration.blackduck.codelocation.bdioupload.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 3 with UploadTarget

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

the class BdioManager method createBdioFiles.

public BdioResult createBdioFiles(String aggregateName, NameVersion projectNameVersion, List<DetectCodeLocation> codeLocations) throws DetectUserFriendlyException {
    DetectBdioWriter detectBdioWriter = new DetectBdioWriter(simpleBdioFactory, detectInfo);
    if (StringUtils.isBlank(aggregateName)) {
        logger.info("Creating BDIO code locations.");
        final BdioCodeLocationResult codeLocationResult = bdioCodeLocationCreator.createFromDetectCodeLocations(codeLocations, projectNameVersion);
        codeLocationResult.getFailedBomToolGroupTypes().forEach(it -> eventSystem.publishEvent(Event.StatusSummary, new DetectorStatus(it, StatusType.FAILURE)));
        logger.info("Creating BDIO files from code locations.");
        CodeLocationBdioCreator codeLocationBdioCreator = new CodeLocationBdioCreator(detectBdioWriter, simpleBdioFactory);
        final List<UploadTarget> uploadTargets = codeLocationBdioCreator.createBdioFiles(directoryManager.getBdioOutputDirectory(), codeLocationResult.getBdioCodeLocations(), projectNameVersion);
        return new BdioResult(uploadTargets);
    } else {
        logger.info("Creating aggregate BDIO file.");
        AggregateBdioCreator aggregateBdioCreator = new AggregateBdioCreator(simpleBdioFactory, integrationEscapeUtil, codeLocationNameManager, detectConfiguration, detectBdioWriter);
        final Optional<UploadTarget> uploadTarget = aggregateBdioCreator.createAggregateBdioFile(directoryManager.getSourceDirectory(), directoryManager.getBdioOutputDirectory(), codeLocations, projectNameVersion);
        if (uploadTarget.isPresent()) {
            return new BdioResult(Arrays.asList(uploadTarget.get()));
        } else {
            return new BdioResult(Collections.emptyList());
        }
    }
}
Also used : DetectorStatus(com.blackducksoftware.integration.hub.detect.workflow.status.DetectorStatus) UploadTarget(com.synopsys.integration.blackduck.codelocation.bdioupload.UploadTarget) BdioCodeLocationResult(com.blackducksoftware.integration.hub.detect.workflow.codelocation.BdioCodeLocationResult)

Aggregations

UploadTarget (com.synopsys.integration.blackduck.codelocation.bdioupload.UploadTarget)3 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 BdioCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.BdioCodeLocation)1 BdioCodeLocationResult (com.blackducksoftware.integration.hub.detect.workflow.codelocation.BdioCodeLocationResult)1 DetectorStatus (com.blackducksoftware.integration.hub.detect.workflow.status.DetectorStatus)1 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdioupload.BdioUploadCodeLocationCreationRequest)1 UploadBatch (com.synopsys.integration.blackduck.codelocation.bdioupload.UploadBatch)1 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.bdioupload.UploadBatchOutput)1 UploadOutput (com.synopsys.integration.blackduck.codelocation.bdioupload.UploadOutput)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1