From 589cb40ca4a843e7d1d0a8ceed7f66d3659cbf9c Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Wed, 4 Nov 2009 22:25:31 +0100 Subject: Fixed NAR-73 --- .../java/org/apache/maven/plugin/nar/Javah.java | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/org/apache/maven/plugin/nar/Javah.java b/src/main/java/org/apache/maven/plugin/nar/Javah.java index 1ea908a..e727bcb 100644 --- a/src/main/java/org/apache/maven/plugin/nar/Javah.java +++ b/src/main/java/org/apache/maven/plugin/nar/Javah.java @@ -236,9 +236,8 @@ public class Javah getJniDirectory().mkdirs(); getTimestampDirectory().mkdirs(); - File javahFile = new File( mojo.getJavaHome( mojo.getAOL() ), "bin" ); - String javah = new File( javahFile, name ).getAbsolutePath(); - + String javah = getJavah(); + mojo.getLog().info( "Running " + javah + " compiler on " + files.size() + " classes..." ); int result = NarUtil.runCommand( javah, generateArgs( files ), null, null, mojo.getLog() ); if ( result != 0 ) @@ -298,6 +297,29 @@ public class Javah return (String[]) args.toArray( new String[args.size()] ); } + private String getJavah() throws MojoExecutionException, MojoFailureException { + String javah = null; + + // try toolchain + Toolchain toolchain = getToolchain(); + if (toolchain != null) { + javah = toolchain.findTool( "javah" ); + } + + // try java home + if (javah == null) { + File javahFile = new File( mojo.getJavaHome( mojo.getAOL() ), "bin" ); + javah = new File( javahFile, name ).getAbsolutePath(); + } + + // forget it... + if (javah == null) { + throw new MojoExecutionException( "NAR: Cannot find 'javah' in Toolchain or on JavaHome" ); + } + + return javah; + } + //TODO remove the part with ToolchainManager lookup once we depend on //2.0.9 (have it as prerequisite). Define as regular component field then. private Toolchain getToolchain() -- cgit v1.2.3