Search in sources :

Example 1 with DetectProject

use of com.blackducksoftware.integration.hub.detect.model.DetectProject 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)

Example 2 with DetectProject

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

the class Application method init.

@PostConstruct
public void init() {
    final long start = System.currentTimeMillis();
    try {
        detectInfo.init();
        detectOptionManager.init();
        final List<DetectOption> options = detectOptionManager.getDetectOptions();
        boolean isPrintHelp = false;
        boolean isPrintHelpDoc = false;
        boolean isInteractive = false;
        for (final String arg : applicationArguments.getSourceArgs()) {
            if (arg.equals("-h") || arg.equals("--help")) {
                isPrintHelp = true;
            } else if (arg.equals("-hdoc") || arg.equals("--helpdocument")) {
                isPrintHelpDoc = true;
            } else if (arg.equals("-i") || arg.equals("--interactive")) {
                isInteractive = true;
            }
        }
        if (isPrintHelp) {
            helpPrinter.printHelpMessage(System.out, options);
            return;
        }
        if (isPrintHelpDoc) {
            helpHtmlWriter.writeHelpMessage(String.format("hub-detect-%s-help.html", detectInfo.getDetectVersion()));
            return;
        }
        if (isInteractive) {
            final InteractiveReader interactiveReader = createInteractiveReader();
            final PrintStream interactivePrintStream = new PrintStream(System.out);
            interactiveManager.interact(interactiveReader, interactivePrintStream);
        }
        detectConfiguration.init();
        logger.info("Configuration processed completely.");
        if (!detectConfiguration.getSuppressConfigurationOutput()) {
            final DetectInfoPrinter infoPrinter = new DetectInfoPrinter();
            final DetectConfigurationPrinter detectConfigurationPrinter = new DetectConfigurationPrinter();
            infoPrinter.printInfo(System.out, detectInfo);
            detectConfigurationPrinter.print(System.out, detectInfo, detectConfiguration, options);
        }
        if (detectConfiguration.getTestConnection()) {
            hubServiceWrapper.assertHubConnection(new SilentLogger());
            return;
        }
        if (!detectConfiguration.getHubOfflineMode()) {
            hubServiceWrapper.init();
        }
        final DetectProject detectProject = detectProjectManager.createDetectProject();
        final List<File> createdBdioFiles = detectProjectManager.createBdioFiles(detectProject);
        if (!detectConfiguration.getHubOfflineMode()) {
            final ProjectVersionView projectVersionView = hubManager.updateHubProjectVersion(detectProject, createdBdioFiles);
            hubManager.performPostHubActions(detectProject, projectVersionView);
        } else if (!detectConfiguration.getHubSignatureScannerDisabled()) {
            hubSignatureScanner.scanPathsOffline(detectProject);
        }
        for (final ExitCodeReporter exitCodeReporter : exitCodeReporters) {
            exitCodeType = ExitCodeType.getWinningExitCodeType(exitCodeType, exitCodeReporter.getExitCodeType());
        }
    } catch (final Exception e) {
        populateExitCodeFromExceptionDetails(e);
    } finally {
        try {
            detectPhoneHomeManager.endPhoneHome();
        } catch (final Exception e) {
            logger.debug(String.format("Error trying to end the phone home task: %s", e.getMessage()));
        }
        if (!detectConfiguration.getSuppressResultsOutput()) {
            detectSummary.logResults(new Slf4jIntLogger(logger), exitCodeType);
        }
        detectFileManager.cleanupDirectories();
    }
    final long end = System.currentTimeMillis();
    logger.info(String.format("Hub-Detect run duration: %s", DurationFormatUtils.formatPeriod(start, end, "HH'h' mm'm' ss's' SSS'ms'")));
    if (detectConfiguration.getForceSuccess() && exitCodeType.getExitCode() != 0) {
        logger.warn("Forcing success: Exiting with 0. Desired exit code was ${exitCodeType.getExitCode()}.");
        System.exit(0);
    } else {
        System.exit(exitCodeType.getExitCode());
    }
}
Also used : PrintStream(java.io.PrintStream) InteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.InteractiveReader) ScannerInteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.ScannerInteractiveReader) ConsoleInteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.ConsoleInteractiveReader) DetectInfoPrinter(com.blackducksoftware.integration.hub.detect.help.print.DetectInfoPrinter) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) DetectOption(com.blackducksoftware.integration.hub.detect.help.DetectOption) DetectProject(com.blackducksoftware.integration.hub.detect.model.DetectProject) ExitCodeReporter(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeReporter) DetectConfigurationPrinter(com.blackducksoftware.integration.hub.detect.help.print.DetectConfigurationPrinter) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) SilentLogger(com.blackducksoftware.integration.log.SilentLogger) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) File(java.io.File) PostConstruct(javax.annotation.PostConstruct)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)2 DetectProject (com.blackducksoftware.integration.hub.detect.model.DetectProject)2 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)1 BomTool (com.blackducksoftware.integration.hub.detect.bomtool.BomTool)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 DetectInfoPrinter (com.blackducksoftware.integration.hub.detect.help.print.DetectInfoPrinter)1 ConsoleInteractiveReader (com.blackducksoftware.integration.hub.detect.interactive.reader.ConsoleInteractiveReader)1 InteractiveReader (com.blackducksoftware.integration.hub.detect.interactive.reader.InteractiveReader)1 ScannerInteractiveReader (com.blackducksoftware.integration.hub.detect.interactive.reader.ScannerInteractiveReader)1 BomToolType (com.blackducksoftware.integration.hub.detect.model.BomToolType)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation)1 SilentLogger (com.blackducksoftware.integration.log.SilentLogger)1 Slf4jIntLogger (com.blackducksoftware.integration.log.Slf4jIntLogger)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 PostConstruct (javax.annotation.PostConstruct)1