Search in sources :

Example 1 with DetectorResult

use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.

the class FormattedOutputManagerTest method detectorOutputStatusDataTest.

@Test
public <T extends Detectable> void detectorOutputStatusDataTest() throws IllegalAccessException {
    EventSystem eventSystem = new EventSystem();
    FormattedOutputManager formattedOutputManager = new FormattedOutputManager(eventSystem);
    DetectorRule rule = Mockito.mock(DetectorRule.class);
    Mockito.when(rule.getDescriptiveName()).thenReturn("");
    Mockito.when(rule.getName()).thenReturn("");
    Mockito.when(rule.getDetectorType()).thenReturn(DetectorType.GO_MOD);
    DetectorEvaluation detectorEvaluation = new DetectorEvaluation(rule);
    ExecutableNotFoundDetectableResult result = new ExecutableNotFoundDetectableResult("go");
    DetectorResult extractableResult = new DetectorResult(result.getPassed(), result.toDescription(), result.getClass(), Collections.emptyList(), Collections.emptyList());
    detectorEvaluation.setExtractable(extractableResult);
    detectorEvaluation.setApplicable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setSearchable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setDetectableEnvironment(new DetectableEnvironment(new File("")));
    DetectorToolResult detectorToolResult = new DetectorToolResult(null, null, null, new HashSet<>(), new DetectorEvaluationTree(null, 0, null, Collections.singletonList(detectorEvaluation), new HashSet<>()), null);
    eventSystem.publishEvent(Event.DetectorsComplete, detectorToolResult);
    DetectInfo detectInfo = new DetectInfo("", null, "");
    FormattedOutput formattedOutput = formattedOutputManager.createFormattedOutput(detectInfo);
    FormattedDetectorOutput detectorOutput = formattedOutput.detectors.get(0);
    Assertions.assertEquals("FAILURE", detectorOutput.status);
    Assertions.assertEquals(DetectorStatusCode.EXECUTABLE_NOT_FOUND, detectorOutput.statusCode);
    Assertions.assertEquals("No go executable was found.", detectorOutput.statusReason);
}
Also used : ExecutableNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult) DetectInfo(com.synopsys.integration.detect.configuration.DetectInfo) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) FormattedOutputManager(com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput) DetectorToolResult(com.synopsys.integration.detect.tool.detector.DetectorToolResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) FormattedDetectorOutput(com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with DetectorResult

use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.

the class DetectorRuleSetEvaluatorTest method test.

@Test
public void test() {
    DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
    DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
    SearchEnvironment environment = Mockito.mock(SearchEnvironment.class);
    Predicate<DetectorRule> rulePredicate = it -> true;
    Mockito.when(environment.getDetectorFilter()).thenReturn(rulePredicate);
    Mockito.when(detectorRule.getMaxDepth()).thenReturn(1);
    Mockito.when(environment.getDepth()).thenReturn(0);
    Set<DetectorRule> appliedSoFar = new HashSet<>();
    Mockito.when(environment.getAppliedSoFar()).thenReturn(appliedSoFar);
    Set<DetectorRule> appliedToParent = new HashSet<>();
    Mockito.when(environment.getAppliedToParent()).thenReturn(appliedToParent);
    Mockito.when(detectorRule.isNestable()).thenReturn(true);
    Mockito.when(environment.isForceNestedSearch()).thenReturn(false);
    Mockito.when(detectorRule.isSelfTypeNestable()).thenReturn(false);
    Mockito.when(detectorRule.getDetectorType()).thenReturn(DetectorType.GRADLE);
    DetectorRuleSetEvaluator evaluator = new DetectorRuleSetEvaluator();
    DetectorResult result = evaluator.evaluateSearchable(detectorRuleSet, detectorRule, environment);
    assertTrue(result.getPassed());
}
Also used : NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) Predicate(java.util.function.Predicate) Set(java.util.Set) SwiftCliDetectable(com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) XcodeWorkspaceDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeWorkspaceDetectable) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) Sets(com.github.jsonldjava.shaded.com.google.common.collect.Sets) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) XcodeProjectDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeProjectDetectable) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with DetectorResult

use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.

the class DetectorRuleSetEvaluator method evaluateSearchable.

public DetectorResult evaluateSearchable(DetectorRuleSet detectorRuleSet, DetectorRule detectorRule, SearchEnvironment environment) {
    if (!environment.getDetectorFilter().test(detectorRule)) {
        return new ExcludedDetectorResult();
    }
    int maxDepth = detectorRule.getMaxDepth();
    if (environment.getDepth() > maxDepth) {
        return new MaxDepthExceededDetectorResult(environment.getDepth(), maxDepth);
    }
    Set<DetectorRule> yieldTo = environment.getAppliedSoFar().stream().filter(it -> detectorRuleSet.getYieldsTo(detectorRule).contains(it)).collect(Collectors.toSet());
    if (yieldTo.size() > 0) {
        return new YieldedDetectorResult(yieldTo.stream().map(DetectorRule::getName).collect(Collectors.toSet()));
    }
    boolean nestable = detectorRule.isNestable();
    boolean selfNestable = detectorRule.isSelfNestable();
    boolean selfTypeNestable = detectorRule.isSelfTypeNestable();
    DetectorType detectorType = detectorRule.getDetectorType();
    Set<DetectorType> notNestableBeneath = detectorRule.getNotNestableBeneath();
    if (environment.isForceNestedSearch()) {
        return new ForcedNestedPassedDetectorResult();
    } else if (nestable) {
        if (!selfNestable && environment.getAppliedToParent().stream().anyMatch(detectorRule::equals)) {
            return new NotSelfNestableDetectorResult();
        }
        if (!selfTypeNestable && environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).anyMatch(detectorType::equals)) {
            return new NotSelfTypeNestableDetectorResult(detectorType);
        }
        if (notNestableBeneath.size() > 0) {
            Optional<DetectorType> notNestableBeneathType = environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).filter(notNestableBeneath::contains).findAny();
            if (notNestableBeneathType.isPresent()) {
                return new NotNestableBeneathDetectorResult(notNestableBeneathType.get());
            }
        }
    } else if (environment.getAppliedToParent().stream().anyMatch(it -> !it.isNestInvisible())) {
        return new NotNestableDetectorResult();
    }
    return new PassedDetectorResult();
}
Also used : MaxDepthExceededDetectorResult(com.synopsys.integration.detector.result.MaxDepthExceededDetectorResult) PassedDetectorResult(com.synopsys.integration.detector.result.PassedDetectorResult) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) NotSelfNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfNestableDetectorResult) Set(java.util.Set) Collectors(java.util.stream.Collectors) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Optional(java.util.Optional) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) ExcludedDetectorResult(com.synopsys.integration.detector.result.ExcludedDetectorResult) NotNestableDetectorResult(com.synopsys.integration.detector.result.NotNestableDetectorResult) YieldedDetectorResult(com.synopsys.integration.detector.result.YieldedDetectorResult) Optional(java.util.Optional) YieldedDetectorResult(com.synopsys.integration.detector.result.YieldedDetectorResult) PassedDetectorResult(com.synopsys.integration.detector.result.PassedDetectorResult) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) MaxDepthExceededDetectorResult(com.synopsys.integration.detector.result.MaxDepthExceededDetectorResult) DetectorType(com.synopsys.integration.detector.base.DetectorType) NotSelfNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfNestableDetectorResult) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) NotNestableDetectorResult(com.synopsys.integration.detector.result.NotNestableDetectorResult) ExcludedDetectorResult(com.synopsys.integration.detector.result.ExcludedDetectorResult)

Example 4 with DetectorResult

use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.

the class DetectorRuleSetEvaluatorTest method nestableExcept.

