use of com.synopsys.integration.detectable.util.NameOptionalVersion 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.util.NameOptionalVersion 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.util.NameOptionalVersion in project synopsys-detect by blackducksoftware.
the class CargoDependencyLineParser method parseDependencyName.
public Optional<NameOptionalVersion> parseDependencyName(String dependencyLine) {
String[] dependencyLinePieces = dependencyLine.split(" ");
if (dependencyLinePieces.length == 0 || StringUtils.isEmpty(dependencyLine)) {
logger.warn("Failed to parse dependency line. It will be ignored: {}", dependencyLine);
return Optional.empty();
}
String name = StringUtils.trim(dependencyLinePieces[0]);
if (dependencyLinePieces.length >= 2) {
String version = StringUtils.trimToNull(dependencyLinePieces[1]);
return Optional.of(new NameOptionalVersion(name, version));
} else {
return Optional.of(new NameOptionalVersion(name));
}
}
use of com.synopsys.integration.detectable.util.NameOptionalVersion 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