[
https://issues.apache.org/jira/browse/MDEP-799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17848585#comment-17848585
]
ASF GitHub Bot commented on MDEP-799:
-------------------------------------
elharo commented on code in PR #391:
URL:
https://github.com/apache/maven-dependency-plugin/pull/391#discussion_r1609815080
##########
src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java:
##########
@@ -137,6 +146,93 @@ public void testTreeTGFSerializing() throws Exception {
assertTrue(findString(contents,
"testGroupId:release:jar:1.0:compile"));
}
+ /**
+ * Test the JSON format serialization
+ */
+ public void testTreeJsonSerializing() throws Exception {
+ List<String> contents = runTreeMojo("tree1.json", "json");
+ assertTrue(findString(contents, "\"groupId\": \"testGroupId\""));
+
+ assertTrue(findString(contents, "\"artifactId\": \"project\""));
+ assertTrue(findString(contents, "\"artifactId\": \"release\""));
+ assertTrue(findString(contents, "\"artifactId\": \"snapshot\""));
+
+ assertTrue(findString(contents, "\"version\": \"1.0\""));
+ assertTrue(findString(contents, "\"version\": \"2.0-SNAPSHOT\""));
+
+ assertTrue(findString(contents, "\"type\": \"jar\""));
+
+ assertTrue(findString(contents, "\"scope\": \"compile\""));
+ }
+
+ /**
+ * Test the JSON format serialization on DependencyNodes with circular
dependence
+ */
+ public void testTreeJsonCircularDependency() throws Exception {
+ String outputFileName = testDir.getAbsolutePath() + "tree2.json";
+ File outputFile = new File(outputFileName);
+ Files.createDirectories(outputFile.getParentFile().toPath());
+ outputFile.createNewFile();
+
+ Artifact artifact1 = this.stubFactory.createArtifact("testGroupId",
"project1", "1.0");
+ Artifact artifact2 = this.stubFactory.createArtifact("testGroupId",
"project2", "1.0");
+ DefaultDependencyNode node1 = new DefaultDependencyNode(artifact1);
+ DefaultDependencyNode node2 = new DefaultDependencyNode(artifact2);
+
+ node1.setChildren(new ArrayList<DependencyNode>());
+ node2.setChildren(new ArrayList<DependencyNode>());
+
+ node1.getChildren().add(node2);
+ node2.getChildren().add(node1);
+
+ JsonDependencyNodeVisitor jsonDependencyNodeVisitor =
+ new JsonDependencyNodeVisitor(new PrintWriter(outputFile));
Review Comment:
PrintWriter swallows exceptions. Just use an OutputStreamWriter
##########
src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java:
##########
@@ -137,6 +146,93 @@ public void testTreeTGFSerializing() throws Exception {
assertTrue(findString(contents,
"testGroupId:release:jar:1.0:compile"));
}
+ /**
+ * Test the JSON format serialization
+ */
+ public void testTreeJsonSerializing() throws Exception {
Review Comment:
Now that you have more robust JSON based tests I'd delete this test unless
you care about JSON insignificant details like whether it's
"artifactId": "snapshot"
or
"artifactId" : "snapshot"
> improve mvn dependency:tree - add optional JSON output of the results
> ---------------------------------------------------------------------
>
> Key: MDEP-799
> URL: https://issues.apache.org/jira/browse/MDEP-799
> Project: Maven Dependency Plugin
> Issue Type: New Feature
> Components: tree
> Reporter: Zhenxu Ke
> Priority: Major
>
> I'd like to add an output type JSON, will open a pull request soon
--
This message was sent by Atlassian Jira
(v8.20.10#820010)