You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Hervé BOUTEMY <he...@free.fr> on 2016/06/16 18:02:59 UTC

Re: svn commit: r1748766 - /maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java

here is my idea on the way to manage consistent and configurable colors across 
Maven core and plugins

to use it:
- use AnsiUtils instead of Ansi class
- same a() methods
- but for colors selections, there are methods defining use cases

Configuration is not yet implemented: need to find a good way to inject info: 
but at least, using this API instead of direct JAnsi's Ansi will ease change 
and consistency

WDYT?

Regards,

Hervé

Le jeudi 16 juin 2016 17:55:00 hboutemy@apache.org a écrit :
> Author: hboutemy
> Date: Thu Jun 16 17:55:00 2016
> New Revision: 1748766
> 
> URL: http://svn.apache.org/viewvc?rev=1748766&view=rev
> Log:
> add methods to manage colors consistently across plugins
> 
> Modified:
>    
> maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/share
> d/project/utils/AnsiUtils.java
> 
> Modified:
> maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/share
> d/project/utils/AnsiUtils.java URL:
> http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/mai
> n/java/org/apache/maven/shared/project/utils/AnsiUtils.java?rev=1748766&r1=1
> 748765&r2=1748766&view=diff
> ===========================================================================
> === ---
> maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/share
> d/project/utils/AnsiUtils.java (original) +++
> maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/share
> d/project/utils/AnsiUtils.java Thu Jun 16 17:55:00 2016 @@ -24,14 +24,27 @@
> import org.fusesource.jansi.Ansi;
>  import org.fusesource.jansi.AnsiConsole;
> 
>  /**
> - * Ansi color utils, to enable colors only if Maven version is at least
> 3.4. + * Ansi color utils, to manage colors colors consistently across
> plugins (only if Maven version is at least 3.4). */
>  public class AnsiUtils
>  {
>      private static final String MINIMUM_MAVEN_VERSION = "3.4.0"; // color
> added in Maven 3.4.0: see MNG-3507
> 
> +    private Ansi ansi;
> +
>      private AnsiUtils()
>      {
> +        ansi = new Ansi();
> +    }
> +
> +    private AnsiUtils( StringBuilder builder )
> +    {
> +        ansi = new Ansi( builder );
> +    }
> +
> +    private AnsiUtils( int size )
> +    {
> +        ansi = new Ansi( size );
>      }
> 
>      public static void systemInstall()
> @@ -48,4 +61,202 @@ public class AnsiUtils
>      {
>          AnsiConsole.systemUninstall();
>      }
> +
> +    public static AnsiUtils ansi()
> +    {
> +        return new AnsiUtils();
> +    }
> +
> +    public static AnsiUtils ansi( StringBuilder builder )
> +    {
> +        return new AnsiUtils( builder );
> +    }
> +
> +    public static AnsiUtils ansi( int size )
> +    {
> +        return new AnsiUtils( size );
> +    }
> +
> +    //
> +    // consistent color management
> +    // TODO make configurable
> +    // settings.xml? during systemInstall(Settings)?
> +    // or project properties (that can be injected by settings)?
> +    //
> +    /**
> +     * Insert color for DEBUG level display.
> +     * @return by default, bold cyan
> +     */
> +    public AnsiUtils debug()
> +    {
> +        ansi.bold().fgCyan();
> +        return this;
> +    }
> +
> +    /**
> +     * Insert color for INFO level display.
> +     * @return by default, bold blue
> +     */
> +    public AnsiUtils info()
> +    {
> +        ansi.bold().fgBlue();
> +        return this;
> +    }
> +
> +    /**
> +     * Insert color for WARNING level or warning message display.
> +     * @return by default, bold yellow
> +     */
> +    public AnsiUtils warning()
> +    {
> +        ansi.bold().fgYellow();
> +        return this;
> +    }
> +
> +    /**
> +     * Insert color for ERROR level display.
> +     * @return by default, bold red
> +     */
> +    public AnsiUtils error()
> +    {
> +        ansi.bold().fgRed();
> +        return this;
> +    }
> +
> +    /**
> +     * Insert color for success message display.
> +     * @return by default, bold green
> +     */
> +    public AnsiUtils success()
> +    {
> +        ansi.bold().fgGreen();
> +        return this;
> +    }
> +
> +    /**
> +     * Insert color for failure message display.
> +     * @return by default, bold red
> +     */
> +    public AnsiUtils failure()
> +    {
> +        ansi.bold().fgRed();
> +        return this;
> +    }
> +
> +    /**
> +     * Insert color for highlighted message display.
> +     * @return by default, bold
> +     */
> +    public AnsiUtils highlight()
> +    {
> +        ansi.bold();
> +        return this;
> +    }
> +
> +    /**
> +     * Insert color for mojo message display.
> +     * @return by default, green
> +     */
> +    public AnsiUtils mojo()
> +    {
> +        ansi.fgGreen();
> +        return this;
> +    }
> +
> +    /**
> +     * Insert color for project message display.
> +     * @return by default, cyan
> +     */
> +    public AnsiUtils project()
> +    {
> +        ansi.fgCyan();
> +        return this;
> +    }
> +
> +    //
> +    // message building methods (modelled after Ansi methods)
> +    //
> +    public AnsiUtils reset()
> +    {
> +        ansi.reset();
> +        return this;
> +    }
> +
> +    public AnsiUtils a( boolean value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( char value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( char[] value, int offset, int len )
> +    {
> +        ansi.a( value, offset, len );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( char[] value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( CharSequence value, int start, int end )
> +    {
> +        ansi.a( value, start, end );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( CharSequence value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( double value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( float value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( int value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( long value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils a( Object value )
> +    {
> +        ansi.a( value );
> +        return this;
> +    }
> +
> +    public AnsiUtils newline()
> +    {
> +        ansi.newline();
> +        return this;
> +    }
> +
> +    public AnsiUtils format( String pattern, Object... args )
> +    {
> +        ansi.format( pattern, args );
> +        return this;
> +    }
>  }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org