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