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