Search in sources :

Example 1 with DetectExcludedDirectoryFilter

use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.

the class ExclusionPatternCreatorTest method testDoesNotCreateRedundantExclusions.

@Test
public void testDoesNotCreateRedundantExclusions() throws IOException {
    File root = new File("root");
    root.mkdir();
    File foo = new File("root", "foo");
    foo.mkdir();
    File bar = new File(foo, "bar");
    bar.mkdir();
    List<String> toExclude = Arrays.asList("foo", "bar");
    DetectExcludedDirectoryFilter filter = new DetectExcludedDirectoryFilter(toExclude);
    ExclusionPatternCreator exclusionPatternCreator = new ExclusionPatternCreator(new SimpleFileFinder(), file -> filter.isExcluded(file), root);
    Set<String> exlusionPatterns = exclusionPatternCreator.determineExclusionPatterns(false, 2, toExclude);
    Assertions.assertEquals(1, exlusionPatterns.size());
    Assertions.assertTrue(exlusionPatterns.contains("/foo/"));
    Assertions.assertFalse(exlusionPatterns.contains("/foo/bar/"));
    FileUtils.deleteDirectory(root);
}
Also used : DetectExcludedDirectoryFilter(com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) File(java.io.File) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with DetectExcludedDirectoryFilter

use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.

the class OperationFactory method createScanPaths.

public List<SignatureScanPath> createScanPaths(NameVersion projectNameVersion, DockerTargetData dockerTargetData) throws OperationException {
    return auditLog.namedInternal("Calculate Signature Scan Paths", () -> {
        List<String> exclusions = detectConfigurationFactory.collectSignatureScannerDirectoryExclusions();
        DetectExcludedDirectoryFilter detectExcludedDirectoryFilter = new DetectExcludedDirectoryFilter(exclusions);
        return new CalculateScanPathsOperation(detectConfigurationFactory.createBlackDuckSignatureScannerOptions(), directoryManager, fileFinder, detectExcludedDirectoryFilter::isExcluded).determinePathsAndExclusions(projectNameVersion, detectConfigurationFactory.createBlackDuckSignatureScannerOptions().getMaxDepth(), dockerTargetData);
    });
}
Also used : DetectExcludedDirectoryFilter(com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter) CalculateScanPathsOperation(com.synopsys.integration.detect.tool.signaturescanner.operation.CalculateScanPathsOperation)

Example 3 with DetectExcludedDirectoryFilter

use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.

the class DetectExcludedDirectoryFilterTest method testIsExcludedDirectoryNamePatterns.

@Test
void testIsExcludedDirectoryNamePatterns() {
    Path sourcePath = new File("my/subDir1/subDir2/file/path").toPath();
    List<String> excludedDirectories = Arrays.asList("*1", "namePatternsDir*");
    DetectExcludedDirectoryFilter detectExcludedDirectoryFilter = new DetectExcludedDirectoryFilter(excludedDirectories);
    File root = new File(sourcePath.toFile(), "root");
    File subDir1 = new File(root, "subDir1");
    File subDir2 = new File(root, "subDir2");
    File deepSubDir2 = new File(subDir1, "subDir2");
    File namePatternsDir = new File(root, "namePatternsDir51134");
    assertFalse(detectExcludedDirectoryFilter.isExcluded(root));
    assertTrue(detectExcludedDirectoryFilter.isExcluded(subDir1));
    assertFalse(detectExcludedDirectoryFilter.isExcluded(subDir2));
    assertFalse(detectExcludedDirectoryFilter.isExcluded(deepSubDir2));
    assertTrue(detectExcludedDirectoryFilter.isExcluded(namePatternsDir));
}
Also used : Path(java.nio.file.Path) DetectExcludedDirectoryFilter(com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter) File(java.io.File) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with DetectExcludedDirectoryFilter

use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.

the class DetectExcludedDirectoryFilterTest method testIsExcludedDirectoryPaths.

@Test
void testIsExcludedDirectoryPaths() {
    Path sourcePath = new File("my/subDir1/subDir2/file/path").toPath();
    List<String> excludedDirectories = Collections.singletonList("subDir1/subDir2");
    DetectExcludedDirectoryFilter detectExcludedDirectoryFilter = new DetectExcludedDirectoryFilter(excludedDirectories);
    File root = new File("path/to/root");
    File subDir1 = new File(root, "subDir1");
    File subDir2 = new File(root, "subDir2");
    File deepSubDir2 = new File(subDir1, "subDir2");
    assertFalse(detectExcludedDirectoryFilter.isExcluded(root));
    assertFalse(detectExcludedDirectoryFilter.isExcluded(subDir1));
    assertFalse(detectExcludedDirectoryFilter.isExcluded(subDir2));
    assertTrue(detectExcludedDirectoryFilter.isExcluded(deepSubDir2));
}
Also used : Path(java.nio.file.Path) DetectExcludedDirectoryFilter(com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter) File(java.io.File) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with DetectExcludedDirectoryFilter

use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.

the class DetectConfigurationFactory method createDetectorFinderOptions.

public DetectorFinderOptions createDetectorFinderOptions() {
    // Normal settings
    Integer maxDepth = detectConfiguration.getValue(DetectProperties.DETECT_DETECTOR_SEARCH_DEPTH);
    DetectExcludedDirectoryFilter fileFilter = new DetectExcludedDirectoryFilter(collectDirectoryExclusions(DefaultDetectorSearchExcludedDirectories.getDirectoryNames()));
    return new DetectorFinderOptions(fileFilter, maxDepth, getFollowSymLinks());
}
Also used : DetectExcludedDirectoryFilter(com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter) DetectorFinderOptions(com.synopsys.integration.detector.finder.DetectorFinderOptions)

Aggregations

DetectExcludedDirectoryFilter (com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter)9 File (java.io.File)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Path (java.nio.file.Path)5 Test (org.junit.jupiter.api.Test)5 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CalculateScanPathsOperation (com.synopsys.integration.detect.tool.signaturescanner.operation.CalculateScanPathsOperation)1 DetectorFinderOptions (com.synopsys.integration.detector.finder.DetectorFinderOptions)1 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)1