Author: vsiveton
Date: Wed Jan 30 15:59:11 2008
New Revision: 616962

URL: http://svn.apache.org/viewvc?rev=616962&view=rev
Log:
o fixed javadoc @since
o improved logging call
o used WriterFactory.newPlatformWriter( ... ) and handle flush()

Modified:
    
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
    
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
    
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
    
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java

Modified: 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java?rev=616962&r1=616961&r2=616962&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
 Wed Jan 30 15:59:11 2008
@@ -22,11 +22,10 @@
 import org.apache.maven.model.Profile;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.WriterFactory;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 import java.util.Date;
@@ -35,85 +34,88 @@
 
 /**
  * Lists the profiles which are currently active for this build.
- * 
+ *
+ * @since 2.0
  * @goal active-profiles
  * @aggregator
  */
 public class ActiveProfilesMojo extends AbstractMojo
 {
-    
     /**
      * This is the list of projects currently slated to be built by Maven.
-     * 
+     *
      * @parameter expression="${reactorProjects}"
      * @required
      * @readonly
      */
     private List projects;
-    
+
     /**
      * This is an optional parameter for a file destination for the output
-     * of this mojo...the listing of active profiles per project.
-     * 
+     * of this mojo.
+     *
      * @parameter expression="${output}"
      */
     private File output;
 
-    /**
-     * @see org.apache.maven.plugin.AbstractMojo#execute()
-     */
+    /** [EMAIL PROTECTED] */
     public void execute()
         throws MojoExecutionException
     {
         StringBuffer message = new StringBuffer();
-        
+
         for ( Iterator it = projects.iterator(); it.hasNext(); )
         {
             MavenProject project = (MavenProject) it.next();
-            
+
             getActiveProfileStatement( project, message );
-            
+
             message.append( "\n\n" );
         }
-        
+
         if ( output != null )
         {
             writeFile( message );
         }
         else
         {
-            Log log = getLog();
-            log.info( message );
+            if ( getLog().isInfoEnabled() )
+            {
+                getLog().info( message );
+            }
         }
     }
-    
+
     /**
      * Method for writing the output file of the active profiles information.
      *
      * @param message   the output to be written to the file
      * @throws MojoExecutionException
      */
-    private void writeFile( StringBuffer message ) 
+    private void writeFile( StringBuffer message )
         throws MojoExecutionException
     {
         Writer writer = null;
         try
         {
             File dir = output.getParentFile();
-            
+
             if ( !dir.exists() )
             {
                 dir.mkdirs();
             }
-            
-            writer = new FileWriter( output );
-            
+
+            writer = WriterFactory.newPlatformWriter( output );
+
             writer.write( "Created by: " + getClass().getName() + "\n" );
             writer.write( "Created on: " + new Date() + "\n\n" );
             writer.write( message.toString() );
             writer.flush();
-            
-            getLog().info( "Active profile report written to: " + output );
+
+            if ( getLog().isInfoEnabled() )
+            {
+                getLog().info( "Active profile report written to: " + output );
+            }
         }
         catch ( IOException e )
         {
@@ -129,7 +131,10 @@
                 }
                 catch ( IOException e )
                 {
-                    getLog().debug( "Failed to close output file writer.", e );
+                    if ( getLog().isDebugEnabled() )
+                    {
+                        getLog().debug( "Failed to close output file writer.", 
e );
+                    }
                 }
             }
         }
@@ -144,11 +149,11 @@
     private void getActiveProfileStatement( MavenProject project, StringBuffer 
message )
     {
         List profiles = collectActiveProfiles( project );
-        
+
         message.append( "\n" );
-        
+
         message.append( "Active Profiles for Project \'" + project.getId() + 
"\': \n\n" );
-        
+
         if ( profiles == null || profiles.isEmpty() )
         {
             message.append( "There are no active profiles." );
@@ -156,19 +161,19 @@
         else
         {
             message.append( "The following profiles are active:\n" );
-            
+
             for ( Iterator it = profiles.iterator(); it.hasNext(); )
             {
                 Profile profile = (Profile) it.next();
-                
+
                 message.append( "\n - " )
                        .append( profile.getId() )
                        .append( " (source: " )
                        .append( profile.getSource() ).append( ")" );
             }
-            
+
         }
-        
+
         message.append( "\n" );
     }
 
@@ -200,5 +205,4 @@
     {
         this.projects = projects;
     }
-
 }

Modified: 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java?rev=616962&r1=616961&r2=616962&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
 Wed Jan 30 15:59:11 2008
