Search in sources :

Example 26 with CodeLocation

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

the class YarnTransformerTest method doAllWorkspacesTest.

private void doAllWorkspacesTest(boolean yarn1Project) throws MissingExternalIdException {
    // Unless filtered out, even workspaces that are not dependencies should be included
    List<NameVersion> workspacesThatAreDependencies = new LinkedList<>();
    workspacesThatAreDependencies.add(new NameVersion("workspace-isdep", "1.0.0"));
    List<NameVersion> workspacesThatAreNotDependencies = new LinkedList<>();
    workspacesThatAreNotDependencies.add(new NameVersion("workspace-notdep", "1.0.0"));
    YarnLockResult yarnLockResult = buildTestYarnLockResult(workspacesThatAreDependencies, workspacesThatAreNotDependencies, yarn1Project);
    List<CodeLocation> codeLocations = createTransformer().generateCodeLocations(yarnLockResult, new ArrayList<>(), ExcludedIncludedWildcardFilter.EMPTY);
    assertEquals(3, codeLocations.size());
    Iterator<CodeLocation> codeLocationIterator = codeLocations.iterator();
    CodeLocation rootProjectCodeLocation = codeLocationIterator.next();
    assertFalse(rootProjectCodeLocation.getExternalId().isPresent());
    DependencyGraph rootProjectDependencyGraph = rootProjectCodeLocation.getDependencyGraph();
    assertEquals(2, rootProjectDependencyGraph.getRootDependencies().size());
    List<String> dependencyNames = rootProjectDependencyGraph.getRootDependencies().stream().map(Dependency::getName).collect(Collectors.toList());
    assertTrue(dependencyNames.contains("foo"));
    assertTrue(dependencyNames.contains("bar"));
    for (int i = 1; i < 3; i++) {
        CodeLocation workspaceCodeLocation = codeLocationIterator.next();
        assertTrue(workspaceCodeLocation.getExternalId().get().getName().startsWith("packages/workspace-"));
        assertTrue(workspaceCodeLocation.getExternalId().get().getName().endsWith("dep"));
        assertEquals("local", workspaceCodeLocation.getExternalId().get().getVersion());
        assertEquals("npmjs", workspaceCodeLocation.getExternalId().get().getForge().getName());
        List<String> workspaceDependencyNames = workspaceCodeLocation.getDependencyGraph().getRootDependencies().stream().map(Dependency::getName).collect(Collectors.toList());
        String workspaceName = StringUtils.substringAfter(workspaceCodeLocation.getExternalId().get().getName(), "packages/");
        assertTrue(workspaceDependencyNames.contains(workspaceName + "-dep"));
        assertTrue(workspaceDependencyNames.contains(workspaceName + "-dev-dep"));
    }
}
Also used : YarnLockResult(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) LinkedList(java.util.LinkedList)

Example 27 with CodeLocation

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

the class PipenvTransformerTest method resolvesLowercaseNameWithFreezeCapital.

@Test
void resolvesLowercaseNameWithFreezeCapital() {
    List<PipFreezeEntry> pipFreezeEntries = new ArrayList<>();
    pipFreezeEntries.add(new PipFreezeEntry("Example", "2.0.0"));
    PipFreeze pipFreeze = new PipFreeze(pipFreezeEntries);
    List<PipenvGraphEntry> pipenvGraphEntries = new ArrayList<>();
    pipenvGraphEntries.add(new PipenvGraphEntry("example", "fuzzy", new ArrayList<>()));
    PipenvGraph pipenvGraph = new PipenvGraph(pipenvGraphEntries);
    PipenvTransformer pipenvTransformer = new PipenvTransformer(new ExternalIdFactory());
    CodeLocation codeLocation = pipenvTransformer.transform("", "", pipFreeze, pipenvGraph, false);
    DependencyGraph graph = codeLocation.getDependencyGraph();
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, graph);
    graphAssert.hasDependency("Example", "2.0.0");
}
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) 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) PipFreezeEntry(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreezeEntry) PipFreeze(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreeze) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 28 with CodeLocation

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

the class PipenvTransformerTest method usesProjectDependencyAsRoot.

@Test
void usesProjectDependencyAsRoot() {
    PipFreeze pipFreeze = new PipFreeze(new ArrayList<>());
    List<PipenvGraphEntry> pipenvGraphEntries = new ArrayList<>();
    List<PipenvGraphDependency> children = new ArrayList<>();
    children.add(new PipenvGraphDependency("shouldBeAtRoot", "shouldbeAtRootVersion", new ArrayList<>()));
    pipenvGraphEntries.add(new PipenvGraphEntry("projectName", "projectVersion", children));
    PipenvGraph pipenvGraph = new PipenvGraph(pipenvGraphEntries);
    PipenvTransformer pipenvTransformer = new PipenvTransformer(new ExternalIdFactory());
    CodeLocation codeLocation = pipenvTransformer.transform("projectName", "projectVersion", pipFreeze, pipenvGraph, false);
    DependencyGraph graph = codeLocation.getDependencyGraph();
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, graph);
    graphAssert.hasRootDependency("shouldBeAtRoot", "shouldbeAtRootVersion");
}
Also used : 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) PipFreeze(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreeze) PipenvTransformer(com.synopsys.integration.detectable.detectables.pipenv.build.parser.PipenvTransformer) PipenvGraphEntry(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry) PipenvGraph(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraph) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 29 with CodeLocation

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

the class PipenvTransformerTest method resolvesFuzzyVersion.

@Test
void resolvesFuzzyVersion() {
    List<PipFreezeEntry> pipFreezeEntries = new ArrayList<>();
    pipFreezeEntries.add(new PipFreezeEntry("example", "2.0.0"));
    PipFreeze pipFreeze = new PipFreeze(pipFreezeEntries);
    List<PipenvGraphEntry> pipenvGraphEntries = new ArrayList<>();
    pipenvGraphEntries.add(new PipenvGraphEntry("example", "fuzzy", new ArrayList<>()));
    PipenvGraph pipenvGraph = new PipenvGraph(pipenvGraphEntries);
    PipenvTransformer pipenvTransformer = new PipenvTransformer(new ExternalIdFactory());
    CodeLocation codeLocation = pipenvTransformer.transform("", "", pipFreeze, pipenvGraph, false);
    DependencyGraph graph = codeLocation.getDependencyGraph();
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, graph);
    graphAssert.hasDependency("example", "2.0.0");
}
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) 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) PipFreezeEntry(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreezeEntry) PipFreeze(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreeze) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 30 with CodeLocation

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

the class PnpmYamlTransformerTest method testGenerateCodeLocation.

@Test
public void testGenerateCodeLocation() throws IntegrationException {
    PnpmLockYaml pnpmLockYaml = createPnpmLockYaml();
    PnpmYamlTransformer transformer = createTransformer();
    CodeLocation codeLocation = transformer.generateCodeLocation(pnpmLockYamlFile, pnpmLockYaml, projectNameVersion, linkedPackageResolver);
    assertTrue(codeLocation.getExternalId().isPresent(), "Expected the codelocation to produce an ExternalId.");
    assertEquals("name", codeLocation.getExternalId().get().getName());
    assertEquals("version", codeLocation.getExternalId().get().getVersion());
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.NPMJS, dependencyGraph);
    graphAssert.hasRootSize(4);
    graphAssert.hasRootDependency("dep", "1.0.0");
    graphAssert.hasRootDependency("devDep", "2.0.0");
    graphAssert.hasRootDependency("optDep", "3.0.0");
    graphAssert.hasParentChildRelationship("dep", "1.0.0", "transitive", "1.1.0");
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) 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)

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