Search in sources :

Example 1 with RequiredDetectorChecker

use of com.blackducksoftware.integration.hub.detect.workflow.detector.RequiredDetectorChecker in project hub-detect by blackducksoftware.

the class ShutdownManager method shutdown.

public void shutdown(Optional<RunResult> runResultOptional) {
    if (connectivityManager.getPhoneHomeManager().isPresent()) {
        try {
            logger.debug("Ending phone home.");
            connectivityManager.getPhoneHomeManager().get().endPhoneHome();
        } catch (final Exception e) {
            logger.debug(String.format("Error trying to end the phone home task: %s", e.getMessage()));
        }
    }
    try {
        if (diagnosticManager.getDiagnosticSystem().isPresent()) {
            logger.debug("Ending diagnostics.");
            diagnosticManager.getDiagnosticSystem().get().finish();
        }
    } catch (final Exception e) {
        logger.debug(String.format("Error trying to finish diagnostics: %s", e.getMessage()));
    }
    try {
        if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_CLEANUP, PropertyAuthority.None)) {
            logger.info("Detect will cleanup.");
            boolean dryRun = detectConfiguration.getBooleanProperty(DetectProperty.DETECT_BLACKDUCK_SIGNATURE_SCANNER_DRY_RUN, PropertyAuthority.None);
            boolean offline = !connectivityManager.isDetectOnline();
            List<File> cleanupToSkip = new ArrayList<>();
            if (dryRun || offline) {
                logger.debug("Will not cleanup scan folder.");
                cleanupToSkip.add(directoryManager.getScanOutputDirectory());
            }
            if (offline) {
                logger.debug("Will not cleanup bdio folder.");
                cleanupToSkip.add(directoryManager.getBdioOutputDirectory());
            }
            logger.debug("Cleaning up directory: " + directoryManager.getRunHomeDirectory().getAbsolutePath());
            cleanup(directoryManager.getRunHomeDirectory(), cleanupToSkip);
        } else {
            logger.info("Skipping cleanup, it is disabled.");
        }
    } catch (final Exception e) {
        logger.debug(String.format("Error trying cleanup: %s", e.getMessage()));
    }
    Set<DetectorType> detectorTypes = new HashSet<>();
    if (runResultOptional.isPresent()) {
        detectorTypes.addAll(runResultOptional.get().getApplicableDetectors());
    }
    // Check required detector types
    String requiredDetectors = detectConfiguration.getProperty(DetectProperty.DETECT_REQUIRED_DETECTOR_TYPES, PropertyAuthority.None);
    RequiredDetectorChecker requiredDetectorChecker = new RequiredDetectorChecker();
    RequiredDetectorChecker.RequiredDetectorResult requiredDetectorResult = requiredDetectorChecker.checkForMissingDetectors(requiredDetectors, detectorTypes);
    if (requiredDetectorResult.wereDetectorsMissing()) {
        String missingDetectors = requiredDetectorResult.getMissingDetectors().stream().map(it -> it.toString()).collect(Collectors.joining(","));
        logger.error("One or more required detector types were not found: " + missingDetectors);
        exitCodeManager.requestExitCode(ExitCodeType.FAILURE_DETECTOR_REQUIRED);
    }
}
Also used : DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) ConnectivityManager(com.blackducksoftware.integration.hub.detect.workflow.ConnectivityManager) File(java.io.File) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiagnosticManager(com.blackducksoftware.integration.hub.detect.workflow.diagnostic.DiagnosticManager) List(java.util.List) ExitCodeType(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType) PropertyAuthority(com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) Optional(java.util.Optional) RunResult(com.blackducksoftware.integration.hub.detect.lifecycle.run.RunResult) DetectStatusManager(com.blackducksoftware.integration.hub.detect.workflow.status.DetectStatusManager) RequiredDetectorChecker(com.blackducksoftware.integration.hub.detect.workflow.detector.RequiredDetectorChecker) ReportManager(com.blackducksoftware.integration.hub.detect.workflow.report.ReportManager) DetectProperty(com.blackducksoftware.integration.hub.detect.configuration.DetectProperty) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) ArrayList(java.util.ArrayList) RequiredDetectorChecker(com.blackducksoftware.integration.hub.detect.workflow.detector.RequiredDetectorChecker) File(java.io.File) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)1 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)1 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)1 DetectorType (com.blackducksoftware.integration.hub.detect.detector.DetectorType)1 ExitCodeType (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType)1 RunResult (com.blackducksoftware.integration.hub.detect.lifecycle.run.RunResult)1 ConnectivityManager (com.blackducksoftware.integration.hub.detect.workflow.ConnectivityManager)1 RequiredDetectorChecker (com.blackducksoftware.integration.hub.detect.workflow.detector.RequiredDetectorChecker)1 DiagnosticManager (com.blackducksoftware.integration.hub.detect.workflow.diagnostic.DiagnosticManager)1 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)1 ReportManager (com.blackducksoftware.integration.hub.detect.workflow.report.ReportManager)1 DetectStatusManager (com.blackducksoftware.integration.hub.detect.workflow.status.DetectStatusManager)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1