[ 
https://issues.apache.org/jira/browse/MNG-6036?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17788081#comment-17788081
 ] 

ASF GitHub Bot commented on MNG-6036:
-------------------------------------

elharo commented on code in PR #1318:
URL: https://github.com/apache/maven/pull/1318#discussion_r1399477511


##########
maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeWriter.java:
##########
@@ -18,49 +18,146 @@
  */
 package org.apache.maven.internal.xml;
 
-import java.io.PrintWriter;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
 import java.io.Writer;
 import java.util.Map;
 
 import org.apache.maven.api.xml.XmlNode;
-import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
-import org.codehaus.plexus.util.xml.XMLWriter;
+import org.codehaus.stax2.util.StreamWriterDelegate;
 
 /**
  *
  */
 public class XmlNodeWriter {
     public static void write(Writer writer, XmlNode dom) {
-        write(new PrettyPrintXMLWriter(writer), dom);
-    }
-
-    public static void write(PrintWriter writer, XmlNode dom) {
-        write(new PrettyPrintXMLWriter(writer), dom);
-    }
-
-    public static void write(XMLWriter xmlWriter, XmlNode dom) {
-        write(xmlWriter, dom, true);
+        try {
+            XMLOutputFactory factory = new 
com.ctc.wstx.stax.WstxOutputFactory();
+            factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, 
false);
+            
factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL,
 true);
+            
factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_ADD_SPACE_AFTER_EMPTY_ELEM,
 true);
+            XMLStreamWriter serializer = new 
IndentingXMLStreamWriter(factory.createXMLStreamWriter(writer));
+            write(serializer, dom);
+            serializer.close();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException("Unexpected error when writing XML", e);

Review Comment:
   It's a public method. It's not safe to assume it's only used by toString.
   Also toString should not throw any exceptions, runtime or otherwise. If an 
exception can be thrown, it should be handled in a way that still returns a 
string. 





> Allow proper namespace usage for pom.xml
> ----------------------------------------
>
>                 Key: MNG-6036
>                 URL: https://issues.apache.org/jira/browse/MNG-6036
>             Project: Maven
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 3.3.9
>         Environment: Apache Maven 3.3.9 
> (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
> Maven home: /usr/local/Cellar/maven/3.3.9/libexec
> Java version: 1.8.0_40, vendor: Oracle Corporation
> Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre
> Default locale: en_US, platform encoding: UTF-8
> OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac"
>            Reporter: Roland Huss
>            Priority: Major
>
> When I use the following pom.xml in order to allow an XSD for my custom 
> plugin configuration:
> {code:xml}
> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>          xmlns="http://maven.apache.org/POM/4.0.0";
>          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
> http://maven.apache.org/POM/4.0.0";>
> ....
>     <plugin>
>          ....
>          <m:configuration xmlns:m="http://maven.apache.org/POM/4.0.0"; 
> xmlns="http://fabric8.io/fabric8-maven-plugin";>
>              <myConfig>.....</myConfig>
>          </m:configuration>
>     </plugin>
>     ....
> </project>
> {code}
> I get this error:
> {code}
> [INFO] Scanning for projects...
> [ERROR] [ERROR] Some problems were encountered while processing the POMs:
> [ERROR] Malformed POM 
> /Users/roland/Development/docker/docker-maven-plugin/samples/data-jolokia-demo/pom.xml:
>  Unrecognised tag: 'm:configuration' (position: START_TAG seen 
> ...che.org/POM/4.0.0" xmlns="http://fabric8.io/fabric8-maven-plugin";>... 
> @91:117)  @ 
> /Users/roland/Development/docker/docker-maven-plugin/samples/data-jolokia-demo/pom.xml,
>  line 91, column 117
>  @
> [ERROR] The build could not read 1 project -> [Help 1]
> [ERROR]
> [ERROR]   The project io.fabric8:docker-jolokia-demo:0.15-SNAPSHOT 
> (/Users/roland/Development/docker/docker-maven-plugin/samples/data-jolokia-demo/pom.xml)
>  has 1 error
> [ERROR]     Malformed POM 
> /Users/roland/Development/docker/docker-maven-plugin/samples/data-jolokia-demo/pom.xml:
>  Unrecognised tag: 'm:configuration' (position: START_TAG seen 
> ...che.org/POM/4.0.0" xmlns="http://fabric8.io/fabric8-maven-plugin";>... 
> @91:117)  @ 
> /Users/roland/Development/docker/docker-maven-plugin/samples/data-jolokia-demo/pom.xml,
>  line 91, column 117 -> [Help 2]
> {code}
> It would be awesome if the XML parser would resolve namespaces properly. Its 
> not about adding namespace features, only for plain XML resolving (each 
> decent XML these days should be able to do this transparently).
> Except for 
> https://cwiki.apache.org/confluence/display/MAVEN/Moving+forward+with+the+POM+data+model
>  I couldn't find any statement when namespaces are supported or tolerated. 
> Are there any plans for this (and maybe also to relax the schema constraints 
> on the {{<configuration>}} tag)  ?
> See also https://github.com/rhuss/poblano/issues/19 for a use case.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to