Search in sources :

Example 1 with PipenvGraphEntry

use of com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry 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 2 with PipenvGraphEntry

use of com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry 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 3 with PipenvGraphEntry

use of com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry 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 4 with PipenvGraphEntry

use of com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry in project synopsys-detect by blackducksoftware.

the class PipenvTransformer method transform.

public CodeLocation transform(String projectName, String projectVersionName, PipFreeze pipFreeze, PipenvGraph pipenvGraph, boolean includeOnlyProjectTree) {
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    for (PipenvGraphEntry entry : pipenvGraph.getEntries()) {
        Dependency entryDependency = nameVersionToDependency(entry.getName(), entry.getVersion(), pipFreeze);
        List<Dependency> children = addDependenciesToGraph(entry.getChildren(), dependencyGraph, pipFreeze);
        if (matchesProject(entryDependency, projectName, projectVersionName)) {
            // The project appears as an entry, we don't want the project to be a dependency of itself.
            dependencyGraph.addChildrenToRoot(children);
        } else if (!includeOnlyProjectTree) {
            // Only add non-project matches if we are not project tree only.
            dependencyGraph.addChildToRoot(entryDependency);
            dependencyGraph.addParentWithChildren(entryDependency, children);
        }
    }
    ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName);
    return new CodeLocation(dependencyGraph, projectExternalId);
}
Also used : PipenvGraphEntry(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) PipenvGraphDependency(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 5 with PipenvGraphEntry

use of com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry 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)

Aggregations

DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)5 PipenvGraphEntry (com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry)5 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)4 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)4 PipFreeze (com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreeze)4 PipenvGraph (com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraph)4 PipenvTransformer (com.synopsys.integration.detectable.detectables.pipenv.build.parser.PipenvTransformer)4 NameVersionGraphAssert (com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert)4 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 PipenvGraphDependency (com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphDependency)3 PipFreezeEntry (com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreezeEntry)2 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1