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