use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class SwiftPackageTransformer method transform.
public CodeLocation transform(SwiftPackage rootSwiftPackage) {
DependencyGraph dependencyGraph = new BasicDependencyGraph();
for (SwiftPackage swiftPackageDependency : rootSwiftPackage.getDependencies()) {
Dependency dependency = convertToDependency(dependencyGraph, swiftPackageDependency);
dependencyGraph.addChildToRoot(dependency);
}
return new CodeLocation(dependencyGraph);
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class NugetInspectorExtractor method extract.
public Extraction extract(List<File> targets, File outputDirectory, ExecutableTarget 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<>();
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);
// TODO: I don't like this casting, perhaps this doesn't have to happen here in 8.0.0. JM-04/2022
destination.getDependencyGraph().copyGraphToRoot((BasicDependencyGraph) 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();
}
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class Rebar3TreeParser method parseRebarTreeOutput.
public RebarParseResult parseRebarTreeOutput(List<String> dependencyTreeOutput) {
DependencyGraph graph = new BasicDependencyGraph();
DependencyHistory history = new DependencyHistory();
Dependency project = null;
for (String line : dependencyTreeOutput) {
if (!line.contains(HORIZONTAL_SEPARATOR_CHARACTER)) {
continue;
}
Dependency currentDependency = createDependencyFromLine(line);
int lineLevel = getDependencyLevelFromLine(line);
try {
history.clearDependenciesDeeperThan(lineLevel);
} catch (IllegalStateException e) {
logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
}
if (history.isEmpty() && isProject(line)) {
project = currentDependency;
} else if (history.getLastDependency().equals(project)) {
graph.addChildToRoot(currentDependency);
} else if (history.isEmpty()) {
graph.addChildToRoot(currentDependency);
} else {
graph.addChildWithParents(currentDependency, history.getLastDependency());
}
history.add(currentDependency);
}
if (project == null) {
CodeLocation codeLocation = new CodeLocation(graph);
return new RebarParseResult(codeLocation);
} else {
CodeLocation codeLocation = new CodeLocation(graph, project.getExternalId());
return new RebarParseResult(new NameVersion(project.getName(), project.getVersion()), codeLocation);
}
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class GemlockExtractor method extract.
public Extraction extract(File gemlock) {
try {
List<String> gemlockText = Files.readAllLines(gemlock.toPath(), StandardCharsets.UTF_8);
GemlockParser gemlockParser = new GemlockParser(externalIdFactory);
DependencyGraph dependencyGraph = gemlockParser.parseProjectDependencies(gemlockText);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations