bodewig     2004/12/15 04:31:44

  Modified:    .        Tag: ANT_16_BRANCH WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/rmic Tag:
                        ANT_16_BRANCH KaffeRmic.java
  Log:
  merge
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.503.2.150 +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.503.2.149
  retrieving revision 1.503.2.150
  diff -u -r1.503.2.149 -r1.503.2.150
  --- WHATSNEW  14 Dec 2004 23:48:00 -0000      1.503.2.149
  +++ WHATSNEW  15 Dec 2004 12:31:43 -0000      1.503.2.150
  @@ -29,6 +29,9 @@
   * Refactored Target invocation into org.apache.tools.ant.Executor
     implementations.  Bugzilla Reports 21421, 29248.
   
  +* <rmic> now also supports Kaffe's rmic version shipping with Kaffe
  +  1.1.2 and above.
  +
   Fixed bugs:
   -----------
   
  
  
  
  No                   revision
  No                   revision
  1.11.2.5  +56 -15    
ant/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java
  
  Index: KaffeRmic.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java,v
  retrieving revision 1.11.2.4
  retrieving revision 1.11.2.5
  diff -u -r1.11.2.4 -r1.11.2.5
  --- KaffeRmic.java    9 Mar 2004 17:01:54 -0000       1.11.2.4
  +++ KaffeRmic.java    15 Dec 2004 12:31:44 -0000      1.11.2.5
  @@ -29,33 +29,74 @@
    * @since Ant 1.4
    */
   public class KaffeRmic extends DefaultRmicAdapter {
  +    public static final String RMIC_CLASSNAME = "gnu.java.rmi.rmic.RMIC";
  +    // pre Kaffe 1.1.2
  +    private static final String OLD_RMIC_CLASSNAME = "kaffe.rmi.rmic.RMIC";
  +
  +    /**
  +     * the name of this adapter for users to select
  +     */
  +    public static final String COMPILER_NAME = "kaffe";
  +
   
       public boolean execute() throws BuildException {
           getRmic().log("Using Kaffe rmic", Project.MSG_VERBOSE);
           Commandline cmd = setupRmicCommand();
   
  -        try {
  +        Class c = getRmicClass();
  +        if (c == null) {
  +            throw new BuildException("Cannot use Kaffe rmic, as it is not "
  +                                     + "available.  Neither "
  +                                     + RMIC_CLASSNAME
  +                                     + " nor "
  +                                     + OLD_RMIC_CLASSNAME
  +                                     + " have been found.  "
  +                                     + "A common solution is to "
  +                                     + "set the environment variable "
  +                                     + "JAVA_HOME or CLASSPATH.",
  +                                     getRmic().getLocation());
  +        }
   
  -            Class c = Class.forName("kaffe.rmi.rmic.RMIC");
  +        try {
               Constructor cons = c.getConstructor(new Class[] 
{String[].class});
               Object rmic = cons.newInstance(new Object[] 
{cmd.getArguments()});
  -            Method doRmic = c.getMethod("run", null);
  -            Boolean ok = (Boolean) doRmic.invoke(rmic, null);
  +            Method doRmic = c.getMethod("run", (Class[]) null);
  +            Boolean ok = (Boolean) doRmic.invoke(rmic, (Object[]) null);
   
               return ok.booleanValue();
  -        } catch (ClassNotFoundException ex) {
  -            throw new BuildException("Cannot use Kaffe rmic, as it is not "
  -                                     + "available.  A common solution is to "
  -                                     + "set the environment variable "
  -                                     + "JAVA_HOME or CLASSPATH.",
  -                                     getRmic().getLocation());
  +        } catch (BuildException ex) {
  +            //rethrow
  +            throw ex;
           } catch (Exception ex) {
  -            if (ex instanceof BuildException) {
  -                throw (BuildException) ex;
  -            } else {
  -                throw new BuildException("Error starting Kaffe rmic: ",
  -                                         ex, getRmic().getLocation());
  +            //wrap
  +           throw new BuildException("Error starting Kaffe rmic: ",
  +                                    ex, getRmic().getLocation());
  +        }
  +    }
  +
  +    /**
  +     * test for kaffe being on the system
  +     * @return true if kaffe is on the current classpath
  +     */
  +    public static boolean isAvailable() {
  +        return getRmicClass() != null;
  +    }
  +
  +    /**
  +     * tries to load Kaffe RMIC and falls back to the older class name
  +     * if necessary.
  +     *
  +     * @return null if neither class can get loaded.
  +     */
  +    private static Class getRmicClass() {
  +        try {
  +            return Class.forName(RMIC_CLASSNAME);
  +        } catch (ClassNotFoundException cnfe) {
  +            try {
  +                return Class.forName(OLD_RMIC_CLASSNAME);
  +            } catch (ClassNotFoundException cnfe2) {
               }
           }
  +        return null;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to