use of com.synopsys.integration.detectable.detectables.docker.DockerInspectorInfo in project synopsys-detect by blackducksoftware.
the class ArtifactoryDockerInspectorResolver method install.
private DockerInspectorInfo install() throws IntegrationException, IOException, DetectUserFriendlyException {
Optional<File> airGapDockerFolder = airGapInspectorPaths.getDockerInspectorAirGapFile();
// TODO: Handle null better.
Optional<Path> providedJarPath = dockerDetectableOptions.getDockerInspectorPath();
if (providedJarPath.isPresent()) {
logger.info("Docker tool will attempt to use the provided docker inspector.");
return findProvidedJar(providedJarPath.get());
} else if (airGapDockerFolder.isPresent()) {
logger.info("Docker tool will attempt to use the air gapped docker inspector.");
Optional<DockerInspectorInfo> airGapInspector = findAirGapInspector();
return airGapInspector.orElse(null);
} else {
logger.info("Docker tool will attempt to download or find docker inspector.");
File dockerDirectory = directoryManager.getPermanentDirectory(DOCKER_SHARED_DIRECTORY_NAME);
// TODO: Handle null better.
String dockerVersion = dockerDetectableOptions.getDockerInspectorVersion().orElse("");
File inspector = null;
Optional<File> cachedInstall = installedToolLocator.locateTool(INSTALLED_TOOL_JSON_KEY);
try {
inspector = dockerInspectorInstaller.installJar(dockerDirectory, Optional.of(dockerVersion));
} catch (Exception e) {
if (!cachedInstall.isPresent()) {
throw e;
}
}
if (inspector == null) {
if (cachedInstall.isPresent()) {
logger.debug("Using docker inspector from previous install.");
return new DockerInspectorInfo(cachedInstall.get());
}
return null;
} else {
installedToolManager.saveInstalledToolLocation(INSTALLED_TOOL_JSON_KEY, inspector.getAbsolutePath());
return new DockerInspectorInfo(inspector);
}
}
}
use of com.synopsys.integration.detectable.detectables.docker.DockerInspectorInfo 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.detectable.detectables.docker.DockerInspectorInfo in project synopsys-detect by blackducksoftware.
the class ArtifactoryDockerInspectorResolver method findProvidedJar.
private DockerInspectorInfo findProvidedJar(@NotNull Path providedJarPath) throws IntegrationException {
File providedJar = null;
logger.debug(String.format("Using user-provided docker inspector jar path: %s", providedJarPath));
File providedJarCandidate = providedJarPath.toFile();
if (providedJarCandidate.isFile()) {
logger.debug(String.format("Found user-specified jar: %s", providedJarCandidate.getAbsolutePath()));
providedJar = providedJarCandidate;
} else {
throw new IntegrationException(String.format("Provided Docker Inspector path (%s) does not exist or is not a file", providedJarCandidate.getAbsolutePath()));
}
return new DockerInspectorInfo(providedJar);
}
Aggregations