Search in sources :

Example 1 with CargoLockData

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();
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) ArrayList(java.util.ArrayList) CargoLockData(com.synopsys.integration.detectable.detectables.cargo.data.CargoLockData) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Toml(com.moandjiezana.toml.Toml) CargoLockPackage(com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage)

Aggregations

Toml (com.moandjiezana.toml.Toml)1 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 CargoLockData (com.synopsys.integration.detectable.detectables.cargo.data.CargoLockData)1 CargoLockPackage (com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 NameVersion (com.synopsys.integration.util.NameVersion)1 ArrayList (java.util.ArrayList)1