You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2009/10/21 20:44:49 UTC
svn commit: r828136 - in /maven/plugins/trunk/maven-invoker-plugin/src:
it/selector-conditions/src/it/maven-version-match/
it/selector-conditions/src/it/maven-version-mismatch/
main/java/org/apache/maven/plugin/invoker/ site/apt/examples/
Author: stephenc
Date: Wed Oct 21 18:44:48 2009
New Revision: 828136
URL: http://svn.apache.org/viewvc?rev=828136&view=rev
Log:
[MINVOKER-96] Adding a selector based on current maven version
- I have opted to keep the version selection syntax the same as for JRE and OS versions
- Detection of the maven version is via the classloader for MavenProject. This assumes that MavenProject is always in org.apache.maven:maven-core. This is the case for 2.x and 3.x, but if this changes the plugin will need to be fixed.
Added:
maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-match/
- 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-conditions/src/it/maven-version-match/invoker.properties
- copied, changed from r828118, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/invoker.properties
maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-match/pom.xml
- copied unchanged from r828118, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/pom.xml
maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-match/postbuild.bsh
- copied unchanged from r828118, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/postbuild.bsh
maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-mismatch/
- copied from r826599, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-mismatch/
maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-mismatch/invoker.properties
- copied, changed from r828118, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-mismatch/invoker.properties
maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-mismatch/pom.xml
- copied unchanged from r828118, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-mismatch/pom.xml
maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-mismatch/postbuild.bsh
- copied unchanged from r828118, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-mismatch/postbuild.bsh
Modified:
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/InvokerProperties.java
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SelectorUtils.java
maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/selector-conditions.apt.vm
Copied: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-match/invoker.properties (from r828118, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/invoker.properties)
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-match/invoker.properties?p2=maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-match/invoker.properties&p1=maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/invoker.properties&r1=828118&r2=828136&rev=828136&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-match/invoker.properties (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-match/invoker.properties Wed Oct 21 18:44:48 2009
@@ -1 +1 @@
-invoker.java.version = 1.4-, 1.4, 1.5+
+invoker.maven.version = 2.0+
Copied: maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-mismatch/invoker.properties (from r828118, maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-mismatch/invoker.properties)
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-mismatch/invoker.properties?p2=maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-mismatch/invoker.properties&p1=maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-mismatch/invoker.properties&r1=828118&r2=828136&rev=828136&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/jre-version-mismatch/invoker.properties (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/selector-conditions/src/it/maven-version-mismatch/invoker.properties Wed Oct 21 18:44:48 2009
@@ -1 +1 @@
-invoker.java.version = 1.2
+invoker.maven.version = 1.2
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=828136&r1=828135&r2=828136&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 Wed Oct 21 18:44:48 2009
@@ -1100,6 +1100,11 @@
*/
private boolean isSelected( InvokerProperties invokerProperties )
{
+ if ( !SelectorUtils.isMavenVersion( invokerProperties.getMavenVersion() ) )
+ {
+ return false;
+ }
+
if ( !SelectorUtils.isJreVersion( invokerProperties.getJreVersion() ) )
{
return false;
Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java?rev=828136&r1=828135&r2=828136&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java Wed Oct 21 18:44:48 2009
@@ -133,6 +133,17 @@
}
/**
+ * Gets the specification of Maven versions on which this build job should be run.
+ *
+ * @return The specification of Maven versions on which this build job should be run.
+ * @since 1.5
+ */
+ public String getMavenVersion()
+ {
+ return this.properties.getProperty( "invoker.maven.version", "" );
+ }
+
+ /**
* Gets the specification of OS families on which this build job should be run.
*
* @return The specification of OS families or an empty string if not set.
Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SelectorUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SelectorUtils.java?rev=828136&r1=828135&r2=828136&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SelectorUtils.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SelectorUtils.java Wed Oct 21 18:44:48 2009
@@ -19,17 +19,19 @@
* under the License.
*/
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.Os;
+import org.codehaus.plexus.util.StringUtils;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-
-import org.codehaus.plexus.util.Os;
-import org.codehaus.plexus.util.StringUtils;
+import java.util.Properties;
/**
* Provides utility methods for selecting build jobs based on environmental conditions.
- *
+ *
* @author Benjamin Bentmann
*/
class SelectorUtils
@@ -85,6 +87,40 @@
}
}
+ /**
+ * Retrieves the current Maven version.
+ * @return The current Maven version.
+ */
+ static String getMavenVersion()
+ {
+ try
+ {
+ // This relies on the fact that MavenProject is the in core classloader
+ // and that the core classloader is for the maven-core artifact
+ // and that should have a pom.properties file
+ // if this ever changes, we will have to revisit this code.
+ Properties properties = new Properties();
+ properties.load( MavenProject.class.getClassLoader().getResourceAsStream(
+ "META-INF/maven/org.apache.maven/maven-core/pom.properties" ) );
+ return StringUtils.trim( properties.getProperty( "version" ) );
+ }
+ catch ( Exception e )
+ {
+ return null;
+ }
+ }
+
+ static boolean isMavenVersion( String mavenSpec )
+ {
+ List includes = new ArrayList();
+ List excludes = new ArrayList();
+ parseList( mavenSpec, includes, excludes );
+
+ List mavenVersionList = parseVersion( getMavenVersion() );
+
+ return isJreVersion( mavenVersionList, includes, true ) && !isJreVersion( mavenVersionList, excludes, false );
+ }
+
static boolean isJreVersion( String jreSpec )
{
List includes = new ArrayList();
@@ -135,8 +171,8 @@
else
{
// 1.5 <=> [1.5,1.6)
- return checkVersion.size() <= jreVersion.size()
- && checkVersion.equals( jreVersion.subList( 0, checkVersion.size() ) );
+ return checkVersion.size() <= jreVersion.size() && checkVersion.equals(
+ jreVersion.subList( 0, checkVersion.size() ) );
}
}
@@ -158,7 +194,7 @@
static int compareVersions( List version1, List version2 )
{
- for ( Iterator it1 = version1.iterator(), it2 = version2.iterator();; )
+ for ( Iterator it1 = version1.iterator(), it2 = version2.iterator(); ; )
{
if ( !it1.hasNext() )
{
Modified: 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-conditions.apt.vm?rev=828136&r1=828135&r2=828136&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-conditions.apt.vm Wed Oct 21 18:44:48 2009
@@ -39,6 +39,14 @@
invoker.os.family = !windows
-------------------
+ In addition, with plugin version 1.5, there is the ability to skip individual projects based on the current Maven
+ version as illustrated in the example below:
+
+-------------------
+# build project is Maven version is 2.0.10 or higher, but exclude versions 2.1.0 and 2.2.0
+invoker.maven.version = 2.0.10+, !2.1.0, !2.2.0
+-------------------
+
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.