Search in sources :

Example 1 with BomToolType

use of com.blackducksoftware.integration.hub.detect.model.BomToolType in project hub-detect by blackducksoftware.

the class DetectProjectManager method createDetectProject.

public DetectProject createDetectProject() throws IntegrationException {
    final DetectProject detectProject = new DetectProject();
    final EnumSet<BomToolType> applicableBomTools = EnumSet.noneOf(BomToolType.class);
    for (final BomTool bomTool : bomTools) {
        final BomToolType bomToolType = bomTool.getBomToolType();
        final String bomToolTypeString = bomToolType.toString();
        try {
            if (!detectConfiguration.shouldRun(bomTool)) {
                logger.debug(String.format("Skipping %s.", bomToolTypeString));
                continue;
            }
            logger.info(String.format("%s applies given the current configuration.", bomToolTypeString));
            bomToolSummaryResults.put(bomTool.getBomToolType(), Result.FAILURE);
            foundAnyBomTools = true;
            final List<DetectCodeLocation> codeLocations = bomTool.extractDetectCodeLocations(detectProject);
            if (codeLocations != null && codeLocations.size() > 0) {
                bomToolSummaryResults.put(bomTool.getBomToolType(), Result.SUCCESS);
                detectProject.addAllDetectCodeLocations(codeLocations);
                applicableBomTools.add(bomToolType);
            } else {
                logger.error(String.format("Did not find any projects from %s even though it applied.", bomToolTypeString));
            }
        } catch (final Exception e) {
            // any bom tool failure should not prevent other bom tools from running
            logger.error(String.format("%s threw an Exception: %s", bomToolTypeString, e.getMessage()));
            // log the stacktrace if and only if running at trace level
            if (logger.isTraceEnabled()) {
                logger.error("Exception details: ", e);
            }
        }
    }
    // we've gone through all applicable bom tools so we now have the
    // complete metadata to phone home
    detectPhoneHomeManager.startPhoneHome(applicableBomTools);
    final String prefix = detectConfiguration.getProjectCodeLocationPrefix();
    final String suffix = detectConfiguration.getProjectCodeLocationSuffix();
    // ensure that the project name is set, use some reasonable defaults
    detectProject.setProjectDetails(getProjectName(detectProject.getProjectName()), getProjectVersionName(detectProject.getProjectVersionName()), prefix, suffix);
    if (!foundAnyBomTools) {
        logger.info(String.format("No package managers were detected - will register %s for signature scanning of %s/%s", detectConfiguration.getSourcePath(), detectProject.getProjectName(), detectProject.getProjectVersionName()));
        hubSignatureScanner.registerPathToScan(ScanPathSource.DETECT_SOURCE, detectConfiguration.getSourceDirectory());
    } else if (detectConfiguration.getHubSignatureScannerSnippetMode()) {
        logger.info(String.format("Snippet mode is enabled - will register %s for signature scanning of %s/%s", detectConfiguration.getSourcePath(), detectProject.getProjectName(), detectProject.getProjectVersionName()));
        hubSignatureScanner.registerPathToScan(ScanPathSource.SNIPPET_SOURCE, detectConfiguration.getSourceDirectory());
    }
    if (StringUtils.isBlank(detectConfiguration.getAggregateBomName())) {
        detectProject.processDetectCodeLocations(logger, detectFileManager, bdioFileNamer, codeLocationNameService);
        for (final BomToolType bomToolType : detectProject.getFailedBomTools()) {
            bomToolSummaryResults.put(bomToolType, Result.FAILURE);
        }
    }
    return detectProject;
}
Also used : DetectProject(com.blackducksoftware.integration.hub.detect.model.DetectProject) BomTool(com.blackducksoftware.integration.hub.detect.bomtool.BomTool) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation) BomToolType(com.blackducksoftware.integration.hub.detect.model.BomToolType) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IOException(java.io.IOException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 BomTool (com.blackducksoftware.integration.hub.detect.bomtool.BomTool)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 BomToolType (com.blackducksoftware.integration.hub.detect.model.BomToolType)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation)1 DetectProject (com.blackducksoftware.integration.hub.detect.model.DetectProject)1 IOException (java.io.IOException)1