maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1408460 - in /maven/plugins/trunk/maven-invoker-plugin: pom.xml src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java src/main/java/org/apache/maven/plugin/invoker/SystemPropertyPrinter.java
Date Mon, 12 Nov 2012 21:10:05 GMT
Author: rfscholte
Date: Mon Nov 12 21:10:04 2012
New Revision: 1408460

URL: http://svn.apache.org/viewvc?rev=1408460&view=rev
Log:
[MINVOKER-106] invoker.java.version is always evaluated against current JVM instead of JVM
running the builds 

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SystemPropertyPrinter.java
Modified:
    maven/plugins/trunk/maven-invoker-plugin/pom.xml
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java

Modified: maven/plugins/trunk/maven-invoker-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/pom.xml?rev=1408460&r1=1408459&r2=1408460&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-invoker-plugin/pom.xml Mon Nov 12 21:10:04 2012
@@ -63,7 +63,7 @@ under the License.
     <groovy-groupId>org.codehaus.groovy</groovy-groupId>
     <groovy-artifactId>groovy-all</groovy-artifactId>
     <groovy-version>2.0.1</groovy-version>
-    <mavenPluginPluginVersion>3.1</mavenPluginPluginVersion>
+    <mavenPluginPluginVersion>3.2</mavenPluginPluginVersion>
   </properties>
 
   <dependencies>

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=1408460&r1=1408459&r2=1408460&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
Mon Nov 12 21:10:04 2012
@@ -54,6 +54,7 @@ import org.apache.maven.artifact.Artifac
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Profile;
 import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.invoker.model.BuildJob;
@@ -88,6 +89,10 @@ import org.codehaus.plexus.util.Interpol
 import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
@@ -352,6 +357,9 @@ public abstract class AbstractInvokerMoj
      */
     @Component
     private MavenProject project;
+    
+    @Component
+    private MojoExecution mojoExecution;
 
     /**
      * A comma separated list of projectname patterns to run. Specify this parameter to run
individual tests by file name,
@@ -583,6 +591,12 @@ public abstract class AbstractInvokerMoj
      */
     private String actualJreVersion;
     
+    
+    private final void setActualJreVersion( String actualJreVersion )
+    {
+        this.actualJreVersion = actualJreVersion;
+    }
+    
     /**
      * Invokes Maven on the configured test projects.
      *
@@ -1122,7 +1136,7 @@ public abstract class AbstractInvokerMoj
         
         if ( javaHome != null )
         {
-            actualJreVersion = SelectorUtils.getJreVersion( javaHome );
+            resolveExternalJreVersion();
         }
         else
         {
@@ -1189,6 +1203,35 @@ public abstract class AbstractInvokerMoj
         }
     }
 
+    private void resolveExternalJreVersion()
+    {
+        Artifact pluginArtifact = mojoExecution.getMojoDescriptor().getPluginDescriptor().getPluginArtifact();
+        pluginArtifact.getFile();
+        
+        Commandline commandLine = new Commandline();
+        commandLine.setExecutable( new File( javaHome, "bin/java").getAbsolutePath() );
+        commandLine.createArg().setValue( "-cp" );
+        commandLine.createArg().setFile( pluginArtifact.getFile() );
+        commandLine.createArg().setValue( SystemPropertyPrinter.class.getName() );
+        commandLine.createArg().setValue( "java.version" );
+        
+        StreamConsumer consumer = new StreamConsumer()
+        {
+            public void consumeLine( String line )
+            {
+                setActualJreVersion( line );
+            }
+        };
+        try
+        {
+            CommandLineUtils.executeCommandLine( commandLine, consumer, null );
+        }
+        catch ( CommandLineException e )
+        {
+            getLog().warn( e.getMessage() );
+        }
+    }
+
     /**
      * Runs the specified project.
      *

Added: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SystemPropertyPrinter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SystemPropertyPrinter.java?rev=1408460&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SystemPropertyPrinter.java
(added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/SystemPropertyPrinter.java
Mon Nov 12 21:10:04 2012
@@ -0,0 +1,43 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Print specified system properties to the output stream.
+ * Useful to detect certain values from a JVM different to the default JAVA_HOME. 
+ * 
+ * 
+ * @author Robert Scholte
+ * @since 1.8
+ */
+public class SystemPropertyPrinter
+{
+    /**
+     * @param args
+     */
+    public static void main( String[] args )
+    {
+        for ( String arg : args )
+        {
+            System.out.println( System.getProperty( arg, "" ) );
+        }
+    }
+
+}



Mime
View raw message