use of com.synopsys.integration.detectable.detectables.cargo.data.CargoLockData 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();
}
Aggregations