@Test
public void nestableExcept() {
    DetectorRuleSetBuilder ruleSet = new DetectorRuleSetBuilder();
    DetectorRule xcode = ruleSet.addDetector(DetectorType.XCODE, "Xcode", XcodeProjectDetectable.class, (e) -> null).defaults().build();
    DetectorRule swift = ruleSet.addDetector(DetectorType.SWIFT, "Swift", SwiftCliDetectable.class, (e) -> null).defaults().nestableExceptTo(DetectorType.XCODE).build();
    // XCODE applied at depth 0, we are now scanning a folder at depth 2.
    Set<DetectorRule> appliedToParent = Sets.newHashSet(xcode);
    Set<DetectorRule> appliedSoFar = Sets.newHashSet();
    SearchEnvironment searchEnvironment = new SearchEnvironment(2, (d) -> true, false, false, appliedToParent, appliedSoFar);
    DetectorResult result = new DetectorRuleSetEvaluator().evaluateSearchable(ruleSet.build(), swift, searchEnvironment);
    Assertions.assertEquals(NotNestableBeneathDetectorResult.class, result.getClass());
}
Also used : NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) Predicate(java.util.function.Predicate) Set(java.util.Set) SwiftCliDetectable(com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) XcodeWorkspaceDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeWorkspaceDetectable) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) Sets(com.github.jsonldjava.shaded.com.google.common.collect.Sets) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) XcodeProjectDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeProjectDetectable) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) SwiftCliDetectable(com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with DetectorResult

use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.

the class DetectorRuleSetEvaluatorTest method nestableExceptByDetectorType.

@Test
public void nestableExceptByDetectorType() {
    DetectorRuleSetBuilder ruleSet = new DetectorRuleSetBuilder();
    DetectorRule workspaceRule = ruleSet.addDetector(DetectorType.XCODE, "Xcode Workspace", XcodeWorkspaceDetectable.class, (e) -> null).defaults().notSelfTypeNestable().build();
    DetectorRule projectRule = ruleSet.addDetector(DetectorType.XCODE, "Xcode Project", XcodeProjectDetectable.class, (e) -> null).defaults().notSelfTypeNestable().build();
    // XCODE applied at depth 0, we are now scanning a folder at depth 2.
    Set<DetectorRule> appliedToParent = Sets.newHashSet(workspaceRule);
    Set<DetectorRule> appliedSoFar = Sets.newHashSet();
    SearchEnvironment searchEnvironment = new SearchEnvironment(2, (d) -> true, false, false, appliedToParent, appliedSoFar);
    DetectorResult result = new DetectorRuleSetEvaluator().evaluateSearchable(ruleSet.build(), projectRule, searchEnvironment);
    Assertions.assertEquals(NotSelfTypeNestableDetectorResult.class, result.getClass());
}
Also used : XcodeWorkspaceDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeWorkspaceDetectable) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) Predicate(java.util.function.Predicate) Set(java.util.Set) SwiftCliDetectable(com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) XcodeWorkspaceDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeWorkspaceDetectable) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) Sets(com.github.jsonldjava.shaded.com.google.common.collect.Sets) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) XcodeProjectDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeProjectDetectable) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) XcodeProjectDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeProjectDetectable) Test(org.junit.jupiter.api.Test)

Aggregations

DetectorResult (com.synopsys.integration.detector.result.DetectorResult)8 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)6 HashSet (java.util.HashSet)5 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)4 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)4 DetectorType (com.synopsys.integration.detector.base.DetectorType)4 NotNestableBeneathDetectorResult (com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult)4 NotSelfTypeNestableDetectorResult (com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult)4 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)4 Set (java.util.Set)4 Test (org.junit.jupiter.api.Test)4 Sets (com.github.jsonldjava.shaded.com.google.common.collect.Sets)3 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)3 SwiftCliDetectable (com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable)3 XcodeProjectDetectable (com.synopsys.integration.detectable.detectables.xcode.XcodeProjectDetectable)3 XcodeWorkspaceDetectable (com.synopsys.integration.detectable.detectables.xcode.XcodeWorkspaceDetectable)3 DetectorRuleSetBuilder (com.synopsys.integration.detector.rule.DetectorRuleSetBuilder)3 Predicate (java.util.function.Predicate)3 Assertions (org.junit.jupiter.api.Assertions)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3