Search in sources :

Example 26 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class BinaryScanFindMultipleTargetsOperation method zipFilesForUpload.

private File zipFilesForUpload(File sourceDir, List<File> multipleTargets) throws DetectUserFriendlyException {
    try {
        String zipPath = "binary-upload.zip";
        File zip = new File(directoryManager.getBinaryOutputDirectory(), zipPath);
        Map<String, Path> uploadTargets = collectUploadTargetsByRelPath(sourceDir, multipleTargets);
        DetectZipUtil.zip(zip, uploadTargets);
        logger.info("Binary scan created the following zip for upload: " + zip.toPath());
        return zip;
    } catch (IOException e) {
        throw new DetectUserFriendlyException("Unable to create binary scan archive for upload.", e, ExitCodeType.FAILURE_UNKNOWN_ERROR);
    }
}
Also used : Path(java.nio.file.Path) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IOException(java.io.IOException) File(java.io.File)

Example 27 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class MapToParentOperation method mapToParentProjectVersion.

public void mapToParentProjectVersion(String parentProjectName, String parentVersionName, ProjectVersionWrapper projectVersionWrapper) throws DetectUserFriendlyException {
    logger.debug("Will attempt to add this project to a parent.");
    String projectName = projectVersionWrapper.getProjectView().getName();
    String projectVersionName = projectVersionWrapper.getProjectVersionView().getVersionName();
    if (StringUtils.isBlank(parentProjectName) || StringUtils.isBlank(parentVersionName)) {
        String errorReason = "Both the parent project name and the parent project version name must be specified if either is specified.";
        throw new DetectUserFriendlyException(errorReason, ExitCodeType.FAILURE_CONFIGURATION);
    }
    try {
        Optional<ProjectVersionWrapper> parentWrapper = projectService.getProjectVersion(parentProjectName, parentVersionName);
        if (parentWrapper.isPresent()) {
            ProjectVersionView parentProjectVersionView = parentWrapper.get().getProjectVersionView();
            BlackDuckRequestFilter filter = BlackDuckRequestFilter.createFilterWithSingleValue("bomComponentSource", "custom_project");
            BlackDuckMultipleRequest<ProjectVersionComponentVersionView> spec = new BlackDuckRequestBuilder().commonGet().addBlackDuckFilter(filter).buildBlackDuckRequest(parentProjectVersionView.metaComponentsLink());
            List<ProjectVersionComponentVersionView> components = blackDuckService.getAllResponses(spec);
            Optional<ProjectVersionComponentVersionView> existingProjectComponent = components.stream().filter(component -> component.getComponentName().equals(projectName)).filter(component -> component.getComponentVersionName().equals(projectVersionName)).findFirst();
            if (existingProjectComponent.isPresent()) {
                logger.debug("This project already exists on the parent so it will not be added to the parent again.");
            } else {
                projectBomService.addProjectVersionToProjectVersion(projectVersionWrapper.getProjectVersionView(), parentWrapper.get().getProjectVersionView());
            }
        } else {
            throw new DetectUserFriendlyException("Unable to find parent project or parent project version on the server.", ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
        }
    } catch (IntegrationException e) {
        String errorReason = "Unable to add project to parent.";
        throw new DetectUserFriendlyException(errorReason, e, ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) ExitCodeType(com.synopsys.integration.detect.configuration.enumeration.ExitCodeType) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) IntegrationException(com.synopsys.integration.exception.IntegrationException) Logger(org.slf4j.Logger) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) LoggerFactory(org.slf4j.LoggerFactory) ProjectBomService(com.synopsys.integration.blackduck.service.dataservice.ProjectBomService) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) StringUtils(org.apache.commons.lang3.StringUtils) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) List(java.util.List) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckRequestFilter(com.synopsys.integration.blackduck.http.BlackDuckRequestFilter) Optional(java.util.Optional) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckRequestFilter(com.synopsys.integration.blackduck.http.BlackDuckRequestFilter) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 28 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class SetApplicationIdOperation method setApplicationId.

public void setApplicationId(ProjectView projectView, String applicationId) throws DetectUserFriendlyException {
    try {
        logger.debug("Populating project 'Application ID'");
        projectMappingService.populateApplicationId(projectView, applicationId);
    } catch (IntegrationException e) {
        String errorReason = String.format("Unable to set Application ID for project: %s", projectView.getName());
        throw new DetectUserFriendlyException(errorReason, e, ExitCodeType.FAILURE_CONFIGURATION);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException)

Example 29 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class BdioUploadOperation method checkForUploadFailure.

private void checkForUploadFailure(CodeLocationCreationData<UploadBatchOutput> response) throws DetectUserFriendlyException {
    for (UploadOutput uploadOutput : response.getOutput()) {
        if (uploadOutput.getResult() == Result.FAILURE) {
            logger.error(String.format("Failed to upload code location: %s", uploadOutput.getCodeLocationName()));
            logger.error(String.format("Reason: %s", uploadOutput.getErrorMessage().orElse("Unknown reason.")));
            throw new DetectUserFriendlyException("An error occurred uploading a bdio file.", uploadOutput.getException().orElse(null), ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
        }
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput)

Example 30 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class BdioUploadOperation method uploadBdioFiles.

public BdioUploadResult uploadBdioFiles(BdioResult bdioResult) throws DetectUserFriendlyException {
    UploadBatch uploadBatch = createBatch(bdioResult);
    CodeLocationCreationData<UploadBatchOutput> response;
    try {
        response = executeUpload(uploadBatch);
    } catch (IntegrationException ex) {
        logger.error("Error uploading bdio files", ex);
        throw new DetectUserFriendlyException("Error uploading bdio files", ex, ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
    }
    checkForUploadFailure(response);
    return new BdioUploadResult(response);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException) BdioUploadResult(com.synopsys.integration.detect.lifecycle.run.operation.blackduck.BdioUploadResult) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)

Aggregations

DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)33 File (java.io.File)14 IntegrationException (com.synopsys.integration.exception.IntegrationException)12 IOException (java.io.IOException)12 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 ExitCodeType (com.synopsys.integration.detect.configuration.enumeration.ExitCodeType)3 ArrayList (java.util.ArrayList)3 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 SpdxCreator (com.synopsys.integration.bdio.model.SpdxCreator)2 Bdio2Writer (com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 ProductRunData (com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)2 CustomFieldOperation (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation)2 CustomFieldView (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldView)2 SilentIntLogger (com.synopsys.integration.log.SilentIntLogger)2 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)2 FileOutputStream (java.io.FileOutputStream)2