diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/apache/maven/plugin/nar/Javah.java | 28 |
1 files changed, 25 insertions, 3 deletions
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() |