Search in sources :

Example 1 with DockerInspectorInfo

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);
        }
    }
}
Also used : Path(java.nio.file.Path) Optional(java.util.Optional) File(java.io.File) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException) IOException(java.io.IOException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DockerInspectorInfo(com.synopsys.integration.detectable.detectables.docker.DockerInspectorInfo)

Example 2 with DockerInspectorInfo

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

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);
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) File(java.io.File) DockerInspectorInfo(com.synopsys.integration.detectable.detectables.docker.DockerInspectorInfo)

Aggregations

DockerInspectorInfo (com.synopsys.integration.detectable.detectables.docker.DockerInspectorInfo)3 File (java.io.File)3 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)1 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)1 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)1 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)1 DockerExtractor (com.synopsys.integration.detectable.detectables.docker.DockerExtractor)1 DockerProperties (com.synopsys.integration.detectable.detectables.docker.DockerProperties)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Optional (java.util.Optional)1