use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class DetectorSearchEvaluator method searchable.
public DetectorResult searchable(final DetectorSearchRule searchRules, final List<Detector> appliedSoFar, DetectorEnvironment environment) {
Detector detector = searchRules.getDetector();
final DetectorType detectorType = detector.getDetectorType();
if (!environment.getDetectorFilter().shouldInclude(detectorType.toString())) {
return new ExcludedDetectorResult();
}
final int maxDepth = searchRules.getMaxDepth();
if (environment.getDepth() > maxDepth) {
return new MaxDepthExceededDetectorResult(environment.getDepth(), maxDepth);
}
final Set<Detector> yieldTo = appliedSoFar.stream().filter(it -> searchRules.getYieldsTo().contains(it)).collect(Collectors.toSet());
if (yieldTo.size() > 0) {
return new YieldedDetectorResult(yieldTo);
}
final boolean nestable = searchRules.isNestable();
if (environment.getForceNestedSearch()) {
return new ForcedNestedPassedDetectorResult();
} else if (nestable) {
if (environment.getAppliedToParent().stream().anyMatch(applied -> applied.isSame(detector))) {
return new NotSelfNestableDetectorResult();
}
} else if (!nestable && environment.getAppliedToParent().size() > 0) {
return new NotNestableDetectorResult();
}
return new PassedDetectorResult();
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class DetectorFinder method findApplicableBomTools.
private List<DetectorEvaluation> findApplicableBomTools(final List<File> directoriesToSearch, final Set<Detector> appliedBefore, final int depth, final DetectorFinderOptions options) throws DetectorException, DetectUserFriendlyException {
final List<DetectorEvaluation> results = new ArrayList<>();
if (depth > options.getMaximumDepth()) {
return results;
}
if (null == directoriesToSearch || directoriesToSearch.size() == 0) {
return results;
}
for (final File directory : directoriesToSearch) {
if (depth > 0 && options.getDetectorSearchFilter().shouldExclude(directory)) {
// NEVER skip at depth 0.
logger.info("Skipping excluded directory: " + directory.getPath());
continue;
}
logger.info("Searching directory: " + directory.getPath());
final Set<DetectorType> applicableTypes = new HashSet<>();
final Set<Detector> applied = new HashSet<>();
final List<DetectorEvaluation> evaluations = processDirectory(directory, appliedBefore, depth, options);
results.addAll(evaluations);
final List<Detector> appliedBomTools = evaluations.stream().filter(it -> it.isApplicable()).map(it -> it.getDetector()).collect(Collectors.toList());
applied.addAll(appliedBomTools);
// TODO: Used to have a remaining detectors and would bail early here, not sure how to go about that?
final Set<Detector> everApplied = new HashSet<>();
everApplied.addAll(applied);
everApplied.addAll(appliedBefore);
final List<File> subdirectories = getSubDirectories(directory, options.getDetectorSearchFilter());
final List<DetectorEvaluation> recursiveResults = findApplicableBomTools(subdirectories, everApplied, depth + 1, options);
results.addAll(recursiveResults);
logger.debug(directory + ": " + applicableTypes.stream().map(it -> it.toString()).collect(Collectors.joining(", ")));
}
return results;
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class BomToolProfiler method addAggregateByBomToolGroupType.
private void addAggregateByBomToolGroupType(final Map<DetectorType, Long> aggregate, final List<DetectorTime> detectorTimes) {
for (final DetectorTime detectorTime : detectorTimes) {
final DetectorType type = detectorTime.getDetector().getDetectorType();
if (!aggregate.containsKey(type)) {
aggregate.put(type, 0L);
}
final long time = detectorTime.getMs();
final Long currentTime = aggregate.get(type);
final Long sum = time + currentTime;
aggregate.put(type, sum);
}
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class DetectorManager method runDetectors.
public DetectorToolResult runDetectors() throws DetectUserFriendlyException {
List<DetectorEvaluation> detectorEvaluations = new ArrayList<>();
// search
SearchResult searchResult = searchManager.performSearch();
eventSystem.publishEvent(Event.SearchCompleted, searchResult);
detectorEvaluations.addAll(searchResult.getDetectorEvaluations());
// prepare
PreparationResult preparationResult = preparationManager.prepareExtractions(detectorEvaluations);
eventSystem.publishEvent(Event.PreparationsCompleted, preparationResult);
// extract
ExtractionResult extractionResult = extractionManager.performExtractions(detectorEvaluations);
eventSystem.publishEvent(Event.ExtractionsCompleted, extractionResult);
// create results
DetectorToolResult detectorToolResult = new DetectorToolResult();
detectorToolResult.evaluatedDetectors = detectorEvaluations;
detectorToolResult.bomToolCodeLocations = extractionResult.getDetectCodeLocations();
detectorToolResult.applicableDetectorTypes = searchResult.getApplicableBomTools();
detectorToolResult.failedDetectorTypes.addAll(preparationResult.getFailedBomToolTypes());
detectorToolResult.failedDetectorTypes.addAll(extractionResult.getFailedBomToolTypes());
detectorToolResult.succesfullDetectorTypes.addAll(preparationResult.getSuccessfulBomToolTypes());
detectorToolResult.succesfullDetectorTypes.addAll(extractionResult.getSuccessfulBomToolTypes());
detectorToolResult.succesfullDetectorTypes.removeIf(it -> detectorToolResult.failedDetectorTypes.contains(it));
// post status
Map<DetectorType, StatusType> detectorStatus = new HashMap<>();
detectorToolResult.succesfullDetectorTypes.forEach(it -> detectorStatus.put(it, StatusType.SUCCESS));
detectorToolResult.failedDetectorTypes.forEach(it -> detectorStatus.put(it, StatusType.FAILURE));
detectorStatus.forEach((detector, status) -> eventSystem.publishEvent(Event.StatusSummary, new DetectorStatus(detector, status)));
return detectorToolResult;
}
use of com.blackducksoftware.integration.hub.detect.detector.DetectorType in project hub-detect by blackducksoftware.
the class RequiredDetectorChecker method parseRequiredDetectors.
private Set<DetectorType> parseRequiredDetectors(final String rawRequiredTypeString) {
final Set<DetectorType> required = new HashSet<>();
final String[] rawRequiredTypes = rawRequiredTypeString.split(",");
for (final String rawType : rawRequiredTypes) {
if (StringUtils.isBlank(rawType))
continue;
try {
final DetectorType type = DetectorType.valueOf(rawType.toUpperCase());
required.add(type);
} catch (IllegalArgumentException e) {
logger.error("Unable to parse detector type: " + rawType);
}
}
return required;
}
Aggregations