Search in sources :

Example 16 with Executable

use of com.synopsys.integration.executable.Executable in project synopsys-detect by blackducksoftware.

the class DockerExtractorTest method testExtractImageReturningSquashedImage.

@Test
@DisabledOnOs(WINDOWS)
public void testExtractImageReturningSquashedImage() throws ExecutableRunnerException, IOException {
    final String image = "ubuntu:latest";
    String imageId = null;
    String tar = null;
    DetectableExecutableRunner executableRunner = getDetectableExecutableRunner();
    Extraction extraction = extract(image, imageId, tar, fakeContainerFileSystemFile, fakeSquashedImageFile, fakeResultsFile, executableRunner);
    assertEquals("ubuntu:latest", extraction.getMetaData(DockerExtractor.DOCKER_IMAGE_NAME_META_DATA).get());
    assertTrue(extraction.getMetaData(DockerExtractor.SQUASHED_IMAGE_META_DATA).get().getName().endsWith("_squashedimage.tar.gz"));
    ArgumentCaptor<Executable> executableArgumentCaptor = ArgumentCaptor.forClass(Executable.class);
    Mockito.verify(executableRunner).execute(executableArgumentCaptor.capture());
    Executable executableToVerify = executableArgumentCaptor.getValue();
    List<String> command = executableToVerify.getCommandWithArguments();
    assertTrue(command.get(0).endsWith("/fake/test/java"));
    assertEquals("-jar", command.get(1));
    assertTrue(command.get(2).endsWith("/fake/test/dockerinspector.jar"));
    assertTrue(command.get(3).startsWith("--spring.config.location="));
    assertTrue(command.get(3).endsWith("/application.properties"));
    assertEquals("--docker.image=ubuntu:latest", command.get(4));
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 17 with Executable

use of com.synopsys.integration.executable.Executable in project synopsys-detect by blackducksoftware.

the class DockerExtractor method executeDocker.

private Extraction executeDocker(File outputDirectory, String imageArgument, String suppliedImagePiece, String dockerTarFilePath, File directory, ExecutableTarget javaExe, ExecutableTarget dockerExe, DockerInspectorInfo dockerInspectorInfo, DockerProperties dockerProperties) throws IOException, ExecutableRunnerException {
    File dockerPropertiesFile = new File(outputDirectory, "application.properties");
    dockerProperties.populatePropertiesFile(dockerPropertiesFile, outputDirectory);
    Map<String, String> environmentVariables = new HashMap<>(0);
    List<String> dockerArguments = new ArrayList<>();
    dockerArguments.add("-jar");
    dockerArguments.add(dockerInspectorInfo.getDockerInspectorJar().getAbsolutePath());
    dockerArguments.add("--spring.config.location=file:" + dockerPropertiesFile.getCanonicalPath());
    dockerArguments.add(imageArgument);
    if (dockerInspectorInfo.hasAirGapImageFiles()) {
        importTars(dockerInspectorInfo.getAirGapInspectorImageTarFiles(), outputDirectory, environmentVariables, dockerExe);
    }
    Executable dockerExecutable = ExecutableUtils.createFromTarget(outputDirectory, environmentVariables, javaExe, dockerArguments);
    executableRunner.execute(dockerExecutable);
    File producedSquashedImageFile = fileFinder.findFile(outputDirectory, SQUASHED_IMAGE_FILENAME_PATTERN);
    if (producedSquashedImageFile != null) {
        logger.debug("Returning squashed image: {}", producedSquashedImageFile.getAbsolutePath());
    }
    File producedContainerFileSystemFile = fileFinder.findFile(outputDirectory, CONTAINER_FILESYSTEM_FILENAME_PATTERN);
    if (producedContainerFileSystemFile != null) {
        logger.debug("Returning container filesystem: {}", producedContainerFileSystemFile.getAbsolutePath());
    }
    Extraction.Builder extractionBuilder = findCodeLocations(outputDirectory, directory);
    // The value of DOCKER_IMAGE_NAME_META_DATA is built into the codelocation name, so changing how its value is derived is likely to
    // change how codelocation names are generated. Currently either an image repo, repo:tag, or tarfile path gets written there.
    // It's tempting to always store the image repo:tag in that field, but that would change code location naming with consequences for users.
    String imageIdentifier = getImageIdentifierFromOutputDirectoryIfImageIdPresent(outputDirectory, suppliedImagePiece, imageIdentifierType);
    extractionBuilder.metaData(SQUASHED_IMAGE_META_DATA, producedSquashedImageFile).metaData(CONTAINER_FILESYSTEM_META_DATA, producedContainerFileSystemFile).metaData(DOCKER_IMAGE_NAME_META_DATA, imageIdentifier);
    if (StringUtils.isNotBlank(dockerTarFilePath)) {
        File givenDockerTarfile = new File(dockerTarFilePath);
        logger.debug("Returning given docker tarfile: {}", givenDockerTarfile.getAbsolutePath());
        extractionBuilder.metaData(DOCKER_TAR_META_DATA, givenDockerTarfile);
    }
    return extractionBuilder.build();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable) File(java.io.File)

Example 18 with Executable

use of com.synopsys.integration.executable.Executable in project blackduck-docker-inspector by blackducksoftware.

the class UpdateArtifactoryPropertiesTask method curlResponse.

public ExecutableOutput curlResponse(final List<String> curlArgs) throws ExecutableRunnerException {
    final File workingDirectory = new File(System.getProperty("user.dir"));
    final List<String> command = new ArrayList<>(Collections.singletonList("curl"));
    command.addAll(curlArgs);
    final Executable executable = new Executable(workingDirectory, new HashMap<>(), command);
    final ProcessBuilderRunner processBuilderRunner = new ProcessBuilderRunner(logger);
    return processBuilderRunner.execute(executable);
}
Also used : ProcessBuilderRunner(com.synopsys.integration.executable.ProcessBuilderRunner) ArrayList(java.util.ArrayList) Executable(com.synopsys.integration.executable.Executable) File(java.io.File)

Aggregations

Executable (com.synopsys.integration.executable.Executable)18 Extraction (com.synopsys.integration.detectable.extraction.Extraction)11 File (java.io.File)9 ArrayList (java.util.ArrayList)8 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)7 HashMap (java.util.HashMap)7 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)6 Test (org.junit.jupiter.api.Test)6 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)4 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)3 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)3 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)3 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)3 ProcessBuilderRunner (com.synopsys.integration.executable.ProcessBuilderRunner)3 GoModCliExtractor (com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor)2 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)2 IOException (java.io.IOException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 GraphParser (com.paypal.digraph.parser.GraphParser)1