use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class CargoExtractor method extract.
public Extraction extract(File cargoLockFile, @Nullable File cargoTomlFile) throws IOException, DetectableException, MissingExternalIdException {
CargoLockData cargoLockData = new Toml().read(cargoLockFile).to(CargoLockData.class);
List<CargoLockPackage> packages = cargoLockData.getPackages().orElse(new ArrayList<>()).stream().map(cargoLockPackageDataTransformer::transform).collect(Collectors.toList());
DependencyGraph graph = cargoLockPackageTransformer.transformToGraph(packages);
Optional<NameVersion> projectNameVersion = Optional.empty();
if (cargoTomlFile != null) {
String cargoTomlContents = FileUtils.readFileToString(cargoTomlFile, StandardCharsets.UTF_8);
projectNameVersion = cargoTomlParser.parseNameVersionFromCargoToml(cargoTomlContents);
}
// TODO: Consider for 8.0.0 providing an external ID.
CodeLocation codeLocation = new CodeLocation(graph);
return new Extraction.Builder().success(codeLocation).nameVersionIfPresent(projectNameVersion).build();
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class PodlockExtractor method extract.
public Extraction extract(File podlock) {
String podLockText;
try {
logger.trace(String.format("Reading from the pod lock file %s", podlock.getAbsolutePath()));
podLockText = FileUtils.readFileToString(podlock, StandardCharsets.UTF_8);
logger.trace("Finished reading from the pod lock file.");
} catch (IOException e) {
return new Extraction.Builder().exception(e).build();
}
DependencyGraph dependencyGraph;
try {
logger.trace("Attempting to create the dependency graph from the pod lock file.");
dependencyGraph = podlockParser.extractDependencyGraph(podLockText);
logger.trace("Finished creating the dependency graph from the pod lock file.");
} catch (IOException | MissingExternalIdException e) {
return new Extraction.Builder().exception(e).build();
}
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).build();
}
use of com.synopsys.integration.detectable.extraction.Extraction 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.extraction.Extraction 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.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class SbtResolutionCacheExtractor method extract.
public Extraction extract(File directory, SbtResolutionCacheOptions sbtResolutionCacheOptions) {
// TODO: Extractor should not use DetectableOptions
try {
// TODO: Handle null better.
List<String> included = sbtResolutionCacheOptions.getIncludedConfigurations();
List<String> excluded = sbtResolutionCacheOptions.getExcludedConfigurations();
int depth = sbtResolutionCacheOptions.getReportDepth();
SbtProject project = extractProject(directory, sbtResolutionCacheOptions.isFollowSymLinks(), depth, included, excluded);
List<CodeLocation> codeLocations = new ArrayList<>();
String projectName = null;
String projectVersion = null;
for (SbtDependencyModule module : project.getModules()) {
CodeLocation codeLocation;
if (project.getProjectExternalId() != null) {
codeLocation = new CodeLocation(module.getGraph(), project.getProjectExternalId());
} else {
codeLocation = new CodeLocation(module.getGraph());
}
if (projectName == null) {
projectName = project.getProjectName();
projectVersion = project.getProjectVersion();
}
codeLocations.add(codeLocation);
}
if (codeLocations.size() > 0) {
return new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
} else {
logger.error("Unable to find any dependency information.");
return new Extraction.Builder().failure("Unable to find any dependency information.").build();
}
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations