Search in sources :

Example 6 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView 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 7 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-detect by blackducksoftware.

the class HubManager method updateHubProjectVersion.

public ProjectVersionView updateHubProjectVersion(final DetectProject detectProject, final List<File> createdBdioFiles) throws IntegrationException {
    final ProjectService projectService = hubServiceWrapper.createProjectService();
    ProjectVersionView projectVersionView = ensureProjectVersionExists(detectProject, projectService);
    if (null != createdBdioFiles && !createdBdioFiles.isEmpty()) {
        final HubServerConfig hubServerConfig = hubServiceWrapper.getHubServerConfig();
        final CodeLocationService codeLocationService = hubServiceWrapper.createCodeLocationService();
        bdioUploader.uploadBdioFiles(hubServerConfig, codeLocationService, detectProject, createdBdioFiles);
    } else {
        logger.debug("Did not create any bdio files.");
    }
    if (!detectConfiguration.getHubSignatureScannerDisabled()) {
        final HubServerConfig hubServerConfig = hubServiceWrapper.getHubServerConfig();
        final SignatureScannerService signatureScannerService = hubServiceWrapper.createSignatureScannerService();
        final ProjectVersionView scanProject = hubSignatureScanner.scanPaths(hubServerConfig, signatureScannerService, detectProject);
        if (null == projectVersionView) {
            projectVersionView = scanProject;
        }
    }
    return projectVersionView;
}
Also used : CodeLocationService(com.blackducksoftware.integration.hub.service.CodeLocationService) SignatureScannerService(com.blackducksoftware.integration.hub.service.SignatureScannerService) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService)

Example 8 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class BlackDuckFortifyPushThread method getProjectVersionItemsAndMaxBomUpdatedDate.

/**
 * Iterate the hub project versions mapper and get the project version view for each item and calculate the max BOM
 * updated date
 *
 * @param hubProjectVersions
 * @return
 * @throws IllegalArgumentException
 * @throws IntegrationException
 */
private List<ProjectVersionView> getProjectVersionItemsAndMaxBomUpdatedDate(final List<HubProjectVersion> hubProjectVersions) throws IllegalArgumentException, IntegrationException {
    List<ProjectVersionView> projectVersionItems = new ArrayList<>();
    for (HubProjectVersion hubProjectVersion : hubProjectVersions) {
        String projectName = hubProjectVersion.getHubProject();
        String projectVersion = hubProjectVersion.getHubProjectVersion();
        // Get the project version
        final ProjectVersionView projectVersionItem = hubServices.getProjectVersion(projectName, projectVersion);
        projectVersionItems.add(projectVersionItem);
        Date bomUpdatedValueAt = hubServices.getBomLastUpdatedAt(projectVersionItem);
        if (maxBomUpdatedDate == null || bomUpdatedValueAt.after(maxBomUpdatedDate)) {
            maxBomUpdatedDate = bomUpdatedValueAt;
        }
        logger.debug("bomUpdatedValueAt::" + bomUpdatedValueAt);
    }
    return projectVersionItems;
}
Also used : HubProjectVersion(com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 9 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class HubServicesTest method getBomLastUpdatedAt.

@Test
public void getBomLastUpdatedAt() throws IllegalArgumentException, IntegrationException {
    System.out.println("Executing getBomLastUpdatedAt");
    ProjectVersionView projectVersionItem = null;
    try {
        projectVersionItem = hubServices.getProjectVersion(PROJECT_NAME, VERSION_NAME);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IntegrationException e) {
        e.printStackTrace();
    }
    Date bomLastUpdatedAt = hubServices.getBomLastUpdatedAt(projectVersionItem);
    System.out.println("bomLastUpdatedAt::" + bomLastUpdatedAt);
    assertNotNull(bomLastUpdatedAt);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) Date(java.util.Date) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class HubServicesTest method getProjectVersionWithInvalidProjectName.

@Test
public void getProjectVersionWithInvalidProjectName() {
    System.out.println("Executing getProjectVersionWithInvalidProjectName");
    ProjectVersionView projectVersionItem = null;
    try {
        projectVersionItem = hubServices.getProjectVersion("Solr1", VERSION_NAME);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IntegrationException e) {
        // e.printStackTrace();
        System.out.println("Error message::" + e.getMessage());
        assertTrue(e.getMessage().contains("This Project does not exist"));
    }
    assertNull(projectVersionItem);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)12 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)9 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Date (java.util.Date)4 Vulnerability (com.blackducksoftware.integration.fortify.batch.model.Vulnerability)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HubProjectVersion (com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion)2 VulnerableComponentView (com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView)2 JsonIOException (com.google.gson.JsonIOException)2 File (java.io.File)2 ProjectRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest)1 HubScanConfig (com.blackducksoftware.integration.hub.configuration.HubScanConfig)1 HubScanConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder)1 HubServerConfig (com.blackducksoftware.integration.hub.configuration.HubServerConfig)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ExitCodeReporter (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeReporter)1 DetectOption (com.blackducksoftware.integration.hub.detect.help.DetectOption)1 DetectConfigurationPrinter (com.blackducksoftware.integration.hub.detect.help.print.DetectConfigurationPrinter)1