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);
}
}
Aggregations