Search in sources :

Example 1 with DetectorRuleSet

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);
    });
}
Also used : DetectorToolOptions(com.synopsys.integration.detect.configuration.DetectorToolOptions) DetectorFinder(com.synopsys.integration.detector.finder.DetectorFinder) DetectorIssuePublisher(com.synopsys.integration.detect.tool.detector.DetectorIssuePublisher) DetectorRuleFactory(com.synopsys.integration.detect.tool.detector.DetectorRuleFactory) DetectorTool(com.synopsys.integration.detect.tool.detector.DetectorTool) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet)

Example 2 with DetectorRuleSet

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"));
}
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 3 with DetectorRuleSet

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());
}
Also used : Test(org.junit.jupiter.api.Test) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Assertions(org.junit.jupiter.api.Assertions) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) GradleDetectable(com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable) GradleDetectable(com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Test(org.junit.jupiter.api.Test)

Example 4 with DetectorRuleSet

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());
}
Also used : Test(org.junit.jupiter.api.Test) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Assertions(org.junit.jupiter.api.Assertions) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) GradleDetectable(com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) GradleDetectable(com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Test(org.junit.jupiter.api.Test)

Example 5 with DetectorRuleSet

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());
}
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)

Aggregations

DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)13 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)8 Test (org.junit.jupiter.api.Test)7 File (java.io.File)6 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)5 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)4 Detectable (com.synopsys.integration.detectable.Detectable)4 DetectorType (com.synopsys.integration.detector.base.DetectorType)4 Optional (java.util.Optional)4 Predicate (java.util.function.Predicate)4 DetectorRuleFactory (com.synopsys.integration.detect.tool.detector.DetectorRuleFactory)3 DetectorFinder (com.synopsys.integration.detector.finder.DetectorFinder)3 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)3 DetectorRuleSetBuilder (com.synopsys.integration.detector.rule.DetectorRuleSetBuilder)3 List (java.util.List)3 Set (java.util.Set)3 Assertions (org.junit.jupiter.api.Assertions)3 Gson (com.google.gson.Gson)2 DetectProperties (com.synopsys.integration.detect.configuration.DetectProperties)2 ExitCodePublisher (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher)2