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/02/20 23:22:08 UTC

[maven-help-plugin] branch MPH-87 updated (58dd63b -> 658a0bb)

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

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


 discard 58dd63b  [MPH-87] help:effective-pom/effective-settings uses platform encoding and garbles non-ASCII characters, emits invalid XML
     new 658a0bb  [MPH-87] help:effective-pom/effective-settings uses platform encoding and garbles non-ASCII characters, emits invalid XML

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (58dd63b)
            \
             N -- N -- N   refs/heads/MPH-87 (658a0bb)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java | 1 +
 1 file changed, 1 insertion(+)

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

[maven-help-plugin] 01/01: [MPH-87] help:effective-pom/effective-settings uses platform encoding and garbles non-ASCII characters, emits invalid XML

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 658a0bb94f9952262d8654b57eb560303cd12306
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Feb 21 00:10:00 2018 +0100

    [MPH-87] help:effective-pom/effective-settings uses platform encoding and garbles non-ASCII characters, emits invalid XML
    
    The fix for this issues requires a series of changes:
    * When writing XML content to file, don't provide an encoding, let the
      writer read the prolog by itself. This avoids mismatches when encoding
      is not provided (UTF-8), but platform encoding is not UTF-8.
    * Rather than feeding the model encoding unconditionally to
      PrettyPrintXMLWriter provide the encoding of the output stream written to.
    * PrettyPrintFormat does not replay the input encoding of a file, but
      always uses UTF-8 unless told otherwise. This meant that the prolog did
      not match to the actual file encoding.
    * PrettyPrintFormat default to \r\n line ending which produces
      inconsistent endings on Unix.
---
 .../maven/plugins/help/AbstractEffectiveMojo.java       |  9 +--------
 .../org/apache/maven/plugins/help/EffectivePomMojo.java | 17 +++++++++++------
 .../maven/plugins/help/EffectiveSettingsMojo.java       | 16 +++++++++-------
 3 files changed, 21 insertions(+), 21 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 eaf216c..597d594 100644
--- a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java
@@ -34,7 +34,6 @@ import java.util.Set;
 
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.WriterFactory;
 import org.codehaus.plexus.util.xml.XMLWriter;
 import org.codehaus.plexus.util.xml.XmlWriterUtil;
@@ -72,7 +71,7 @@ public abstract class AbstractEffectiveMojo
      * @throws IOException if any
      * @see AbstractHelpMojo#writeFile(File, String) if encoding is null.
      */
-    protected static void writeXmlFile( File output, String content, String encoding )
+    protected static void writeXmlFile( File output, String content )
         throws IOException
     {
         if ( output == null )
@@ -80,12 +79,6 @@ public abstract class AbstractEffectiveMojo
             return;
         }
 
-        if ( StringUtils.isEmpty( encoding ) )
-        {
-            writeFile( output, content );
-            return;
-        }
-
         Writer out = null;
         try
         {
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 f030ea7..c459cbc 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
@@ -83,7 +83,7 @@ public class EffectivePomMojo
      * <br>
      * <b>Note</b>: Should respect the Maven format, i.e. <code>groupId:artifactId[:version]</code>. The
      * latest version of the artifact will be used when no version is specified.
-     * 
+     *
      * @since 3.0.0
      */
     @Parameter( property = "artifact" )
@@ -103,9 +103,11 @@ public class EffectivePomMojo
         }
 
         StringWriter w = new StringWriter();
+        String encoding = output != null ? project.getModel().getModelEncoding()
+                                : System.getProperty( "file.encoding" );
         XMLWriter writer =
             new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
-                                      project.getModel().getModelEncoding(), null );
+                                      encoding, null );
 
         writeHeader( writer );
 
@@ -121,7 +123,7 @@ public class EffectivePomMojo
             writer.endElement();
 
             effectivePom = w.toString();
-            effectivePom = prettyFormat( effectivePom );
+            effectivePom = prettyFormat( effectivePom, encoding );
         }
         else
         {
@@ -134,7 +136,7 @@ public class EffectivePomMojo
         {
             try
             {
-                writeXmlFile( output, effectivePom, project.getModel().getModelEncoding() );
+                writeXmlFile( output, effectivePom );
             }
             catch ( IOException e )
             {
@@ -161,7 +163,7 @@ public class EffectivePomMojo
      * Determines if all effective POMs of all the projects in the reactor should be written. When this goal is started
      * on the command-line, it is always the case. However, when it is bound to a phase in the lifecycle, it is only the
      * case when the current project being built is the head project in the reactor.
-     * 
+     *
      * @return <code>true</code> if all effective POMs should be written, <code>false</code> otherwise.
      */
     private boolean shouldWriteAllEffectivePOMsInReactor()
@@ -223,9 +225,10 @@ public class EffectivePomMojo
 
     /**
      * @param effectivePom not null
+     * @param encoding not null
      * @return pretty format of the xml  or the original <code>effectivePom</code> if an error occurred.
      */
-    private static String prettyFormat( String effectivePom )
+    private static String prettyFormat( String effectivePom, String encoding )
     {
         SAXBuilder builder = new SAXBuilder();
 
@@ -235,6 +238,8 @@ public class EffectivePomMojo
 
             StringWriter w = new StringWriter();
             Format format = Format.getPrettyFormat();
+            format.setEncoding( encoding );
+            format.setLineSeparator( System.lineSeparator() );
             XMLOutputter out = new XMLOutputter( format );
             out.output( effectiveDocument, w );
 
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 bbcac03..a960f82 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
@@ -91,9 +91,11 @@ public class EffectiveSettingsMojo
         }
 
         StringWriter w = new StringWriter();
+        String encoding = output != null ? copySettings.getModelEncoding()
+                                : System.getProperty( "file.encoding" );
         XMLWriter writer =
             new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
-                                      copySettings.getModelEncoding(), null );
+                                      encoding, null );
 
         writeHeader( writer );
 
@@ -105,7 +107,7 @@ public class EffectiveSettingsMojo
         {
             try
             {
-                writeXmlFile( output, effectiveSettings, copySettings.getModelEncoding() );
+                writeXmlFile( output, effectiveSettings );
             }
             catch ( IOException e )
             {
@@ -172,7 +174,7 @@ public class EffectiveSettingsMojo
         {
             return null;
         }
-        
+
         // Not a deep copy in M2.2.1 !!!
         Settings clone = SettingsUtils.copySettings( settings );
 
@@ -189,11 +191,11 @@ public class EffectiveSettingsMojo
             clonedServer.setPrivateKey( server.getPrivateKey() );
             clonedServer.setSourceLevel( server.getSourceLevel() );
             clonedServer.setUsername( server.getUsername() );
-            
+
             clonedServers.add( clonedServer );
         }
         clone.setServers( clonedServers );
-        
+
         List<Proxy> clonedProxies = new ArrayList<Proxy>( settings.getProxies().size() );
         for ( Proxy proxy : settings.getProxies() )
         {
@@ -207,11 +209,11 @@ public class EffectiveSettingsMojo
             clonedProxy.setProtocol( proxy.getProtocol() );
             clonedProxy.setSourceLevel( proxy.getSourceLevel() );
             clonedProxy.setUsername( proxy.getUsername() );
-            
+
             clonedProxies.add( clonedProxy );
         }
         clone.setProxies( clonedProxies );
-        
+
         return clone;
     }
 

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