@@ -20,7 +20,6 @@
  */
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 import java.util.Iterator;
@@ -49,10 +48,12 @@
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.component.repository.ComponentRequirement;
+import org.codehaus.plexus.util.WriterFactory;
 
 /**
  * Describes the attributes of a plugin and/or plugin mojo.
  *
+ * @since 2.0
  * @goal describe
  * @requiresProject false
  * @aggregator
@@ -60,7 +61,6 @@
 public class DescribeMojo
     extends AbstractMojo
 {
-
     /**
      * The plugin/mojo to describe. This must be specified in one of three 
ways:
      * <br/>
@@ -188,9 +188,7 @@
      */
     private boolean medium;
 
-    /**
-     * @see org.apache.maven.plugin.AbstractMojo#execute()
-     */
+    /** [EMAIL PROTECTED] */
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
@@ -242,9 +240,11 @@
             {
                 output.getParentFile().mkdirs();
 
-                out = new FileWriter( output );
+                out = WriterFactory.newPlatformWriter( output );
 
                 out.write( descriptionBuffer.toString() );
+
+                out.flush();
             }
             catch ( IOException e )
             {
@@ -260,16 +260,25 @@
                     }
                     catch ( IOException e )
                     {
-                        getLog().debug( "Error closing file output.", e );
+                        if ( getLog().isDebugEnabled() )
+                        {
+                            getLog().debug( "Error closing file output.", e );
+                        }
                     }
                 }
             }
 
-            getLog().info( "Wrote descriptions to: " + output );
+            if ( getLog().isInfoEnabled() )
+            {
+                getLog().info( "Wrote descriptions to: " + output );
+            }
         }
         else
         {
-            getLog().info( descriptionBuffer.toString() );
+            if ( getLog().isInfoEnabled() )
+            {
+                getLog().info( descriptionBuffer.toString() );
+            }
         }
     }
 
@@ -352,12 +361,18 @@
             }
             catch ( PluginNotFoundException e )
             {
-                getLog().debug( "Unable to find plugin", e );
+                if ( getLog().isDebugEnabled() )
+                {
+                    getLog().debug( "Unable to find plugin", e );
+                }
                 throw new MojoFailureException( "Plugin does not exist: " + 
e.getMessage() );
             }
             catch ( PluginVersionNotFoundException e )
             {
-                getLog().debug( "Unable to find plugin version", e );
+                if ( getLog().isDebugEnabled() )
+                {
+                    getLog().debug( "Unable to find plugin version", e );
+                }
                 throw new MojoFailureException( e.getMessage() );
             }
         }

Modified: 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java?rev=616962&r1=616961&r2=616962&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
 Wed Jan 30 15:59:11 2008
@@ -24,18 +24,20 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.WriterFactory;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.io.Writer;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 
 /**
  * Display the effective POM for this build, with the active profiles factored 
in.
- * 
+ *
+ * @since 2.0
  * @goal effective-pom
  * @aggregator
  */
@@ -43,6 +45,9 @@
     extends AbstractMojo
 {
     /**
+     * The Maven project.
+     *
+     * @since 2.0.2
      * @parameter expression="${project}"
      * @required
      * @readonly
@@ -52,7 +57,7 @@
     /**
      * The projects in the current build. The effective-POM for
      * each of these projects will written.
-     * 
+     *
      * @parameter expression="${reactorProjects}"
      * @required
      * @readonly
@@ -61,14 +66,12 @@
 
     /**
      * If specified, write the output to this path.
-     * 
+     *
      * @parameter expression="${output}"
      */
     private File output;
 
-    /**
-     * @see org.apache.maven.plugin.AbstractMojo#execute()
-     */
+    /** [EMAIL PROTECTED] */
     public void execute()
         throws MojoExecutionException
     {
@@ -81,9 +84,9 @@
             for ( Iterator it = projects.iterator(); it.hasNext(); )
             {
                 MavenProject project = (MavenProject) it.next();
-                
+
                 getEffectivePom( project, message );
-                
+
                 message.append( "\n\n" );
             }
         }
@@ -92,10 +95,10 @@
             getEffectivePom( project, message );
             message.append( "\n\n" );
         }
