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;
}
use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class NugetInspectorExtractor method executeTarget.
private NugetTargetResult executeTarget(NugetInspector inspector, File targetFile, File outputDirectory, NugetInspectorOptions nugetInspectorOptions) throws ExecutableRunnerException, IOException, DetectableException {
if (!outputDirectory.exists() && !outputDirectory.mkdirs()) {
throw new DetectableException(String.format("Executing the nuget inspector failed, could not create output directory: %s", outputDirectory));
}
ExecutableOutput executableOutput = inspector.execute(outputDirectory, targetFile, outputDirectory, nugetInspectorOptions);
if (executableOutput.getReturnCode() != 0) {
throw new DetectableException(String.format("Executing the nuget inspector failed: %s", executableOutput.getReturnCode()));
}
List<File> dependencyNodeFiles = fileFinder.findFiles(outputDirectory, INSPECTOR_OUTPUT_PATTERN);
List<NugetParseResult> parseResults = new ArrayList<>();
if (dependencyNodeFiles != null) {
for (File dependencyNodeFile : dependencyNodeFiles) {
String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8);
NugetParseResult result = nugetInspectorParser.createCodeLocation(text);
parseResults.add(result);
}
}
NugetTargetResult targetResult = new NugetTargetResult();
targetResult.codeLocations = parseResults.stream().flatMap(it -> it.getCodeLocations().stream()).collect(Collectors.toList());
targetResult.nameVersion = parseResults.stream().filter(it -> StringUtils.isNotBlank(it.getProjectName())).map(it -> new NameVersion(it.getProjectName(), it.getProjectVersion())).findFirst().orElse(null);
return targetResult;
}
use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class BazelCommandExecutor method executeToString.
public Optional<String> executeToString(List<String> args) throws ExecutableFailedException {
ExecutableOutput targetDependenciesQueryResults = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(workspaceDir, bazelExe, args));
String cmdStdErr = targetDependenciesQueryResults.getErrorOutput();
if (cmdStdErr != null && cmdStdErr.contains("ERROR")) {
logger.warn("Bazel error: {}", cmdStdErr.trim());
}
String cmdStdOut = targetDependenciesQueryResults.getStandardOutput();
if ((StringUtils.isBlank(cmdStdOut))) {
logger.debug("bazel command produced no output");
return Optional.empty();
}
return Optional.of(cmdStdOut);
}
use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class CpanCliExtractor method extract.
public Extraction extract(ExecutableTarget cpanExe, ExecutableTarget cpanmExe, File workingDirectory) throws ExecutableRunnerException {
toolVersionLogger.log(workingDirectory, cpanExe);
// TODO: Consider command runner to reduce cognitive load.
ExecutableOutput cpanListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, cpanExe, "-l"));
List<String> listText = cpanListOutput.getStandardOutputAsList();
ExecutableOutput showdepsOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, cpanmExe, "--showdeps", "."));
List<String> showdeps = showdepsOutput.getStandardOutputAsList();
DependencyGraph dependencyGraph = cpanListParser.parse(listText, showdeps);
CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(detectCodeLocation).build();
}
use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class CondaCliExtractor method extract.
public Extraction extract(File directory, ExecutableTarget condaExe, File workingDirectory, String condaEnvironmentName) {
try {
toolVersionLogger.log(workingDirectory, condaExe);
List<String> condaListOptions = new ArrayList<>();
condaListOptions.add("list");
if (StringUtils.isNotBlank(condaEnvironmentName)) {
condaListOptions.add("-n");
condaListOptions.add(condaEnvironmentName);
}
condaListOptions.add("--json");
ExecutableOutput condaListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, condaExe, condaListOptions));
String listJsonText = condaListOutput.getStandardOutput();
ExecutableOutput condaInfoOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, condaExe, "info", "--json"));
String infoJsonText = condaInfoOutput.getStandardOutput();
DependencyGraph dependencyGraph = condaListParser.parse(listJsonText, infoJsonText);
CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(detectCodeLocation).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations