use of com.synopsys.integration.detector.rule.DetectorRuleSet in project synopsys-detect by blackducksoftware.
the class OperationFactory method executeDetectors.
public final DetectorToolResult executeDetectors() throws OperationException {
return auditLog.namedPublic("Execute Detectors", "Detectors", () -> {
DetectorToolOptions detectorToolOptions = detectConfigurationFactory.createDetectorToolOptions();
DetectorRuleFactory detectorRuleFactory = new DetectorRuleFactory();
DetectorRuleSet detectRuleSet = detectorRuleFactory.createRules(detectDetectableFactory, detectorToolOptions.isBuildless());
DetectorTool detectorTool = new DetectorTool(new DetectorFinder(), extractionEnvironmentProvider, eventSystem, codeLocationConverter, new DetectorIssuePublisher(), statusEventPublisher, exitCodePublisher, detectorEventPublisher);
return detectorTool.performDetectors(directoryManager.getSourceDirectory(), detectRuleSet, detectConfigurationFactory.createDetectorFinderOptions(), detectConfigurationFactory.createDetectorEvaluationOptions(), detectorToolOptions.getProjectBomTool(), detectorToolOptions.getRequiredDetectors(), fileFinder);
});
}
use of com.synopsys.integration.detector.rule.DetectorRuleSet 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.rule.DetectorRuleSet in project synopsys-detect by blackducksoftware.
the class DetectorRuleSetBuilderTest method testOrderGivenUsed.
@Test
public void testOrderGivenUsed() {
DetectorRuleSetBuilder ruleSetBuilder = new DetectorRuleSetBuilder();
ruleSetBuilder.addDetector(DetectorType.GRADLE, "Gradle", GradleDetectable.class, (e) -> null).build();
ruleSetBuilder.addDetector(DetectorType.NPM, "Npm", NpmCliDetectable.class, (e) -> null).build();
DetectorRuleSet ruleSet = ruleSetBuilder.build();
Assertions.assertEquals(2, ruleSet.getOrderedDetectorRules().size());
Assertions.assertEquals("Gradle", ruleSet.getOrderedDetectorRules().get(0).getName());
Assertions.assertEquals("Npm", ruleSet.getOrderedDetectorRules().get(1).getName());
}
use of com.synopsys.integration.detector.rule.DetectorRuleSet in project synopsys-detect by blackducksoftware.
the class DetectorRuleSetBuilderTest method testReorderedWithYield.
@Test
public void testReorderedWithYield() {
DetectorRuleSetBuilder ruleSetBuilder = new DetectorRuleSetBuilder();
DetectorRule gradle = ruleSetBuilder.addDetector(DetectorType.GRADLE, "Gradle", GradleDetectable.class, (e) -> null).build();
DetectorRule npm = ruleSetBuilder.addDetector(DetectorType.NPM, "Npm", NpmCliDetectable.class, (e) -> null).build();
ruleSetBuilder.yield(gradle).to(npm);
DetectorRuleSet ruleSet = ruleSetBuilder.build();
Assertions.assertEquals(2, ruleSet.getOrderedDetectorRules().size());
Assertions.assertEquals("Npm", ruleSet.getOrderedDetectorRules().get(0).getName());
Assertions.assertEquals("Gradle", ruleSet.getOrderedDetectorRules().get(1).getName());
}
use of com.synopsys.integration.detector.rule.DetectorRuleSet 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());
}
Aggregations