-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support --print-graph with mvn-plugin
- Loading branch information
Showing
8 changed files
with
233 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.snyk.example</groupId> | ||
<artifactId>child-project</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>Test project</name> | ||
<description>Test child project for Snyk CLI</description> | ||
|
||
<properties> | ||
<axis.version>1.4</axis.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>axis</groupId> | ||
<artifactId>axis</artifactId> | ||
<version>${axis.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.snyk.example</groupId> | ||
<artifactId>test-project</artifactId> | ||
<packaging>pom</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>Test project</name> | ||
<description>Test project for Snyk CLI</description> | ||
|
||
<modules> | ||
<module>child-project</module> | ||
</modules> | ||
|
||
<properties> | ||
<axis.version>1.4</axis.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>axis</groupId> | ||
<artifactId>axis</artifactId> | ||
<version>${axis.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.snyk.example</groupId> | ||
<artifactId>test-project</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>Test project</name> | ||
<description>Test project for the Maven CLI plugin</description> | ||
|
||
<properties> | ||
<axis.version>1.4</axis.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>axis</groupId> | ||
<artifactId>axis</artifactId> | ||
<version>${axis.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { createProjectFromWorkspace } from '../../util/createProject'; | ||
import { runSnykCLI } from '../../util/runSnykCLI'; | ||
|
||
jest.setTimeout(1000 * 60); | ||
|
||
describe('print graph', () => { | ||
test("`snyk test --print-graph` should print a project's dep-graph", async () => { | ||
const project = await createProjectFromWorkspace('npm-package'); | ||
|
||
const { code, stdout } = await runSnykCLI('test --print-graph', { | ||
cwd: project.path(), | ||
}); | ||
|
||
expect(code).toEqual(0); | ||
expect(stdout).toMatch('DepGraph data:'); | ||
expect(stdout).toMatch('DepGraph target:\npackage-lock.json'); | ||
}); | ||
|
||
test('`snyk test --print-graph` should not prune dependencies', async () => { | ||
const project = await createProjectFromWorkspace('maven-many-paths'); | ||
|
||
const { code, stdout } = await runSnykCLI('test --print-graph', { | ||
cwd: project.path(), | ||
}); | ||
|
||
expect(code).toEqual(0); | ||
const depGraph = JSON.parse( | ||
stdout.split('DepGraph data:')[1]?.split('DepGraph target:')[0], | ||
); | ||
let numEdges = 0; | ||
for (const node of depGraph.graph.nodes) { | ||
numEdges += node.deps.length; | ||
} | ||
expect(numEdges).toEqual(7); | ||
}); | ||
|
||
test('`snyk test --print-graph --all-projects` should not prune dependencies', async () => { | ||
const project = await createProjectFromWorkspace('maven-many-paths'); | ||
|
||
const { code, stdout } = await runSnykCLI( | ||
'test --print-graph --all-projects', | ||
{ | ||
cwd: project.path(), | ||
}, | ||
); | ||
|
||
expect(code).toEqual(0); | ||
const depGraphs = stdout | ||
.split('DepGraph data:') | ||
.filter(Boolean) | ||
.map((s) => JSON.parse(s.split('DepGraph target:')[0])); | ||
|
||
let numEdges = 0; | ||
for (const depGraph of depGraphs) { | ||
for (const node of depGraph.graph.nodes) { | ||
numEdges += node.deps.length; | ||
} | ||
} | ||
expect(numEdges).toEqual(14); | ||
}); | ||
}); |