use of com.synopsys.integration.detectable.detectable.inspector.nuget.NugetInspector 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.detectable.detectable.inspector.nuget.NugetInspector 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