Search in sources :

Example 6 with DetectorEvaluation

use of com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation 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;
}
Also used : Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Logger(org.slf4j.Logger) Files(java.nio.file.Files) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DetectorEnvironment(com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment) List(java.util.List) ExitCodeType(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType) Stream(java.util.stream.Stream) DetectorSearchRuleSet(com.blackducksoftware.integration.hub.detect.workflow.search.rules.DetectorSearchRuleSet) DetectorException(com.blackducksoftware.integration.hub.detect.detector.DetectorException) Path(java.nio.file.Path) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) ArrayList(java.util.ArrayList) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) File(java.io.File) HashSet(java.util.HashSet)

Example 7 with DetectorEvaluation

use of com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation in project hub-detect by blackducksoftware.

the class OverviewSummarizer method createData.

private Stream<OverviewSummaryData> createData(final String directory, final List<DetectorEvaluation> evaluations) {
    List<OverviewSummaryData> overviewSummaryDatas = new ArrayList<>();
    for (DetectorEvaluation evaluation : evaluations) {
        if (evaluation.isApplicable()) {
            String name = evaluation.getDetector().getName();
            boolean wasExtractable = evaluation.isExtractable();
            String error = "";
            if (!wasExtractable) {
                error = evaluation.getExtractabilityMessage();
            }
            boolean wasExtracted = evaluation.getExtraction() != null && evaluation.getExtraction().result == Extraction.ExtractionResultType.SUCCESS;
            if (evaluation.getExtraction() != null && StringUtils.isNotBlank(evaluation.getExtraction().description)) {
                error = evaluation.getExtraction().description;
            }
            Map<String, String> associatedData = new HashMap<>();
            ObjectPrinter.populateObjectPrivate(null, evaluation.getDetector(), associatedData);
            OverviewSummaryData overviewSummaryData = new OverviewSummaryData(directory, name, wasExtractable, wasExtracted, associatedData, error);
            overviewSummaryDatas.add(overviewSummaryData);
        }
    }
    return overviewSummaryDatas.stream();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)

Example 8 with DetectorEvaluation

use of com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation 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;
}
Also used : DetectorToolResult(com.blackducksoftware.integration.hub.detect.tool.detector.DetectorToolResult) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) DetectorStatus(com.blackducksoftware.integration.hub.detect.workflow.status.DetectorStatus) PreparationResult(com.blackducksoftware.integration.hub.detect.workflow.extraction.PreparationResult) HashMap(java.util.HashMap) StatusType(com.blackducksoftware.integration.hub.detect.workflow.status.StatusType) ArrayList(java.util.ArrayList) SearchResult(com.blackducksoftware.integration.hub.detect.workflow.search.SearchResult) ExtractionResult(com.blackducksoftware.integration.hub.detect.workflow.extraction.ExtractionResult) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)

Aggregations

DetectorEvaluation (com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)8 ArrayList (java.util.ArrayList)5 DetectorType (com.blackducksoftware.integration.hub.detect.detector.DetectorType)4 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Detector (com.blackducksoftware.integration.hub.detect.detector.Detector)2 DetectorEnvironment (com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment)2 DetectorSearchRuleSet (com.blackducksoftware.integration.hub.detect.workflow.search.rules.DetectorSearchRuleSet)2 HashMap (java.util.HashMap)2 DetectorException (com.blackducksoftware.integration.hub.detect.detector.DetectorException)1 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ExitCodeType (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType)1 DetectorToolResult (com.blackducksoftware.integration.hub.detect.tool.detector.DetectorToolResult)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)1 Event (com.blackducksoftware.integration.hub.detect.workflow.event.Event)1 EventSystem (com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem)1