Search in sources :

Example 1 with DetectorRuleSetBuilder

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

the class DetectorRuleFactory method createRules.

// TODO: It would just be nice not to have to call 'build' after each of the addDetectors.
private DetectorRuleSet createRules(DetectDetectableFactory detectableFactory) {
    DetectorRuleSetBuilder ruleSet = new DetectorRuleSetBuilder();
    // TODO: Verify we still need to pass detector name here. We may now be able to get it from the detectable class - before we could not as it was not instantiated.
    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.BITBAKE, "Bitbake", BitbakeDetectable.class, detectableFactory::createBitbakeDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.COCOAPODS, "Pod Lock", PodlockDetectable.class, detectableFactory::createPodLockDetectable).defaults().build();
    DetectorRule<?> xcodeProject = ruleSet.addDetector(DetectorType.XCODE, "Xcode Project", XcodeProjectDetectable.class, detectableFactory::createXcodeProjectDetectable).defaults().notSelfTypeNestable().build();
    DetectorRule<?> xcodeWorkspace = ruleSet.addDetector(DetectorType.XCODE, "Xcode Workspace", XcodeWorkspaceDetectable.class, detectableFactory::createXcodeWorkspaceDetectable).defaults().notSelfTypeNestable().build();
    DetectorRule<?> swiftCli = ruleSet.addDetector(DetectorType.SWIFT, "Swift CLI", SwiftCliDetectable.class, detectableFactory::createSwiftCliDetectable).defaults().nestableExceptTo(DetectorType.XCODE).build();
    DetectorRule<?> swiftPackageResolved = ruleSet.addDetector(DetectorType.SWIFT, "Swift Package Resolved", SwiftPackageResolvedDetectable.class, detectableFactory::createSwiftPackageResolvedDetectable).defaults().nestableExceptTo(DetectorType.XCODE).build();
    ruleSet.yield(swiftPackageResolved).to(swiftCli);
    ruleSet.yield(xcodeProject).to(xcodeWorkspace);
    DetectorRule<?> conanCliRule = ruleSet.addDetector(DetectorType.CONAN, "Conan CLI", ConanCliDetectable.class, detectableFactory::createConanCliDetectable).defaults().build();
    DetectorRule<?> conanLockfileRule = ruleSet.addDetector(DetectorType.CONAN, "Conan Lockfile", ConanLockfileDetectable.class, detectableFactory::createConanLockfileDetectable).defaults().build();
    ruleSet.yield(conanCliRule).to(conanLockfileRule);
    ruleSet.addDetector(DetectorType.CONDA, "Conda Cli", CondaCliDetectable.class, detectableFactory::createCondaCliDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.CPAN, "Cpan Cli", CpanCliDetectable.class, detectableFactory::createCpanCliDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.CRAN, "Packrat Lock", PackratLockDetectable.class, detectableFactory::createPackratLockDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.DART, "Dart Pub Deps", DartPubDepDetectable.class, detectableFactory::createDartPubDepDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.GO_MOD, "Go Mod Cli", GoModCliDetectable.class, detectableFactory::createGoModCliDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.GO_GRADLE, "Go Gradle", GoGradleDetectable.class, detectableFactory::createGoGradleDetectable).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 Inspector", GradleDetectable.class, detectableFactory::createGradleDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.IVY, "Ivy Parse", IvyParseDetectable.class, detectableFactory::createIvyParseDetectable).defaultLock().build();
    ruleSet.addDetector(DetectorType.HEX, "Rebar", RebarDetectable.class, detectableFactory::createRebarDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.MAVEN, "Maven Pom", MavenPomDetectable.class, detectableFactory::createMavenPomDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.MAVEN, "Maven Wrapper", MavenPomWrapperDetectable.class, detectableFactory::createMavenPomWrapperDetectable).defaults().build();
    DetectorRule<?> lernaDetectable = ruleSet.addDetector(DetectorType.LERNA, "Lerna", LernaDetectable.class, detectableFactory::createLernaDetectable).defaults().build();
    DetectorRule<?> yarnLock = ruleSet.addDetector(DetectorType.YARN, "Yarn Lock", YarnLockDetectable.class, detectableFactory::createYarnLockDetectable).defaultLock().build();
    DetectorRule<?> npmPackageLock = ruleSet.addDetector(DetectorType.NPM, "Package Lock", NpmPackageLockDetectable.class, detectableFactory::createNpmPackageLockDetectable).defaultLock().build();
    DetectorRule<?> npmShrinkwrap = ruleSet.addDetector(DetectorType.NPM, "Shrinkwrap", NpmShrinkwrapDetectable.class, detectableFactory::createNpmShrinkwrapDetectable).defaultLock().build();
    DetectorRule<?> npmCli = ruleSet.addDetector(DetectorType.NPM, "Npm Cli", NpmCliDetectable.class, detectableFactory::createNpmCliDetectable).defaults().build();
    DetectorRule<?> pnpmLock = ruleSet.addDetector(DetectorType.PNPM, "Pnpm Lock", PnpmLockDetectable.class, detectableFactory::createPnpmLockDetectable).defaults().build();
    ruleSet.yield(npmPackageLock).to(lernaDetectable);
    ruleSet.yield(npmShrinkwrap).to(lernaDetectable);
    ruleSet.yield(npmCli).to(lernaDetectable);
    ruleSet.yield(yarnLock).to(lernaDetectable);
    ruleSet.yield(pnpmLock).to(lernaDetectable);
    ruleSet.yield(npmPackageLock).to(npmShrinkwrap);
    ruleSet.yield(npmCli).to(npmPackageLock);
    ruleSet.yield(npmCli).to(npmShrinkwrap);
    ruleSet.yield(npmCli).to(yarnLock);
    ruleSet.yield(npmPackageLock).to(yarnLock);
    ruleSet.yield(npmShrinkwrap).to(yarnLock);
    ruleSet.yield(npmCli).to(pnpmLock);
    DetectorRule<?> nugetSolution = ruleSet.addDetector(DetectorType.NUGET, "Solution", NugetSolutionDetectable.class, detectableFactory::createNugetSolutionDetectable).defaults().build();
    // The Project detectable is "notNestable" because it will falsely apply under a solution (the solution includes all of the projects).
    DetectorRule<?> nugetProject = ruleSet.addDetector(DetectorType.NUGET, "Project", NugetProjectDetectable.class, detectableFactory::createNugetProjectDetectable).notNestable().noMaxDepth().build();
    ruleSet.yield(nugetProject).to(nugetSolution);
    ruleSet.addDetector(DetectorType.PACKAGIST, "Composer", ComposerLockDetectable.class, detectableFactory::createComposerDetectable).defaults().build();
    DetectorRule<?> pipEnv = ruleSet.addDetector(DetectorType.PIP, "Pip Env", PipenvDetectable.class, detectableFactory::createPipenvDetectable).defaults().build();
    DetectorRule<?> pipfileLock = ruleSet.addDetector(DetectorType.PIP, "Pipfile Lock", PipfileLockDetectable.class, detectableFactory::createPipfileLockDetectable).defaults().build();
    DetectorRule<?> pipInspector = ruleSet.addDetector(DetectorType.PIP, "Pip Inspector", PipInspectorDetectable.class, detectableFactory::createPipInspectorDetectable).defaults().build();
    DetectorRule<?> poetry = ruleSet.addDetector(DetectorType.POETRY, "Poetry", PoetryDetectable.class, detectableFactory::createPoetryDetectable).defaults().build();
    ruleSet.yield(pipInspector).to(pipEnv);
    ruleSet.yield(poetry).to(pipEnv);
    ruleSet.yield(pipfileLock).to(pipEnv);
    ruleSet.yield(pipfileLock).to(pipInspector);
    ruleSet.addDetector(DetectorType.RUBYGEMS, "Gemlock", GemlockDetectable.class, detectableFactory::createGemlockDetectable).defaults().build();
    // TODO: Yield
    ruleSet.addDetector(DetectorType.SBT, "Sbt", SbtDetectable.class, detectableFactory::createSbtDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.PEAR, "Pear", PearCliDetectable.class, detectableFactory::createPearCliDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.CLANG, "Clang", ClangDetectable.class, detectableFactory::createClangDetectable).defaults().build();
    ruleSet.addDetector(DetectorType.GIT, "Git", GitDetectable.class, detectableFactory::createGitDetectable).defaults().build();
    return ruleSet.build();
}
Also used : XcodeWorkspaceDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeWorkspaceDetectable) SwiftPackageResolvedDetectable(com.synopsys.integration.detectable.detectables.swift.lock.SwiftPackageResolvedDetectable) SwiftCliDetectable(com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable) NugetProjectDetectable(com.synopsys.integration.detectable.detectables.nuget.NugetProjectDetectable) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) XcodeProjectDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeProjectDetectable)

