Add colors to resolve-goal for modules

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1806840 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 3f59f07..ac7e908 100644
--- a/pom.xml
+++ b/pom.xml
@@ -224,6 +224,11 @@
       <artifactId>maven-artifact-transfer</artifactId>
       <version>0.9.2-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-shared-utils</artifactId>
+      <version>3.2.0</version>
+    </dependency>
 
     <dependency>
       <groupId>commons-lang</groupId>
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java
index e93af2e..c8b1e73 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java
@@ -31,6 +31,8 @@
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
+import org.apache.maven.shared.utils.logging.MessageBuilder;
+import org.apache.maven.shared.utils.logging.MessageUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -42,6 +44,7 @@
 import java.util.List;
 import java.util.Set;
 import java.util.jar.JarFile;
+import java.util.jar.Manifest;
 
 /**
  * Goal that resolves the project dependencies from the repository. 
@@ -177,56 +180,61 @@
         List<String> artifactStringList = new ArrayList<String>();
         for ( Artifact artifact : artifacts )
         {
-            String artifactFilename = null;
+            MessageBuilder messageBuilder = MessageUtils.buffer();
+            
+            messageBuilder.a( "   " );
+            
+            if ( outputScope )
+            {
+                messageBuilder.a( artifact.toString() );
+            }
+            else
+            {
+                messageBuilder.a( artifact.getId() );
+            }
+            
             if ( outputAbsoluteArtifactFilename )
             {
                 try
                 {
                     // we want to print the absolute file name here
-                    artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
+                    String artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
+                    
+                    messageBuilder.a( ':' ).a( artifactFilename );
                 }
                 catch ( NullPointerException e )
                 {
                     // ignore the null pointer, we'll output a null string
-                    artifactFilename = null;
                 }
             }
 
-            String id = outputScope ? artifact.toString() : artifact.getId();
-            String optionalMarker = "";
             if ( outputScope && artifact.isOptional() )
             {
-                optionalMarker = " (optional) ";
+                messageBuilder.a( " (optional) " );
             }
 
-            String moduleNameMarker = "";
-
             // dependencies:collect won't download jars
             if ( artifact.getFile() != null )
             {
                 ModuleDescriptor moduleDescriptor = getModuleDescriptor( artifact.getFile() );
                 if ( moduleDescriptor != null )
                 {
-                    moduleNameMarker = " -- module " + moduleDescriptor.name;
+                    messageBuilder.project( " -- module " + moduleDescriptor.name );
 
                     if ( moduleDescriptor.automatic )
                     {
                         if ( "MANIFEST".equals( moduleDescriptor.moduleNameSource ) )
                         {
-                            moduleNameMarker += " [auto]";
+                            messageBuilder.strong( " [auto]" );
                         }
                         else
                         {
-                            moduleNameMarker += " (auto)";
+                            messageBuilder.warning( " (auto)" );
                         }
                     }
                 }
             }
-
-            artifactStringList.add( "   " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" )
-                + optionalMarker
-                + moduleNameMarker
-                + "\n" );
+            artifactStringList.add( messageBuilder.toString() + "\n" );
         }
         if ( sort )
         {
@@ -281,7 +289,10 @@
                         {
                             jarFile = new JarFile( artifactFile );
                             
-                            if ( jarFile.getManifest().getMainAttributes().getValue( "Automatic-Module-Name" ) != null )
+                            Manifest manifest = jarFile.getManifest();
+                            
+                            if ( manifest != null
+                                && manifest.getMainAttributes().getValue( "Automatic-Module-Name" ) != null )
                             {
                                 moduleDescriptor.moduleNameSource = "MANIFEST";
                             }