use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class PoetryExtractor method extract.
public Extraction extract(File poetryLock, @Nullable TomlTable toolDotPoetrySection) {
try {
DependencyGraph graph = poetryLockParser.parseLockFile(FileUtils.readFileToString(poetryLock, StandardCharsets.UTF_8));
CodeLocation codeLocation = new CodeLocation(graph);
Optional<NameVersion> poetryNameVersion = extractNameVersionFromToolDotPoetrySection(toolDotPoetrySection);
if (poetryNameVersion.isPresent()) {
return new Extraction.Builder().success(codeLocation).projectName(poetryNameVersion.get().getName()).projectVersion(poetryNameVersion.get().getVersion()).build();
}
return new Extraction.Builder().success(codeLocation).build();
} catch (IOException e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.extraction.Extraction 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.detectable.extraction.Extraction 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.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class CodeLocationConverter method toDetectCodeLocation.
public Map<CodeLocation, DetectCodeLocation> toDetectCodeLocation(File detectSourcePath, DetectorEvaluation evaluation) {
Map<CodeLocation, DetectCodeLocation> detectCodeLocations = new HashMap<>();
if (evaluation.wasExtractionSuccessful()) {
Extraction extraction = evaluation.getExtraction();
String name = evaluation.getDetectorType().toString();
return toDetectCodeLocation(detectSourcePath, extraction, evaluation.getDetectableEnvironment().getDirectory(), name);
}
return detectCodeLocations;
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class PubDepsExtractor method extract.
public Extraction extract(File directory, @Nullable ExecutableTarget dartExe, @Nullable ExecutableTarget flutterExe, DartPubDepsDetectableOptions dartPubDepsDetectableOptions, File pubSpecYamlFile) {
try {
toolVersionLogger.log(directory, dartExe);
toolVersionLogger.log(directory, flutterExe);
List<String> pubDepsCommand = new ArrayList<>();
pubDepsCommand.add("pub");
pubDepsCommand.add("deps");
if (dartPubDepsDetectableOptions.getDependencyTypeFilter().shouldExclude(DartPubDependencyType.DEV)) {
pubDepsCommand.add("--no-dev");
}
ExecutableOutput pubDepsOutput = null;
if (dartExe != null) {
pubDepsOutput = runPubDepsCommand(directory, dartExe, pubDepsCommand);
}
if (pubDepsOutput == null || pubDepsOutput.getReturnCode() != 0) {
if (flutterExe == null && dartExe != null) {
return new Extraction.Builder().failure(String.format("An error occurred trying to run %s %s", dartExe.toCommand(), String.join(" ", pubDepsCommand))).build();
} else {
// If command does not work with Dart, it could be because at least one of the packages requires Flutter
logger.debug("Running dart pub deps was not successful. Going to try running flutter pub deps.");
pubDepsCommand.add(0, "--no-version-check");
pubDepsOutput = runPubDepsCommand(directory, flutterExe, pubDepsCommand);
}
}
Optional<NameVersion> nameVersion = Optional.empty();
if (pubSpecYamlFile != null) {
List<String> pubSpecYamlLines = Files.readAllLines(pubSpecYamlFile.toPath(), StandardCharsets.UTF_8);
nameVersion = nameVersionParser.parseNameVersion(pubSpecYamlLines);
}
DependencyGraph dependencyGraph = pubDepsParser.parse(pubDepsOutput.getStandardOutputAsList());
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).nameVersionIfPresent(nameVersion).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations