use of com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper in project hub-detect by blackducksoftware.
the class HubManager method ensureProjectVersionExists.
public ProjectVersionView ensureProjectVersionExists(final DetectProject detectProject, final ProjectService projectService) throws IntegrationException {
final ProjectRequestBuilder builder = new ProjectRequestBuilder();
builder.setProjectName(detectProject.getProjectName());
builder.setVersionName(detectProject.getProjectVersionName());
builder.setProjectLevelAdjustments(detectConfiguration.getProjectLevelMatchAdjustments());
builder.setPhase(detectConfiguration.getProjectVersionPhase());
builder.setDistribution(detectConfiguration.getProjectVersionDistribution());
builder.setProjectTier(detectConfiguration.getProjectTier());
builder.setReleaseComments(detectConfiguration.getProjectVersionNotes());
final ProjectRequest projectRequest = builder.build();
final ProjectVersionWrapper projectVersionWrapper = projectService.getProjectVersionAndCreateIfNeeded(projectRequest);
return projectVersionWrapper.getProjectVersionView();
}
use of com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper in project hub-detect by blackducksoftware.
the class HubSignatureScanner method scanPaths.
public ProjectVersionView scanPaths(final HubServerConfig hubServerConfig, final SignatureScannerService signatureScannerService, final DetectProject detectProject) throws IntegrationException {
ProjectVersionView projectVersionView = null;
final ProjectRequest projectRequest = createProjectRequest(detectProject);
Set<String> canonicalPathsToScan = registeredPaths;
if (null != detectProject.getProjectName() && null != detectProject.getProjectVersionName() && null != detectConfiguration.getHubSignatureScannerPaths() && detectConfiguration.getHubSignatureScannerPaths().length > 0) {
canonicalPathsToScan = new HashSet<>();
for (final String path : detectConfiguration.getHubSignatureScannerPaths()) {
try {
canonicalPathsToScan.add(new File(path).getCanonicalPath());
} catch (final IOException e) {
throw new IntegrationException(e.getMessage(), e);
}
}
}
final List<ScanPathCallable> scanPathCallables = new ArrayList<>();
for (final String canonicalPath : canonicalPathsToScan) {
final HubScanConfigBuilder hubScanConfigBuilder = createScanConfigBuilder(detectProject, canonicalPath);
final HubScanConfig hubScanConfig = hubScanConfigBuilder.build();
final ScanPathCallable scanPathCallable = new ScanPathCallable(signatureScannerService, hubServerConfig, hubScanConfig, projectRequest, canonicalPath, scanSummaryResults);
scanPathCallables.add(scanPathCallable);
}
final ExecutorService pool = Executors.newFixedThreadPool(detectConfiguration.getHubSignatureScannerParallelProcessors());
try {
for (final ScanPathCallable scanPathCallable : scanPathCallables) {
pool.submit(scanPathCallable);
}
for (final ScanPathCallable scanPathCallable : scanPathCallables) {
final ProjectVersionWrapper projectVersionWrapperFromScan = scanPathCallable.call();
if (projectVersionWrapperFromScan != null) {
projectVersionView = projectVersionWrapperFromScan.getProjectVersionView();
}
}
} finally {
// get() was called on every java.util.concurrent.Future, no need to wait any longer
pool.shutdownNow();
}
return projectVersionView;
}
use of com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper in project hub-detect by blackducksoftware.
the class ScanPathCallable method call.
@Override
public ProjectVersionWrapper call() {
ProjectVersionWrapper projectVersionWrapper = null;
try {
logger.info(String.format("Attempting to scan %s for %s/%s", canonicalPath, projectRequest.name, projectRequest.versionRequest.versionName));
projectVersionWrapper = signatureScannerService.installAndRunControlledScan(hubServerConfig, hubScanConfig, projectRequest, false);
scanSummaryResults.put(canonicalPath, Result.SUCCESS);
logger.info(String.format("%s was successfully scanned by the BlackDuck CLI.", canonicalPath));
} catch (final Exception e) {
logger.error(String.format("%s/%s - %s was not scanned by the BlackDuck CLI: %s", projectRequest.name, projectRequest.versionRequest.versionName, canonicalPath, e.getMessage()));
return null;
}
return projectVersionWrapper;
}
use of com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper in project hub-detect by blackducksoftware.
the class HubManager method performPostHubActions.
public void performPostHubActions(final DetectProject detectProject, final ProjectVersionView projectVersionView) throws DetectUserFriendlyException {
try {
if (detectConfiguration.getPolicyCheck() || detectConfiguration.getRiskReportPdf() || detectConfiguration.getNoticesReport()) {
final ProjectService projectService = hubServiceWrapper.createProjectService();
final ScanStatusService scanStatusService = hubServiceWrapper.createScanStatusService();
waitForBomUpdate(hubServiceWrapper.createHubService(), scanStatusService, projectVersionView);
if (detectConfiguration.getPolicyCheck()) {
final PolicyStatusDescription policyStatusDescription = policyChecker.getPolicyStatus(projectService, projectVersionView);
logger.info(policyStatusDescription.getPolicyStatusMessage());
if (policyChecker.policyViolated(policyStatusDescription)) {
exitCodeType = ExitCodeType.FAILURE_POLICY_VIOLATION;
}
}
if (detectConfiguration.getRiskReportPdf()) {
final ReportService reportService = hubServiceWrapper.createReportService();
logger.info("Creating risk report pdf");
final File pdfFile = reportService.createReportPdfFile(new File(detectConfiguration.getRiskReportPdfOutputDirectory()), detectProject.getProjectName(), detectProject.getProjectVersionName());
logger.info(String.format("Created risk report pdf : %s", pdfFile.getCanonicalPath()));
}
if (detectConfiguration.getNoticesReport()) {
final ReportService reportService = hubServiceWrapper.createReportService();
logger.info("Creating notices report");
final File noticesFile = reportService.createNoticesReportFile(new File(detectConfiguration.getNoticesReportOutputDirectory()), detectProject.getProjectName(), detectProject.getProjectVersionName());
if (noticesFile != null) {
logger.info(String.format("Created notices report : %s", noticesFile.getCanonicalPath()));
}
}
}
if (null != detectProject.getDetectCodeLocations() && !detectProject.getDetectCodeLocations().isEmpty() && !detectConfiguration.getHubSignatureScannerDisabled()) {
// only log BOM URL if we have updated it in some way
final ProjectService projectService = hubServiceWrapper.createProjectService();
final HubService hubService = hubServiceWrapper.createHubService();
final ProjectVersionWrapper projectVersionWrapper = projectService.getProjectVersion(detectProject.getProjectName(), detectProject.getProjectVersionName());
final String componentsLink = hubService.getFirstLinkSafely(projectVersionWrapper.getProjectVersionView(), ProjectVersionView.COMPONENTS_LINK);
logger.info(String.format("To see your results, follow the URL: %s", componentsLink));
} else {
logger.debug("Found no code locations and did not run a scan.");
}
} catch (final IllegalStateException e) {
throw new DetectUserFriendlyException(String.format("Your Hub configuration is not valid: %s", e.getMessage()), e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
} catch (final IntegrationRestException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
} catch (final HubTimeoutExceededException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_TIMEOUT);
} catch (final Exception e) {
throw new DetectUserFriendlyException(String.format("There was a problem: %s", e.getMessage()), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
use of com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper in project hub-fortify-ssc-integration-service by blackducksoftware.
the class HubServices method getProjectVersion.
/**
* Get the Hub project version information
*
* @param projectName
* @param versionName
* @return
* @throws IllegalArgumentException
* @throws IntegrationException
*/
public ProjectVersionView getProjectVersion(final String projectName, final String projectVersionName) throws IllegalArgumentException, IntegrationException {
logger.info("Getting Hub project and project version info for::" + projectName + ", " + projectVersionName);
final ProjectService projectVersionRequestService = hubServicesFactory.createProjectService();
final ProjectVersionWrapper projectVersionWrapper = projectVersionRequestService.getProjectVersion(projectName, projectVersionName);
if (projectVersionWrapper != null && projectVersionWrapper.getProjectVersionView() != null) {
logger.debug("ProjectVersionView::" + projectVersionWrapper.getProjectVersionView().json);
return projectVersionWrapper.getProjectVersionView();
} else {
throw new IntegrationException("Project Version does not Exists!");
}
}
Aggregations