Example 2 with DetectorRuleSetBuilder

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

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

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

the class DetectorRuleSetBuilderTest method testCircularYieldThrows.

@Test
public void testCircularYieldThrows() {
    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);
    ruleSetBuilder.yield(npm).to(gradle);
    Assertions.assertThrows(RuntimeException.class, ruleSetBuilder::build);
}
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) Test(org.junit.jupiter.api.Test)

Example 5 with DetectorRuleSetBuilder

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

the class DetectorRuleSetEvaluatorTest method nestableExcept.

@Test
public void nestableExcept() {
    DetectorRuleSetBuilder ruleSet = new DetectorRuleSetBuilder();
    DetectorRule xcode = ruleSet.addDetector(DetectorType.XCODE, "Xcode", XcodeProjectDetectable.class, (e) -> null).defaults().build();
    DetectorRule swift = ruleSet.addDetector(DetectorType.SWIFT, "Swift", SwiftCliDetectable.class, (e) -> null).defaults().nestableExceptTo(DetectorType.XCODE).build();
    // XCODE applied at depth 0, we are now scanning a folder at depth 2.
    Set<DetectorRule> appliedToParent = Sets.newHashSet(xcode);
    Set<DetectorRule> appliedSoFar = Sets.newHashSet();
    SearchEnvironment searchEnvironment = new SearchEnvironment(2, (d) -> true, false, false, appliedToParent, appliedSoFar);
    DetectorResult result = new DetectorRuleSetEvaluator().evaluateSearchable(ruleSet.build(), swift, searchEnvironment);
    Assertions.assertEquals(NotNestableBeneathDetectorResult.class, result.getClass());
}
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) SwiftCliDetectable(com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable) 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) Test(org.junit.jupiter.api.Test)

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