elharo commented on code in PR #128:
URL: https://github.com/apache/maven-archetype/pull/128#discussion_r1155406961


##########
archetype-common/src/main/java/org/apache/maven/archetype/common/util/PomUtils.java:
##########
@@ -127,7 +129,16 @@ public static boolean addNewModule( String artifactId, 
Reader fileReader, Writer
             tf.setAttribute( XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "" );
 
             tf.setAttribute( "indent-number", 2 );
-            Transformer tr = tf.newTransformer();
+            final Transformer tr;
+            InputStream xsl = PomUtils.class.getResourceAsStream( 
"/prettyprint.xsl" );
+            try

Review Comment:
   Use try with resources here so no explicit close is needed



##########
archetype-common/src/main/java/org/apache/maven/archetype/common/util/PomUtils.java:
##########
@@ -127,7 +129,16 @@ public static boolean addNewModule( String artifactId, 
Reader fileReader, Writer
             tf.setAttribute( XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "" );
 
             tf.setAttribute( "indent-number", 2 );
-            Transformer tr = tf.newTransformer();
+            final Transformer tr;

Review Comment:
   This belongs inside the try block



##########
archetype-common/src/test/java/org/apache/maven/archetype/common/TestPomManager.java:
##########
@@ -0,0 +1,55 @@
+package org.apache.maven.archetype.common;
+
+/*
+ * 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 java.io.File;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class TestPomManager {
+
+  //ref: https://www.baeldung.com/java-pretty-print-xml
+  //https://bugs.openjdk.java.net/browse/JDK-8262285?attachmentViewMode=list
+  @Test
+  public void testAddModule() throws Exception {
+    PomManager pomManager = new DefaultPomManager();
+
+    URL pom = getClass().getResource("/projects/generate-9/pom.xml.sample");
+    File pomFileSrc = new File(pom.toURI());
+    File pomFile = new File(pomFileSrc.getAbsolutePath() + "-copied.xml");
+    FileUtils.copyFile(pomFileSrc, pomFile);
+    final int moduleNumber = 4;
+    for (int i =0; i< moduleNumber; i++ ) {
+      pomManager.addModule(pomFile, "test" + i);
+    }
+    String fileText = FileUtils.fileRead( pomFile );
+    Pattern pattern = Pattern.compile("(^[ ]+[\\r\\n]+){"+moduleNumber + "}", 
Pattern.MULTILINE);
+    System.out.println(fileText);

Review Comment:
   delete this line as passing tests should generate no output



##########
archetype-common/src/test/java/org/apache/maven/archetype/common/TestPomManager.java:
##########
@@ -0,0 +1,55 @@
+package org.apache.maven.archetype.common;
+
+/*
+ * 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 java.io.File;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class TestPomManager {
+
+  //ref: https://www.baeldung.com/java-pretty-print-xml
+  //https://bugs.openjdk.java.net/browse/JDK-8262285?attachmentViewMode=list
+  @Test
+  public void testAddModule() throws Exception {
+    PomManager pomManager = new DefaultPomManager();
+
+    URL pom = getClass().getResource("/projects/generate-9/pom.xml.sample");
+    File pomFileSrc = new File(pom.toURI());
+    File pomFile = new File(pomFileSrc.getAbsolutePath() + "-copied.xml");
+    FileUtils.copyFile(pomFileSrc, pomFile);
+    final int moduleNumber = 4;
+    for (int i =0; i< moduleNumber; i++ ) {

Review Comment:
   spaces on both sides of = and &lt;



##########
archetype-common/src/test/java/org/apache/maven/archetype/common/TestPomManager.java:
##########
@@ -0,0 +1,55 @@
+package org.apache.maven.archetype.common;
+
+/*
+ * 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 java.io.File;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.codehaus.plexus.util.FileUtils;

Review Comment:
   Use apache commons instead



##########
archetype-common/src/test/java/org/apache/maven/archetype/common/TestPomManager.java:
##########
@@ -0,0 +1,55 @@
+package org.apache.maven.archetype.common;
+
+/*

Review Comment:
   License above the package statement



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

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to