You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2019/12/05 07:29:19 UTC

[GitHub] [maven-dependency-plugin] mthmulders commented on a change in pull request #24: [MDEP-435] Added xml outputType to dependency tree

mthmulders commented on a change in pull request #24: [MDEP-435] Added xml outputType to dependency tree
URL: https://github.com/apache/maven-dependency-plugin/pull/24#discussion_r354144278
 
 

 ##########
 File path: src/main/java/org/apache/maven/plugins/dependency/tree/XMLDependencyNodeVisitor.java
 ##########
 @@ -0,0 +1,186 @@
+package org.apache.maven.plugins.dependency.tree;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.shared.dependency.graph.DependencyNode;
+import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import java.io.Writer;
+import java.util.List;
+
+/**
+ * A dependency node visitor that serializes visited nodes to
+ * <a href="https://en.wikipedia.org/wiki/XML">XML format</a>
+ *
+ * @author <a href="mailto:sikora.bogdan@webscope.io">Bogdan Sikora</a>
+ * @since 3.1.2
+ */
+public class XMLDependencyNodeVisitor
+    extends AbstractSerializingVisitor
+    implements DependencyNodeVisitor
+{
+    /**
+     * Constructor.
+     *
+     * @param writer the writer to write to.
+     */
+    public XMLDependencyNodeVisitor( Writer writer )
+    {
+        super( writer );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean visit( DependencyNode node )
+    {
+        try
+        {
+            if ( node.getParent() == null || node.getParent() == node )
+            {
+                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
 
 Review comment:
   I agree with @rfscholte that this is quite a heavy approach. The `PrettyPrintXMLWriter` from maven-shared-utils looks promising to me. It looks promising (less code, simpler code) but I'm struggling to make the tests pass. Simply put, I don't know how verify if I did it correctly.
   
   @S4n60w3n, if I created a pull request on your MDEP-435 branch, could you verify that the PrettyPrintXMLWriter-approach gives the same outcome as your DOM-based one? Alternatively, could you tell me how I can verify that your implementation and mine have the same outcome?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services