use of com.synopsys.integration.detectable.extraction.Extraction 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));
}
use of com.synopsys.integration.detectable.extraction.Extraction 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();
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class NugetInspectorExtractor method extract.
public Extraction extract(List<File> targets, File outputDirectory, NugetInspector inspector, NugetInspectorOptions nugetInspectorOptions) {
try {
List<NugetTargetResult> results = new ArrayList<>();
for (int i = 0; i < targets.size(); i++) {
File targetDirectory = new File(outputDirectory, "inspection-" + i);
results.add(executeTarget(inspector, targets.get(i), targetDirectory, nugetInspectorOptions));
}
List<CodeLocation> codeLocations = results.stream().flatMap(it -> it.codeLocations.stream()).collect(Collectors.toList());
Map<File, CodeLocation> codeLocationsBySource = new HashMap<>();
DependencyGraphCombiner combiner = new DependencyGraphCombiner();
codeLocations.forEach(codeLocation -> {
File sourcePathFile = codeLocation.getSourcePath().orElse(null);
if (codeLocationsBySource.containsKey(sourcePathFile)) {
logger.debug("Combined code location for: " + sourcePathFile);
CodeLocation destination = codeLocationsBySource.get(sourcePathFile);
combiner.addGraphAsChildrenToRoot((MutableDependencyGraph) destination.getDependencyGraph(), codeLocation.getDependencyGraph());
} else {
codeLocationsBySource.put(sourcePathFile, codeLocation);
}
});
Optional<NameVersion> nameVersion = results.stream().filter(it -> it.nameVersion != null).map(it -> it.nameVersion).findFirst();
List<CodeLocation> uniqueCodeLocations = new ArrayList<>(codeLocationsBySource.values());
return new Extraction.Builder().success(uniqueCodeLocations).nameVersionIfPresent(nameVersion).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations