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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
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);
}
Aggregations