Search in sources :

Example 1 with DetectDirectoryFileFilter

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

the class DetectDirectoryFileFilterTest method testFileInclusion.

@Test
void testFileInclusion() {
    List<String> excludedDirs = Arrays.asList("excludeme");
    List<String> includedFiles = Arrays.asList("*.txt");
    DetectDirectoryFileFilter filter = new DetectDirectoryFileFilter(excludedDirs, includedFiles);
    assertTrue(filter.test(includedFile));
    assertTrue(filter.test(includedFileInIncludedDir));
    assertFalse(filter.test(new File(tempDir, "dir/nonexistent.txt")));
    assertFalse(filter.test(nonMatchingFile));
}
Also used : DetectDirectoryFileFilter(com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with DetectDirectoryFileFilter

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

the class DetectDirectoryFileFilterTest method testDirExclusion.

@Test
void testDirExclusion() {
    List<String> excludedDirs = Arrays.asList("excludeme");
    List<String> includedFiles = Arrays.asList("*.txt");
    DetectDirectoryFileFilter filter = new DetectDirectoryFileFilter(excludedDirs, includedFiles);
    assertFalse(filter.test(includedDir));
    assertTrue(filter.test(excludedDir));
}
Also used : DetectDirectoryFileFilter(com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter) Test(org.junit.jupiter.api.Test)

Example 3 with DetectDirectoryFileFilter

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

the class BinaryUploadOperationTest method testDirExclusion.

@Test
public void testDirExclusion() throws DetectUserFriendlyException, IOException, IntegrationException {
    SimpleFileFinder fileFinder = new SimpleFileFinder();
    DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    File rootDirectory = Files.createTempDirectory("BinaryScannerTest").toFile();
    createDirWithFiles(rootDirectory, "includedDir");
    createDirWithFiles(rootDirectory, "excludedDir");
    ArrayList<String> targetPaths = new ArrayList<>();
    targetPaths.add("*.txt");
    Mockito.when(directoryManager.getSourceDirectory()).thenReturn(rootDirectory);
    Mockito.when(directoryManager.getBinaryOutputDirectory()).thenReturn(rootDirectory);
    BinaryScanFindMultipleTargetsOperation multipleTargets = new BinaryScanFindMultipleTargetsOperation(fileFinder, directoryManager);
    DetectDirectoryFileFilter fileFilter = new DetectDirectoryFileFilter(Arrays.asList("excludedDir"), targetPaths);
    Optional<File> zip = multipleTargets.searchForMultipleTargets(fileFilter, false, 3);
    Assertions.assertTrue(zip.isPresent());
    List<String> entries = getZipEntries(zip);
    Assertions.assertTrue(entries.contains("includedDir/binaryTestFile_1.txt"));
    Assertions.assertFalse(entries.contains("includedDir/binaryTestFile_2.text"));
    Assertions.assertFalse(entries.contains("excludedDir/binaryTestFile_1.txt"));
    Assertions.assertFalse(entries.contains("excludedDir/binaryTestFile_2.text"));
    FileUtils.deleteDirectory(rootDirectory);
}
Also used : SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) DetectDirectoryFileFilter(com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with DetectDirectoryFileFilter

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

the class BinaryUploadOperationTest method testMultipleTargetPaths.

@Test
public void testMultipleTargetPaths() throws DetectUserFriendlyException, IOException, IntegrationException {
    SimpleFileFinder fileFinder = new SimpleFileFinder();
    DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    File rootDirectory = Files.createTempDirectory("BinaryScannerTest").toFile();
    createDirWithFiles(rootDirectory, "BinaryScannerSubDirectory");
    ArrayList<String> targetPaths = new ArrayList<>();
    targetPaths.add("binaryTestFile_1.txt");
    targetPaths.add("*.text");
    Mockito.when(directoryManager.getSourceDirectory()).thenReturn(rootDirectory);
    Mockito.when(directoryManager.getBinaryOutputDirectory()).thenReturn(rootDirectory);
    BinaryScanFindMultipleTargetsOperation multipleTargets = new BinaryScanFindMultipleTargetsOperation(fileFinder, directoryManager);
    DetectDirectoryFileFilter fileFilter = new DetectDirectoryFileFilter(Collections.emptyList(), targetPaths);
    Optional<File> zip = multipleTargets.searchForMultipleTargets(fileFilter, false, 3);
    Assertions.assertTrue(zip.isPresent());
    List<String> entries = getZipEntries(zip);
    Assertions.assertTrue(entries.contains("BinaryScannerSubDirectory/binaryTestFile_1.txt"));
    Assertions.assertTrue(entries.contains("BinaryScannerSubDirectory/binaryTestFile_2.text"));
    FileUtils.deleteDirectory(rootDirectory);
}
Also used : SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) DetectDirectoryFileFilter(com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with DetectDirectoryFileFilter

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

the class DetectConfigurationFactory method createBinaryScanOptions.

public BinaryScanOptions createBinaryScanOptions() {
    Path singleTarget = detectConfiguration.getPathOrNull(DetectProperties.DETECT_BINARY_SCAN_FILE);
    List<String> fileInclusionPatterns = detectConfiguration.getValue(DetectProperties.DETECT_BINARY_SCAN_FILE_NAME_PATTERNS);
    DetectDirectoryFileFilter fileFilter = null;
    if (fileInclusionPatterns.stream().anyMatch(StringUtils::isNotBlank)) {
        fileFilter = new DetectDirectoryFileFilter(collectDirectoryExclusions(), fileInclusionPatterns);
    }
    Integer searchDepth = detectConfiguration.getValue(DetectProperties.DETECT_BINARY_SCAN_SEARCH_DEPTH);
    return new BinaryScanOptions(singleTarget, fileFilter, searchDepth, getFollowSymLinks());
}
Also used : Path(java.nio.file.Path) DetectDirectoryFileFilter(com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter) StringUtils(org.apache.commons.lang3.StringUtils) BinaryScanOptions(com.synopsys.integration.detect.tool.binaryscanner.BinaryScanOptions)

Aggregations

DetectDirectoryFileFilter (com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter)5 Test (org.junit.jupiter.api.Test)4 File (java.io.File)3 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)2 DirectoryManager (com.synopsys.integration.detect.workflow.file.DirectoryManager)2 ArrayList (java.util.ArrayList)2 BinaryScanOptions (com.synopsys.integration.detect.tool.binaryscanner.BinaryScanOptions)1 Path (java.nio.file.Path)1 StringUtils (org.apache.commons.lang3.StringUtils)1