Author: dennisl Date: Thu Jan 3 10:05:31 2013 New Revision: 1428257 URL: http://svn.apache.org/viewvc?rev=1428257&view=rev Log: [MCHANGES-300] Make it possible to run the changes-check and changes-validate goals only once for a multi-module project
Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/AbstractChangesMojo.java - copied, changed from r1428189, maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesCheckMojo.java maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java?rev=1428257&r1=1428256&r2=1428257&view=diff ============================================================================== --- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java (original) +++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java Thu Jan 3 10:05:31 2013 @@ -19,9 +19,7 @@ package org.apache.maven.plugin.announce * under the License. */ -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugin.changes.AbstractChangesMojo; import org.apache.maven.plugins.annotations.Parameter; /** @@ -31,25 +29,9 @@ import org.apache.maven.plugins.annotati * @since 2.3 */ public abstract class AbstractAnnouncementMojo - extends AbstractMojo + extends AbstractChangesMojo { /** - * The current project base directory. - * - * @since 2.1 - */ - @Parameter( property = "basedir", required = true ) - protected String basedir; - - /** - * The Maven Session. - * - * @since 2.3 - */ - @Component - protected MavenSession mavenSession; - - /** * This will cause the execution to be run only at the top of a given module * tree. That is, run in the project contained in the same folder where the * mvn execution was launched. @@ -58,26 +40,4 @@ public abstract class AbstractAnnounceme */ @Parameter( property = "announcement.runOnlyAtExecutionRoot", defaultValue = "false" ) protected boolean runOnlyAtExecutionRoot; - - /** - * Returns <code>true</code> if the current project is located at the - * Execution Root Directory (where mvn was launched). - * - * @return <code>true</code> if the current project is at the Execution Root - */ - protected boolean isThisTheExecutionRoot() - { - getLog().debug( "Root Folder:" + mavenSession.getExecutionRootDirectory() ); - getLog().debug( "Current Folder:" + basedir ); - boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase( basedir.toString() ); - if ( result ) - { - getLog().debug( "This is the execution root." ); - } - else - { - getLog().debug( "This is NOT the execution root." ); - } - return result; - } } Copied: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/AbstractChangesMojo.java (from r1428189, maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java) URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/AbstractChangesMojo.java?p2=maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/AbstractChangesMojo.java&p1=maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java&r1=1428189&r2=1428257&rev=1428257&view=diff ============================================================================== --- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java (original) +++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/AbstractChangesMojo.java Thu Jan 3 10:05:31 2013 @@ -1,4 +1,4 @@ -package org.apache.maven.plugin.announcement; +package org.apache.maven.plugin.changes; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,8 +19,8 @@ package org.apache.maven.plugin.announce * under the License. */ -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; @@ -28,9 +28,9 @@ import org.apache.maven.plugins.annotati * Abstract superclass for announcement mojos. * * @version $Id$ - * @since 2.3 + * @since 2.9 */ -public abstract class AbstractAnnouncementMojo +public abstract class AbstractChangesMojo extends AbstractMojo { /** @@ -54,9 +54,9 @@ public abstract class AbstractAnnounceme * tree. That is, run in the project contained in the same folder where the * mvn execution was launched. * - * @since 2.3 + * @since 2.9 */ - @Parameter( property = "announcement.runOnlyAtExecutionRoot", defaultValue = "false" ) + @Parameter( property = "changes.runOnlyAtExecutionRoot", defaultValue = "false" ) protected boolean runOnlyAtExecutionRoot; /** Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesCheckMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesCheckMojo.java?rev=1428257&r1=1428256&r2=1428257&view=diff ============================================================================== --- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesCheckMojo.java (original) +++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesCheckMojo.java Thu Jan 3 10:05:31 2013 @@ -25,7 +25,6 @@ import java.text.SimpleDateFormat; import java.util.List; import org.apache.commons.lang.StringUtils; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -41,7 +40,7 @@ import org.apache.maven.plugins.changes. */ @Mojo( name = "changes-check", threadSafe = true ) public class ChangesCheckMojo - extends AbstractMojo + extends AbstractChangesMojo { /** * The format that a correct release date should have. This value will be @@ -80,27 +79,35 @@ public class ChangesCheckMojo public void execute() throws MojoExecutionException { - if ( this.version.endsWith( "-SNAPSHOT" ) && this.skipSnapshots ) + // Run only at the execution root + if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() ) { - getLog().info( "Skipping snapshot version '" + this.version + "'." ); + getLog().info( "Skipping the changes check in this project because it's not the Execution Root" ); } - else if ( xmlPath.exists() ) + else { - ChangesXML xml = new ChangesXML( xmlPath, getLog() ); - ReleaseUtils releaseUtils = new ReleaseUtils( getLog() ); - Release release = - releaseUtils.getLatestRelease( releaseUtils.convertReleaseList( xml.getReleaseList() ), version ); - - if ( !isValidDate( release.getDateRelease(), releaseDateFormat ) ) + if ( this.version.endsWith( "-SNAPSHOT" ) && this.skipSnapshots ) { - throw new MojoExecutionException( - "The file " + xmlPath.getAbsolutePath() + " has an invalid release date." ); + getLog().info( "Skipping snapshot version '" + this.version + "'." ); + } + else if ( xmlPath.exists() ) + { + ChangesXML xml = new ChangesXML( xmlPath, getLog() ); + ReleaseUtils releaseUtils = new ReleaseUtils( getLog() ); + Release release = + releaseUtils.getLatestRelease( releaseUtils.convertReleaseList( xml.getReleaseList() ), version ); + + if ( !isValidDate( release.getDateRelease(), releaseDateFormat ) ) + { + throw new MojoExecutionException( + "The file " + xmlPath.getAbsolutePath() + " has an invalid release date." ); + } + } + else + { + getLog().warn( "The file " + xmlPath.getAbsolutePath() + " does not exist." ); } - } - else - { - getLog().warn( "The file " + xmlPath.getAbsolutePath() + " does not exist." ); } } Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java?rev=1428257&r1=1428256&r2=1428257&view=diff ============================================================================== --- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java (original) +++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java Thu Jan 3 10:05:31 2013 @@ -22,7 +22,6 @@ package org.apache.maven.plugin.changes; import java.io.File; import java.util.List; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.changes.schema.ChangesSchemaValidator; @@ -43,7 +42,7 @@ import org.xml.sax.SAXParseException; */ @Mojo( name = "changes-validate", threadSafe = true ) public class ChangesValidatorMojo - extends AbstractMojo + extends AbstractChangesMojo { /** @@ -75,38 +74,45 @@ public class ChangesValidatorMojo public void execute() throws MojoExecutionException, MojoFailureException { - - if ( !xmlPath.exists() ) + // Run only at the execution root + if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() ) { - getLog().warn( "changes.xml file " + xmlPath.getAbsolutePath() + " does not exist." ); - return; + getLog().info( "Skipping the changes validate in this project because it's not the Execution Root" ); } - - try + else { - XmlValidationHandler xmlValidationHandler = changesSchemaValidator - .validateXmlWithSchema( xmlPath, changesXsdVersion, failOnError ); - boolean hasErrors = !xmlValidationHandler.getErrors().isEmpty(); - if ( hasErrors ) + if ( !xmlPath.exists() ) { - logSchemaValidation( xmlValidationHandler.getErrors() ); - if ( failOnError ) - { - throw new MojoExecutionException( "changes.xml file " + xmlPath.getAbsolutePath() - + " is not valid, see previous errors." ); - } - else + getLog().warn( "changes.xml file " + xmlPath.getAbsolutePath() + " does not exist." ); + return; + } + + try + { + XmlValidationHandler xmlValidationHandler = changesSchemaValidator + .validateXmlWithSchema( xmlPath, changesXsdVersion, failOnError ); + boolean hasErrors = !xmlValidationHandler.getErrors().isEmpty(); + if ( hasErrors ) { - getLog().info( " skip previous validation errors due to failOnError=false." ); + logSchemaValidation( xmlValidationHandler.getErrors() ); + if ( failOnError ) + { + throw new MojoExecutionException( "changes.xml file " + xmlPath.getAbsolutePath() + + " is not valid, see previous errors." ); + } + else + { + getLog().info( " skip previous validation errors due to failOnError=false." ); + } } } - } - catch ( SchemaValidatorException e ) - { - if ( failOnError ) + catch ( SchemaValidatorException e ) { - throw new MojoExecutionException( "failed to validate changes.xml file " + xmlPath.getAbsolutePath() - + ": " + e.getMessage(), e ); + if ( failOnError ) + { + throw new MojoExecutionException( "failed to validate changes.xml file " + xmlPath.getAbsolutePath() + + ": " + e.getMessage(), e ); + } } } }