refactor: Start removing some complexity of the class.
@@ -138,18 +138,8 @@ public class DetectorTool {
logger.debug("Total number of detectors: " + extractionCount);
logger.debug("Starting detector project discovery.");
- Optional<DetectorType> preferredProjectDetector = Optional.empty();
- if (StringUtils.isNotBlank(projectDetector)) {
- preferredProjectDetector = preferredDetectorTypeFromString(projectDetector);
- }
-
- DetectorNameVersionHandler detectorNameVersionHandler;
- if (preferredProjectDetector.isPresent()) {
- detectorNameVersionHandler = new PreferredDetectorNameVersionHandler(preferredProjectDetector.get());
- } else {
- detectorNameVersionHandler = new DetectorNameVersionHandler(Collections.singletonList(DetectorType.GIT));
- }
+ DetectorNameVersionHandler detectorNameVersionHandler = createNameVersionHandler(projectDetector);
detectorEvaluator.discoveryEvaluation(rootEvaluation, new DetectDiscoveryFilter(eventSystem, detectorNameVersionHandler));
eventSystem.publishEvent(Event.DiscoveriesCompleted, rootEvaluation);
@@ -195,15 +185,7 @@ public class DetectorTool {
codeLocationMap
);
- //Check required detector types
- Set<DetectorType> missingDetectors = requiredDetectors.stream()
- .filter(it -> !applicable.contains(it))
- .collect(Collectors.toSet());
- if (missingDetectors.size() > 0) {
- String missingDetectorDisplay = missingDetectors.stream().map(Enum::toString).collect(Collectors.joining(","));
- logger.error("One or more required detector types were not found: " + missingDetectorDisplay);
- eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_DETECTOR_REQUIRED));
- }
+ handleMissingDetectors(requiredDetectors, applicable);
//Completed.
logger.debug("Finished running detectors.");
@@ -212,6 +194,22 @@ public class DetectorTool {
return detectorToolResult;
}
+ private DetectorNameVersionHandler createNameVersionHandler(String projectDetector) {
+ Optional<DetectorType> preferredProjectDetector = Optional.empty();
+ if (StringUtils.isNotBlank(projectDetector)) {
+ preferredProjectDetector = preferredDetectorTypeFromString(projectDetector);
+ }
+
+ DetectorNameVersionHandler detectorNameVersionHandler;
+ if (preferredProjectDetector.isPresent()) {
+ detectorNameVersionHandler = new PreferredDetectorNameVersionHandler(preferredProjectDetector.get());
+ } else {
+ detectorNameVersionHandler = new DetectorNameVersionHandler(Collections.singletonList(DetectorType.GIT));
+ }
+
+ return detectorNameVersionHandler;
+ }
+
private Map<DetectorType, StatusType> extractStatus(List<DetectorEvaluation> detectorEvaluations) {
Map<DetectorType, StatusType> statusMap = new HashMap<>();
for (DetectorEvaluation detectorEvaluation : detectorEvaluations) {
@@ -263,4 +261,15 @@ public class DetectorTool {
}
return Optional.empty();
}
+
+ private void handleMissingDetectors(List<DetectorType> requiredDetectors, Set<DetectorType> applicable) {
+ Set<DetectorType> missingDetectors = requiredDetectors.stream()
+ .filter(it -> !applicable.contains(it))
+ .collect(Collectors.toSet());
+ if (missingDetectors.size() > 0) {
+ String missingDetectorDisplay = missingDetectors.stream().map(Enum::toString).collect(Collectors.joining(","));
+ logger.error("One or more required detector types were not found: " + missingDetectorDisplay);
+ eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_DETECTOR_REQUIRED));
+ }
+ }
}
