Search in sources :

Example 6 with FileFinder

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

the class NpmCliDetectableTest method testApplicable.

@Test
public void testApplicable() {
    NpmResolver npmResolver = null;
    NpmCliExtractor npmCliExtractor = null;
    DetectableEnvironment environment = MockDetectableEnvironment.empty();
    FileFinder fileFinder = MockFileFinder.withFileNamed("package.json");
    NpmCliDetectable detectable = new NpmCliDetectable(environment, fileFinder, npmResolver, npmCliExtractor, new NpmCliExtractorOptions(EnumListFilter.fromExcluded(NpmDependencyType.DEV, NpmDependencyType.PEER), ""));
    assertTrue(detectable.applicable().getPassed());
}
Also used : NpmCliExtractorOptions(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliExtractorOptions) NpmResolver(com.synopsys.integration.detectable.detectable.executable.resolver.NpmResolver) NpmCliExtractor(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliExtractor) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) MockFileFinder(com.synopsys.integration.detectable.util.MockFileFinder) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) MockDetectableEnvironment(com.synopsys.integration.detectable.util.MockDetectableEnvironment) Test(org.junit.jupiter.api.Test)

Example 7 with FileFinder

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

the class PubDepsDetectableTest method testThrowExceptionWhenLockFilePresentButNotYaml.

@Test
public void testThrowExceptionWhenLockFilePresentButNotYaml() throws DetectableException {
    FileFinder fileFinder = Mockito.mock(FileFinder.class);
    Mockito.when(fileFinder.findFile(null, "pubspec.yaml")).thenReturn(null);
    Mockito.when(fileFinder.findFile(null, "pubspec.lock")).thenReturn(new File(""));
    DartPubDepDetectable dartPubDepDetectable = new DartPubDepDetectable(new DetectableEnvironment(null), fileFinder, null, null, null, null);
    DetectableResult applicable = dartPubDepDetectable.applicable();
    Assertions.assertTrue(applicable.getPassed());
    DetectableResult extractable = dartPubDepDetectable.extractable();
    Assertions.assertTrue(extractable instanceof FileNotFoundDetectableResult);
}
Also used : FileNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.FileNotFoundDetectableResult) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) FileNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.FileNotFoundDetectableResult) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DartPubDepDetectable(com.synopsys.integration.detectable.detectables.dart.pubdep.DartPubDepDetectable) Test(org.junit.jupiter.api.Test)

Example 8 with FileFinder

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

the class DockerExtractorTest method extract.

private Extraction extract(String image, String imageId, String tar, File returnedContainerFileSystemFile, File returnedSquashedImageFile, File resultsFile, DetectableExecutableRunner executableRunner) throws IOException, ExecutableRunnerException {
    FileFinder fileFinder = Mockito.mock(FileFinder.class);
    DockerExtractor dockerExtractor = getMockDockerExtractor(executableRunner, fileFinder);
    File directory = new File(".");
    File outputDirectory = new File("build/tmp/test/DockerExtractorTest");
    ExecutableTarget bashExe = null;
    ExecutableTarget javaExe = ExecutableTarget.forFile(new File("fake/test/java"));
    DockerInspectorInfo dockerInspectorInfo = Mockito.mock(DockerInspectorInfo.class);
    Mockito.when(fileFinder.findFile(outputDirectory, DockerExtractor.CONTAINER_FILESYSTEM_FILENAME_PATTERN)).thenReturn(returnedContainerFileSystemFile);
    Mockito.when(fileFinder.findFile(outputDirectory, DockerExtractor.SQUASHED_IMAGE_FILENAME_PATTERN)).thenReturn(returnedSquashedImageFile);
    Mockito.when(fileFinder.findFile(outputDirectory, DockerExtractor.RESULTS_FILENAME_PATTERN)).thenReturn(resultsFile);
    Mockito.when(dockerInspectorInfo.getDockerInspectorJar()).thenReturn(new File("fake/test/dockerinspector.jar"));
    return dockerExtractor.extract(directory, outputDirectory, bashExe, javaExe, image, imageId, tar, dockerInspectorInfo, Mockito.mock(DockerProperties.class));
}
Also used : DockerProperties(com.synopsys.integration.detectable.detectables.docker.DockerProperties) DockerExtractor(com.synopsys.integration.detectable.detectables.docker.DockerExtractor) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) File(java.io.File) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) DockerInspectorInfo(com.synopsys.integration.detectable.detectables.docker.DockerInspectorInfo)

Example 9 with FileFinder

use of com.synopsys.integration.common.util.finder.FileFinder 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 10 with FileFinder

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

the class PoetryFalsePositiveTest method testApplicableNoFalsePositive.

@Test
public void testApplicableNoFalsePositive() throws URISyntaxException {
    FileFinder fileFinder = Mockito.mock(SimpleFileFinder.class);
    File currentDirectory = new File(System.getProperty("user.dir"));
    File pyprojectToml = new File(getClass().getClassLoader().getResource("detectables/unit/pip/poetry/false_positive_pyproject.toml").toURI());
    Mockito.when(fileFinder.findFile(currentDirectory, "pyproject.toml")).thenReturn(pyprojectToml);
    PoetryDetectable poetryDetectable = new PoetryDetectable(new DetectableEnvironment(currentDirectory), fileFinder, new PoetryExtractor(new PoetryLockParser()), new ToolPoetrySectionParser());
    Assertions.assertFalse(poetryDetectable.applicable().getPassed());
}
Also used : PoetryExtractor(com.synopsys.integration.detectable.detectables.poetry.PoetryExtractor) PoetryDetectable(com.synopsys.integration.detectable.detectables.poetry.PoetryDetectable) PoetryLockParser(com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) ToolPoetrySectionParser(com.synopsys.integration.detectable.detectables.poetry.parser.ToolPoetrySectionParser) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

FileFinder (com.synopsys.integration.common.util.finder.FileFinder)15 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)12 Test (org.junit.jupiter.api.Test)12 MockDetectableEnvironment (com.synopsys.integration.detectable.util.MockDetectableEnvironment)9 MockFileFinder (com.synopsys.integration.detectable.util.MockFileFinder)8 File (java.io.File)6 NugetInspectorResolver (com.synopsys.integration.detectable.detectable.inspector.nuget.NugetInspectorResolver)3 NugetInspectorExtractor (com.synopsys.integration.detectable.detectables.nuget.NugetInspectorExtractor)3 NugetInspectorOptions (com.synopsys.integration.detectable.detectables.nuget.NugetInspectorOptions)3 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)2 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)2 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)2 DockerExtractor (com.synopsys.integration.detectable.detectables.docker.DockerExtractor)2 NugetSolutionDetectable (com.synopsys.integration.detectable.detectables.nuget.NugetSolutionDetectable)2 Gson (com.google.gson.Gson)1 DetectInfo (com.synopsys.integration.detect.configuration.DetectInfo)1 DetectBootResult (com.synopsys.integration.detect.lifecycle.boot.DetectBootResult)1 ExitManager (com.synopsys.integration.detect.lifecycle.exit.ExitManager)1 ProductRunData (com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)1 ExceptionUtility (com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility)1