Search in sources :

Example 1 with Detector

use of com.blackducksoftware.integration.hub.detect.detector.Detector in project hub-detect by blackducksoftware.

the class DetectorFactoryTest method testNewBomToolsCreatedEveryTime.

@Test
public void testNewBomToolsCreatedEveryTime() {
    DetectorFactory detectorFactory = runContext.getBean(DetectorFactory.class);
    DetectorSearchProvider provider = new DetectorSearchProvider(detectorFactory);
    DetectorEnvironment mockEnv = Mockito.mock(DetectorEnvironment.class);
    DetectorSearchRuleSet ruleSet1 = provider.createBomToolSearchRuleSet(mockEnv);
    DetectorSearchRuleSet ruleSet2 = provider.createBomToolSearchRuleSet(mockEnv);
    Detector detector1 = ruleSet1.getOrderedBomToolRules().get(0).getDetector();
    Detector detector2 = ruleSet2.getOrderedBomToolRules().get(0).getDetector();
    // Sanity check they are the same class
    Assert.assertTrue(detector1.getClass().isInstance(detector2));
    // And check they are not the same instance
    Assert.assertFalse(detector1 == detector2);
}
Also used : Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) DetectorFactory(com.blackducksoftware.integration.hub.detect.detector.DetectorFactory) DetectorSearchProvider(com.blackducksoftware.integration.hub.detect.workflow.search.rules.DetectorSearchProvider) DetectorEnvironment(com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment) DetectorSearchRuleSet(com.blackducksoftware.integration.hub.detect.workflow.search.rules.DetectorSearchRuleSet) Test(org.junit.Test)

Example 2 with Detector

use of com.blackducksoftware.integration.hub.detect.detector.Detector in project hub-detect by blackducksoftware.

the class DetectorSearchEvaluator method evaluate.

public List<DetectorEvaluation> evaluate(DetectorSearchRuleSet rules, EventSystem eventSystem) {
    final List<DetectorEvaluation> evaluations = new ArrayList<>();
    final List<Detector> appliedSoFar = new ArrayList<>();
    for (final DetectorSearchRule searchRule : rules.getOrderedBomToolRules()) {
        final Detector detector = searchRule.getDetector();
        final DetectorEvaluation evaluation = new DetectorEvaluation(detector, rules.getEnvironment());
        evaluations.add(evaluation);
        evaluation.setSearchable(searchable(searchRule, appliedSoFar, rules.getEnvironment()));
        if (evaluation.isSearchable()) {
            eventSystem.publishEvent(Event.ApplicableStarted, detector);
            evaluation.setApplicable(detector.applicable());
            eventSystem.publishEvent(Event.ApplicableEnded, detector);
            if (evaluation.isApplicable()) {
                appliedSoFar.add(detector);
            }
        }
    }
    return evaluations;
}
Also used : Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) ArrayList(java.util.ArrayList) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)

Example 3 with Detector

use of com.blackducksoftware.integration.hub.detect.detector.Detector in project hub-detect by blackducksoftware.

the class BomToolTimekeeper method getTimings.

public List<DetectorTime> getTimings() {
    final List<DetectorTime> bomToolTimings = new ArrayList<>();
    for (final Detector detector : bomToolMap.keySet()) {
        final StopWatch sw = bomToolMap.get(detector);
        final long ms = sw.getTime();
        final DetectorTime detectorTime = new DetectorTime(detector, ms);
        bomToolTimings.add(detectorTime);
    }
    return bomToolTimings;
}
Also used : Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) ArrayList(java.util.ArrayList) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 4 with Detector

use of com.blackducksoftware.integration.hub.detect.detector.Detector 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();
}
Also used : Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) NotNestableDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.NotNestableDetectorResult) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) Set(java.util.Set) EventSystem(com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem) NotSelfNestableDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.NotSelfNestableDetectorResult) Collectors(java.util.stream.Collectors) ForcedNestedPassedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.ForcedNestedPassedDetectorResult) ArrayList(java.util.ArrayList) DetectorEnvironment(com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment) PassedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.PassedDetectorResult) List(java.util.List) Event(com.blackducksoftware.integration.hub.detect.workflow.event.Event) DetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorResult) MaxDepthExceededDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.MaxDepthExceededDetectorResult) ExcludedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.ExcludedDetectorResult) YieldedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.YieldedDetectorResult) YieldedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.YieldedDetectorResult) ForcedNestedPassedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.ForcedNestedPassedDetectorResult) PassedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.PassedDetectorResult) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) MaxDepthExceededDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.MaxDepthExceededDetectorResult) NotSelfNestableDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.NotSelfNestableDetectorResult) Detector(com.blackducksoftware.integration.hub.detect.detector.Detector) ForcedNestedPassedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.ForcedNestedPassedDetectorResult) NotNestableDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.NotNestableDetectorResult) ExcludedDetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.ExcludedDetectorResult)

Example 5 with Detector

use of com.blackducksoftware.integration.hub.detect.detector.Detector 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)

Aggregations

Detector (com.blackducksoftware.integration.hub.detect.detector.Detector)7 ArrayList (java.util.ArrayList)5 DetectorEnvironment (com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment)3 DetectorEvaluation (com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)3 DetectorType (com.blackducksoftware.integration.hub.detect.detector.DetectorType)2 DetectorSearchRuleSet (com.blackducksoftware.integration.hub.detect.workflow.search.rules.DetectorSearchRuleSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 DetectorException (com.blackducksoftware.integration.hub.detect.detector.DetectorException)1 DetectorFactory (com.blackducksoftware.integration.hub.detect.detector.DetectorFactory)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ExitCodeType (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType)1 Event (com.blackducksoftware.integration.hub.detect.workflow.event.Event)1 EventSystem (com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem)1 DetectorResult (com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorResult)1 ExcludedDetectorResult (com.blackducksoftware.integration.hub.detect.workflow.search.result.ExcludedDetectorResult)1 ForcedNestedPassedDetectorResult (com.blackducksoftware.integration.hub.detect.workflow.search.result.ForcedNestedPassedDetectorResult)1 MaxDepthExceededDetectorResult (com.blackducksoftware.integration.hub.detect.workflow.search.result.MaxDepthExceededDetectorResult)1 NotNestableDetectorResult (com.blackducksoftware.integration.hub.detect.workflow.search.result.NotNestableDetectorResult)1