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 2022/07/27 15:48:31 UTC

[maven-doxia] 01/02: Simplify line separator handling

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

michaelo pushed a commit to branch simplify-ls
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git

commit 768a5ffa2c18103a0eb51d8d576b0794a49c9acf
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Jul 27 17:18:24 2022 +0200

    Simplify line separator handling
---
 .../java/org/apache/maven/doxia/index/IndexEntry.java  |  6 +++---
 .../main/java/org/apache/maven/doxia/macro/Macro.java  |  2 +-
 .../maven/doxia/macro/snippet/SnippetReader.java       |  8 ++++----
 .../java/org/apache/maven/doxia/markup/Markup.java     |  2 +-
 .../org/apache/maven/doxia/sink/impl/AbstractSink.java |  2 +-
 .../apache/maven/doxia/sink/impl/AbstractXmlSink.java  |  4 ++--
 .../java/org/apache/maven/doxia/util/LineBreaker.java  |  8 ++++----
 .../maven/doxia/parser/Xhtml5BaseParserTest.java       |  9 ++++-----
 .../apache/maven/doxia/sink/impl/SinkTestDocument.java |  5 ++---
 .../org/apache/maven/doxia/sink/impl/TextSink.java     |  2 +-
 .../apache/maven/doxia/xsd/AbstractXmlValidator.java   | 18 +++++++++---------
 .../org/apache/maven/doxia/module/apt/AptSink.java     |  2 +-
 .../apache/maven/doxia/module/xdoc/XdocParserTest.java |  2 +-
 13 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java b/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java
index 43536131..af0e98f0 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexEntry.java
@@ -53,9 +53,9 @@ public class IndexEntry
     private List<IndexEntry> childEntries = new ArrayList<>();
 
     /**
-     * System-dependent EOL.
+     * System-dependent line separator.
      */
-    private static final String EOL = System.getProperty( "line.separator" );
+    private static final String LS = System.lineSeparator();
 
     /**
      * Constructor.
@@ -300,7 +300,7 @@ public class IndexEntry
             message.append( ", title: " ).append( title );
         }
 
-        message.append( EOL );
+        message.append( LS );
 
         StringBuilder indent = new StringBuilder();
 
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java b/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java
index 2ae82096..b8541bfd 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java
@@ -31,7 +31,7 @@ public interface Macro
 {
 
     /** The vm line separator */
-    String EOL = System.getProperty( "line.separator" );
+    String EOL = System.lineSeparator();
 
     /**
      * Execute the current macro using the given MacroRequest,
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java b/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
index c313bd61..504e8ddf 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
@@ -35,8 +35,8 @@ import org.codehaus.plexus.util.IOUtil;
  */
 public class SnippetReader
 {
-    /** System-dependent EOL. */
-    private static final String EOL = System.getProperty( "line.separator" );
+    /** System-dependent line separator. */
+    private static final String LS = System.lineSeparator();
 
     /** The source. */
     private URL source;
@@ -82,7 +82,7 @@ public class SnippetReader
         for ( String line : lines )
         {
             result.append( line.substring( minIndent ) );
-            result.append( EOL );
+            result.append( LS );
         }
         return result;
     }
@@ -219,7 +219,7 @@ public class SnippetReader
         String snippetRegExp = "(^|\\W)(?i:SNIPPET)($|\\W)";
         String snippetIdRegExp = "(^|\\W)" + snippetId + "($|\\W)";
         String whatRegExp = "(^|\\W)(?i:" + what + ")($|\\W)";
