You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2009/07/05 13:36:50 UTC
svn commit: r791226 - in /maven/plugins/trunk/maven-javadoc-plugin: ./
src/main/java/org/apache/maven/plugin/javadoc/ src/site/apt/examples/
src/test/java/org/apache/maven/plugin/javadoc/
src/test/resources/unit/fix-test/
Author: vsiveton
Date: Sun Jul 5 11:36:50 2009
New Revision: 791226
URL: http://svn.apache.org/viewvc?rev=791226&view=rev
Log:
o replaced the clirr-maven-plugin dependency by the maven invoker
o updated log
o updated doc and test
Modified:
maven/plugins/trunk/maven-javadoc-plugin/pom.xml
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/FixJavadocMojo.java
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/TestFixJavadocMojo.java
maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/pom.xml
Modified: maven/plugins/trunk/maven-javadoc-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/pom.xml?rev=791226&r1=791225&r2=791226&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/pom.xml Sun Jul 5 11:36:50 2009
@@ -107,6 +107,11 @@
<artifactId>maven-archiver</artifactId>
<version>2.3</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-invoker</artifactId>
+ <version>2.0.9</version>
+ </dependency>
<!-- Doxia -->
<dependency>
@@ -140,28 +145,6 @@
<artifactId>qdox</artifactId>
<version>1.9.1</version>
</dependency>
- <dependency>
- <groupId>net.sf.clirr</groupId>
- <artifactId>clirr-core</artifactId>
- <version>0.6</version>
- <exclusions>
- <exclusion>
- <groupId>bcel</groupId>
- <artifactId>bcel</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.bcel</groupId>
- <artifactId>bcel</artifactId>
- <version>5.2</version>
- </dependency>
- <!-- to use clirr in the fix goal without reinventing the wheel-->
- <dependency>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>clirr-maven-plugin</artifactId>
- <version>2.2.2</version>
- </dependency>
<!-- Plexus -->
<dependency>
@@ -214,12 +197,6 @@
<version>1.2</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-invoker</artifactId>
- <version>2.0.10</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java?rev=791226&r1=791225&r2=791226&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java Sun Jul 5 11:36:50 2009
@@ -23,6 +23,8 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
@@ -35,44 +37,40 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Properties;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import net.sf.clirr.core.ApiDifference;
-import net.sf.clirr.core.MessageTranslator;
-
import org.apache.commons.lang.ClassUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.settings.Settings;
-import org.codehaus.mojo.clirr.AbstractClirrMojo;
-import org.codehaus.mojo.clirr.ArtifactSpecification;
-import org.codehaus.mojo.clirr.ClirrDiffListener;
+import org.apache.maven.shared.invoker.DefaultInvocationRequest;
+import org.apache.maven.shared.invoker.DefaultInvoker;
+import org.apache.maven.shared.invoker.InvocationOutputHandler;
+import org.apache.maven.shared.invoker.InvocationRequest;
+import org.apache.maven.shared.invoker.InvocationResult;
+import org.apache.maven.shared.invoker.Invoker;
+import org.apache.maven.shared.invoker.MavenInvocationException;
+import org.apache.maven.shared.invoker.PrintStreamHandler;
import org.codehaus.plexus.components.interactivity.InputHandler;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.ReflectionUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.AbstractInheritableJavaEntity;
@@ -158,30 +156,21 @@
/** <code>private</code> parameter used by {@link #level} **/
private static final String LEVEL_PRIVATE = "private";
- // ----------------------------------------------------------------------
- // Mojo components
- // ----------------------------------------------------------------------
+ /** The Clirr Maven plugin groupId <code>org.codehaus.mojo</code> **/
+ private static final String CLIRR_MAVEN_PLUGIN_GROUPID = "org.codehaus.mojo";
- /**
- * Used by {@link ClirrMojoWrapper} class.
- *
- * @component
- */
- private ArtifactFactory artifactFactory;
+ /** The Clirr Maven plugin artifactId <code>clirr-maven-plugin</code> **/
+ private static final String CLIRR_MAVEN_PLUGIN_ARTIFACTID = "clirr-maven-plugin";
- /**
- * Used by {@link ClirrMojoWrapper} class.
- *
- * @component
- */
- private ArtifactMetadataSource artifactMetadataSource;
+ /** The latest Clirr Maven plugin version <code>2.2.2</code> **/
+ private static final String CLIRR_MAVEN_PLUGIN_VERSION = "2.2.2";
- /**
- * Used by {@link ClirrMojoWrapper} class.
- *
- * @component
- */
- private ArtifactResolver artifactResolver;
+ /** The Clirr Maven plugin goal <code>check</code> **/
+ private static final String CLIRR_MAVEN_PLUGIN_GOAL = "check";
+
+ // ----------------------------------------------------------------------
+ // Mojo components
+ // ----------------------------------------------------------------------
/**
* Input handler, needed for command line handling.
@@ -190,29 +179,13 @@
*/
private InputHandler inputHandler;
- /**
- * Used by {@link ClirrMojoWrapper} class.
- *
- * @parameter default-value="${localRepository}"
- * @required
- * @readonly
- */
- private ArtifactRepository localRepository;
-
- /**
- * Used by {@link ClirrMojoWrapper} class.
- *
- * @component
- */
- private MavenProjectBuilder mavenProjectBuilder;
-
// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------
/**
- * Version to compare the current code against.
- * Used by {@link ClirrMojoWrapper} class.
+ * Version to compare the current code against using the
+ * <a href="http://mojo.codehaus.org/clirr-maven-plugin/">Clirr Maven Plugin</a>.
* <br/>
* See <a href="#defaultSince">defaultSince</a>.
*
@@ -391,10 +364,7 @@
{
if ( !fixClassComment && !fixFieldComment && !fixMethodComment )
{
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "Specified to NOT fix classes, fields and methods. Nothing to do." );
- }
+ getLog().info( "Specified to NOT fix classes, fields and methods. Nothing to do." );
return;
}
@@ -403,10 +373,7 @@
if ( fixTagsSplitted.length == 0 )
{
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "No fix tag specified. Nothing to do." );
- }
+ getLog().info( "No fix tag specified. Nothing to do." );
return;
}
@@ -445,11 +412,6 @@
// ----------------------------------------------------------------------
/**
- * @return the current classes directory.
- */
- protected abstract File getClassesDirectory();
-
- /**
* @return the artifact type.
*/
protected String getArtifactType( MavenProject p )
@@ -573,10 +535,7 @@
}
else
{
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "Unrecognized '" + s + "' for fixTags parameter. Ignored it!" );
- }
+ getLog().warn( "Unrecognized '" + s + "' for fixTags parameter. Ignored it!" );
}
}
fixTags = StringUtils.join( filtered.iterator(), "," );
@@ -586,12 +545,9 @@
// encoding
if ( StringUtils.isEmpty( encoding ) )
{
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn(
- "File encoding has not been set, using platform encoding "
- + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!" );
- }
+ getLog().warn(
+ "File encoding has not been set, using platform encoding "
+ + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!" );
encoding = ReaderFactory.FILE_ENCODING;
}
@@ -599,11 +555,8 @@
if ( !( LEVEL_PUBLIC.equalsIgnoreCase( level.trim() ) || LEVEL_PROTECTED.equalsIgnoreCase( level.trim() )
|| LEVEL_PACKAGE.equalsIgnoreCase( level.trim() ) || LEVEL_PRIVATE.equalsIgnoreCase( level.trim() ) ) )
{
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "Unrecognized '" + level + "' for level parameter, using 'protected' level." );
- level = "protected";
- }
+ getLog().warn( "Unrecognized '" + level + "' for level parameter, using 'protected' level." );
+ level = "protected";
}
}
@@ -619,41 +572,33 @@
return true;
}
- if ( outputDirectory != null && !outputDirectory.getAbsolutePath().equals( getProjectSourceDirectory().getAbsolutePath() ) )
+ if ( outputDirectory != null
+ && !outputDirectory.getAbsolutePath().equals( getProjectSourceDirectory().getAbsolutePath() ) )
{
return true;
}
if ( !settings.isInteractiveMode() )
{
- if ( getLog().isErrorEnabled() )
- {
- getLog().error(
- "Maven is not attempt to interact with the user for input. "
- + "Verify the <interactiveMode/> configuration in your settings." );
- }
+ getLog().error(
+ "Maven is not attempt to interact with the user for input. "
+ + "Verify the <interactiveMode/> configuration in your settings." );
return false;
}
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "" );
- getLog().warn( " WARRANTY DISCLAIMER" );
- getLog().warn( "" );
- getLog().warn( "All warranties with regard to this Maven goal are disclaimed!" );
- getLog().warn( "The changes will be done directly in the source code." );
- getLog().warn(
- "The Maven Team strongly recommends the use of a SCM software BEFORE executing this "
- + "goal." );
- getLog().warn( "" );
- }
+ getLog().warn( "" );
+ getLog().warn( " WARRANTY DISCLAIMER" );
+ getLog().warn( "" );
+ getLog().warn( "All warranties with regard to this Maven goal are disclaimed!" );
+ getLog().warn( "The changes will be done directly in the source code." );
+ getLog().warn(
+ "The Maven Team strongly recommends the use of a SCM software BEFORE executing this "
+ + "goal." );
+ getLog().warn( "" );
while ( true )
{
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "Are you sure to proceed? [Y]es [N]o" );
- }
+ getLog().info( "Are you sure to proceed? [Y]es [N]o" );
try
{
@@ -661,19 +606,13 @@
if ( userExpression == null || userExpression.toLowerCase( Locale.ENGLISH ).equalsIgnoreCase( "Y" )
|| userExpression.toLowerCase( Locale.ENGLISH ).equalsIgnoreCase( "Yes" ) )
{
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "OK, let's proceed..." );
- }
+ getLog().info( "OK, let's proceed..." );
break;
}
if ( userExpression == null || userExpression.toLowerCase( Locale.ENGLISH ).equalsIgnoreCase( "N" )
|| userExpression.toLowerCase( Locale.ENGLISH ).equalsIgnoreCase( "No" ) )
{
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "No changes in your sources occur." );
- }
+ getLog().info( "No changes in your sources occur." );
return false;
}
}
@@ -687,152 +626,258 @@
}
/**
- * Calling Clirr to find API differences via clirr-maven-plugin.
- *
- * @throws MojoExecutionException if any
+ * Invoke Maven to run clirr-maven-plugin to find API differences.
*/
private void executeClirr()
- throws MojoExecutionException
{
if ( ignoreClirr )
{
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "Clirr is ignored." );
- }
+ getLog().info( "Clirr is ignored." );
return;
}
- ClirrMojoWrapper wrapper = null;
- try
+ String mavenHome = getMavenHome();
+ if ( StringUtils.isEmpty( getMavenHome() ) )
{
- wrapper =
- new ClirrMojoWrapper( getClassesDirectory(), comparisonVersion, getArtifactType( project ),
- artifactFactory, localRepository, mavenProjectBuilder,
- artifactMetadataSource, project, artifactResolver, includes, excludes );
+ getLog().info( "Cannot invoke Maven because no Maven home is defined, Clirr is ignored." );
+ return;
+ }
+
+ Invoker invoker = new DefaultInvoker();
+ invoker.setMavenHome( new File( mavenHome ) );
- wrapper.execute();
+ InvocationRequest request = new DefaultInvocationRequest();
+ request.setBaseDirectory( project.getBasedir() );
+ request.setPomFile( project.getFile() );
+
+ File invokerLogFile = new File( project.getBuild().getDirectory(), "invoker-clirr-maven-plugin.txt" );
+ PrintStream ps;
+ try
+ {
+ ps = new PrintStream( invokerLogFile );
}
- catch ( MojoExecutionException e )
+ catch ( FileNotFoundException e )
{
- if ( e.getCause().getClass().isAssignableFrom( ArtifactNotFoundException.class ) )
- {
- getLog().warn( "Clirr is ignored because no previous artifact has been deployed." );
- }
- else
- {
- if ( getLog().isDebugEnabled() )
- {
- getLog().error( "Error when executing Clirr: " + e.getMessage(), e );
- }
- else
- {
- getLog().error( "Error when executing Clirr: " + e.getMessage() );
- }
- getLog().error( "Clirr is ignored due to the error above." );
- }
- return;
+ getLog().error( "FileNotFoundException: " + e.getMessage() + ". Using System.out to log the invoker." );
+ ps = System.out;
+ }
+
+ InvocationOutputHandler outputHandler = new PrintStreamHandler( ps, false );
+ request.setOutputHandler( outputHandler );
+ request.setDebug( true );
+ String clirrGoal = getFullClirrGoal();
+ request.setGoals( Collections.singletonList( clirrGoal ) );
+
+ // http://mojo.codehaus.org/clirr-maven-plugin/check-mojo.html
+ File clirrTextOutputFile = new File( project.getBuild().getDirectory(), "clirr.txt" );
+ Properties prop = new Properties();
+ prop.put( "textOutputFile", clirrTextOutputFile.getAbsolutePath() );
+ prop.put( "comparisonVersion", comparisonVersion );
+ prop.put( "failOnError", "false" );
+ request.setProperties( prop );
+
+ InvocationResult result;
+ try
+ {
+ getLog().debug( "Invoking Maven for the goal: " + clirrGoal );
+ result = invoker.execute( request );
}
- catch ( MojoFailureException e )
+ catch ( MavenInvocationException e )
{
if ( getLog().isDebugEnabled() )
{
- getLog().error( "Error when executing Clirr: " + e.getMessage(), e );
+ getLog().error( "MavenInvocationException: " + e.getMessage(), e );
}
else
{
- getLog().error( "Error when executing Clirr: " + e.getMessage() );
+ getLog().error( "MavenInvocationException: " + e.getMessage() );
}
- getLog().error( "Clirr is ignored due to the error above." );
+ getLog().error( "Error when invoking Maven, consult the invoker log. Clirr is ignored." );
return;
}
- catch ( Exception e )
+
+ if ( result.getExitCode() != 0 )
{
- getLog().error( "Error when executing Clirr: " + e.getMessage() );
+ getLog().error( "Error when invoking Maven, consult the invoker log. Clirr is ignored." );
return;
}
- clirrNewClasses = wrapper.getNewClasses();
- clirrNewMethods = wrapper.getNewMethods();
+ try
+ {
+ if ( invokerLogFile.exists() )
+ {
+ String invokerLogContent = readFile( invokerLogFile, "UTF-8" );
+ // see org.codehaus.mojo.clirr.AbstractClirrMojo#getComparisonArtifact()
+ final String artifactNotFoundMsg =
+ "Unable to find a previous version of the project in the repository";
+ if ( invokerLogContent.indexOf( artifactNotFoundMsg ) != -1 )
+ {
+ getLog().warn( "No previous artifact has been deployed, Clirr is ignored." );
+ return;
+ }
+ }
+ }
+ catch ( IOException e )
+ {
+ getLog().debug( "IOException: " + e.getMessage() );
+ }
- if ( getLog().isInfoEnabled() )
+ try
{
- if ( clirrNewClasses.isEmpty() && clirrNewMethods.isEmpty() )
+ parseClirrTextOutputFile( clirrTextOutputFile );
+ }
+ catch ( IOException e )
+ {
+ if ( getLog().isDebugEnabled() )
{
- getLog().info( "Clirr NOT found API differences." );
+ getLog().debug( "IOException: " + e.getMessage(), e );
}
- else
+ getLog().info(
+ "IOException when parsing Clirr output '" + clirrTextOutputFile.getAbsolutePath()
+ + "', Clirr is ignored." );
+ }
+ }
+
+ /**
+ * @return the full clirr goal, i.e. <code>groupId:artifactId:version:goal</code>. The clirr-plugin version
+ * could be load from the pom.properties in the clirr-maven-plugin dependency.
+ */
+ private String getFullClirrGoal()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( CLIRR_MAVEN_PLUGIN_GROUPID ).append( ":" );
+ sb.append( CLIRR_MAVEN_PLUGIN_ARTIFACTID ).append( ":" );
+ String clirrVersion = CLIRR_MAVEN_PLUGIN_VERSION;
+ InputStream resourceAsStream = null;
+ try
+ {
+ String resource =
+ "META-INF/maven/" + CLIRR_MAVEN_PLUGIN_GROUPID + "/" + CLIRR_MAVEN_PLUGIN_ARTIFACTID
+ + "/pom.properties";
+ resourceAsStream = AbstractFixJavadocMojo.class.getClassLoader().getResourceAsStream( resource );
+
+ if ( resourceAsStream != null )
{
- getLog().info( "Clirr found API differences, i.e. new classes/interfaces or methods." );
- try
+ Properties properties = new Properties();
+ properties.load( resourceAsStream );
+
+ if ( StringUtils.isNotEmpty( properties.getProperty( "version" ) ) )
{
- writeClirr();
- }
- catch ( IOException e )
- {
- if ( getLog().isDebugEnabled() )
- {
- getLog().error( "IOException: " + e.getMessage(), e );
- }
- else
- {
- getLog().error( "IOException: " + e.getMessage() );
- }
+ clirrVersion = properties.getProperty( "version" );
}
}
}
+ catch ( IOException e )
+ {
+ // nop
+ }
+ finally
+ {
+ IOUtil.close( resourceAsStream );
+ }
+ sb.append( clirrVersion ).append( ":" );
+ sb.append( CLIRR_MAVEN_PLUGIN_GOAL );
+
+ return sb.toString();
}
/**
- * In debug mode, write {@link #clirrNewClasses} and {@link #clirrNewMethods} in the file
- * <code>project.getBuild().getDirectory()/clirr.diff</code>.
- * @throws IOException
+ * @param clirrTextOutputFile not null
+ * @throws IOException if any
*/
- private void writeClirr()
+ private void parseClirrTextOutputFile( File clirrTextOutputFile )
throws IOException
{
- if ( !getLog().isDebugEnabled() )
+ if ( !clirrTextOutputFile.exists() )
{
+ getLog().info(
+ "No Clirr output file '" + clirrTextOutputFile.getAbsolutePath()
+ + "' exists, Clirr is ignored." );
return;
}
- StringBuffer sb = new StringBuffer();
+ getLog().info( "Clirr output file was created: " + clirrTextOutputFile.getAbsolutePath() );
- for ( Iterator it = clirrNewClasses.iterator(); it.hasNext(); )
- {
- String newClass = (String) it.next();
+ clirrNewClasses = new LinkedList();
+ clirrNewMethods = new LinkedHashMap();
- sb.append( "Added Class " );
- sb.append( "'" ).append( newClass ).append( "'" );
- sb.append( EOL );
- }
-
- for ( Iterator it = clirrNewMethods.entrySet().iterator(); it.hasNext(); )
+ BufferedReader input = new BufferedReader( ReaderFactory.newReader( clirrTextOutputFile, "UTF-8" ) );
+ String line = null;
+ while ( ( line = input.readLine() ) != null )
{
- Map.Entry entry = (Map.Entry) it.next();
+ String[] split = StringUtils.split( line, ":" );
+ if ( split.length != 4 )
+ {
+ getLog().debug( "Unable to parse the clirr line: " + line );
+ continue;
+ }
- sb.append( "In the Class " );
- sb.append( "'" ).append( entry.getKey() ).append( "'" );
- sb.append( EOL );
+ int code;
+ try
+ {
+ code = Integer.parseInt( split[1].trim() );
+ }
+ catch ( NumberFormatException e )
+ {
+ getLog().debug( "Unable to parse the clirr line: " + line );
+ continue;
+ }
- for ( Iterator it2 = ( (List) entry.getValue() ).iterator(); it2.hasNext(); )
+ // http://clirr.sourceforge.net/clirr-core/exegesis.html
+ // 7011 - Method Added
+ // 7012 - Method Added to Interface
+ // 8000 - Class Added
+ List list;
+ String[] splits2;
+ switch ( code )
{
- String newMethod = (String) it2.next();
+ case 7011:
+ list = (List) clirrNewMethods.get( split[2] );
+ if ( list == null )
+ {
+ list = new ArrayList();
+ }
+ splits2 = StringUtils.split( split[3], "'" );
+ if ( splits2.length != 3 )
+ {
+ continue;
+ }
+ list.add( splits2[1] );
+ clirrNewMethods.put( split[2], list );
+ break;
- sb.append( "\tAdded Method " );
- sb.append( "'" ).append( newMethod ).append( "'" );
- if ( it2.hasNext() )
- {
- sb.append( EOL );
- }
+ case 7012:
+ list = (List) clirrNewMethods.get( split[2] );
+ if ( list == null )
+ {
+ list = new ArrayList();
+ }
+ splits2 = StringUtils.split( split[3], "'" );
+ if ( splits2.length != 3 )
+ {
+ continue;
+ }
+ list.add( splits2[1] );
+ clirrNewMethods.put( split[2], list );
+ break;
+
+ case 8000:
+ clirrNewClasses.add( split[2] );
+ break;
+ default:
+ break;
}
- sb.append( EOL );
}
- File f = new File( project.getBuild().getDirectory(), "clirr.diff" );
- writeFile( f, WriterFactory.UTF_8, sb.toString() );
-
- getLog().debug( "Writing Clirr difference to: " + f.getAbsolutePath() );
+ if ( clirrNewClasses.isEmpty() && clirrNewMethods.isEmpty() )
+ {
+ getLog().info( "Clirr NOT found API differences." );
+ }
+ else
+ {
+ getLog().info( "Clirr found API differences, i.e. new classes/interfaces or methods." );
+ }
}
/**
@@ -871,10 +916,7 @@
{
if ( "pom".equals( project.getPackaging().toLowerCase() ) )
{
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "This project has 'pom' packaging, no Java sources will be available." );
- }
+ getLog().warn( "This project has 'pom' packaging, no Java sources will be available." );
return null;
}
@@ -888,10 +930,7 @@
}
else
{
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( f + " doesn't exist. Ignored it." );
- }
+ getLog().warn( f + " doesn't exist. Ignored it." );
}
}
@@ -915,10 +954,7 @@
catch ( ParseException e )
{
// QDOX-118
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "QDOX ParseException: " + e.getMessage() );
- }
+ getLog().warn( "QDOX ParseException: " + e.getMessage() );
}
}
@@ -941,19 +977,11 @@
return;
}
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "Reading '" + javaClass.getFullyQualifiedName() + "' class." );
- }
-
File javaFile = new File( javaClass.getSource().getURL().getFile() );
// the original java content in memory
final String originalContent = readFile( javaFile, encoding );
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "Fixing " + javaClass.getFullyQualifiedName() );
- }
+ getLog().debug( "Fixing " + javaClass.getFullyQualifiedName() );
final StringWriter stringWriter = new StringWriter();
BufferedReader reader = null;
@@ -1028,12 +1056,10 @@
IOUtil.close( reader );
}
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "Saving " + javaClass.getFullyQualifiedName() );
- }
+ getLog().debug( "Saving " + javaClass.getFullyQualifiedName() );
- if ( outputDirectory != null && !outputDirectory.getAbsolutePath().equals( getProjectSourceDirectory().getAbsolutePath() ) )
+ if ( outputDirectory != null
+ && !outputDirectory.getAbsolutePath().equals( getProjectSourceDirectory().getAbsolutePath() ) )
{
String path =
StringUtils.replace( javaFile.getAbsolutePath().replaceAll( "\\\\", "/" ),
@@ -2830,6 +2856,28 @@
}
/**
+ * @return the maven home defined in the "maven.home" system property or defined in M2_HOME system env variables
+ * or null if never setted.
+ */
+ private static String getMavenHome()
+ {
+ String mavenHome = System.getProperty( "maven.home" );
+ if ( mavenHome == null )
+ {
+ try
+ {
+ mavenHome = CommandLineUtils.getSystemEnvVars().getProperty( "M2_HOME" );
+ }
+ catch ( IOException e )
+ {
+ // nop
+ }
+ }
+
+ return mavenHome;
+ }
+
+ /**
* @param javaFile not null
* @param encoding not null
* @param content not null
@@ -3202,14 +3250,7 @@
line = reader.readLine();
}
- try
- {
- return (String[]) lines.toArray( new String[0] );
- }
- finally
- {
- IOUtil.close( reader );
- }
+ return (String[]) lines.toArray( new String[0] );
}
/**
@@ -3257,129 +3298,6 @@
}
/**
- * Wrapper implementation of the {@link AbstractClirrMojo}.
- */
- private static class ClirrMojoWrapper
- extends AbstractClirrMojo
- {
- private List clirrNewClasses;
-
- private Map clirrNewMethods;
-
- public ClirrMojoWrapper( File classesDirectory, String comparisonVersion, String artifactType,
- ArtifactFactory factory, ArtifactRepository localRepository,
- MavenProjectBuilder mavenProjectBuilder, ArtifactMetadataSource metadataSource,
- MavenProject project, ArtifactResolver resolver, String includes, String excludes )
- throws MojoFailureException
- {
- super();
-
- try
- {
- super.classesDirectory = classesDirectory;
- ArtifactSpecification artifactSpec = new ArtifactSpecification();
- artifactSpec.setGroupId( project.getGroupId() );
- artifactSpec.setArtifactId( project.getArtifactId() );
- artifactSpec.setVersion( comparisonVersion );
- artifactSpec.setType( artifactType );
- artifactSpec.setClassifier( null );
- super.comparisonArtifacts = new ArtifactSpecification[] { artifactSpec };
- super.factory = factory;
- super.localRepository = localRepository;
- ReflectionUtils.setVariableValueInObject( this, "mavenProjectBuilder", mavenProjectBuilder );
- ReflectionUtils.setVariableValueInObject( this, "metadataSource", metadataSource );
- super.project = project;
- super.resolver = resolver;
- // TODO align includes/excludes with org.codehaus.mojo.clirr.ClirrClassFilter
- if ( includes != null )
- {
- super.includes = StringUtils.split( "**", "," );
- }
- if ( excludes != null )
- {
- super.excludes = null;
- }
- }
- catch ( IllegalArgumentException e )
- {
- throw new MojoFailureException( "IllegalArgumentException: " + e.getMessage() );
- }
- catch ( SecurityException e )
- {
- throw new MojoFailureException( "SecurityException: " + e.getMessage() );
- }
- catch ( IllegalAccessException e )
- {
- throw new MojoFailureException( "IllegalAccessException: " + e.getMessage() );
- }
- }
-
- /** {@inheritDoc} */
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- ClirrDiffListener clirrDiffListener = executeClirr();
-
- clirrNewClasses = new ArrayList();
- clirrNewMethods = new HashMap();
-
- MessageTranslator translator = new MessageTranslator();
- translator.setLocale( Locale.ENGLISH );
-
- for ( Iterator it = clirrDiffListener.getApiDifferences().iterator(); it.hasNext(); )
- {
- ApiDifference diff = (ApiDifference) it.next();
- String msg = diff.getReport( translator );
-
- // Align to Clirr messages
- if ( msg.startsWith( "Class" ) && msg.endsWith( "added" ) )
- {
- clirrNewClasses.add( diff.getAffectedClass() );
- }
-
- if ( msg.startsWith( "Method" ) && msg.endsWith( "added" ) )
- {
- List list = (List) clirrNewMethods.get( diff.getAffectedClass() );
- if ( list == null )
- {
- list = new ArrayList();
- }
- list.add( diff.getAffectedMethod() );
- clirrNewMethods.put( diff.getAffectedClass(), list );
- }
-
- if ( msg.startsWith( "Method" ) && msg.endsWith( "added to an interface" ) )
- {
- List list = (List) clirrNewMethods.get( diff.getAffectedClass() );
- if ( list == null )
- {
- list = new ArrayList();
- }
- list.add( diff.getAffectedMethod() );
- clirrNewMethods.put( diff.getAffectedClass(), list );
- }
- }
- }
-
- /**
- * @return a list of added classes.
- */
- public List getNewClasses()
- {
- return clirrNewClasses;
- }
-
- /**
- * @return a map with the String of affected class (as key) and a list of the String of added methods
- * (as value).
- */
- public Map getNewMethods()
- {
- return clirrNewMethods;
- }
- }
-
- /**
* Wrapper class for the entity's tags.
*/
private class JavaEntityTags
Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/FixJavadocMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/FixJavadocMojo.java?rev=791226&r1=791225&r2=791226&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/FixJavadocMojo.java (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/FixJavadocMojo.java Sun Jul 5 11:36:50 2009
@@ -19,8 +19,6 @@
* under the License.
*/
-import java.io.File;
-
/**
* Fix Javadoc documentation and tags for the <code>Java code</code> for the project.
* See <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html#wheretags">Where Tags Can Be Used</a>.
@@ -35,17 +33,5 @@
public class FixJavadocMojo
extends AbstractFixJavadocMojo
{
- /**
- * The classes of this project to compare the last release against.
- * Used by {@link AbstractFixJavadocMojo.ClirrMojoWrapper} class.
- *
- * @parameter default-value="${project.build.outputDirectory}
- */
- private File classesDirectory;
-
- /** {@inheritDoc} */
- protected File getClassesDirectory()
- {
- return classesDirectory;
- }
+ // nop
}
Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/TestFixJavadocMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/TestFixJavadocMojo.java?rev=791226&r1=791225&r2=791226&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/TestFixJavadocMojo.java (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/TestFixJavadocMojo.java Sun Jul 5 11:36:50 2009
@@ -19,8 +19,6 @@
* under the License.
*/
-import java.io.File;
-import java.util.Collections;
import java.util.List;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -42,20 +40,6 @@
public class TestFixJavadocMojo
extends AbstractFixJavadocMojo
{
- /**
- * The classes of this project to compare the last release against.
- * Used by {@link AbstractFixJavadocMojo.ClirrMojoWrapper} class.
- *
- * @parameter default-value="${project.build.testOutputDirectory}
- */
- private File classesDirectory;
-
- /** {@inheritDoc} */
- protected File getClassesDirectory()
- {
- return classesDirectory;
- }
-
/** {@inheritDoc} */
protected List getProjectSourceRoots( MavenProject p )
{
Modified: maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt?rev=791226&r1=791225&r2=791226&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt Sun Jul 5 11:36:50 2009
@@ -3,7 +3,7 @@
------
Vincent Siveton
------
- 2009-02-22
+ 2009-07-05
------
~~ Licensed to the Apache Software Foundation (ASF) under one
@@ -29,13 +29,14 @@
Fixing Javadoc Comments
When developers write code, they could forget to create (or update) the Javadoc comments. The <fix> and <test-fix>
- goals are interactive goals to fix the actual Javadoc comments.
+ goals are interactive goals (i.e. used generally in command line) to fix the actual Javadoc comments in your classes.
You need to call <mvn javadoc:fix> to fix main Java source files (i.e. inside src/main/java directory) or
<mvn javadoc:test-fix> to fix test Java source files (i.e. inside src/test/java directory).
<<Important Note>>: Since the changes are done <<directly>> in the source code, we recommend <<strongly>> the use of
- a SCM, so you could always do a revert if a problem occurs.
+ a SCM, so you could always do a revert if a problem occurs. You could always add <<<-DoutputDirectory=/path/to/dir>>>
+ to specify a target directory where classes will be generated.
* Feature Summary
@@ -48,9 +49,10 @@
selective tags like author, version...
Also, the user could specify default value for some tags, i.e. {{{../fix-mojo.html#defaultAuthor}defaultAuthor}}.
- The <javadoc:fix> goal could use {{{http://clirr.sourceforge.net/}Clirr}}, a tool that checks Java libraries for
+ The <javadoc:fix> goal could use {{{http://clirr.sourceforge.net/}Clirr}} via the
+ {{{http://mojo.codehaus.org/clirr-maven-plugin/}clirr-maven-plugin}}, a tool that checks Java libraries for
binary and source compatibility with older releases. So, the <@since> tags will be dynamically added for the current
- project version. You need to add the <comparisonVersion> parameter.
+ project version. You need to add the <comparisonVersion> parameter (see below).
Finally, the user could process specific Java files using the
{{{../fix-mojo.html#includes}includes}}/{{{../fix-mojo.html#excludes}excludes}} parameters.
@@ -58,7 +60,7 @@
* Example Call
+-----+
-mvn org.apache.maven.plugins:maven-javadoc-plugin:2.6:fix -DcomparisonVersion=1.0
+mvn javadoc:fix -DcomparisonVersion=1.0
...
[INFO] [javadoc:fix]
[WARNING]
@@ -71,8 +73,8 @@
[INFO] Are you sure to proceed? [Y]es [N]o
y
[INFO] OK, let's proceed...
-[debug] Comparing to <groupId>:<artifactId>:1.0:null:jar
-[INFO] Clirr found Api differences.
+[INFO] Clirr output file was created: target/clirr.txt
+[INFO] Clirr found API differences, i.e. new classes/interfaces or methods.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
@@ -80,3 +82,48 @@
+-----+
You could review the changes and commit.
+
+* Using Clirr Integration
+
+ <<Note>>: the artifact should be deploy firstly.
+
+** Comparing against a specific version
+
+ By default, the goals compare the current code against the latest released version, which is lower than the current
+ version.
+
++-----+
+mvn javadoc:fix -DcomparisonVersion=1.0
+...
+[INFO] Clirr output file was created: target/clirr.txt
+[INFO] Clirr found API differences, i.e. new classes/interfaces or methods.
+...
++-----+
+
+** Using another Clirr version
+
+ By default, the <fix> and <test-fix> goals use the {{{http://mojo.codehaus.org/clirr-maven-plugin/}clirr-maven-plugin}}, version <<<2.2.2>>>.
+ To use another version, you need to add a dependency in the Javadoc plugin, similar to the following:
+
++-----+
+<project>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ ...
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>clirr-maven-plugin</artifactId>
+ <version>2.3-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ ...
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Modified: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java?rev=791226&r1=791225&r2=791226&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java Sun Jul 5 11:36:50 2009
@@ -39,7 +39,6 @@
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineUtils;
/**
@@ -80,23 +79,12 @@
M2_HOME = new File( mavenHome );
}
- private File testPomBasedir;
-
/** {@inheritDoc} */
protected void setUp()
throws Exception
{
// required for mojo lookups to work
super.setUp();
-
- testPomBasedir = new File( getBasedir(), "target/test/unit/fix-test/" );
-
- // Using unit test dir
- if ( !testPomBasedir.exists() )
- {
- FileUtils.copyDirectoryStructure( new File( getBasedir(), "src/test/resources/unit/fix-test/" ),
- testPomBasedir );
- }
}
/** {@inheritDoc} */
@@ -112,6 +100,10 @@
public void testFix()
throws Exception
{
+ File testPomBasedir = new File( getBasedir(), "target/test/unit/fix-test" );
+
+ prepareTestProjects( testPomBasedir.getName() );
+
File testPom = new File( testPomBasedir, "pom.xml" );
assertTrue( testPom.getAbsolutePath() + " should exist", testPom.exists() );
@@ -269,8 +261,8 @@
request.setBaseDirectory( testPom.getParentFile() );
request.setPomFile( testPom );
- ByteArrayOutputStream outLog = new ByteArrayOutputStream();
- InvocationOutputHandler outputHandler = new PrintStreamHandler( new PrintStream( outLog ), false );
+ ByteArrayOutputStream invokerLog = new ByteArrayOutputStream();
+ InvocationOutputHandler outputHandler = new PrintStreamHandler( new PrintStream( invokerLog ), false );
request.setOutputHandler( outputHandler );
request.setDebug( true );
@@ -283,27 +275,50 @@
try
{
InvocationResult result = invoker.execute( request );
- assertEquals( 0, result.getExitCode() );
+ if ( result.getExitCode() != 0 )
+ {
+ if ( getContainer().getLogger().isDebugEnabled() )
+ {
+ StringBuffer msg = new StringBuffer();
+ msg.append( "Ouput from invoker:" ).append( "\n\n" );
+ msg.append( invokerLog ).append( "\n\n" );
+
+ getContainer().getLogger().debug( msg.toString() );
+ }
+
+ fail( "Error when invoking Maven, see invoker log above" );
+ }
}
catch ( MavenInvocationException e )
{
- getContainer().getLogger().error( "Error when invoking Maven: " + e.getMessage(), e );
if ( getContainer().getLogger().isDebugEnabled() )
{
StringBuffer msg = new StringBuffer();
- msg.append( "Ouput from invoker:" ).append( "\n" );
- msg.append( StringUtils.repeat( "-", 78 ) ).append( "\n" );
- msg.append( outLog ).append( "\n" );
- msg.append( StringUtils.repeat( "-", 78 ) ).append( "\n" );
+ msg.append( "Ouput from invoker:" ).append( "\n\n" );
+ msg.append( invokerLog ).append( "\n\n" );
getContainer().getLogger().debug( msg.toString() );
}
- fail( "Error when invoking Maven: " + e.getMessage() );
+ fail( "Error when invoking Maven, see invoker log above" );
}
}
/**
+ * @param testDir not null
+ * @throws IOException if any
+ */
+ private static void prepareTestProjects( String testDir )
+ throws IOException
+ {
+ File testPomBasedir = new File( getBasedir(), "target/test/unit/" + testDir );
+
+ // Using unit test dir
+ FileUtils.copyDirectoryStructure( new File( getBasedir(), "src/test/resources/unit/" + testDir ),
+ testPomBasedir );
+ }
+
+ /**
* @param file not null
* @return the content of the given file
* @throws IOException if any
Modified: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/pom.xml?rev=791226&r1=791225&r2=791226&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/pom.xml (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/pom.xml Sun Jul 5 11:36:50 2009
@@ -42,7 +42,6 @@
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<project implementation="org.apache.maven.plugin.javadoc.stubs.FixMavenProjectStub"/>
- <localRepository>${localRepository}</localRepository>
<outputDirectory>${basedir}/target/test/unit/fix-test/target/generated</outputDirectory>
<defaultSince>1.0-SNAPSHOT</defaultSince>
<encoding>UTF-8</encoding>