Search in sources :

Example 1 with PackageJsonFiles

use of com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonFiles in project synopsys-detect by blackducksoftware.

the class PnpmLockExtractorTest method testNoFailureOnNullPackageJson.

@Test
public void testNoFailureOnNullPackageJson() {
    PackageJsonFiles packageJsonFiles = new PackageJsonFiles(new PackageJsonReader(new Gson()));
    EnumListFilter<PnpmDependencyType> dependencyTypeFilter = EnumListFilter.fromExcluded(PnpmDependencyType.APP);
    PnpmLockExtractor extractor = new PnpmLockExtractor(new PnpmLockYamlParser(new PnpmYamlTransformer(dependencyTypeFilter)), packageJsonFiles);
    File pnpmLockYaml = FunctionalTestFiles.asFile("/pnpm/pnpm-lock.yaml");
    Extraction extraction = extractor.extract(pnpmLockYaml, null, new PnpmLinkedPackageResolver(new File(""), packageJsonFiles));
    Assertions.assertTrue(extraction.isSuccess());
}
Also used : PnpmLinkedPackageResolver(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLinkedPackageResolver) PackageJsonReader(com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonReader) PnpmYamlTransformer(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer) PnpmLockYamlParser(com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLockYamlParser) Gson(com.google.gson.Gson) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PackageJsonFiles(com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonFiles) File(java.io.File) PnpmDependencyType(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmDependencyType) PnpmLockExtractor(com.synopsys.integration.detectable.detectables.pnpm.lockfile.PnpmLockExtractor) Test(org.junit.jupiter.api.Test)

Example 2 with PackageJsonFiles

use of com.synopsys.integration.detectable.detectables.yarn.packagejson.PackageJsonFiles 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)

Aggregations

Gson (com.google.gson.Gson)2 PnpmDependencyType (com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmDependencyType)2 PnpmLinkedPackageResolver (com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLinkedPackageResolver)2 PnpmLockYamlParser (com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmLockYamlParser)2 PnpmYamlTransformer (com.synopsys.integration.detectable.detectables.pnpm.lockfile.process.PnpmYamlTransformer)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 Test (org.junit.jupiter.api.Test)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 EnumListFilter (com.synopsys.integration.detectable.detectable.util.EnumListFilter)1 PnpmLockExtractor (com.synopsys.integration.detectable.detectables.pnpm.lockfile.PnpmLockExtractor)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 FunctionalTestFiles (com.synopsys.integration.detectable.util.FunctionalTestFiles)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 NameVersion (com.synopsys.integration.util.NameVersion)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1