Author: stephenc Date: Tue Oct 20 19:18:02 2009 New Revision: 827765 URL: http://svn.apache.org/viewvc?rev=827765&view=rev Log: Implements MINVOKER-95
Added: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/ (props changed) - copied from r826599, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-false/ (props changed) - copied from r826599, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-false/selector.bsh maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-other/ (props changed) - copied from r826599, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-other/selector.bsh maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-quiet/ (props changed) - copied from r826599, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-quiet/selector.bsh maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/ (props changed) - copied from r826599, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/selector.bsh maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-throw/ (props changed) - copied from r826599, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-throw/selector.bsh maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildErrorException.java - copied, changed from r826599, maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildFailureException.java maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-scripts.apt.vm - copied, changed from r826599, maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-conditions.apt.vm Removed: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/jre-version-match/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/jre-version-mismatch/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/os-family-match/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/os-family-mismatch/ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-false/invoker.properties maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-other/invoker.properties maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-quiet/invoker.properties maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/invoker.properties maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-throw/invoker.properties Modified: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/pom.xml maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/postbuild.bsh maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/verify.bsh maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerSession.java maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java maven/plugins/trunk/maven-invoker-plugin/src/site/site.xml Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Oct 20 19:18:02 2009 @@ -0,0 +1,9 @@ +build.log +interpolated-pom.xml +target +*.iml +*.ipr +*.iws +.classpath +.project +.settings Modified: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/pom.xml?rev=827765&r1=826599&r2=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/pom.xml (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/pom.xml Tue Oct 20 19:18:02 2009 @@ -23,11 +23,11 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>selector-conditions</artifactId> + <artifactId>selector-scripts</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> - <description>Test to check for selection of builds based on OS and/or JRE.</description> + <description>Test to check for selection of builds based on scripted conditions.</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> @@ -44,7 +44,8 @@ <pomIncludes> <pomInclude>*/pom.xml</pomInclude> </pomIncludes> - <preBuildHookScript>prebuild</preBuildHookScript> + <selectorScript>selector</selectorScript> + <ignoreFailures>true</ignoreFailures> <postBuildHookScript>postbuild</postBuildHookScript> <goals> <goal>validate</goal> Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-false/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Oct 20 19:18:02 2009 @@ -0,0 +1,8 @@ +build.log +target +*.iml +*.ipr +*.iws +.classpath +.project +.settings Added: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-false/selector.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-false/selector.bsh?rev=827765&view=auto ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-false/selector.bsh (added) +++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-false/selector.bsh Tue Oct 20 19:18:02 2009 @@ -0,0 +1,3 @@ +import java.io.*; + +return false; Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-other/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Oct 20 19:18:02 2009 @@ -0,0 +1,9 @@ +build.log +target +*.iml +*.ipr +*.iws +.classpath +.project +.settings + Added: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-other/selector.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-other/selector.bsh?rev=827765&view=auto ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-other/selector.bsh (added) +++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-other/selector.bsh Tue Oct 20 19:18:02 2009 @@ -0,0 +1,3 @@ +import java.io.*; + +return "Some thing"; Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-quiet/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Oct 20 19:18:02 2009 @@ -0,0 +1,9 @@ +build.log +target +*.iml +*.ipr +*.iws +.classpath +.project +.settings + Added: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-quiet/selector.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-quiet/selector.bsh?rev=827765&view=auto ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-quiet/selector.bsh (added) +++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-quiet/selector.bsh Tue Oct 20 19:18:02 2009 @@ -0,0 +1,2 @@ +import java.io.*; + Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Oct 20 19:18:02 2009 @@ -0,0 +1,9 @@ +build.log +target +*.iml +*.ipr +*.iws +.classpath +.project +.settings + Modified: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/postbuild.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/postbuild.bsh?rev=827765&r1=826599&r2=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/postbuild.bsh (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/postbuild.bsh Tue Oct 20 19:18:02 2009 @@ -5,3 +5,4 @@ System.out.println( "Creating touch file: " + touchFile ); touchFile.getParentFile().mkdirs(); touchFile.createNewFile(); +return true; Added: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/selector.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/selector.bsh?rev=827765&view=auto ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/selector.bsh (added) +++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-ret-true/selector.bsh Tue Oct 20 19:18:02 2009 @@ -0,0 +1,3 @@ +import java.io.*; + +return true; Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-throw/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Oct 20 19:18:02 2009 @@ -0,0 +1,9 @@ +build.log +target +*.iml +*.ipr +*.iws +.classpath +.project +.settings + Added: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-throw/selector.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-throw/selector.bsh?rev=827765&view=auto ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-throw/selector.bsh (added) +++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/src/it/script-throw/selector.bsh Tue Oct 20 19:18:02 2009 @@ -0,0 +1,3 @@ +import java.io.*; + +throw new NullPointerException( "Bite me" ); Modified: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/verify.bsh?rev=827765&r1=826599&r2=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/verify.bsh (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-scripts/verify.bsh Tue Oct 20 19:18:02 2009 @@ -2,11 +2,13 @@ import java.util.*; import java.util.regex.*; +import org.codehaus.plexus.util.*; + try { String[] expected = { - "src/it/jre-version-match/target/touch.txt", - "src/it/os-family-match/target/touch.txt", + "src/it/script-ret-true/target/touch.txt", + "src/it/script-ret-quiet/target/touch.txt", }; for ( String file : expected ) { @@ -20,8 +22,9 @@ } String[] unexpected = { - "src/it/jre-version-mismatch/target/touch.txt", - "src/it/os-family-mismatch/target/touch.txt", + "src/it/script-ret-false/target/touch.txt", + "src/it/script-ret-other/target/touch.txt", + "src/it/script-throws/target/touch.txt", }; for ( String file : unexpected ) { @@ -33,6 +36,56 @@ return false; } } + + String[] success = { + "target/invoker-reports/BUILD-script-ret-true.xml", + "target/invoker-reports/BUILD-script-ret-quiet.xml", + }; + for ( String file : success ) + { + File resultFile = new File( basedir, file ); + System.out.println( "Checking build result: " + resultFile ); + String xml = FileUtils.fileRead( resultFile, "UTF-8" ); + if ( !xml.contains("result=\"success\"") && !xml.contains("result='success'") ) + { + System.out.println( "FAILED!" ); + return false; + } + } + + String[] skipped = { + "target/invoker-reports/BUILD-script-ret-false.xml", + "target/invoker-reports/BUILD-script-ret-other.xml", + }; + for ( String file : skipped ) + { + File resultFile = new File( basedir, file ); + System.out.println( "Checking build result: " + resultFile ); + String xml = FileUtils.fileRead( resultFile, "UTF-8" ); + if ( !xml.contains("result=\"skipped\"") && !xml.contains("result='skipped'") ) + { + System.out.println( "FAILED!" ); + return false; + } + } + + + String[] inerror = { + "target/invoker-reports/BUILD-script-throw.xml", + }; + for ( String file : inerror ) + { + File resultFile = new File( basedir, file ); + System.out.println( "Checking build result: " + resultFile ); + String xml = FileUtils.fileRead( resultFile, "UTF-8" ); + if ( !xml.contains("result=\"error\"") && !xml.contains("result='error'") ) + { + System.out.println( "FAILED!" ); + return false; + } + } + + } catch( Throwable t ) { Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java?rev=827765&r1=827764&r2=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java Tue Oct 20 19:18:02 2009 @@ -225,6 +225,18 @@ private Invoker invoker; /** + * Relative path of a selector script to run prior to executing the build. This script may be written with + * either BeanShell or Groovy (since 1.3). If the file extension is omitted (e.g. <code>prebuild</code>), the plugin + * searches for the file by trying out the well-known extensions <code>.bsh</code> and <code>.groovy</code>. If this + * script exists for a particular project but returns any non-null value different from <code>true</code> or throws + * an exception, the corresponding build is flagged as skipped. In this case, none of the pre-build hook script, + * Maven nor the post-build hook script will be invoked. + * + * @parameter expression="${invoker.selectorScript}" default-value="selector" + */ + private String selectorScript; + + /** * Relative path of a pre-build hook script to run prior to executing the build. This script may be written with * either BeanShell or Groovy (since 1.3). If the file extension is omitted (e.g. <code>prebuild</code>), the plugin * searches for the file by trying out the well-known extensions <code>.bsh</code> and <code>.groovy</code>. If this @@ -1004,9 +1016,10 @@ if ( isSelected( invokerProperties ) ) { long milliseconds = System.currentTimeMillis(); + boolean executed; try { - runBuild( basedir, interpolatedPomFile, settingsFile, invokerProperties ); + executed = runBuild( basedir, interpolatedPomFile, settingsFile, invokerProperties ); } finally { @@ -1014,11 +1027,24 @@ buildJob.setTime( milliseconds / 1000.0 ); } - buildJob.setResult( BuildJob.Result.SUCCESS ); + if ( executed ) + { - if ( !suppressSummaries ) + buildJob.setResult( BuildJob.Result.SUCCESS ); + + if ( !suppressSummaries ) + { + getLog().info( "..SUCCESS " + formatTime( buildJob.getTime() ) ); + } + } + else { - getLog().info( "..SUCCESS " + formatTime( buildJob.getTime() ) ); + buildJob.setResult( BuildJob.Result.SKIPPED ); + + if ( !suppressSummaries ) + { + getLog().info( "..SKIPPED " + formatTime( buildJob.getTime() ) ); + } } } else @@ -1031,6 +1057,17 @@ } } } + catch ( BuildErrorException e ) + { + buildJob.setResult( BuildJob.Result.ERROR ); + buildJob.setFailureMessage( e.getMessage() ); + + if ( !suppressSummaries ) + { + getLog().info( "..ERROR " + formatTime( buildJob.getTime() ) ); + getLog().info( " " + e.getMessage() ); + } + } catch ( BuildFailureException e ) { buildJob.setResult( e.getType() ); @@ -1139,10 +1176,12 @@ * @param settingsFile The (already interpolated) user settings file for the build, may be <code>null</code> to use * the current user settings. * @param invokerProperties The properties to use. + * @return <code>true</code> if the project was launched or <code>false</code> if the selector script indicated that + * the project should be skipped. * @throws org.apache.maven.plugin.MojoExecutionException If the project could not be launched. * @throws org.apache.maven.plugin.invoker.BuildFailureException If either a hook script or the build itself failed. */ - private void runBuild( File basedir, File pomFile, File settingsFile, InvokerProperties invokerProperties ) + private boolean runBuild( File basedir, File pomFile, File settingsFile, InvokerProperties invokerProperties ) throws MojoExecutionException, BuildFailureException { if ( getLog().isDebugEnabled() && !invokerProperties.getProperties().isEmpty() ) @@ -1166,6 +1205,20 @@ FileLogger logger = setupLogger( basedir ); try { + try + { + scriptRunner.run( "selector script", basedir, selectorScript, context, logger, + BuildJob.Result.SKIPPED ); + } + catch ( BuildErrorException e ) + { + throw e; + } + catch ( BuildFailureException e ) + { + return false; + } + scriptRunner.run( "pre-build script", basedir, preBuildHookScript, context, logger, BuildJob.Result.FAILURE_PRE_HOOK ); @@ -1265,6 +1318,7 @@ logger.close(); } } + return true; } /** Copied: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildErrorException.java (from r826599, maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildFailureException.java) URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildErrorException.java?p2=maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildErrorException.java&p1=maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildFailureException.java&r1=826599&r2=827765&rev=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildFailureException.java (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BuildErrorException.java Tue Oct 20 19:18:02 2009 @@ -20,14 +20,14 @@ */ /** - * Signals a failure of a sub build run by the Invoker Plugin. This can be caused by an unsuccessful pre-/post-build - * script or a failure of the forked Maven build itself. + * Signals an error in a sub build run by the Invoker Plugin. This can be caused by a selector/pre-build + * script throwing an exception or an error in forking the Maven build itself. * - * @author Benjamin Bentmann + * @author Stephen Connolly * @version $Id$ */ -class BuildFailureException - extends Exception +class BuildErrorException + extends BuildFailureException { /** @@ -36,34 +36,16 @@ private static final long serialVersionUID = 236131530635863815L; /** - * The type of the build failure. - */ - private final String type; - - /** * Creates a new exception with the specified detail message. * * @param message The detail message, may be <code>null</code>. * @param type The type of build failure, may not be <code>null</code>. + * @param cause The cause of the build error. */ - public BuildFailureException( String message, String type ) - { - super( message ); - if ( type == null ) - { - throw new IllegalArgumentException( "missing failure type" ); - } - this.type = type; - } - - /** - * Returns the type of build failure. - * - * @return The type of build failure, never <code>null</code>. - */ - public String getType() + public BuildErrorException( String message, String type, Throwable cause ) { - return type; + super( message, type ); + initCause( cause ); } } Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerSession.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerSession.java?rev=827765&r1=827764&r2=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerSession.java (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerSession.java Tue Oct 20 19:18:02 2009 @@ -40,6 +40,8 @@ private List failedJobs; + private List errorJobs; + private List successfulJobs; private List skippedJobs; @@ -121,6 +123,18 @@ } /** + * Gets the build jobs which had errors for this session. + * + * @return The build jobs in error for this session, can be empty but never <code>null</code>. + */ + public List getErrorJobs() + { + updateStats(); + + return errorJobs; + } + + /** * Gets the skipped build jobs in this session. * * @return The skipped build jobs in this session, can be empty but never <code>null</code>. @@ -137,11 +151,12 @@ successfulJobs = null; failedJobs = null; skippedJobs = null; + errorJobs = null; } private void updateStats() { - if ( successfulJobs != null && skippedJobs != null && failedJobs != null ) + if ( successfulJobs != null && skippedJobs != null && failedJobs != null && errorJobs != null ) { return; } @@ -149,6 +164,7 @@ successfulJobs = new ArrayList(); failedJobs = new ArrayList(); skippedJobs = new ArrayList(); + errorJobs = new ArrayList(); for ( Iterator iterator = buildJobs.iterator(); iterator.hasNext(); ) { @@ -162,6 +178,10 @@ { skippedJobs.add( buildJob ); } + else if ( BuildJob.Result.ERROR.equals( buildJob.getResult() ) ) + { + errorJobs.add( buildJob ); + } else if ( buildJob.getResult() != null ) { failedJobs.add( buildJob ); @@ -183,9 +203,10 @@ logger.info( separator ); logger.info( "Execution Summary:" ); - logger.info( " Builds Passing: " + successfulJobs.size() ); - logger.info( " Builds Failing: " + failedJobs.size() ); - logger.info( " Builds Skipped: " + skippedJobs.size() ); + logger.info( " Builds Passing: " + successfulJobs.size() ); + logger.info( " Builds Failing: " + failedJobs.size() ); + logger.info( " Builds in Error: " + errorJobs.size() ); + logger.info( " Builds Skipped: " + skippedJobs.size() ); logger.info( separator ); if ( !failedJobs.isEmpty() ) @@ -244,6 +265,19 @@ throw new MojoFailureException( this, message, message ); } } + if ( !errorJobs.isEmpty() ) + { + String message = errorJobs.size() + " build" + ( errorJobs.size() == 1 ? "" : "s" ) + " in error."; + + if ( ignoreFailures ) + { + logger.warn( "Ignoring that " + message ); + } + else + { + throw new MojoFailureException( this, message, message ); + } + } } } Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java?rev=827765&r1=827764&r2=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java Tue Oct 20 19:18:02 2009 @@ -215,7 +215,7 @@ { t.printStackTrace( logger.getPrintStream() ); } - throw new BuildFailureException( "The " + scriptDescription + " did not succeed. " + msg, stage ); + throw new BuildErrorException( "The " + scriptDescription + " did not succeed. " + msg, stage, t ); } if ( !( result == null || Boolean.TRUE.equals( result ) || "true".equals( result ) ) ) Copied: maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-scripts.apt.vm (from r826599, maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-conditions.apt.vm) URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-scripts.apt.vm?p2=maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-scripts.apt.vm&p1=maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-conditions.apt.vm&r1=826599&r2=827765&rev=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-conditions.apt.vm (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-scripts.apt.vm Tue Oct 20 19:18:02 2009 @@ -1,9 +1,9 @@ ------ - Selector Conditions + Selector Scripts ------ - Benjamin Bentmann + Stephen Connolly ------ - 2009-09-19 + 2009-10-20 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one @@ -26,34 +26,63 @@ ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html -Selector Conditions +Selector Scripts - Starting with plugin version 1.4, some keys of the {{{./invoker-properties.html}Invoker Properties}} can be used to - skip individual projects based on the current JRE version or OS family as illustrated in the example below: + Starting with plugin version 1.5, a custom script can be used to skip individual projects based on + whatever critria are expressed in the script as illustrated in the following example. Assume the + following directory structure: ------------------- -# build project if JRE version is 1.4 or higher, but exclude version 1.4.1 -invoker.java.version = 1.4+, !1.4.1 +./ ++- pom.xml ++- src/ + +- it/ + +- settings.xml + +- conditional-it/ + +- pom.xml + +- check-assumptions.bsh + +- src/ +------------------- + + The plugin configuration for this example would look like this: -# build project if OS family is not Windows -invoker.os.family = !windows +------------------- +<project> + ... + <build> + <plugins> + <plugin> + <artifactId>maven-invoker-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <projectsDirectory>src/it</projectsDirectory> + <cloneProjectsTo>\${project.build.directory}/it</cloneProjectsTo> + <pomIncludes> + <pomInclude>*/pom.xml</pomInclude> + </pomIncludes> + <settingsFile>src/it/settings.xml</settingsFile> + <localRepositoryPath>\${project.build.directory}/local-repo</localRepositoryPath> + <selectorScript>check-assumptions.bsh</selectorScript> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <goals> + <goal>install</goal> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project> ------------------- - The values of these keys are comma separated tokens. A token prefixed with "!" denotes an exclusion, otherwise it - denotes an inclusion. A project is build if no exclusion matches and if no inclusions are given or at least one of - them matches the current environment. - - The tokens to describe JRE versions can be suffixed with "+" or "-". The table below shows how the different styles - of version tokens translate to a version range: - -*----------------+----------------------------+ -|| Version Token || Equivalent Version Range | -*----------------+----------------------------+ -| 1.5 | [1.5,1.6) | -*----------------+----------------------------+ -| 1.5+ | [1.5,) | -*----------------+----------------------------+ -| 1.5- | (,1.5) | -*----------------+----------------------------+ + If the check-assumptions.bsh script returns <<<true>>> or does not return a value, then the project will be executed. - For the OS family, the tokens "windows", "unix" and "mac" are supported. + If the script returns any value other than <<<true>>>, then the project will be executed. + + If the script throws an exception, then the project will be marked as being in ERROR. + Modified: maven/plugins/trunk/maven-invoker-plugin/src/site/site.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/site/site.xml?rev=827765&r1=827764&r2=827765&view=diff ============================================================================== --- maven/plugins/trunk/maven-invoker-plugin/src/site/site.xml (original) +++ maven/plugins/trunk/maven-invoker-plugin/src/site/site.xml Tue Oct 20 19:18:02 2009 @@ -39,6 +39,7 @@ <item name="Installing Artifacts" href="examples/install-artifacts.html"/> <item name="Invoker Properties" href="examples/invoker-properties.html"/> <item name="Selector Conditions" href="examples/selector-conditions.html"/> + <item name="Selector Scripts" href="examples/selector-scripts.html"/> <item name="Using a Post Build Script" href="examples/post-build-script.html"/> <item name="Preparing the Build Environment" href="examples/prepare-build-env.html"/> <item name="Skipping Invocations" href="examples/skipping.html"/>