use of com.synopsys.integration.common.util.finder.SimpleFileFinder 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.common.util.finder.SimpleFileFinder in project synopsys-detect by blackducksoftware.
the class DetectorFinderTest method testSymLinks.
private void testSymLinks(boolean followSymLinks) throws IOException {
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS);
File initialDirectory = createDirWithSymLink("testSymLinks");
DetectorRuleSet detectorRuleSet = new DetectorRuleSet(new ArrayList<>(0), new HashMap<>(0));
DetectorFinderOptions options = createFinderOptions(followSymLinks);
DetectorFinder finder = new DetectorFinder();
Optional<DetectorEvaluationTree> tree = finder.findDetectors(initialDirectory, detectorRuleSet, options, new SimpleFileFinder());
// make sure the symlink was omitted from results
// final Set<DetectorEvaluationTree> subDirResults = tree.get().getChildren().iterator().next().getChildren();
Set<DetectorEvaluationTree> testDirs = tree.get().getChildren();
DetectorEvaluationTree symLinkTestDir = null;
for (DetectorEvaluationTree testDir : testDirs) {
if (testDir.getDirectory().getName().equals("testSymLinks")) {
symLinkTestDir = testDir;
break;
}
}
Set<DetectorEvaluationTree> subDirResults = symLinkTestDir.getChildren();
if (followSymLinks) {
assertEquals(2, subDirResults.size());
} else {
assertEquals(1, subDirResults.size());
String subDirContentsName = subDirResults.iterator().next().getDirectory().getName();
assertEquals("regularDir", subDirContentsName);
}
FileUtils.deleteDirectory(initialDirectory);
}
use of com.synopsys.integration.common.util.finder.SimpleFileFinder in project synopsys-detect by blackducksoftware.
the class Application method run.
@Override
public void run(ApplicationArguments applicationArguments) {
long startTime = System.currentTimeMillis();
// Events, Status and Exit Codes are required even if boot fails.
EventSystem eventSystem = new EventSystem();
DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
ExceptionUtility exceptionUtility = new ExceptionUtility();
ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exceptionUtility);
ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
ReportListener.createDefault(eventSystem);
FormattedOutputManager formattedOutputManager = new FormattedOutputManager(eventSystem);
InstalledToolManager installedToolManager = new InstalledToolManager();
// Before boot even begins, we create a new Spring context for Detect to work within.
logger.debug("Initializing detect.");
DetectRunId detectRunId = DetectRunId.createDefault();
Gson gson = BlackDuckServicesFactory.createDefaultGsonBuilder().setPrettyPrinting().create();
DetectInfo detectInfo = DetectInfoUtility.createDefaultDetectInfo();
FileFinder fileFinder = new SimpleFileFinder();
boolean shouldForceSuccess = false;
Optional<DetectBootResult> detectBootResultOptional = bootApplication(detectRunId, applicationArguments.getSourceArgs(), eventSystem, exitCodeManager, gson, detectInfo, fileFinder, installedToolManager, exceptionUtility);
if (detectBootResultOptional.isPresent()) {
DetectBootResult detectBootResult = detectBootResultOptional.get();
shouldForceSuccess = detectBootResult.shouldForceSuccess();
runApplication(eventSystem, exitCodeManager, detectBootResult, exceptionUtility);
detectBootResult.getProductRunData().filter(ProductRunData::shouldUseBlackDuckProduct).map(ProductRunData::getBlackDuckRunData).flatMap(BlackDuckRunData::getPhoneHomeManager).ifPresent(PhoneHomeManager::phoneHomeOperations);
// Create status output file.
logger.info("");
detectBootResult.getDirectoryManager().ifPresent(directoryManager -> createStatusOutputFile(formattedOutputManager, detectInfo, directoryManager));
// Create installed tool data file.
detectBootResult.getDirectoryManager().ifPresent(directoryManager -> createOrUpdateInstalledToolsFile(installedToolManager, directoryManager.getPermanentDirectory()));
shutdownApplication(detectBootResult, exitCodeManager);
} else {
logger.info("Will not create status file, detect did not boot.");
}
logger.debug("All Detect actions completed.");
exitApplication(exitManager, startTime, shouldForceSuccess);
}
use of com.synopsys.integration.common.util.finder.SimpleFileFinder 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);
}
use of com.synopsys.integration.common.util.finder.SimpleFileFinder in project synopsys-detect by blackducksoftware.
the class DetectorToolTest method testFailWhenMisConfigured.
@Test
public void testFailWhenMisConfigured() throws DetectUserFriendlyException {
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(".");
DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
DetectorFinderOptions detectorFinderOptions = Mockito.mock(DetectorFinderOptions.class);
DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
String projectBomTool = "testBomTool";
tool.performDetectors(directory, detectorRuleSet, detectorFinderOptions, evaluationOptions, projectBomTool, new ArrayList<>(), new SimpleFileFinder());
Mockito.verify(exitCodePublisher).publishExitCode(Mockito.any(ExitCodeType.class), Mockito.anyString());
}
Aggregations