Search in sources :

Example 1 with ProjectVersionWrapper

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();
}
Also used : ProjectRequestBuilder(com.blackducksoftware.integration.hub.service.model.ProjectRequestBuilder) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)

Example 2 with ProjectVersionWrapper

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;
}
Also used : HubScanConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HubScanConfig(com.blackducksoftware.integration.hub.configuration.HubScanConfig) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)

Example 3 with ProjectVersionWrapper

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;
}
Also used : ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)

Example 4 with 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);
    }
}
Also used : PolicyStatusDescription(com.blackducksoftware.integration.hub.service.model.PolicyStatusDescription) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) DoesNotExistException(com.blackducksoftware.integration.hub.exception.DoesNotExistException) HubTimeoutExceededException(com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ReportService(com.blackducksoftware.integration.hub.service.ReportService) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ScanStatusService(com.blackducksoftware.integration.hub.service.ScanStatusService) HubTimeoutExceededException(com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException) File(java.io.File) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper) HubService(com.blackducksoftware.integration.hub.service.HubService)

Example 5 with ProjectVersionWrapper

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!");
    }
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)

Aggregations

ProjectVersionWrapper (com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)5 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 ProjectRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest)2 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)2 File (java.io.File)2 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)1 HubScanConfig (com.blackducksoftware.integration.hub.configuration.HubScanConfig)1 HubScanConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 DoesNotExistException (com.blackducksoftware.integration.hub.exception.DoesNotExistException)1 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)1 HubTimeoutExceededException (com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException)1 IntegrationRestException (com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException)1 HubService (com.blackducksoftware.integration.hub.service.HubService)1 ReportService (com.blackducksoftware.integration.hub.service.ReportService)1 ScanStatusService (com.blackducksoftware.integration.hub.service.ScanStatusService)1 PolicyStatusDescription (com.blackducksoftware.integration.hub.service.model.PolicyStatusDescription)1 ProjectRequestBuilder (com.blackducksoftware.integration.hub.service.model.ProjectRequestBuilder)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1