Search in sources :

Example 6 with PnpmYamlTransformer

use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.

the class PnpmYamlTransformerTest method testParseFileDependencies.

@Test
public void testParseFileDependencies() throws IntegrationException {
    PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
    PnpmYamlTransformer transformer = createTransformer(PnpmDependencyType.DEV, PnpmDependencyType.OPTIONAL);
    DependencyGraph dependencyGraph = transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver).getDependencyGraph();
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, dependencyGraph);
    graphAssert.hasRootSize(2);
    graphAssert.hasDependency("fileDep", "1.0.0");
}
Also used : PnpmYamlTransformer(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PnpmLockYaml(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test)

Example 7 with PnpmYamlTransformer

use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.

the class PnpmLockYamlParserTest method testParse.

@Test
public void testParse() throws IOException, IntegrationException {
    File pnpmLockYaml = FunctionalTestFiles.asFile("/pnpm/pnpm-lock.yaml");
    EnumListFilter<PnpmDependencyType> dependencyTypeFilter = EnumListFilter.excludeNone();
    PnpmLockYamlParser pnpmLockYamlParser = new PnpmLockYamlParser(new PnpmYamlTransformer(dependencyTypeFilter));
    PnpmLinkedPackageResolver pnpmLinkedPackageResolver = new PnpmLinkedPackageResolver(FunctionalTestFiles.asFile("/pnpm"), new PackageJsonFiles(new PackageJsonReader(new Gson())));
    List<CodeLocation> codeLocations = pnpmLockYamlParser.parse(pnpmLockYaml, new NameVersion("project", "version"), pnpmLinkedPackageResolver);
    Assertions.assertEquals(2, codeLocations.size());
    // Did we correctly identify root project package in "importers"?
    Assertions.assertTrue(codeLocations.stream().map(CodeLocation::getExternalId).filter(Optional::isPresent).map(Optional::get).anyMatch(externalId -> externalId.getName().equals("project") && externalId.getVersion().equals("version")));
    // Do all code locations have a source path?
    Assertions.assertAll(codeLocations.stream().map(codeLocation -> () -> Assertions.assertTrue(codeLocation.getSourcePath().isPresent(), String.format("Expected source path to be present for all code locations. But code location with id %s does not have one set.", codeLocation.getExternalId().map(ExternalId::createExternalId).orElse("N/A")))));
    // Did we generate a unique source path for each code location?
    Map<String, List<File>> collect = codeLocations.stream().map(CodeLocation::getSourcePath).filter(Optional::isPresent).map(Optional::get).collect(Collectors.groupingBy(File::getAbsolutePath));
    Assertions.assertAll(collect.entrySet().stream().map(codeLocationGrouping -> () -> {
        int numberOfCodeLocations = codeLocationGrouping.getValue().size();
        Assertions.assertEquals(1, numberOfCodeLocations, String.format("Expected unique code locations paths. But found %d with that same path of %s", numberOfCodeLocations, codeLocationGrouping.getKey()));
    }));
}
Also used : FunctionalTestFiles(com.synopsys.integration.detectable.util.FunctionalTestFiles) IntegrationException(com.synopsys.integration.exception.IntegrationException) EnumListFilter(com.synopsys.integration.detectable.detectable.util.EnumListFilter) PnpmLinkedPackageResolver(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLinkedPackageResolver) PackageJsonReader(com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonReader) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) PnpmYamlTransformer(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer) File(java.io.File) Test(org.junit.jupiter.api.Test) PackageJsonFiles(com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonFiles) NameVersion(com.synopsys.integration.util.NameVersion) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Gson(com.google.gson.Gson) PnpmDependencyType(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmDependencyType) PnpmLockYamlParser(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLockYamlParser) Map(java.util.Map) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) PnpmLinkedPackageResolver(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLinkedPackageResolver) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) Optional(java.util.Optional) PackageJsonReader(com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonReader) PnpmLockYamlParser(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLockYamlParser) Gson(com.google.gson.Gson) PnpmDependencyType(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmDependencyType) PnpmYamlTransformer(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer) List(java.util.List) PackageJsonFiles(com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonFiles) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 8 with PnpmYamlTransformer

use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.

the class PnpmYamlTransformerTest method testExcludeDevDependencies.

@Test
public void testExcludeDevDependencies() throws IntegrationException {
    PnpmYamlTransformer transformer = createTransformer(PnpmDependencyType.DEV);
    PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
    DependencyGraph dependencyGraph = transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver).getDependencyGraph();
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, dependencyGraph);
    graphAssert.hasRootSize(3);
    graphAssert.hasNoDependency("devDep", "2.0.0");
}
Also used : PnpmYamlTransformer(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PnpmLockYaml(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test)

Example 9 with PnpmYamlTransformer

use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.

the class PnpmYamlTransformerTest method testExcludeDependencies.

@Test
public void testExcludeDependencies() throws IntegrationException {
    PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
    PnpmYamlTransformer transformer = createTransformer(PnpmDependencyType.APP);
    DependencyGraph dependencyGraph = transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver).getDependencyGraph();
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, dependencyGraph);
    graphAssert.hasRootSize(2);
}
Also used : PnpmYamlTransformer(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PnpmLockYaml(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test)

Example 10 with PnpmYamlTransformer

use of com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer in project synopsys-detect by blackducksoftware.

the class PnpmYamlTransformerTest method testThrowExceptionOnNullPackagesSection.

@Test
public void testThrowExceptionOnNullPackagesSection() {
    PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
    PnpmYamlTransformer transformer = createTransformer();
    pnpmLockYaml.packages = null;
    assertThrows(IntegrationException.class, () -> transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver));
}
Also used : PnpmYamlTransformer(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer) PnpmLockYaml(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml) Test(org.junit.jupiter.api.Test)

Aggregations

PnpmYamlTransformer (com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer)10 Test (org.junit.jupiter.api.Test)9 PnpmLockYaml (com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml)7 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 NameVersionGraphAssert (com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert)5 PnpmLockYamlParser (com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLockYamlParser)3 Gson (com.google.gson.Gson)2 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 PnpmLockExtractor (com.synopsys.integration.detectable.detectables.pnpm.lockfile.PnpmLockExtractor)2 PnpmDependencyType (com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmDependencyType)2 PnpmLinkedPackageResolver (com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLinkedPackageResolver)2 PackageJsonFiles (com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonFiles)2 PackageJsonReader (com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonReader)2 File (java.io.File)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 EnumListFilter (com.synopsys.integration.detectable.detectable.util.EnumListFilter)1 PnpmLockDetectable (com.synopsys.integration.detectable.detectables.pnpm.lockfile.PnpmLockDetectable)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 FunctionalTestFiles (com.synopsys.integration.detectable.util.FunctionalTestFiles)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1