You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2022/11/25 12:58:22 UTC

[maven-shared-utils] 01/01: don't trim

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

elharo pushed a commit to branch MSHARED-953
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit bd7b38620c0adf5c6b3b20ef9bbcc704dfb1b0ac
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Fri Nov 25 07:55:38 2022 -0500

    don't trim
---
 .../maven/shared/utils/xml/Xpp3DomBuilder.java     | 30 ++++++++++------------
 .../maven/shared/utils/xml/Xpp3DomBuilderTest.java |  5 ++--
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
index 2b8f4ab..ecd4200 100644
--- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
+++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
@@ -42,7 +42,6 @@ import java.util.List;
  */
 public class Xpp3DomBuilder
 {
-    private static final boolean DEFAULT_TRIM = true;
 
     /**
      * @param reader {@link Reader}
@@ -52,7 +51,7 @@ public class Xpp3DomBuilder
     public static Xpp3Dom build( @WillClose @Nonnull Reader reader )
         throws XmlPullParserException
     {
-        return build( reader, DEFAULT_TRIM );
+        return build( reader, false );
     }
 
     /**
@@ -64,23 +63,23 @@ public class Xpp3DomBuilder
     public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding )
         throws XmlPullParserException
     {
-        return build( is, encoding, DEFAULT_TRIM );
+        return build( is, encoding, false );
     }
 
     /**
      * @param is {@link InputStream}
      * @param encoding the encoding
-     * @param trim true/false
+     * @param noop vestigial argument with no effect
      * @return the built DOM
      * @throws XmlPullParserException in case of an error
      */
-    public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding, boolean trim )
+    public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding, boolean noop )
         throws XmlPullParserException
     {
         try
         {
             Reader reader = new InputStreamReader( is, encoding );
-            return build( reader, trim );
+            return build( reader );
         }
         catch ( UnsupportedEncodingException e )
         {
@@ -89,17 +88,19 @@ public class Xpp3DomBuilder
     }
 
     /**
+     * deprecated use {#build(java.io.Reader)}
      * @param in {@link Reader}
-     * @param trim true/false
+     * @param noop vestigial argument with no effect
      * @return the built DOM
      * @throws XmlPullParserException in case of an error
      */
-    public static Xpp3Dom build( @WillClose Reader in, boolean trim )
+    @Deprecated
+    public static Xpp3Dom build( @WillClose Reader in, boolean noop )
         throws XmlPullParserException
     {
         try ( Reader reader = in )  
         {
-            DocHandler docHandler = parseSax( new InputSource( reader ), trim );
+            DocHandler docHandler = parseSax( new InputSource( reader ) );
             reader.close();
             return docHandler.result;
         }
@@ -109,12 +110,12 @@ public class Xpp3DomBuilder
         }
     }
 
-    private static DocHandler parseSax( @Nonnull InputSource inputSource, boolean trim )
+    private static DocHandler parseSax( @Nonnull InputSource inputSource )
         throws XmlPullParserException
     {
         try
         {
-            DocHandler ch = new DocHandler( trim );
+            DocHandler ch = new DocHandler();
             XMLReader parser = createXmlReader();
             parser.setContentHandler( ch );
             parser.parse( inputSource );
@@ -189,13 +190,10 @@ public class Xpp3DomBuilder
 
         Xpp3Dom result = null;
 
-        private final boolean trim;
-
         private boolean spacePreserve = false;
 
-        DocHandler( boolean trim )
+        DocHandler()
         {
-            this.trim = trim;
         }
 
         @Override
@@ -274,7 +272,7 @@ public class Xpp3DomBuilder
             throws SAXException
         {
             String text = new String( ch, start, length );
-            appendToTopValue( ( trim && !spacePreserve ) ? text.trim() : text );
+            appendToTopValue( text );
         }
 
         private void appendToTopValue( String toAppend )
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
index cef681e..49c7e69 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
@@ -74,7 +74,8 @@ public class Xpp3DomBuilderTest
     }
 
     
-    @Test
+    @SuppressWarnings("deprecation")
+	@Test
     public void trimming()
         throws Exception
     {
@@ -82,7 +83,7 @@ public class Xpp3DomBuilderTest
 
         Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( domString ), true );
 
-        assertEquals( "element1value", dom.getChild( "element1" ).getValue() );
+        assertEquals( " element1value\n ", dom.getChild( "element1" ).getValue() );
 
         assertEquals( "  preserve space  ", dom.getChild( "element6" ).getValue() );