Search in sources :

Example 1 with CargoLockPackage

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();
}
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)

Example 2 with CargoLockPackage

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);
}
Also used : NameOptionalVersion(com.synopsys.integration.detectable.util.NameOptionalVersion) NameVersion(com.synopsys.integration.util.NameVersion) Optional(java.util.Optional) CargoLockPackage(com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage)

Example 3 with CargoLockPackage

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");
}
Also used : ArrayList(java.util.ArrayList) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) CargoLockPackage(com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage) Test(org.junit.jupiter.api.Test)

Example 4 with CargoLockPackage

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);
}
Also used : NameOptionalVersion(com.synopsys.integration.detectable.util.NameOptionalVersion) ArrayList(java.util.ArrayList) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) CargoLockPackage(com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage) Test(org.junit.jupiter.api.Test)

Example 5 with CargoLockPackage

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));
}
Also used : NameOptionalVersion(com.synopsys.integration.detectable.util.NameOptionalVersion) NameVersion(com.synopsys.integration.util.NameVersion) CargoLockPackageData(com.synopsys.integration.detectable.detectables.cargo.data.CargoLockPackageData) CargoDependencyLineParser(com.synopsys.integration.detectable.detectables.cargo.parse.CargoDependencyLineParser) CargoLockPackage(com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage) Test(org.junit.jupiter.api.Test)

Aggregations

CargoLockPackage (com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage)6 NameVersion (com.synopsys.integration.util.NameVersion)4 Test (org.junit.jupiter.api.Test)4 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)3 NameOptionalVersion (com.synopsys.integration.detectable.util.NameOptionalVersion)3 ArrayList (java.util.ArrayList)3 CargoLockPackageData (com.synopsys.integration.detectable.detectables.cargo.data.CargoLockPackageData)2 CargoDependencyLineParser (com.synopsys.integration.detectable.detectables.cargo.parse.CargoDependencyLineParser)2 NameVersionGraphAssert (com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert)2 Toml (com.moandjiezana.toml.Toml)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 CargoLockData (com.synopsys.integration.detectable.detectables.cargo.data.CargoLockData)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 Optional (java.util.Optional)1