-        
+
         return Pattern.compile( snippetRegExp ).matcher( line ).find()
             && Pattern.compile( whatRegExp ).matcher( line ).find()
             && Pattern.compile( snippetIdRegExp ).matcher( line ).find();
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java b/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java
index 0eff103b..08493a77 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java
@@ -29,7 +29,7 @@ package org.apache.maven.doxia.markup;
 public interface Markup
 {
     /** The vm line separator */
-    String EOL = System.getProperty( "line.separator" );
+    String EOL = System.lineSeparator();
 
     // ----------------------------------------------------------------------
     // Generic separator characters
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/AbstractSink.java b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/AbstractSink.java
index e5495cf2..fa142373 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/AbstractSink.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/AbstractSink.java
@@ -34,7 +34,7 @@ public abstract class AbstractSink
 {
     /**
       * Parses the given String and replaces all occurrences of
-      * '\n', '\r' and '\r\n' with the system EOL. All Sinks should
+      * '\n', '\r' and '\r\n' with the system LS. All Sinks should
       * make sure that text output is filtered through this method.
       *
       * @param text the text to scan.
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/AbstractXmlSink.java b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/AbstractXmlSink.java
index 5dbb5591..a956a09f 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/AbstractXmlSink.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/AbstractXmlSink.java
@@ -148,7 +148,7 @@ public abstract class AbstractXmlSink
     }
 
     /**
-     * Writes a system EOL.
+     * Writes a system LS.
      *
      * @since 1.1
      */
@@ -158,7 +158,7 @@ public abstract class AbstractXmlSink
     }
 
     /**
-     * Ends a Tag without writing an EOL. For instance: <pre>&lt;/tag&gt;</pre>.
+     * Ends a Tag without writing an LS. For instance: <pre>&lt;/tag&gt;</pre>.
      *
      * @param t a tag.
      */
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/util/LineBreaker.java b/doxia-core/src/main/java/org/apache/maven/doxia/util/LineBreaker.java
index 6a0898e0..a7d7670c 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/util/LineBreaker.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/util/LineBreaker.java
@@ -33,8 +33,8 @@ public class LineBreaker
     /** The default maximal line length. */
     public static final int DEFAULT_MAX_LINE_LENGTH = 78;
 
-    /** The system dependent EOL. */
-    private static final String EOL = System.getProperty( "line.separator" );
+    /** The system dependent line separator. */
+    private static final String LS = System.lineSeparator();
 
     /** The destination writer. */
     private Writer destination;
@@ -139,7 +139,7 @@ public class LineBreaker
 
                     case '\n':
                         writeWord();
-                        writer.write( EOL );
+                        writer.write( LS );
                         lineLength = 0;
                         break;
 
@@ -187,7 +187,7 @@ public class LineBreaker
             {
                 if ( lineLength + 1 + length > maxLineLength )
                 {
-                    writer.write( EOL );
+                    writer.write( LS );
                     lineLength = 0;
                 }
                 else
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/parser/Xhtml5BaseParserTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/parser/Xhtml5BaseParserTest.java
index 9fd83ef4..4dd446b0 100644
--- a/doxia-core/src/test/java/org/apache/maven/doxia/parser/Xhtml5BaseParserTest.java
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/parser/Xhtml5BaseParserTest.java
@@ -211,9 +211,8 @@ public class Xhtml5BaseParserTest
         assertFalse( it.hasNext() );
 
 
-        // same test with EOL
-        String eol = System.getProperty( "line.separator" );
-        text = "<p><b>word</b>" + eol + "<i>word</i></p>";
+        // same test with system line separator
+        text = "<p><b>word</b>" + Xhtml5BaseParser.EOL + "<i>word</i></p>";
 
         sink.reset();
         parser.parse( text, sink );
@@ -236,7 +235,7 @@ public class Xhtml5BaseParserTest
         assertFalse( it.hasNext() );
 
 
-        // DOXIA-189: there should be no EOL after closing tag
+        // DOXIA-189: there should be no LS after closing tag
         text = "<p>There should be no space after the last <i>word</i>.</p>";
 
         sink.reset();
@@ -298,7 +297,7 @@ public class Xhtml5BaseParserTest
     public void testPreEOL()
         throws Exception
     {
-        // test EOLs within <pre>: the sink MUST receive a text event for the EOL
+        // test EOLs within <pre>: the sink MUST receive a text event for the LS
         String text = "<pre><a href=\"what.html\">what</a>" + Xhtml5BaseParser.EOL
                 + "<a href=\"what.html\">what</a></pre>";
 
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/SinkTestDocument.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/SinkTestDocument.java
index f11d9172..ea94d52a 100644
--- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/SinkTestDocument.java
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/SinkTestDocument.java
@@ -1,5 +1,6 @@
 package org.apache.maven.doxia.sink.impl;
 
+import org.apache.maven.doxia.markup.Markup;
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
 
@@ -248,8 +249,6 @@ public class SinkTestDocument
      */
     public static void generateDefinitionList( Sink sink )
     {
-        String eol = System.getProperty( "line.separator" );
-
         sink.definitionList();
 
         sink.definitionListItem();
@@ -268,7 +267,7 @@ public class SinkTestDocument
         sink.definition();
         sink.text( "of definition list." );
         sink.verbatim( SinkEventAttributeSet.BOXED );
-        sink.text( "Verbatim text" + eol + "                        in a box        " );
+        sink.text( "Verbatim text" + Markup.EOL + "                        in a box        " );
         sink.verbatim_();
         sink.definition_();
         sink.definitionListItem_();
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/TextSink.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/TextSink.java
index b5a34f76..dbccd672 100644
--- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/TextSink.java
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/TextSink.java
@@ -1020,7 +1020,7 @@ public class TextSink
     }
 
     /**
-     * Writes the given string + EOL.
+     * Writes the given string + LS.
      *
      * @param text The text to write.
      */
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidator.java b/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidator.java
index 4ac46a59..412711d6 100644
--- a/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidator.java
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidator.java
@@ -55,7 +55,7 @@ import static org.junit.jupiter.api.Assertions.fail;
 public abstract class AbstractXmlValidator
 {
 
-    protected static final String EOL = System.getProperty( "line.separator" );
+    protected static final String LS = System.lineSeparator();
 
     protected final Logger logger = LoggerFactory.getLogger( getClass() );
 
@@ -113,13 +113,13 @@ public abstract class AbstractXmlValidator
             {
                 if ( isFailErrorMessage( error.getMessage() ) )
                 {
-                    fail( entry.getKey() + EOL + error.toString() );
+                    fail( entry.getKey() + LS + error );
                 }
                 else
                 {
                     if ( logger.isDebugEnabled() )
                     {
-                        logger.debug( entry.getKey() + EOL + error.toString() );
+                        logger.debug( entry.getKey() + LS + error );
                     }
                 }
             }
@@ -287,12 +287,12 @@ public abstract class AbstractXmlValidator
         {
             StringBuilder sb = new StringBuilder( 512 );
 
-            sb.append( level ).append( EOL );
-            sb.append( "  Public ID: " ).append( publicID ).append( EOL );
-            sb.append( "  System ID: " ).append( systemID ).append( EOL );
-            sb.append( "  Line number: " ).append( lineNumber ).append( EOL );
-            sb.append( "  Column number: " ).append( columnNumber ).append( EOL );
-            sb.append( "  Message: " ).append( message ).append( EOL );
+            sb.append( level ).append( LS );
+            sb.append( "  Public ID: " ).append( publicID ).append( LS );
+            sb.append( "  System ID: " ).append( systemID ).append( LS );
+            sb.append( "  Line number: " ).append( lineNumber ).append( LS );
+            sb.append( "  Column number: " ).append( columnNumber ).append( LS );
+            sb.append( "  Message: " ).append( message ).append( LS );
 
             return sb.toString();
         }
diff --git a/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java b/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java
index c263fb9a..27ea91eb 100644
--- a/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java
+++ b/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java
@@ -433,7 +433,7 @@ public class AptSink
     public void listItem()
     {
         //if ( !numberedList )
-        //write( EOL + listNestingIndent + "*" );
+        //write( LS + listNestingIndent + "*" );
         //else
         numberedListItem();
         itemFlag = true;
diff --git a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
index 7469c59a..4909b048 100644
--- a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
+++ b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
@@ -314,7 +314,7 @@ public class XdocParserTest
     public void testPreEOL()
         throws Exception
     {
-        // test EOLs within <source>: the sink MUST receive a text event for the EOL
+        // test EOLs within <source>: the sink MUST receive a text event for the LS
         String text = "<source><a href=\"what.html\">what</a>" + EOL
                 + "<a href=\"what.html\">what</a></source>";