use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project synopsys-detect by blackducksoftware.
the class RapidScanUploadService method uploadFiles.
private HttpUrl uploadFiles(UploadTarget uploadTarget, List<BdioFileContent> bdioFiles, RapidScanOptions rapidScanOptions, @Nullable NameVersion nameVersion, @Nullable File rapidScanConfig, @Nullable File rapidScanWorkingDirectory) throws IntegrationException, IOException {
if (bdioFiles.isEmpty()) {
throw new IllegalArgumentException("BDIO files cannot be empty.");
}
BdioFileContent header = bdioFiles.stream().filter(content -> content.getFileName().equals(FILE_NAME_BDIO_HEADER_JSONLD)).findFirst().orElseThrow(() -> new BlackDuckIntegrationException("Cannot find BDIO header file" + FILE_NAME_BDIO_HEADER_JSONLD + "."));
List<BdioFileContent> remainingFiles = bdioFiles.stream().filter(content -> !content.getFileName().equals(FILE_NAME_BDIO_HEADER_JSONLD)).collect(Collectors.toList());
int count = remainingFiles.size();
logger.debug("BDIO upload file count = " + count);
BlackDuckRequestBuilderEditor editor = builder -> {
builder.addHeader(RapidCompareMode.HEADER_NAME, rapidScanOptions.getCompareMode().getHeaderValue());
if (nameVersion != null) {
builder.addHeader(Bdio2StreamUploader.PROJECT_NAME_HEADER, nameVersion.getName()).addHeader(Bdio2StreamUploader.VERSION_NAME_HEADER, nameVersion.getVersion());
}
};
HttpUrl url;
if (rapidScanConfig != null) {
url = bdio2Uploader.startWithConfig(zip(uploadTarget, rapidScanConfig, header, rapidScanWorkingDirectory), editor);
} else {
url = bdio2Uploader.start(header, editor);
}
for (BdioFileContent content : remainingFiles) {
bdio2Uploader.append(url, count, content, editor);
}
bdio2Uploader.finish(url, count, editor);
return url;
}
use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project synopsys-detect by blackducksoftware.
the class ReportService method createReportPdfFile.
public File createReportPdfFile(File outputDirectory, ReportData reportData, FontLoader fontLoader, FontLoader boldFontLoader) throws BlackDuckIntegrationException {
try {
logger.trace("Creating Risk Report Pdf in : " + outputDirectory.getCanonicalPath());
RiskReportPdfWriter writer = new RiskReportPdfWriter(logger, fontLoader, boldFontLoader, Color.BLACK, 10.0f);
File pdfFile = writer.createPDFReportFile(outputDirectory, reportData);
logger.trace("Created Risk Report Pdf : " + pdfFile.getCanonicalPath());
return pdfFile;
} catch (RiskReportException | IOException e) {
throw new BlackDuckIntegrationException(e.getMessage(), e);
}
}
use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project synopsys-detect by blackducksoftware.
the class ReportService method isReportFinishedGenerating.
/**
* Checks the report URL every 5 seconds until the report has a finished time available, then we know it is done being generated. Throws BlackDuckIntegrationException after 30 minutes if the report has not been generated yet.
*/
public ProjectVersionReportView isReportFinishedGenerating(HttpUrl reportUrl) throws InterruptedException, IntegrationException {
long startTime = System.currentTimeMillis();
long elapsedTime = 0;
Date timeFinished = null;
ProjectVersionReportView reportInfo = null;
while (timeFinished == null) {
reportInfo = blackDuckApiClient.getResponse(reportUrl, ProjectVersionReportView.class);
timeFinished = reportInfo.getFinishedAt();
if (timeFinished != null) {
break;
}
if (elapsedTime >= timeoutInMilliseconds) {
String formattedTime = String.format("%d minutes", TimeUnit.MILLISECONDS.toMinutes(timeoutInMilliseconds));
throw new BlackDuckIntegrationException("The Report has not finished generating in : " + formattedTime);
}
// Retry every 5 seconds
Thread.sleep(5000);
elapsedTime = System.currentTimeMillis() - startTime;
}
return reportInfo;
}
use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project synopsys-detect by blackducksoftware.
the class ReportService method generateBlackDuckNoticesReport.
/**
* Assumes the BOM has already been updated
*/
public String generateBlackDuckNoticesReport(ProjectVersionView version, ReportFormatType reportFormat) throws InterruptedException, IntegrationException {
if (version.hasLink(ProjectVersionView.LICENSE_REPORTS_LINK)) {
try {
logger.debug("Starting the Notices Report generation.");
HttpUrl reportUrl = startGeneratingBlackDuckNoticesReport(version, reportFormat);
logger.debug("Waiting for the Notices Report to complete.");
ProjectVersionReportView reportInfo = isReportFinishedGenerating(reportUrl);
HttpUrl contentUrl = reportInfo.getFirstLink(ReportView.CONTENT_LINK);
if (contentUrl == null) {
throw new BlackDuckIntegrationException("Could not find content link for the report at : " + reportUrl);
}
logger.debug("Getting the Notices Report content.");
String noticesReport = getNoticesReportContent(contentUrl);
logger.debug("Finished retrieving the Notices Report.");
logger.debug("Cleaning up the Notices Report on the server.");
deleteBlackDuckReport(reportUrl);
return noticesReport;
} catch (IntegrationRestException e) {
if (e.getHttpStatusCode() == 402) {
// unlike the policy module, the licenseReports link is still present when the module is not enabled
logger.warn("Can not create the notice report, the Black Duck notice module is not enabled.");
} else {
throw e;
}
}
} else {
logger.warn("Can not create the notice report, the Black Duck notice module is not enabled.");
}
return null;
}
use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project synopsys-detect by blackducksoftware.
the class ReportService method createNoticesReportFile.
private File createNoticesReportFile(File outputDirectory, String noticesReportContent, String projectName, String projectVersionName) throws BlackDuckIntegrationException {
if (noticesReportContent == null) {
return null;
}
String escapedProjectName = escapeUtil.replaceWithUnderscore(projectName);
String escapedProjectVersionName = escapeUtil.replaceWithUnderscore(projectVersionName);
File noticesReportFile = new File(outputDirectory, escapedProjectName + "_" + escapedProjectVersionName + "_Black_Duck_Notices_Report.txt");
if (noticesReportFile.exists()) {
boolean deleted = noticesReportFile.delete();
if (!deleted) {
logger.warn(String.format("Unable to delete existing file %s before re-creating it", noticesReportFile.getAbsolutePath()));
}
}
try (FileWriter writer = new FileWriter(noticesReportFile)) {
logger.trace("Creating Notices Report in : " + outputDirectory.getCanonicalPath());
writer.write(noticesReportContent);
logger.trace("Created Notices Report : " + noticesReportFile.getCanonicalPath());
return noticesReportFile;
} catch (IOException e) {
throw new BlackDuckIntegrationException(e.getMessage(), e);
}
}
Aggregations