Search in sources :

Example 6 with SimpleFileFinder

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);
}
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 7 with SimpleFileFinder

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);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) File(java.io.File) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet)

Example 8 with SimpleFileFinder

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);
}
Also used : ExitManager(com.synopsys.integration.detect.lifecycle.exit.ExitManager) DetectRunId(com.synopsys.integration.detect.workflow.DetectRunId) DetectInfo(com.synopsys.integration.detect.configuration.DetectInfo) Gson(com.google.gson.Gson) DetectBootResult(com.synopsys.integration.detect.lifecycle.boot.DetectBootResult) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) PhoneHomeManager(com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager) FormattedOutputManager(com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData) InstalledToolManager(com.synopsys.integration.detect.tool.cache.InstalledToolManager) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) ExceptionUtility(com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectStatusManager(com.synopsys.integration.detect.workflow.status.DetectStatusManager) ExitCodeManager(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager)

Example 9 with SimpleFileFinder

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);
}
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 10 with SimpleFileFinder

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());
}
Also used : DetectorEvaluationOptions(com.synopsys.integration.detector.evaluation.DetectorEvaluationOptions) DetectorFinderOptions(com.synopsys.integration.detector.finder.DetectorFinderOptions) ExtractionEnvironmentProvider(com.synopsys.integration.detect.tool.detector.extraction.ExtractionEnvironmentProvider) ExitCodePublisher(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) ExitCodeType(com.synopsys.integration.detect.configuration.enumeration.ExitCodeType) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) DetectorFinder(com.synopsys.integration.detector.finder.DetectorFinder) StatusEventPublisher(com.synopsys.integration.detect.workflow.status.StatusEventPublisher) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)11 File (java.io.File)10 Test (org.junit.jupiter.api.Test)6 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)4 EventSystem (com.synopsys.integration.detect.workflow.event.EventSystem)3 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 ExitCodePublisher (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher)2 ExtractionEnvironmentProvider (com.synopsys.integration.detect.tool.detector.extraction.ExtractionEnvironmentProvider)2 DetectDirectoryFileFilter (com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter)2 DetectExcludedDirectoryFilter (com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter)2 DirectoryManager (com.synopsys.integration.detect.workflow.file.DirectoryManager)2 StatusEventPublisher (com.synopsys.integration.detect.workflow.status.StatusEventPublisher)2 DetectorEvaluationOptions (com.synopsys.integration.detector.evaluation.DetectorEvaluationOptions)2 DetectorFinder (com.synopsys.integration.detector.finder.DetectorFinder)2 DetectorFinderOptions (com.synopsys.integration.detector.finder.DetectorFinderOptions)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Predicate (java.util.function.Predicate)2