Search in sources :

Example 91 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class PipenvTransformerTest method ignoresNonProject.

@Test
void ignoresNonProject() {
    PipFreeze pipFreeze = new PipFreeze(new ArrayList<>());
    List<PipenvGraphEntry> pipenvGraphEntries = new ArrayList<>();
    pipenvGraphEntries.add(new PipenvGraphEntry("projectName", "projectVersion", Collections.singletonList(new PipenvGraphDependency("child", "childVersion", Collections.emptyList()))));
    pipenvGraphEntries.add(new PipenvGraphEntry("non-projectName", "non-projectVersion", new ArrayList<>()));
    PipenvGraph pipenvGraph = new PipenvGraph(pipenvGraphEntries);
    PipenvTransformer pipenvTransformer = new PipenvTransformer(new ExternalIdFactory());
    CodeLocation codeLocation = pipenvTransformer.transform("projectName", "projectVersion", pipFreeze, pipenvGraph, true);
    DependencyGraph graph = codeLocation.getDependencyGraph();
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, graph);
    graphAssert.hasRootDependency("child", "childVersion");
    graphAssert.hasNoDependency("non-projectName", "non-projectVersion");
}
Also used : PipenvTransformer(com.synopsys.integration.detectable.detectables.pipenv.build.parser.PipenvTransformer) PipenvGraphEntry(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) PipenvGraphDependency(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphDependency) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ArrayList(java.util.ArrayList) NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) PipenvGraph(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraph) PipFreeze(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreeze) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 92 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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 93 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class PackageJsonExtractorFunctionalTest method extractWithPeerDependencies.

@Test
void extractWithPeerDependencies() {
    Extraction extraction = createExtractor(NpmDependencyType.DEV).extract(packageJsonInputStream);
    assertEquals(1, extraction.getCodeLocations().size());
    CodeLocation codeLocation = extraction.getCodeLocations().get(0);
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    GraphAssert graphAssert = new GraphAssert(Forge.RUBYGEMS, dependencyGraph);
    graphAssert.hasRootDependency(testDep1);
    graphAssert.hasRootDependency(testDep2);
    graphAssert.hasRootDependency(testPeerDep1);
    graphAssert.hasRootDependency(testPeerDep2);
    graphAssert.hasNoDependency(testDevDep1);
    graphAssert.hasNoDependency(testDevDep2);
    graphAssert.hasRootSize(4);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GraphAssert(com.synopsys.integration.detectable.util.graph.GraphAssert) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Example 94 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class BitbakeExtractor method extract.

public Extraction extract(File sourceDirectory, ExecutableTarget bashExecutable, File buildEnvironmentFile) throws ExecutableFailedException, IOException {
    toolVersionLogger.log(() -> bitbakeCommandRunner.runBitbakeVersion(sourceDirectory, bashExecutable, buildEnvironmentFile));
    File buildDirectory = determineBuildDirectory(sourceDirectory, bashExecutable, buildEnvironmentFile);
    BitbakeEnvironment bitbakeEnvironment = executeBitbakeForEnvironment(sourceDirectory, bashExecutable, buildEnvironmentFile);
    ShowRecipesResults showRecipesResults = executeBitbakeForRecipeLayerCatalog(sourceDirectory, bashExecutable, buildEnvironmentFile);
    List<CodeLocation> codeLocations = packageNames.stream().map(targetPackage -> generateCodeLocationForTargetPackage(targetPackage, sourceDirectory, bashExecutable, buildEnvironmentFile, buildDirectory, showRecipesResults, bitbakeEnvironment)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    if (codeLocations.isEmpty()) {
        return Extraction.failure("No Code Locations were generated during extraction");
    } else {
        return Extraction.success(codeLocations);
    }
}
Also used : BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IntegrationException(com.synopsys.integration.exception.IntegrationException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) BitbakeDependencyGraphTransformer(com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeDependencyGraphTransformer) ToolVersionLogger(com.synopsys.integration.detectable.util.ToolVersionLogger) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) PwdOutputParser(com.synopsys.integration.detectable.detectables.bitbake.parse.PwdOutputParser) Charset(java.nio.charset.Charset) Map(java.util.Map) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph) Logger(org.slf4j.Logger) EnumListFilter(com.synopsys.integration.detectable.detectable.util.EnumListFilter) BitbakeGraphTransformer(com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeGraphTransformer) GraphParser(com.paypal.digraph.parser.GraphParser) BuildFileFinder(com.synopsys.integration.detectable.detectables.bitbake.collect.BuildFileFinder) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BitbakeEnvironmentParser(com.synopsys.integration.detectable.detectables.bitbake.parse.BitbakeEnvironmentParser) BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) BitbakeCommandRunner(com.synopsys.integration.detectable.detectables.bitbake.collect.BitbakeCommandRunner) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ShowRecipesResults(com.synopsys.integration.detectable.detectables.bitbake.data.ShowRecipesResults) Optional(java.util.Optional) BitbakeRecipesParser(com.synopsys.integration.detectable.detectables.bitbake.parse.BitbakeRecipesParser) LicenseManifestParser(com.synopsys.integration.detectable.detectables.bitbake.parse.LicenseManifestParser) InputStream(java.io.InputStream) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Optional(java.util.Optional) ShowRecipesResults(com.synopsys.integration.detectable.detectables.bitbake.data.ShowRecipesResults) File(java.io.File)

Example 95 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class CarthageExtractor method extract.

public Extraction extract(File cartfileResolved) throws IOException {
    List<String> dependencyDeclarations = Files.readAllLines(cartfileResolved.toPath());
    List<CarthageDeclaration> carthageDeclarations = cartfileResolvedParser.parseDependencies(dependencyDeclarations);
    DependencyGraph dependencyGraph = declarationTransformer.transform(carthageDeclarations);
    CodeLocation codeLocation = new CodeLocation(dependencyGraph);
    // No project info - hoping git can help with that.
    return Extraction.success(codeLocation);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) CarthageDeclaration(com.synopsys.integration.detectable.detectables.carthage.model.CarthageDeclaration) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph)

Aggregations

CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)104 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)60 Extraction (com.synopsys.integration.detectable.extraction.Extraction)41 File (java.io.File)24 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)22 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)21 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)20 NameVersion (com.synopsys.integration.util.NameVersion)19 IOException (java.io.IOException)19 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)16 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)16 List (java.util.List)14 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)13 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10