Search in sources :

Example 6 with DetectorEvaluationTree

use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.

the class SearchSummaryReporter method printDirectoriesInfo.

private void printDirectoriesInfo(ReportWriter writer, List<DetectorEvaluationTree> trees) {
    ReporterUtils.printHeader(writer, "Search results");
    boolean printedAtLeastOne = false;
    for (DetectorEvaluationTree tree : trees) {
        List<DetectorEvaluation> applicable = DetectorEvaluationUtils.applicableChildren(tree);
        if (applicable.size() > 0) {
            writer.writeLine(tree.getDirectory().toString());
            writer.writeLine("\tAPPLIES: " + applicable.stream().map(it -> it.getDetectorRule().getDescriptiveName()).sorted().collect(Collectors.joining(", ")));
            printedAtLeastOne = true;
        }
    }
    if (!printedAtLeastOne) {
        writer.writeLine("No detectors found.");
    }
    ReporterUtils.printFooter(writer);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation)

Example 7 with DetectorEvaluationTree

use of com.synopsys.integration.detector.base.DetectorEvaluationTree 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 8 with DetectorEvaluationTree

use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.

the class DetectorFinderTest method testSimple.

@Test
// TODO: See if we can fix on windows.
@DisabledOnOs(WINDOWS)
public void testSimple() {
    Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    File initialDirectory = initialDirectoryPath.toFile();
    File subDir = new File(initialDirectory, "testSimple");
    subDir.mkdirs();
    File subSubDir1 = new File(subDir, "subSubDir1");
    subSubDir1.mkdir();
    File subSubDir2 = new File(subDir, "subSubDir2");
    subSubDir2.mkdir();
    DetectorRuleSet detectorRuleSet = new DetectorRuleSet(new ArrayList<>(0), new HashMap<>(0));
    Predicate<File> fileFilter = f -> true;
    int maximumDepth = 10;
    DetectorFinderOptions options = new DetectorFinderOptions(fileFilter, maximumDepth, false);
    DetectorFinder finder = new DetectorFinder();
    Optional<DetectorEvaluationTree> tree = finder.findDetectors(initialDirectory, detectorRuleSet, options, new SimpleFileFinder());
    // make sure both dirs were found
    Set<DetectorEvaluationTree> testDirs = tree.get().getChildren();
    DetectorEvaluationTree simpleTestDir = null;
    for (DetectorEvaluationTree testDir : testDirs) {
        if (testDir.getDirectory().getName().equals("testSimple")) {
            simpleTestDir = testDir;
            break;
        }
    }
    Set<DetectorEvaluationTree> subDirResults = simpleTestDir.getChildren();
    assertEquals(2, subDirResults.size());
    String subDirContentsName = subDirResults.iterator().next().getDirectory().getName();
    assertTrue(subDirContentsName.startsWith("subSubDir"));
}
Also used : Files(java.nio.file.Files) Predicate(java.util.function.Predicate) SystemUtils(org.apache.commons.lang3.SystemUtils) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) FileUtils(org.apache.commons.io.FileUtils) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) File(java.io.File) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Assumptions(org.junit.jupiter.api.Assumptions) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) NotNull(org.jetbrains.annotations.NotNull) Path(java.nio.file.Path) WINDOWS(org.junit.jupiter.api.condition.OS.WINDOWS) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) File(java.io.File) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 9 with DetectorEvaluationTree

use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.

the class ApplicableEvaluatorTest method testEvaluationSuccess.

@Test
public void testEvaluationSuccess() {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ApplicableEvaluator evaluator = new ApplicableEvaluator(evaluationOptions);
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, true);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).applicableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setDetectableEnvironment(Mockito.any(DetectableEnvironment.class));
    Mockito.verify(detectorEvaluation).setDetectable(Mockito.any(Detectable.class));
    Mockito.verify(detectorEvaluatorListener).applicableEnded(detectorEvaluation);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Detectable(com.synopsys.integration.detectable.Detectable) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Example 10 with DetectorEvaluationTree

use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.

the class ApplicableEvaluatorTest method testEvaluationNotApplicable.

@Test
public void testEvaluationNotApplicable() {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ApplicableEvaluator evaluator = new ApplicableEvaluator(evaluationOptions);
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, true, true);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).applicableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setDetectableEnvironment(Mockito.any(DetectableEnvironment.class));
    Mockito.verify(detectorEvaluation).setDetectable(Mockito.any(Detectable.class));
    Mockito.verify(detectorEvaluatorListener).applicableEnded(detectorEvaluation);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Detectable(com.synopsys.integration.detectable.Detectable) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)37 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)28 File (java.io.File)18 Test (org.junit.jupiter.api.Test)17 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)11 Detectable (com.synopsys.integration.detectable.Detectable)10 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)9 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)8 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)7 Predicate (java.util.function.Predicate)7 Mockito (org.mockito.Mockito)7 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)6 List (java.util.List)6 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 Extraction (com.synopsys.integration.detectable.extraction.Extraction)5 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 HashSet (java.util.HashSet)5