use of com.synopsys.integration.executable.Executable in project synopsys-detect by blackducksoftware.
the class DockerExtractorTest method testExtractTarReturningOriginalTar.
@Test
@DisabledOnOs(WINDOWS)
public void testExtractTarReturningOriginalTar() throws ExecutableRunnerException, IOException {
String image = null;
String imageId = null;
String tar = fakeDockerTarFile.getAbsolutePath();
DetectableExecutableRunner executableRunner = getDetectableExecutableRunner();
Extraction extraction = extract(image, imageId, tar, null, null, fakeResultsFile, executableRunner);
// No returned .tar.gz: scan given docker tar instead
assertTrue(extraction.getMetaData(DockerExtractor.DOCKER_IMAGE_NAME_META_DATA).get().endsWith("testDockerTarfile.tar"));
assertTrue(extraction.getMetaData(DockerExtractor.DOCKER_TAR_META_DATA).get().getName().endsWith("testDockerTarfile.tar"));
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"));
assertTrue(command.get(4).startsWith("--docker.tar="));
assertTrue(command.get(4).endsWith("testDockerTarfile.tar"));
}
use of com.synopsys.integration.executable.Executable in project synopsys-detect by blackducksoftware.
the class BatteryDetectRunner method executeDetectScript.
private DetectOutput executeDetectScript(List<String> detectArguments) throws ExecutableRunnerException {
List<String> shellArguments = new ArrayList<>();
String target = "";
if (SystemUtils.IS_OS_WINDOWS) {
target = "powershell";
shellArguments.add("\"[Net.ServicePointManager]::SecurityProtocol = 'tls12'; irm https://detect.synopsys.com/detect.ps1?$(Get-Random) | iex; detect\"");
} else {
File scriptTarget = new File(scriptDirectory, "detect.sh");
if (scriptTarget.exists()) {
Assertions.assertTrue(scriptTarget.delete(), "Failed to cleanup an existing detect shell script. This file is cleaned up to ensure latest script is always used.");
}
ExecutableOutput downloadOutput = downloadDetectBash(scriptTarget);
Assertions.assertTrue(downloadOutput.getReturnCode() == 0 && scriptTarget.exists(), "Something went wrong downloading the detect script.");
Assertions.assertTrue(scriptTarget.setExecutable(true), "Failed to change script permissions to execute. The downloaded detect script must be executable.");
target = scriptTarget.toString();
}
shellArguments.addAll(detectArguments);
Map<String, String> environmentVariables = new HashMap<>();
if (StringUtils.isNotBlank(detectVersion)) {
environmentVariables.put("DETECT_LATEST_RELEASE_VERSION", detectVersion);
}
Executable executable = Executable.create(outputDirectory, environmentVariables, target, shellArguments);
ProcessBuilderRunner executableRunner = new ProcessBuilderRunner(new Slf4jIntLogger(logger));
ExecutableOutput result = executableRunner.execute(executable);
Assertions.assertEquals(0, result.getReturnCode(), "Detect returned a non-zero exit code:" + result.getReturnCode());
List<String> lines = result.getStandardOutputAsList();
Assertions.assertTrue(lines.size() > 0, "Detect wrote nothing to standard out.");
return new DetectOutput(result.getStandardOutputAsList());
}
use of com.synopsys.integration.executable.Executable in project synopsys-detect by blackducksoftware.
the class BatteryDetectRunner method downloadDetectBash.
private ExecutableOutput downloadDetectBash(File target) throws ExecutableRunnerException {
List<String> shellArguments = new ArrayList<>();
shellArguments.add("-s");
shellArguments.add("-L");
shellArguments.add("https://detect.synopsys.com/detect.sh");
shellArguments.add("-o");
shellArguments.add(target.toString());
Executable executable = Executable.create(outputDirectory, new HashMap<>(), "curl", shellArguments);
ProcessBuilderRunner executableRunner = new ProcessBuilderRunner(new Slf4jIntLogger(logger));
return executableRunner.execute(executable);
}
use of com.synopsys.integration.executable.Executable in project synopsys-detect by blackducksoftware.
the class RebarExtractor method extract.
public Extraction extract(File directory, ExecutableTarget rebarExe) {
try {
toolVersionLogger.log(directory, rebarExe);
List<CodeLocation> codeLocations = new ArrayList<>();
Map<String, String> envVars = new HashMap<>();
envVars.put("REBAR_COLOR", "none");
List<String> arguments = new ArrayList<>();
arguments.add("tree");
Executable rebar3TreeExe = ExecutableUtils.createFromTarget(directory, envVars, rebarExe, arguments);
List<String> output = executableRunner.execute(rebar3TreeExe).getStandardOutputAsList();
RebarParseResult parseResult = rebarTreeParser.parseRebarTreeOutput(output);
codeLocations.add(parseResult.getCodeLocation());
Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
parseResult.getProjectNameVersion().ifPresent(projectNameVersion -> builder.projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()));
return builder.build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.executable.Executable in project synopsys-detect by blackducksoftware.
the class DockerExtractorTest method testExtractImageReturningContainerFileSystem.
@Test
@DisabledOnOs(WINDOWS)
public void testExtractImageReturningContainerFileSystem() throws ExecutableRunnerException, IOException {
final String image = "ubuntu:latest";
String imageId = null;
String tar = null;
DetectableExecutableRunner executableRunner = getDetectableExecutableRunner();
Extraction extraction = extract(image, imageId, tar, fakeContainerFileSystemFile, null, fakeResultsFile, executableRunner);
assertEquals("ubuntu:latest", extraction.getMetaData(DockerExtractor.DOCKER_IMAGE_NAME_META_DATA).get());
assertTrue(extraction.getMetaData(DockerExtractor.CONTAINER_FILESYSTEM_META_DATA).get().getName().endsWith("_containerfilesystem.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));
}
Aggregations