Search in sources :

Example 6 with DetectorRuleSetBuilder

use of com.synopsys.integration.detector.rule.DetectorRuleSetBuilder 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)

Example 7 with DetectorRuleSetBuilder

use of com.synopsys.integration.detector.rule.DetectorRuleSetBuilder in project synopsys-detect by blackducksoftware.

the class DetectorRuleFactory method createBuildlessRules.

private DetectorRuleSet createBuildlessRules(DetectDetectableFactory detectableFactory) {
    DetectorRuleSetBuilder ruleSet = new DetectorRuleSetBuilder();
    ruleSet.addDetector(DetectorType.CARGO, "Cargo", CargoDetectable.class, detectableFactory::createCargoDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.CARTHAGE, "Carthage", CarthageDetectable.class, detectableFactory::createCarthageDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.COCOAPODS, "Pod Lock", PodlockDetectable.class, detectableFactory::createPodLockDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.SWIFT, "Swift Package Resolved", SwiftPackageResolvedDetectable.class, detectableFactory::createSwiftPackageResolvedDetectable).defaults().notNestableBeneath(DetectorType.XCODE).build();
    ruleSet.addDetector(DetectorType.PACKAGIST, "Packrat Lock", PackratLockDetectable.class, detectableFactory::createPackratLockDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.DART, "Dart Pub Spec", DartPubSpecLockDetectable.class, detectableFactory::createDartPubSpecLockDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.GO_DEP, "Go Lock", GoDepLockDetectable.class, detectableFactory::createGoLockDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.GO_VNDR, "Go Vndr", GoVndrDetectable.class, detectableFactory::createGoVndrDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.GO_VENDOR, "Go Vendor", GoVendorDetectable.class, detectableFactory::createGoVendorDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.GRADLE, "Gradle Project Inspector", GradleProjectInspectorDetectable.class, detectableFactory::createGradleProjectInspectorDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.GO_GRADLE, "Go Gradle", GoGradleDetectable.class, detectableFactory::createGoGradleDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.IVY, "Ivy Parse", IvyParseDetectable.class, detectableFactory::createIvyParseDetectable).defaultLock().build();
    ruleSet.addDetector(DetectorType.MAVEN, "Maven Pom Parse", MavenParseDetectable.class, detectableFactory::createMavenParseDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.MAVEN, "Maven Project Inspector", MavenProjectInspectorDetectable.class, detectableFactory::createMavenProjectInspectorDetectable).defaults().build();
    DetectorRule<?> pipfileLock = ruleSet.addDetector(DetectorType.PIP, "Pipfile Lock", PipfileLockDetectable.class, detectableFactory::createPipfileLockDetectable).defaults().build();
    DetectorRule<?> poetry = ruleSet.addDetector(DetectorType.POETRY, "Poetry", PoetryDetectable.class, detectableFactory::createPoetryDetectable).defaults().build();
    ruleSet.yield(pipfileLock).to(poetry);
    DetectorRule<?> yarnLock = ruleSet.addDetector(DetectorType.YARN, "Yarn Lock", YarnLockDetectable.class, detectableFactory::createYarnLockDetectable).defaults().build();
    DetectorRule<?> npmPackageLock = ruleSet.addDetector(DetectorType.NPM, "Package Lock", NpmPackageLockDetectable.class, detectableFactory::createNpmPackageLockDetectable).defaults().build();
    DetectorRule<?> npmShrinkwrap = ruleSet.addDetector(DetectorType.NPM, "Shrinkwrap", NpmShrinkwrapDetectable.class, detectableFactory::createNpmShrinkwrapDetectable).defaults().build();
    DetectorRule<?> npmPackageJsonParse = ruleSet.addDetector(DetectorType.NPM, "Package Json Parse", NpmPackageJsonParseDetectable.class, detectableFactory::createNpmPackageJsonParseDetectable).defaults().build();
    DetectorRule<?> pnpmLock = ruleSet.addDetector(DetectorType.PNPM, "Pnpm Lock", PnpmLockDetectable.class, detectableFactory::createPnpmLockDetectable).defaults().build();
    ruleSet.yield(npmPackageLock).to(npmShrinkwrap);
    ruleSet.yield(npmPackageJsonParse).to(npmPackageLock);
    ruleSet.yield(npmPackageJsonParse).to(npmShrinkwrap);
    ruleSet.yield(npmPackageJsonParse).to(yarnLock);
    ruleSet.yield(npmPackageLock).to(yarnLock);
    ruleSet.yield(npmShrinkwrap).to(yarnLock);
    ruleSet.yield(npmPackageJsonParse).to(pnpmLock);
    ruleSet.addDetector(DetectorType.NUGET, "NuGet Project Inspector", NugetProjectInspectorDetectable.class, detectableFactory::createNugetParseDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.PACKAGIST, "Composer", ComposerLockDetectable.class, detectableFactory::createComposerDetectable).defaults().build();
    DetectorRule<?> gemlock = ruleSet.addDetector(DetectorType.RUBYGEMS, "Gemlock", GemlockDetectable.class, detectableFactory::createGemlockDetectable).defaults().build();
    DetectorRule<?> gemspec = ruleSet.addDetector(DetectorType.RUBYGEMS, "Gemspec", GemspecParseDetectable.class, detectableFactory::createGemspecParseDetectable).defaults().build();
    ruleSet.yield(gemspec).to(gemlock);
    ruleSet.addDetector(DetectorType.GIT, "Git Parse", GitParseDetectable.class, detectableFactory::createGitParseDetectable).defaults().build();
    return ruleSet.build();
}
Also used : SwiftPackageResolvedDetectable(com.synopsys.integration.detectable.detectables.swift.lock.SwiftPackageResolvedDetectable) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder)

Example 8 with DetectorRuleSetBuilder

use of com.synopsys.integration.detector.rule.DetectorRuleSetBuilder in project synopsys-detect by blackducksoftware.

the class DetectorToolTest method createRuleSet.

private DetectorRuleSet createRuleSet(DetectorRule<GoModCliDetectable> rule) {
    DetectorRuleSetBuilder ruleSetBuilder = new DetectorRuleSetBuilder();
    ruleSetBuilder.add(rule);
    return ruleSetBuilder.build();
}
Also used : DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder)

Aggregations

DetectorRuleSetBuilder (com.synopsys.integration.detector.rule.DetectorRuleSetBuilder)8 DetectorType (com.synopsys.integration.detector.base.DetectorType)5 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)5 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)5 Assertions (org.junit.jupiter.api.Assertions)5 Test (org.junit.jupiter.api.Test)5 GradleDetectable (com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable)3 NpmCliDetectable (com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable)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 Sets (com.github.jsonldjava.shaded.com.google.common.collect.Sets)2 SwiftPackageResolvedDetectable (com.synopsys.integration.detectable.detectables.swift.lock.SwiftPackageResolvedDetectable)2 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)2 NotNestableBeneathDetectorResult (com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult)2 NotSelfTypeNestableDetectorResult (com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2