use of com.synopsys.integration.common.util.finder.SimpleFileFinder in project synopsys-detect by blackducksoftware.
the class SimpleFileFinderTest method findFiles.
private List<File> findFiles(boolean followSymLinks) throws IOException {
// Create a subDir with a symlink that points to isolated directory
File initialDirectory = initialDirectoryPath.toFile();
File subDir = new File(initialDirectory, "sub");
subDir.mkdirs();
File link = new File(subDir, "linkToInitial");
Path linkPath = link.toPath();
Files.createSymbolicLink(linkPath, initialDirectoryPath);
File regularDir = new File(subDir, "regularDir");
regularDir.mkdir();
File regularFile = new File(subDir, "regularFile");
regularFile.createNewFile();
SimpleFileFinder finder = new SimpleFileFinder();
List<String> filenamePatterns = Arrays.asList("sub", "linkToInitial", "regularDir", "regularFile");
return finder.findFiles(initialDirectoryPath.toFile(), filenamePatterns, followSymLinks, 10);
}
use of com.synopsys.integration.common.util.finder.SimpleFileFinder 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);
}
use of com.synopsys.integration.common.util.finder.SimpleFileFinder in project synopsys-detect by blackducksoftware.
the class DetectorFinderTest method testSimple.
@Test
// TODO: See if we can fix on windows.
@DisabledOnOs(WINDOWS)
public void testSimple() {
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS);
File initialDirectory = initialDirectoryPath.toFile();
File subDir = new File(initialDirectory, "testSimple");
subDir.mkdirs();
File subSubDir1 = new File(subDir, "subSubDir1");
subSubDir1.mkdir();
File subSubDir2 = new File(subDir, "subSubDir2");
subSubDir2.mkdir();
DetectorRuleSet detectorRuleSet = new DetectorRuleSet(new ArrayList<>(0), new HashMap<>(0));
Predicate<File> fileFilter = f -> true;
int maximumDepth = 10;
DetectorFinderOptions options = new DetectorFinderOptions(fileFilter, maximumDepth, false);
DetectorFinder finder = new DetectorFinder();
Optional<DetectorEvaluationTree> tree = finder.findDetectors(initialDirectory, detectorRuleSet, options, new SimpleFileFinder());
// make sure both dirs were found
Set<DetectorEvaluationTree> testDirs = tree.get().getChildren();
DetectorEvaluationTree simpleTestDir = null;
for (DetectorEvaluationTree testDir : testDirs) {
if (testDir.getDirectory().getName().equals("testSimple")) {
simpleTestDir = testDir;
break;
}
}
Set<DetectorEvaluationTree> subDirResults = simpleTestDir.getChildren();
assertEquals(2, subDirResults.size());
String subDirContentsName = subDirResults.iterator().next().getDirectory().getName();
assertTrue(subDirContentsName.startsWith("subSubDir"));
}
use of com.synopsys.integration.common.util.finder.SimpleFileFinder in project synopsys-detect by blackducksoftware.
the class DetectorToolTest method executeToolTest.
private DetectorToolResult executeToolTest(Extraction extraction, DetectableResult extractionResult, String projectBomTool) throws DetectableException, ExecutableFailedException {
ExtractionEnvironmentProvider extractionEnvironmentProvider = Mockito.mock(ExtractionEnvironmentProvider.class);
DetectorFinder detectorFinder = Mockito.mock(DetectorFinder.class);
EventSystem eventSystem = Mockito.mock(EventSystem.class);
CodeLocationConverter codeLocationConverter = Mockito.mock(CodeLocationConverter.class);
DetectorIssuePublisher detectorIssuePublisher = Mockito.mock(DetectorIssuePublisher.class);
StatusEventPublisher statusEventPublisher = Mockito.mock(StatusEventPublisher.class);
ExitCodePublisher exitCodePublisher = Mockito.mock(ExitCodePublisher.class);
DetectorEventPublisher detectorEventPublisher = Mockito.mock(DetectorEventPublisher.class);
DetectorTool tool = new DetectorTool(detectorFinder, extractionEnvironmentProvider, eventSystem, codeLocationConverter, detectorIssuePublisher, statusEventPublisher, exitCodePublisher, detectorEventPublisher);
File directory = new File(".");
GoModCliDetectable detectable = createDetectable(extraction, extractionResult);
DetectorRule<GoModCliDetectable> rule = createRule(detectable);
DetectorRuleSet detectorRuleSet = createRuleSet(rule);
DetectorFinderOptions detectorFinderOptions = createFinderOptions();
DetectorEvaluationOptions evaluationOptions = createEvaluationOptions();
DetectorEvaluationTree evaluationTree = createEvaluationTree(extraction, extractionResult, directory, rule, detectorRuleSet);
Mockito.when(detectorFinder.findDetectors(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(Optional.of(evaluationTree));
return tool.performDetectors(directory, detectorRuleSet, detectorFinderOptions, evaluationOptions, projectBomTool, new ArrayList<>(), new SimpleFileFinder());
}
use of com.synopsys.integration.common.util.finder.SimpleFileFinder 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);
}
Aggregations