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/06/06 20:34:01 UTC

[GitHub] [maven-archetype] eolivelli commented on a change in pull request #29: dom4j removal - use Java XML API - reused the same method twice

eolivelli commented on a change in pull request #29: dom4j removal - use Java XML API - reused the same method twice
URL: https://github.com/apache/maven-archetype/pull/29#discussion_r291359655
 
 

 ##########
 File path: archetype-common/src/main/java/org/apache/maven/archetype/common/util/PomUtils.java
 ##########
 @@ -0,0 +1,141 @@
+package org.apache.maven.archetype.common.util;
+
+/*
+ * 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 org.apache.maven.archetype.exception.InvalidPackaging;
+import org.apache.maven.archetype.old.ArchetypeTemplateProcessingException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+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 java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * POM helper class.
+ */
+public final class PomUtils
+{
+    private PomUtils()
+    {
+        throw new IllegalStateException( "no instantiable constructor" );
+    }
+
+    /**
+     * Adds module {@code artifactId} unless the module already presents in {@code fileReader}.
+     *
+     * @param artifactId artifactId of module to add
+     * @param fileReader source POM XML
+     * @param fileWriter target XML
+     * @return {@code true} if modules section in POM is empty or does not exist or {@code artifactId} does not appear
+     * a module in {@code fileReader} XML.
+     * @throws IOException if I/O error
+     * @throws InvalidPackaging if packaging is not "pom" or not exist in POM
+     * @throws ArchetypeTemplateProcessingException if "project" does not exist or "modules" element is duplicated
+     * @throws ParserConfigurationException if parser error
+     * @throws SAXException if parser error
+     * @throws TransformerException if an error writing to {@code fileWriter}
+     */
+    public static boolean addNewModule( String artifactId, Reader fileReader, Writer fileWriter )
+            throws ArchetypeTemplateProcessingException, InvalidPackaging, IOException,
+            ParserConfigurationException, SAXException, TransformerException
+    {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 
 Review comment:
   Please take a look here.
   We should only use safe XML parsers and transformers
   
   https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md

----------------------------------------------------------------
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