use of com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage 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.detectables.cargo.model.CargoLockPackage in project synopsys-detect by blackducksoftware.
the class CargoLockPackageDataTransformer method transform.
public CargoLockPackage transform(CargoLockPackageData cargoLockPackageData) {
String packageName = cargoLockPackageData.getName().orElse("");
String packageVersion = cargoLockPackageData.getVersion().orElse(null);
NameVersion nameOptionalVersion = new NameVersion(packageName, packageVersion);
List<NameOptionalVersion> dependencies = cargoLockPackageData.getDependencies().map((List<String> dependencyLines) -> dependencyLines.stream().map(cargoDependencyLineParser::parseDependencyName).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList())).orElse(Collections.emptyList());
return new CargoLockPackage(nameOptionalVersion, dependencies);
}
use of com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage in project synopsys-detect by blackducksoftware.
the class CargoLockPackageTransformerTest method testParsesNamesAndVersionsSimple.
@Test
public void testParsesNamesAndVersionsSimple() throws DetectableException, MissingExternalIdException, CycleDetectedException {
List<CargoLockPackage> input = new ArrayList<>();
input.add(createPackage("test1", "1.0.0"));
input.add(createPackage("test2", "2.0.0"));
CargoLockPackageTransformer cargoLockPackageTransformer = new CargoLockPackageTransformer();
DependencyGraph graph = cargoLockPackageTransformer.transformToGraph(input);
NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.CRATES, graph);
graphAssert.hasRootSize(2);
graphAssert.hasRootDependency("test1", "1.0.0");
graphAssert.hasRootDependency("test2", "2.0.0");
}
use of com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage in project synopsys-detect by blackducksoftware.
the class CargoLockPackageTransformerTest method testCorrectNumberOfRootDependencies.
@Test
public void testCorrectNumberOfRootDependencies() throws DetectableException, MissingExternalIdException {
List<CargoLockPackage> input = new ArrayList<>();
input.add(createPackage("test1", "1.0.0", new NameOptionalVersion("dep1"), new NameOptionalVersion("dep2")));
input.add(createPackage("dep1", "0.5.0"));
input.add(createPackage("dep2", "0.6.0"));
CargoLockPackageTransformer cargoLockPackageTransformer = new CargoLockPackageTransformer();
DependencyGraph graph = cargoLockPackageTransformer.transformToGraph(input);
NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.CRATES, graph);
graphAssert.hasRootDependency("test1", "1.0.0");
graphAssert.hasRootDependency("dep1", "0.5.0");
graphAssert.hasRootDependency("dep2", "0.6.0");
graphAssert.hasRootSize(3);
}
use of com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage in project synopsys-detect by blackducksoftware.
the class CargoLockPackageDataTransformerTest method transform.
@Test
void transform() {
CargoDependencyLineParser cargoDependencyLineParser = new CargoDependencyLineParser();
CargoLockPackageDataTransformer transformer = new CargoLockPackageDataTransformer(cargoDependencyLineParser);
List<String> dependencies = Arrays.asList("dep1", "dep2 2.0.0", "dep3 3.0.0 (registry+https://some-registry-url");
CargoLockPackageData cargoLockPackageData = new CargoLockPackageData("some-name", "some-version", null, null, dependencies);
CargoLockPackage cargoLockPackage = transformer.transform(cargoLockPackageData);
assertEquals(new NameVersion("some-name", "some-version"), cargoLockPackage.getPackageNameVersion());
assertEquals(3, cargoLockPackage.getDependencies().size());
NameOptionalVersion dep1Actual = cargoLockPackage.getDependencies().get(0);
assertEquals("dep1", dep1Actual.getName());
assertFalse(dep1Actual.getVersion().isPresent());
assertPackageNameVersion("dep2", "2.0.0", cargoLockPackage.getDependencies().get(1));
assertPackageNameVersion("dep3", "3.0.0", cargoLockPackage.getDependencies().get(2));
}
Aggregations