use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class SbtPluginFinder method listPlugins.
private List<String> listPlugins(File directory, ExecutableTarget sbt, @Nullable String sbtCommandAdditionalArguments) throws DetectableException {
try {
List<String> args = sbtCommandArgumentGenerator.generateSbtCmdArgs(sbtCommandAdditionalArguments, "plugins");
ExecutableOutput output = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(directory, sbt, args));
return output.getStandardOutputAsList();
} catch (ExecutableFailedException e) {
throw new DetectableException("Unable to list installed sbt plugins, detect requires a suitable sbt plugin is available to find dependency graphs.", e);
}
}
use of com.synopsys.integration.executable.ExecutableOutput 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.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class BatteryDetectRunner method executeDetectJar.
private DetectOutput executeDetectJar(DetectJar detectJar, List<String> detectArguments) throws ExecutableRunnerException {
List<String> javaArguments = new ArrayList<>();
javaArguments.add("-jar");
javaArguments.add(detectJar.getJar());
javaArguments.addAll(detectArguments);
ProcessBuilderRunner executableRunner = new ProcessBuilderRunner(new Slf4jIntLogger(logger));
ExecutableOutput result = executableRunner.execute(Executable.create(outputDirectory, detectJar.getJava(), javaArguments));
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.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class PearCliExtractor method extract.
public Extraction extract(ExecutableTarget pearExe, File packageXmlFile, File workingDirectory) {
try {
ExecutableOutput pearListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "list"));
ExecutableOutput packageDependenciesOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME));
assertValidExecutableOutput(pearListOutput, packageDependenciesOutput);
Map<String, String> dependencyNameVersionMap = pearListParser.parse(pearListOutput.getStandardOutputAsList());
List<PackageDependency> packageDependencies = pearPackageDependenciesParser.parse(packageDependenciesOutput.getStandardOutputAsList());
DependencyGraph dependencyGraph = pearDependencyGraphTransformer.buildDependencyGraph(dependencyNameVersionMap, packageDependencies);
try (InputStream packageXmlInputStream = new FileInputStream(packageXmlFile)) {
NameVersion projectNameVersion = pearPackageXmlParser.parse(packageXmlInputStream);
ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PEAR, projectNameVersion.getName(), projectNameVersion.getVersion());
CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, externalId);
return new Extraction.Builder().success(detectCodeLocation).projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()).build();
}
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class PipenvExtractor method extract.
public Extraction extract(File directory, ExecutableTarget pythonExe, ExecutableTarget pipenvExe, File setupFile, String providedProjectName, String providedProjectVersionName, boolean includeOnlyProjectTree) {
Extraction extraction;
try {
String projectName = resolveProjectName(directory, pythonExe, setupFile, providedProjectName);
String projectVersionName = resolveProjectVersionName(directory, pythonExe, setupFile, providedProjectVersionName);
ExecutableOutput pipFreezeOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pipenvExe, Arrays.asList("run", "pip", "freeze")));
ExecutableOutput graphOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pipenvExe, Arrays.asList("graph", "--bare", "--json-tree")));
PipFreeze pipFreeze = pipenvFreezeParser.parse(pipFreezeOutput.getStandardOutputAsList());
PipenvGraph pipenvGraph = pipEnvJsonGraphParser.parse(graphOutput.getStandardOutput());
CodeLocation codeLocation = pipenvTransformer.transform(projectName, projectVersionName, pipFreeze, pipenvGraph, includeOnlyProjectTree);
return new Extraction.Builder().projectName(projectName).projectVersion(projectVersionName).success(codeLocation).build();
} catch (Exception e) {
extraction = new Extraction.Builder().exception(e).build();
}
return extraction;
}
Aggregations