You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2018/03/18 23:09:24 UTC

[maven-help-plugin] branch master updated: [MPH-140] Multiple XML declarations written

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ba28c9  [MPH-140] Multiple XML declarations written
9ba28c9 is described below

commit 9ba28c9f2378e9a0e93e7e424bd3090e5a97a5b8
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Mon Mar 19 00:07:11 2018 +0100

    [MPH-140] Multiple XML declarations written
    
    After MPH-138 the XML declaration is written multiple times. This is because
    AbstractEffectiveMojo#addMavenNamespace() did out.output(document.getRootElement())
    which implicitly omitted the declaration. Now, it is always present by the
    Xpp3Writer and cannot be disabled.
    
    Unfortunately, we ar doing pretty-printing several times. A better solution
    would be highly appreciated.
---
 .../java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java    | 4 +++-
 src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java    | 5 +++--
 .../java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java    | 5 +++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java
index 2f38dfe..41e2cc0 100644
--- a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java
@@ -122,9 +122,10 @@ public abstract class AbstractEffectiveMojo
     /**
      * @param effectiveModel not null
      * @param encoding not null
+     * @param omitDeclaration whether the XML declaration should be omitted from the effective pom
      * @return pretty format of the xml or the original {@code effectiveModel} if an error occurred.
      */
-    protected static String prettyFormat( String effectiveModel, String encoding )
+    protected static String prettyFormat( String effectiveModel, String encoding, boolean omitDeclaration )
     {
         SAXBuilder builder = new SAXBuilder();
 
@@ -140,6 +141,7 @@ public abstract class AbstractEffectiveMojo
                 format.setEncoding( encoding );
             }
             format.setLineSeparator( System.lineSeparator() );
+            format.setOmitDeclaration( omitDeclaration );
             XMLOutputter out = new XMLOutputter( format );
             out.output( effectiveDocument, w );
 
diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
index d8ed4e3..26f29cc 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
@@ -120,7 +120,7 @@ public class EffectivePomMojo
             writeEffectivePom( project, writer );
         }
 
-        String effectivePom = prettyFormat( w.toString(), encoding );
+        String effectivePom = prettyFormat( w.toString(), encoding, false );
 
         if ( output != null )
         {
@@ -192,7 +192,8 @@ public class EffectivePomMojo
             throw new MojoExecutionException( "Cannot serialize POM to XML.", e );
         }
 
-        String effectivePom = sWriter.toString();
+        // This removes the XML declaration written by MavenXpp3Writer
+        String effectivePom = prettyFormat( sWriter.toString(), null, true );
 
         writeComment( writer, "Effective POM for project \'" + project.getId() + "\'" );
 
diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
index 8847340..b24174f 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
@@ -101,7 +101,7 @@ public class EffectiveSettingsMojo
 
         writeEffectiveSettings( copySettings, writer );
 
-        String effectiveSettings = prettyFormat( w.toString(), encoding );
+        String effectiveSettings = prettyFormat( w.toString(), encoding, false );
 
         if ( output != null )
         {
@@ -240,7 +240,8 @@ public class EffectiveSettingsMojo
             throw new MojoExecutionException( "Cannot serialize Settings to XML.", e );
         }
 
-        String effectiveSettings = sWriter.toString();
+        // This removes the XML declaration written by MavenXpp3Writer
+        String effectiveSettings = prettyFormat( sWriter.toString(), null, true );
 
         writeComment( writer, "Effective Settings for '" + getUserName() + "' on '" + getHostName() + "'" );
 

-- 
To stop receiving notification emails like this one, please contact
michaelo@apache.org.