use of com.blackducksoftware.integration.hub.detect.detector.DetectorType 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);
}
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class ExtractionManager method performExtractions.
public ExtractionResult performExtractions(final List<DetectorEvaluation> results) {
final List<DetectorEvaluation> extractable = results.stream().filter(result -> result.isExtractable()).collect(Collectors.toList());
for (int i = 0; i < extractable.size(); i++) {
final DetectorEvaluation detectorEvaluation = extractable.get(i);
final String progress = Integer.toString((int) Math.floor((i * 100.0f) / extractable.size()));
logger.info(String.format("Extracting %d of %d (%s%%)", i + 1, extractable.size(), progress));
logger.info(ReportConstants.SEPERATOR);
final ExtractionId extractionId = new ExtractionId(detectorEvaluation.getDetector().getDetectorType(), Integer.toString(i));
detectorEvaluation.setExtractionId(extractionId);
extract(extractable.get(i));
}
final Set<DetectorType> succesfulBomToolGroups = extractable.stream().filter(it -> it.wasExtractionSuccessful()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
final Set<DetectorType> failedBomToolGroups = extractable.stream().filter(it -> !it.wasExtractionSuccessful()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
final List<DetectCodeLocation> codeLocations = extractable.stream().filter(it -> it.wasExtractionSuccessful()).flatMap(it -> it.getExtraction().codeLocations.stream()).collect(Collectors.toList());
return new ExtractionResult(codeLocations, succesfulBomToolGroups, failedBomToolGroups);
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class DetectorEvaluationNameVersionDecider method decideSuggestion.
public Optional<NameVersion> decideSuggestion(final List<DetectorEvaluation> detectorEvaluations, String projectDetector) {
DetectorType preferredDetectorType = null;
if (StringUtils.isNotBlank(projectDetector)) {
final String projectDetectorFixed = projectDetector.toUpperCase();
if (!DetectorType.POSSIBLE_NAMES.contains(projectDetectorFixed)) {
logger.info("A valid preferred detector type was not provided, deciding project name automatically.");
} else {
preferredDetectorType = DetectorType.valueOf(projectDetectorFixed);
}
}
final List<DetectorProjectInfo> detectorProjectInfo = transformIntoProjectInfo(detectorEvaluations);
return detectorNameVersionDecider.decideProjectNameVersion(detectorProjectInfo, preferredDetectorType);
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class DetectorNameVersionDecider method decideProjectNameVersionFromDetector.
private NameVersionDecision decideProjectNameVersionFromDetector(final List<DetectorProjectInfo> projectNamePossibilities, final DetectorType preferredBomToolType) {
final NameVersionDecision decision;
if (preferredBomToolType != null) {
final List<DetectorProjectInfo> possiblePreferred = projectNamePossibilities.stream().filter(it -> it.getDetectorType() == preferredBomToolType).collect(Collectors.toList());
final List<DetectorProjectInfo> lowestDepthPossibilities = projectNamesAtLowestDepth(possiblePreferred);
if (lowestDepthPossibilities.size() == 0) {
decision = new PreferredDetectorNotFoundDecision(preferredBomToolType);
} else if (lowestDepthPossibilities.size() == 1) {
decision = new PreferredDetectorDecision(lowestDepthPossibilities.get(0));
} else {
decision = new TooManyPreferredDetectorTypesFoundDecision(preferredBomToolType);
}
} else {
final List<DetectorProjectInfo> lowestDepthPossibilities = projectNamesAtLowestDepth(projectNamePossibilities);
final Map<DetectorType, Long> lowestDepthTypeCounts = lowestDepthPossibilities.stream().collect(Collectors.groupingBy(it -> it.getDetectorType(), Collectors.counting()));
final List<DetectorType> singleInstanceLowestDepthBomTools = lowestDepthTypeCounts.entrySet().stream().filter(it -> it.getValue() == 1).map(it -> it.getKey()).collect(Collectors.toList());
if (singleInstanceLowestDepthBomTools.size() == 1) {
final DetectorType type = singleInstanceLowestDepthBomTools.get(0);
final Optional<DetectorProjectInfo> chosen = lowestDepthPossibilities.stream().filter(it -> it.getDetectorType() == type).findFirst();
if (chosen.isPresent()) {
decision = new UniqueDetectorDecision(chosen.get());
} else {
decision = new UniqueDetectorNotFoundDecision();
}
} else if (singleInstanceLowestDepthBomTools.size() > 1) {
decision = decideProjectNameVersionArbitrarily(lowestDepthPossibilities, singleInstanceLowestDepthBomTools);
} else {
decision = new UniqueDetectorNotFoundDecision();
}
}
return decision;
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class PreparationManager method prepareExtractions.
public PreparationResult prepareExtractions(final List<DetectorEvaluation> results) {
for (final DetectorEvaluation result : results) {
prepare(result);
}
final Set<DetectorType> succesfulBomToolGroups = results.stream().filter(it -> it.isApplicable()).filter(it -> it.isExtractable()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
final Set<DetectorType> failedBomToolGroups = results.stream().filter(it -> it.isApplicable()).filter(it -> !it.isExtractable()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
return new PreparationResult(succesfulBomToolGroups, failedBomToolGroups, results);
}
Aggregations