maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1749138 - in /maven/shared/trunk/maven-project-utils/src: main/java/org/apache/maven/shared/project/utils/AnsiUtils.java test/java/org/apache/maven/shared/project/utils/AnsiUtilsTest.java
Date Sun, 19 Jun 2016 08:04:25 GMT
Author: hboutemy
Date: Sun Jun 19 08:04:25 2016
New Revision: 1749138

URL: http://svn.apache.org/viewvc?rev=1749138&view=rev
Log:
[MSHARED-562] added colored message rendering helpers style(message) to ease style().a(message).reset()
pattern

Modified:
    maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java
    maven/shared/trunk/maven-project-utils/src/test/java/org/apache/maven/shared/project/utils/AnsiUtilsTest.java

Modified: maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java?rev=1749138&r1=1749137&r2=1749138&view=diff
==============================================================================
--- maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java
(original)
+++ maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java
Sun Jun 19 08:04:25 2016
@@ -85,7 +85,7 @@ public class AnsiUtils
     //
     /**
      * Insert color for DEBUG level display.
-     * @return by default, bold cyan
+     * By default, bold cyan
      */
     public AnsiUtils debug()
     {
@@ -95,7 +95,7 @@ public class AnsiUtils
     
     /**
      * Insert color for INFO level display.
-     * @return by default, bold blue
+     * By default, bold blue
      */
     public AnsiUtils info()
     {
@@ -105,7 +105,7 @@ public class AnsiUtils
     
     /**
      * Insert color for WARNING level or warning message display.
-     * @return by default, bold yellow
+     * By default, bold yellow
      */
     public AnsiUtils warning()
     {
@@ -115,7 +115,7 @@ public class AnsiUtils
     
     /**
      * Insert color for ERROR level display.
-     * @return by default, bold red
+     * By default, bold red
      */
     public AnsiUtils error()
     {
@@ -125,7 +125,7 @@ public class AnsiUtils
     
     /**
      * Insert color for success message display.
-     * @return by default, bold green
+     * By default, bold green
      */
     public AnsiUtils success()
     {
@@ -134,8 +134,16 @@ public class AnsiUtils
     }
     
     /**
+     * Append success message: equivalent to appending success color, then message, then
reset.
+     */
+    public AnsiUtils success( Object message )
+    {
+        return success().a( message ).reset();
+    }
+    
+    /**
      * Insert color for failure message display.
-     * @return by default, bold red
+     * By default, bold red
      */
     public AnsiUtils failure()
     {
@@ -144,8 +152,16 @@ public class AnsiUtils
     }
 
     /**
+     * Append failure message: equivalent to appending failure color, then message, then
reset.
+     */
+    public AnsiUtils failure( Object message )
+    {
+        return failure().a( message ).reset();
+    }
+    
+    /**
      * Insert color for strong message display.
-     * @return by default, bold
+     * By default, bold
      */
     public AnsiUtils strong()
     {
@@ -154,8 +170,16 @@ public class AnsiUtils
     }
 
     /**
+     * Append strong message: equivalent to appending strong color, then message, then reset.
+     */
+    public AnsiUtils strong( Object message )
+    {
+        return strong().a( message ).reset();
+    }
+    
+    /**
      * Insert color for mojo message display.
-     * @return by default, green
+     * By default, green
      */
     public AnsiUtils mojo()
     {
@@ -164,8 +188,16 @@ public class AnsiUtils
     }
 
     /**
+     * Append mojo message: equivalent to appending mojo color, then message, then reset.
+     */
+    public AnsiUtils mojo( Object message )
+    {
+        return mojo().a( message ).reset();
+    }
+    
+    /**
      * Insert color for project message display.
-     * @return by default, cyan
+     * By default, cyan
      */
     public AnsiUtils project()
     {
@@ -173,6 +205,14 @@ public class AnsiUtils
         return this;
     }
 
+    /**
+     * Append project message: equivalent to appending project color, then message, then
reset.
+     */
+    public AnsiUtils project( Object message )
+    {
+        return project().a( message ).reset();
+    }
+    
     //
     // message building methods (modelled after Ansi methods)
     //

Modified: maven/shared/trunk/maven-project-utils/src/test/java/org/apache/maven/shared/project/utils/AnsiUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/test/java/org/apache/maven/shared/project/utils/AnsiUtilsTest.java?rev=1749138&r1=1749137&r2=1749138&view=diff
==============================================================================
--- maven/shared/trunk/maven-project-utils/src/test/java/org/apache/maven/shared/project/utils/AnsiUtilsTest.java
(original)
+++ maven/shared/trunk/maven-project-utils/src/test/java/org/apache/maven/shared/project/utils/AnsiUtilsTest.java
Sun Jun 19 08:04:25 2016
@@ -24,31 +24,39 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotEquals;
 
 import org.fusesource.jansi.Ansi;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 public class AnsiUtilsTest
 {
+    private boolean savedAnsiEnable;
+
+    @Before
+    public void saveAnsiState()
+    {
+        boolean savedAnsiEnable = Ansi.isEnabled();
+    }
+
+    @After
+    public void restoreAnsiState()
+    {
+        Ansi.setEnabled( savedAnsiEnable );
+    }
+
     @Test
     public void constructors()
     {
-        boolean enabled = Ansi.isEnabled();
-        try
-        {
-            // check that ANSI color disable is taken into account
-            Ansi.setEnabled( false );
-            assertEquals( "test", ansi().error().a( "test" ).reset().toString() );
-            assertEquals( "test", ansi( 16 ).error().a( "test" ).reset().toString() );
-            assertEquals( "test", ansi( new StringBuilder() ).error().a( "test" ).reset().toString()
);
-    
-            Ansi.setEnabled( true );
-            assertNotEquals( "test", ansi().error().a( "test" ).reset().toString() );
-            assertNotEquals( "test", ansi( 16 ).error().a( "test" ).reset().toString() );
-            assertNotEquals( "test", ansi( new StringBuilder() ).error().a( "test" ).reset().toString()
);
-        }
-        finally
-        {
-            Ansi.setEnabled( enabled );
-        }
+        // check that ANSI color disable is taken into account
+        Ansi.setEnabled( false );
+        assertEquals( "test", ansi().error().a( "test" ).reset().toString() );
+        assertEquals( "test", ansi( 16 ).error().a( "test" ).reset().toString() );
+        assertEquals( "test", ansi( new StringBuilder() ).error().a( "test" ).reset().toString()
);
+
+        Ansi.setEnabled( true );
+        assertNotEquals( "test", ansi().error().a( "test" ).reset().toString() );
+        assertNotEquals( "test", ansi( 16 ).error().a( "test" ).reset().toString() );
+        assertNotEquals( "test", ansi( new StringBuilder() ).error().a( "test" ).reset().toString()
);
     }
 
     @Test
@@ -62,4 +70,15 @@ public class AnsiUtilsTest
         assertEquals( "true", ansi().a( true ).toString() );
         assertEquals( "c", ansi().a( 'c' ).toString() );
     }
+
+    @Test
+    public void messages()
+    {
+        Ansi.setEnabled( true );
+        assertEquals( ansi().success().a( "test" ).reset().toString(), ansi().success( "test"
).toString() );
+        assertEquals( ansi().failure().a( "test" ).reset().toString(), ansi().failure( "test"
).toString() );
+        assertEquals( ansi().strong().a( "test" ).reset().toString(), ansi().strong( "test"
).toString() );
+        assertEquals( ansi().mojo().a( "test" ).reset().toString(), ansi().mojo( "test" ).toString()
);
+        assertEquals( ansi().project().a( "test" ).reset().toString(), ansi().project( "test"
).toString() );
+    }
 }



Mime
View raw message