On 7/24/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Revision7299AuthorochingDate2008-07-24 05:13:53 -0500 (Thu, 24 Jul 2008)
> Log Message[MEXEC-54]
-update plugin to use toolchain if toolchain is
> found
-added dependency to maven-toolchain-1.0
> Modified Paths
> trunk/mojo/exec-maven-plugin/pom.xml
> trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java
> trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/ExecMojo.java
> Diff
> Modified: trunk/mojo/exec-maven-plugin/pom.xml (7298 =>
> 7299)--- trunk/mojo/exec-maven-plugin/pom.xml 2008-07-24
> 07:03:03 UTC (rev 7298)
+++
> trunk/mojo/exec-maven-plugin/pom.xml 2008-07-24 10:13:53
> UTC (rev 7299)
@@ -79,6 +79,11 @@
<dependencies>
<dependency>
> <groupId>org.apache.maven</groupId>
+
> <artifactId>maven-toolchain</artifactId>
+
> <version>1.0</version>
+ </dependency>
+ <dependency>
+
> <groupId>org.apache.maven</groupId>
> <artifactId>maven-project</artifactId>
> <version>2.0.4</version>
</dependency>
@@ -100,8 +105,7 @@
<dependency>
> <groupId>org.apache.maven</groupId>
> <artifactId>maven-core</artifactId>
-
> <version>2.0</version>
- <scope>test</scope>
+ <version>2.0</version>
> </dependency>
<dependency>
> <groupId>org.apache.maven</groupId>
>
> Modified:
> trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java
> (7298 => 7299)---
> trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java
> 2008-07-24 07:03:03 UTC (rev 7298)
+++
> trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java
> 2008-07-24 10:13:53 UTC (rev 7299)
@@ -22,9 +22,13 @@
import
> java.util.LinkedList;
import java.util.List;
+import
> org.apache.maven.execution.MavenSession;
import
> org.apache.maven.plugin.AbstractMojo;
import
> org.apache.maven.plugin.MojoExecutionException;
import
> org.apache.maven.project.MavenProject;
+import
> org.apache.maven.toolchain.Toolchain;
+import
> org.apache.maven.toolchain.ToolchainManager;
+import
> org.codehaus.plexus.component.repository.exception.ComponentLookupException;
>
/**
* This class is used for unifying functionality between the 2 mojo
> exec plugins ('java' and 'exec').
@@ -68,6 +72,16 @@
* @parameter
> expression="${exec.args}"
*/
private String commandlineArgs;
+
+ /**
+ *
> The current build session instance. This is used for
+ * toolchain manager
> API calls.
+ *
+ * @parameter expression="${session}"
+ * @required
+ *
> @readonly
+ */
Any reason this is added to the abstract base class if only the
ExecMojo is to use it ?
+ private MavenSession session;
/**
* Defines the scope
> of the classpath passed to the plugin. Set to compile,test,runtime or system
> depending
@@ -246,4 +260,31 @@
> project.addTestCompileSourceRoot( testSourceRoot.toString()
> );
}
}
+
+ //TODO remove the part with ToolchainManager lookup once we
> depend on
+ //2.0.9 (have it as prerequisite). Define as regular component
> field then.
+ protected Toolchain getToolchain()
+ {
+ Toolchain tc =
> null;
+
+ try
+ {
+ if ( session != null ) // session is null in tests..
Shouldn´t we set it manualy then ?
> {
+ ToolchainManager toolchainManager =
+ (ToolchainManager)
> session.getContainer().lookup( ToolchainManager.ROLE );
+
+ if (
> toolchainManager != null )
+ {
+ tc =
> toolchainManager.getToolchainFromBuildContext( "jdk",
> session );
+ }
+ }
+ }
+ catch ( ComponentLookupException
> componentLookupException )
+ {
+ // just ignore, could happen in pre-2.0.9
> builds..
+ }
+ return tc;
+ }
+
}
>
> Modified:
> trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/ExecMojo.java
> (7298 => 7299)---
> trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/ExecMojo.java
> 2008-07-24 07:03:03 UTC (rev 7298)
+++
> trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/ExecMojo.java
> 2008-07-24 10:13:53 UTC (rev 7299)
@@ -23,6 +23,7 @@
import
> org.apache.maven.plugin.logging.Log;
import
> org.apache.maven.plugin.MojoExecutionException;
import
> org.apache.maven.project.MavenProject;
+import
> org.apache.maven.toolchain.Toolchain;
import
> org.codehaus.plexus.util.cli.CommandLineException;
import
> org.codehaus.plexus.util.cli.CommandLineUtils;
import
> org.codehaus.plexus.util.cli.Commandline;
@@ -362,20
> +363,28 @@
}
String getExecutablePath()
- {
- File execFile = new File(
> executable );
- // if the file doesn't exist, the exec is probably in the
> PATH...
- // we should probably also test for isFile and canExecute, but the
> second one is only
- // available in SDK 6.
- if ( execFile.exists() )
+ {
>
+ File execFile = new File( executable );
+ if ( execFile.exists() )
{
+
> getLog().warn( "Toolchains are ignored, 'executable' parameter is set to " +
> executable );
return execFile.getAbsolutePath();
- }
- else
- {
-
> getLog().debug( "executable " + executable + " not found in place, assuming
> it is in the PATH." );
- return executable;
- }
+ }
+ else
+ {
+ Toolchain
> tc = getToolchain();
+
+ // if the file doesn't exist & toolchain is null,
> the exec is probably in the PATH...
+ // we should probably also test for
> isFile and canExecute, but the second one is only
+ // available in SDK 6.
+
> if ( tc != null )
+ {
+ getLog().info( "Toolchain in exec-maven-plugin: " +
> tc );
+ executable = tc.findTool( executable );
* Fix code style: indentation.
* if I understand well, this can return null in some cases, right ?
(e.g. cf the pre 2.0.9 comment). Shouldn t there be an else here ?
+ }
+ }
+
+ return
> executable;
}
Jerome
> ________________________________
>
>
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
--
Jerome Lacoste, +47 40867729, Daglig Leder, CoffeeBreaks AS
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email