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);
}
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);
}
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"));
}
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);
}
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);
}
Aggregations