-        
+
         if ( output != null )
         {
-            FileWriter fWriter = null;
+            Writer fWriter = null;
             try
             {
                 File dir = output.getParentFile();
@@ -105,14 +108,18 @@
                     dir.mkdirs();
                 }
 
-                getLog().info( "Writing effective-POM to: " + output );
-
-                fWriter = new FileWriter( output );
+                fWriter = WriterFactory.newPlatformWriter( output );
 
                 fWriter.write( "Created by: " + getClass().getName() + "\n" );
                 fWriter.write( "Created on: " + new Date() + "\n\n" );
-                
                 fWriter.write( message.toString() );
+
+                fWriter.flush();
+
+                if ( getLog().isInfoEnabled() )
+                {
+                    getLog().info( "Effective-POM written to: " + output );
+                }
             }
             catch ( IOException e )
             {
@@ -128,7 +135,10 @@
                     }
                     catch ( IOException e )
                     {
-                        getLog().debug( "Cannot close FileWriter to output 
location: " + output, e );
+                        if ( getLog().isDebugEnabled() )
+                        {
+                            getLog().debug( "Cannot close FileWriter to output 
location: " + output, e );
+                        }
                     }
                 }
             }
@@ -141,7 +151,10 @@
             formatted.append( message.toString() );
             formatted.append( "\n" );
 
-            getLog().info( message );
+            if ( getLog().isInfoEnabled() )
+            {
+                getLog().info( message );
+            }
         }
     }
 
@@ -152,7 +165,7 @@
      * @param message   the information to be displayed
      * @throws MojoExecutionException
      */
-    private void getEffectivePom( MavenProject project, StringBuffer message ) 
+    private void getEffectivePom( MavenProject project, StringBuffer message )
         throws MojoExecutionException
     {
         Model pom = project.getModel();
@@ -164,7 +177,7 @@
         try
         {
             pomWriter.write( sWriter, pom );
-            
+
             message.append( 
"\n************************************************************************************"
 );
             message.append( "\nEffective POM for project \'" + project.getId() 
+ "\'" );
             message.append( 
"\n************************************************************************************"
 );
@@ -188,5 +201,4 @@
     {
         this.projects = projects;
     }
-
 }

Modified: 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java?rev=616962&r1=616961&r2=616962&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
 Wed Jan 30 15:59:11 2008
@@ -23,27 +23,28 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer;
+import org.codehaus.plexus.util.WriterFactory;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.io.Writer;
 
 /**
- * Print out the calculated settings for this project, given any profile 
enhancement and 
+ * Print out the calculated settings for this project, given any profile 
enhancement and
  *  the inheritance of the global settings into the user-level settings.
- *  
+ *
+ * @since 2.0
  * @goal effective-settings
  * @requiresProject false
  */
 public class EffectiveSettingsMojo
     extends AbstractMojo
 {
-
     /**
-     * The system settings for Maven. This is the instance resulting from 
+     * The system settings for Maven. This is the instance resulting from
      * merging global- and user-level settings files.
-     * 
+     *
      * @parameter expression="${settings}"
      * @readonly
      * @required
@@ -52,14 +53,12 @@
 
     /**
      * If specified write the effective settings file out to this path.
-     * 
+     *
      * @parameter expression="${output}"
      */
     private String output;
 
-    /**
-     * @see org.apache.maven.plugin.AbstractMojo#execute() 
-     */
+    /** [EMAIL PROTECTED] */
     public void execute()
         throws MojoExecutionException
     {
@@ -78,7 +77,7 @@
 
         if ( output != null && output.trim().length() > 0 )
         {
-            FileWriter fWriter = null;
+            Writer fWriter = null;
             try
             {
                 File outFile = new File( output ).getAbsoluteFile();
@@ -90,11 +89,15 @@
                     dir.mkdirs();
                 }
 
-                getLog().info( "Writing effective-settings to: " + outFile );
+                fWriter = WriterFactory.newPlatformWriter( outFile );
+                fWriter.write( sWriter.toString() );
 
-                fWriter = new FileWriter( outFile );
+                fWriter.flush();
 
-                fWriter.write( sWriter.toString() );
+                if ( getLog().isInfoEnabled() )
+                {
+                    getLog().info( "Effective-settings written to: " + output 
);
+                }
             }
             catch ( IOException e )
             {
@@ -110,7 +113,10 @@
                     }
                     catch ( IOException e )
                     {
-                        getLog().debug( "Cannot close FileWriter to output 
location: " + output, e );
+                        if ( getLog().isDebugEnabled() )
+                        {
+                            getLog().debug( "Cannot close FileWriter to output 
location: " + output, e );
+                        }
                     }
                 }
             }
@@ -136,5 +142,4 @@
     {
         this.settings = settings;
     }
-
 }


Reply via email to