Browse Source

Make <javah> work on JDK 1.4.2.

PR: 18667
Submitted by:	James Allers <jallers at advancedreality dot com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274418 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
74cf9531d0
2 changed files with 27 additions and 9 deletions
  1. +2
    -0
      WHATSNEW
  2. +25
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/Javah.java

+ 2
- 0
WHATSNEW View File

@@ -225,6 +225,8 @@ Other changes:

* <sql> has a new attribute to control escape processing.

* <javah> will invoke oldjavah on JDK 1.4.2. Bugzilla Report 18667.

Changes from Ant 1.5.2 to Ant 1.5.3
===================================



+ 25
- 9
src/main/org/apache/tools/ant/taskdefs/optional/Javah.java View File

@@ -55,6 +55,8 @@
package org.apache.tools.ant.taskdefs.optional;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -335,15 +337,29 @@ public class Javah extends Task {
throw new BuildException("Compile failed");
}
*/
try {
// Javac uses logstr to change the output stream and calls
// the constructor's invoke method to create a compiler instance
// dynamically. However, javah has a different interface and this
// makes it harder, so here's a simple alternative.
//------------------------------------------------------------------
com.sun.tools.javah.Main main
= new com.sun.tools.javah.Main(cmd.getArguments());
main.run();
Class javahMainClass = null;
try {
// first search for the "old" javah class in 1.4.2 tools.jar
javahMainClass = Class.forName("com.sun.tools.javah.oldjavah.Main");
} catch(ClassNotFoundException cnfe) {
// assume older than 1.4.2 tools.jar
javahMainClass = Class.forName("com.sun.tools.javah.Main");
}
// now search for the constructor that takes in String[] arguments.
Class[] strings = new Class[] {String[].class};
Constructor constructor = javahMainClass.getConstructor(strings);
// construct the javah Main instance
Object javahMain = constructor.newInstance(new Object[] {cmd.getArguments()});
// find the run method
Method runMethod = javahMainClass.getMethod("run",new Class[0]);
runMethod.invoke(javahMain,new Object[0]);
} catch (Exception ex) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
@@ -352,7 +368,7 @@ public class Javah extends Task {
}
}
}
/**
* Does the command line argument processing common to classic and
* modern.


Loading…
Cancel
Save