Author: rfscholte
Date: Sun Oct 28 12:20:51 2012
New Revision: 1402983
URL: http://svn.apache.org/viewvc?rev=1402983&view=rev
Log:
First part of MINVOKER-126: mavenHome in relationship with
invoker.maven.version rule
Get version based on MavenHome
Modified:
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SelectorUtils.java
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=1402983&r1=1402982&r2=1402983&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
Sun Oct 28 12:20:51 2012
@@ -19,16 +19,21 @@ package org.apache.maven.plugin.invoker;
* under the License.
*/
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.Os;
-import org.codehaus.plexus.util.StringUtils;
-
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.Os;
+import org.codehaus.plexus.util.StringUtils;
+
/**
* Provides utility methods for selecting build jobs based on environmental
conditions.
*
@@ -107,6 +112,46 @@ class SelectorUtils
return null;
}
}
+
+ static String getMavenVersion( File mavenHome )
+ {
+ File mavenLib = new File( mavenHome, "lib" );
+ File[] jarFiles = mavenLib.listFiles( new FilenameFilter()
+ {
+ public boolean accept( File dir, String name )
+ {
+ return name.endsWith( ".jar" );
+ }
+ } );
+
+ for ( File file : jarFiles )
+ {
+ try
+ {
+ @SuppressWarnings( "deprecation" )
+ URL url =
+ new URL( "jar:" + file.toURL().toExternalForm()
+ +
"!/META-INF/maven/org.apache.maven/maven-core/pom.properties" );
+
+ Properties properties = new Properties();
+ properties.load( url.openStream() );
+ String version = StringUtils.trim( properties.getProperty(
"version" ) );
+ if ( version != null )
+ {
+ return version;
+ }
+ }
+ catch ( MalformedURLException e )
+ {
+ // ignore
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+ return null;
+ }
static boolean isMavenVersion( String mavenSpec )
{