use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class ConanCodeLocationGenerator method generateCodeLocationFromNodeMap.
@NotNull
public ConanDetectableResult generateCodeLocationFromNodeMap(ExternalIdFactory externalIdFactory, Map<String, ConanNode<String>> nodes) throws DetectableException {
logger.debug("Generating code location from {} dependencies", nodes.keySet().size());
Optional<ConanNode<String>> rootNode = getRoot(nodes.values());
if (!rootNode.isPresent()) {
throw new DetectableException("No root node found");
}
ConanGraphNode rootGraphNode = new ConanGraphNode(rootNode.get());
populateGraphUnderNode(rootGraphNode, nodes);
DependencyGraph dependencyGraph = new BasicDependencyGraph();
CodeLocation codeLocation = generateCodeLocationFromConanGraph(externalIdFactory, dependencyGraph, rootGraphNode);
return new ConanDetectableResult(rootGraphNode.getConanNode().getName().orElse(null), rootGraphNode.getConanNode().getVersion().orElse(null), codeLocation);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class SbtDotExtractor method extract.
public Extraction extract(File directory, ExecutableTarget sbt, String sbtCommandAdditionalArguments) {
try {
List<String> sbtArgs = sbtCommandArgumentGenerator.generateSbtCmdArgs(sbtCommandAdditionalArguments, "dependencyDot");
Executable dotExecutable = ExecutableUtils.createFromTarget(directory, sbt, sbtArgs);
ExecutableOutput dotOutput = executableRunner.executeSuccessfully(dotExecutable);
List<File> dotGraphs = sbtDotOutputParser.parseGeneratedGraphFiles(dotOutput.getStandardOutputAsList());
Extraction.Builder extraction = new Extraction.Builder();
for (File dotGraph : dotGraphs) {
GraphParser graphParser = new GraphParser(FileUtils.openInputStream(dotGraph));
Set<String> rootIDs = sbtRootNodeFinder.determineRootIDs(graphParser);
// typically found in project-folder/target/<>.dot so .parent.parent == project folder
File projectFolder = dotGraph.getParentFile().getParentFile();
if (rootIDs.size() == 1) {
String projectId = rootIDs.stream().findFirst().get();
DependencyGraph graph = sbtGraphParserTransformer.transformDotToGraph(graphParser, projectId);
Dependency projectDependency = graphNodeParser.nodeToDependency(projectId);
extraction.codeLocations(new CodeLocation(graph, projectDependency.getExternalId(), projectFolder));
if (projectFolder.equals(directory)) {
extraction.projectName(projectDependency.getName());
extraction.projectVersion(projectDependency.getVersion());
}
} else {
logger.warn("Unable to determine which node was the project in an SBT graph: " + dotGraph.toString());
logger.warn("This may mean you have extraneous dependencies and should consider removing them. The dependencies are: " + String.join(",", rootIDs));
DependencyGraph graph = sbtGraphParserTransformer.transformDotToGraph(graphParser, rootIDs);
extraction.codeLocations(new CodeLocation(graph, projectFolder));
}
}
return extraction.success().build();
} catch (IOException | DetectableException | ExecutableFailedException e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class ProjectInspectorExtractor method extract.
public Extraction extract(ProjectInspectorOptions projectInspectorOptions, List<String> extra, File targetDirectory, File outputDirectory, ExecutableTarget inspector) throws ExecutableFailedException {
File outputFile = new File(outputDirectory, "inspection.json");
List<String> arguments = new LinkedList<>();
arguments.add("inspect");
arguments.add("--dir");
arguments.add(targetDirectory.toString());
arguments.add("--output-file");
arguments.add(outputFile.toString());
arguments.addAll(extra);
Optional.ofNullable(projectInspectorOptions.getAdditionalArguments()).map(arg -> arg.split(" ")).ifPresent(additionalArguments -> arguments.addAll(Arrays.asList(additionalArguments)));
executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(targetDirectory, inspector, arguments));
try {
String outputContents = FileUtils.readFileToString(outputFile, StandardCharsets.UTF_8);
List<CodeLocation> codeLocations = projectInspectorParser.parse(outputContents);
return new Extraction.Builder().success(codeLocations).build();
} catch (IOException e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class ProjectInspectorParser method codeLocationFromModule.
public CodeLocation codeLocationFromModule(ProjectInspectorModule module) {
Map<String, Dependency> lookup = new HashMap<>();
// build the map of all external ids
module.dependencies.forEach(dependency -> lookup.computeIfAbsent(dependency.id, (missingId) -> convertProjectInspectorDependency(dependency)));
// and add them to the graph
DependencyGraph mutableDependencyGraph = new BasicDependencyGraph();
module.dependencies.forEach(moduleDependency -> {
Dependency dependency = lookup.get(moduleDependency.id);
moduleDependency.includedBy.forEach(parent -> {
if ("DIRECT".equals(parent)) {
mutableDependencyGraph.addChildToRoot(dependency);
} else if (lookup.containsKey(parent)) {
mutableDependencyGraph.addChildWithParent(dependency, lookup.get(parent));
} else {
// Theoretically should not happen according to PI devs. -jp
throw new RuntimeException("An error occurred reading the project inspector output." + " An unknown parent dependency was encountered '" + parent + "' while including dependency '" + moduleDependency.name + "'.");
}
});
});
return new CodeLocation(mutableDependencyGraph, new File(module.moduleFile));
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PnpmLockYamlParser method parse.
public List<CodeLocation> parse(File pnpmLockYamlFile, @Nullable NameVersion projectNameVersion, PnpmLinkedPackageResolver linkedPackageResolver) throws IOException, IntegrationException {
PnpmLockYaml pnpmLockYaml = parseYamlFile(pnpmLockYamlFile);
List<CodeLocation> codeLocationsFromImports = createCodeLocationsFromImports(pnpmLockYamlFile.getParentFile(), pnpmLockYaml, linkedPackageResolver, projectNameVersion);
if (codeLocationsFromImports.isEmpty()) {
return createCodeLocationsFromRoot(pnpmLockYamlFile.getParentFile(), pnpmLockYaml, projectNameVersion, linkedPackageResolver);
}
return codeLocationsFromImports;
}
Aggregations