ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional Javah.java
Date Wed, 09 Apr 2003 13:36:32 GMT
bodewig     2003/04/09 06:36:32

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional Javah.java
  Log:
  Make <javah> work on JDK 1.4.2.
  
  PR: 18667
  Submitted by:	James Allers <jallers at advancedreality dot com>
  
  Revision  Changes    Path
  1.392     +2 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.391
  retrieving revision 1.392
  diff -u -r1.391 -r1.392
  --- WHATSNEW	9 Apr 2003 13:15:31 -0000	1.391
  +++ WHATSNEW	9 Apr 2003 13:36:32 -0000	1.392
  @@ -225,6 +225,8 @@
   
   * <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
   ===================================
   
  
  
  
  1.22      +25 -9     ant/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java
  
  Index: Javah.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Javah.java	10 Feb 2003 14:13:45 -0000	1.21
  +++ Javah.java	9 Apr 2003 13:36:32 -0000	1.22
  @@ -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 @@
               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 @@
               }
           }
       }
  -
  +        
       /**
        * Does the command line argument processing common to classic and
        * modern.
  
  
  

Mime
View raw message