Search in sources :

Example 6 with DetectExcludedDirectoryFilter

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

the class ExclusionPatternCreatorTest method testProducesCorrectExclusions.

@ParameterizedTest
@MethodSource("inputPatternsToExclusionsProvider")
public void testProducesCorrectExclusions(List<String> providedPatterns, List<String> resultingExclusions) throws IOException {
    File root = new File("root");
    root.mkdir();
    File sub1 = new File(root, "sub1");
    sub1.mkdir();
    File sub2 = new File(root, "sub2");
    sub2.mkdir();
    File sub1Sub1 = new File(sub1, "sub1Sub1");
    sub1Sub1.mkdir();
    File sub1Sub2 = new File(sub1, "sub1Sub2");
    sub1Sub2.mkdir();
    File sub2Sub1 = new File(sub2, "sub2Sub1");
    sub2Sub1.mkdir();
    DetectExcludedDirectoryFilter filter = new DetectExcludedDirectoryFilter(providedPatterns);
    ExclusionPatternCreator exclusionPatternCreator = new ExclusionPatternCreator(new SimpleFileFinder(), file -> filter.isExcluded(file), root);
    assertEqualCollections(resultingExclusions, exclusionPatternCreator.determineExclusionPatterns(false, 3, providedPatterns));
    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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with DetectExcludedDirectoryFilter

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

the class DetectExcludedDirectoryFilterTest method testIsExcludedDirectories.

@Test
void testIsExcludedDirectories() {
    Path sourcePath = new File("my/file/path").toPath();
    List<String> excludedDirectories = Arrays.asList("root", "root2");
    DetectExcludedDirectoryFilter detectExcludedDirectoryFilter = new DetectExcludedDirectoryFilter(excludedDirectories);
    File root = new File(sourcePath.toFile(), "root");
    File root2 = new File(sourcePath.toFile(), "root2");
    File doNotExcludeDir = new File(root, "doNotExclude");
    assertTrue(detectExcludedDirectoryFilter.isExcluded(root));
    assertTrue(detectExcludedDirectoryFilter.isExcluded(root2));
    assertFalse(detectExcludedDirectoryFilter.isExcluded(doNotExcludeDir));
}
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 8 with DetectExcludedDirectoryFilter

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

the class DetectExcludedDirectoryFilterTest method testCatchErrorWhenSourcePathDoesNotShareRootWithInspectedFile.

@EnabledOnOs(WINDOWS)
@Test
void testCatchErrorWhenSourcePathDoesNotShareRootWithInspectedFile() {
    Path sourcePath = new File("D:\\").toPath();
    File testFile = new File("C:\\");
    DetectExcludedDirectoryFilter detectExcludedDirectoryFilter = new DetectExcludedDirectoryFilter(Arrays.asList("test"));
    assertFalse(detectExcludedDirectoryFilter.isExcluded(testFile));
}
Also used : Path(java.nio.file.Path) DetectExcludedDirectoryFilter(com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter) File(java.io.File) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with DetectExcludedDirectoryFilter

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

the class DetectExcludedDirectoryFilterTest method testIsExcludedDirectoryPathPatterns.

@ParameterizedTest
@MethodSource("inputPatternsToExclusionsProvider")
void testIsExcludedDirectoryPathPatterns(String exclusionPattern, boolean sub1Excluded, boolean sub2Excluded, boolean sub1Sub1Excluded, boolean sub1Sub2Excluded, boolean sub2Sub1Excluded) {
    Path sourcePath = new File("").toPath();
    DetectExcludedDirectoryFilter filter = new DetectExcludedDirectoryFilter(Collections.singletonList(exclusionPattern));
    File root = new File("root");
    File sub1 = new File(root, "sub1");
    File sub2 = new File(root, "sub2");
    File sub1Sub1 = new File(sub1, "sub1Sub1");
    File sub1Sub2 = new File(sub1, "sub1Sub2");
    File sub2Sub1 = new File(sub2, "sub2Sub1");
    assertEquals(sub1Excluded, filter.isExcluded(sub1));
    assertEquals(sub2Excluded, filter.isExcluded(sub2));
    assertEquals(sub1Sub1Excluded, filter.isExcluded(sub1Sub1));
    assertEquals(sub1Sub2Excluded, filter.isExcluded(sub1Sub2));
    assertEquals(sub2Sub1Excluded, filter.isExcluded(sub2Sub1));
}
Also used : Path(java.nio.file.Path) DetectExcludedDirectoryFilter(com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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