classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RMIC patches


From: Dalibor Topic
Subject: RMIC patches
Date: Wed, 20 Aug 2003 12:07:39 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.4) Gecko/20030624

Hi all,

I've merged in GNU Classpath's RMI implementation into kaffe and fixed a few small issues along the way. Attached you'll find the patch, and the changelog. My paperwork has passed a while ago ;)

The patch adds two new RMIC compilers, jikes and kjc, and adapts CompilerProcess to offer a 'typical' command line argument generation method, to avoid code duplication. That method is now used by all current RMI compiler implementations, gcj, kjc, and jikes.

It also fixes a few small issues with paths of generated stubs and skeletons, as well as with names of constructors, which could contain the full package name.

Finally, the patch fixes one major issue with generated stubs, by making the generated stub implement ony those interfaces (its original class implements) that are derived from java.rmi.Remote. Current implementation generates broken stubs which don't compile if the original class implements interfaces that are not derived from Remote.

cheers,
dalibor topic
        * gnu/java/rmi/rmic/Compile_gcj.java:
        (COMPILER_ARGS) new private constant.
        (computeArguments) use computeTypicalArguments.

        * gnu/java/rmi/rmic/Compile_kjc.java,
        gnu/java/rmi/rmic/Compile_jikes.java,
        gnu/java/rmi/rmic/RMICException.java:
        new files.

        * gnu/java/rmi/rmic/Compiler.java:
        (getDestination) new method.

        * gnu/java/rmi/rmic/CompilerProcess.java:
        Import java.io.InputStream.
        (computeTypicalArguments) new method.
        (compile) print compiler output to System.out. Collect compiler
        error output and use it in exception message.

        * gnu/java/rmi/rmic/RMIC.java:
        Import java.util.Set.
        (destination) initialize to null.
        (run) replace file separator with '.' when processing class.
        (processClass) replace '.' with file separator when compiling
        classes.
        (findClass) use SystemClassLoader to load class.
        (generateStub) use full class name for generated stub, that puts
        it in right path.  Replace '.' with file separator when generating
        stub file name. Write just the stub class name without package
        information as class name, and constructor name. Write only
        interface names for interfaces extending java.rmi.Remote as
        implemented. 
        (generateSkel) use full class name for generated skel, that puts
        it in right path.  Replace '.' with file separator when generating
        stub file name. Write just the stub class name without package
        information as class name.
diff -urN -x CVS -x '*.am' -x '.*' 
/home/topic/CVS/classpath/gnu/java/rmi/rmic/Compile_gcj.java 
gnu/java/rmi/rmic/Compile_gcj.java
--- /home/topic/CVS/classpath/gnu/java/rmi/rmic/Compile_gcj.java        
2002-01-22 17:26:57.000000000 -0500
+++ gnu/java/rmi/rmic/Compile_gcj.java  2003-08-18 13:40:33.000000000 -0400
@@ -40,21 +40,16 @@
 /** Subclass of Compiler that can be used to invoke gcj.  */
 public class Compile_gcj extends CompilerProcess
 {
-  public String[] computeArguments (String filename)
+  private static final String [] COMPILER_ARGS = 
   {
-    int len = 3 + (dest == null ? 0 : 2);
-    String[] result = new String[len];
-    int i = 0;
-
-    result[i++] = "gcj";
-    result[i++] = "-C";
-    if (dest != null)
-      {
-       result[i++] = "-d";
-       result[i++] = dest;
-      }
-    result[i++] = filename;
+    "gcj",
+    "-C"
+  };
 
-    return result;
+  public String[] computeArguments (String filename)
+  {
+    return computeTypicalArguments(COMPILER_ARGS,
+                                  getDestination(),
+                                  filename);
   }
 }
diff -urN -x CVS -x '*.am' -x '.*' 
/home/topic/CVS/classpath/gnu/java/rmi/rmic/Compile_jikes.java 
gnu/java/rmi/rmic/Compile_jikes.java
--- /home/topic/CVS/classpath/gnu/java/rmi/rmic/Compile_jikes.java      
1969-12-31 19:00:00.000000000 -0500
+++ gnu/java/rmi/rmic/Compile_jikes.java        2003-08-18 13:40:33.000000000 
-0400
@@ -0,0 +1,56 @@
+/*
+  Copyright (c) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.rmi.rmic;
+
+/** Subclass of Compiler that can be used to invoke kjc.  */
+public class Compile_jikes extends CompilerProcess
+{
+  /** Compiler arguments to invoke kjc */
+  private static final String [] COMPILER_ARGS = 
+  {
+    "jikes"
+  };
+
+  /** Compute the command line for the process.  */
+  public String[] computeArguments (String filename)
+  {
+    return computeTypicalArguments(COMPILER_ARGS,
+                                  getDestination(),
+                                  filename);
+  }
+}
diff -urN -x CVS -x '*.am' -x '.*' 
/home/topic/CVS/classpath/gnu/java/rmi/rmic/Compile_kjc.java 
gnu/java/rmi/rmic/Compile_kjc.java
--- /home/topic/CVS/classpath/gnu/java/rmi/rmic/Compile_kjc.java        
1969-12-31 19:00:00.000000000 -0500
+++ gnu/java/rmi/rmic/Compile_kjc.java  2003-08-18 13:40:33.000000000 -0400
@@ -0,0 +1,56 @@
+/*
+  Copyright (c) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.rmi.rmic;
+
+/** Subclass of Compiler that can be used to invoke kjc.  */
+public class Compile_kjc extends CompilerProcess
+{
+  /** Compiler arguments to invoke kjc */
+  private static final String [] COMPILER_ARGS = 
+  {
+    "kjc"
+  };
+
+  /** Compute the command line for the process.  */
+  public String[] computeArguments (String filename)
+  {
+    return computeTypicalArguments(COMPILER_ARGS,
+                                  getDestination(),
+                                  filename);
+  }
+}
diff -urN -x CVS -x '*.am' -x '.*' 
/home/topic/CVS/classpath/gnu/java/rmi/rmic/Compiler.java 
gnu/java/rmi/rmic/Compiler.java
--- /home/topic/CVS/classpath/gnu/java/rmi/rmic/Compiler.java   2002-01-22 
17:26:57.000000000 -0500
+++ gnu/java/rmi/rmic/Compiler.java     2003-08-18 13:40:33.000000000 -0400
@@ -68,6 +68,12 @@
     return null;
   }
 
+  /** Get the directory where output files will be put.  */
+  public String getDestination ()
+  {
+    return dest;
+  }
+
   /** Set the directory where output files will be put.  */
   public void setDestination (String dest)
   {
diff -urN -x CVS -x '*.am' -x '.*' 
/home/topic/CVS/classpath/gnu/java/rmi/rmic/CompilerProcess.java 
gnu/java/rmi/rmic/CompilerProcess.java
--- /home/topic/CVS/classpath/gnu/java/rmi/rmic/CompilerProcess.java    
2002-01-22 17:26:57.000000000 -0500
+++ gnu/java/rmi/rmic/CompilerProcess.java      2003-08-18 13:40:33.000000000 
-0400
@@ -37,6 +37,8 @@
 
 package gnu.java.rmi.rmic;
 
+import java.io.InputStream;
+
 /** Subclass of Compiler that can be subclassed to invoke a process to
  * do its work.  */
 public abstract class CompilerProcess extends Compiler
@@ -44,12 +46,58 @@
   /** This is used to compute the command line for the process.  */
   public abstract String[] computeArguments (String filename);
 
+  /** This is used to compute the command line for the process.
+   *  Most compilers typically arrange their arguments as in 
+   *  <compiler name and arguments> <optional destination> <filename>.
+   *  This method builds an argument array out that. It should be used
+   * to define computeArguments for those compilers that follow the
+   * argument convention described above.
+   */
+  public static String[] computeTypicalArguments (String[] compilerArgs, 
String destination, String filename) 
+  {
+    /* length of compiler specific arguments */
+    final int len = compilerArgs.length;
+    /* length of returned array of arguments */
+    final int arglen = len + (destination == null ? 0 : 2) + 1;
+
+    /* Allocate String array for computed arguments. */
+    String [] args = new String[arglen];
+
+    /* Fill in compiler arguments. */
+    System.arraycopy(compilerArgs, 0, args, 0, len);
+
+    /* Fill in destination argument if necessary. */
+    if (destination != null) {
+      args[len] = "-d";
+      args[len + 1] = destination;
+    }
+
+    /* Fill in filename */
+    args[arglen - 1] = filename;
+
+    return args;
+  }
+
   public void compile (String name) throws Exception
   {
     String[] args = computeArguments (name);
     Process p = Runtime.getRuntime ().exec (args);
-    // FIXME: probably should collect compiler output here and then
-    // put it into the exception message.
+
+    /* Print compiler output to System.out. */
+    InputStream procin = p.getInputStream();
+    for (int ch = procin.read(); ch != -1; ch = procin.read()) {
+           System.out.print((char) ch);
+    }
+
+    /* Collect compiler error output in a buffer.
+     * If compilation fails, it will be used for an error message.
+     */
+    StringBuffer stderr = new StringBuffer();
+    InputStream procerr = p.getErrorStream();
+    for (int ch = procerr.read(); ch != -1; ch = procerr.read()) {
+           stderr.append((char) ch);
+    }
+
     int result;
     while (true)
       {
@@ -65,7 +113,8 @@
     if (result != 0)
       {
        // FIXME: wrong exception class.
-       throw new Exception ("compiler exited with status: " + result);
+       throw new Exception ("compiler exited with status: " + result,
+                            new RMICException(stderr.toString()));
       }
   }
 }
diff -urN -x CVS -x '*.am' -x '.*' 
/home/topic/CVS/classpath/gnu/java/rmi/rmic/RMICException.java 
gnu/java/rmi/rmic/RMICException.java
--- /home/topic/CVS/classpath/gnu/java/rmi/rmic/RMICException.java      
1969-12-31 19:00:00.000000000 -0500
+++ gnu/java/rmi/rmic/RMICException.java        2003-08-18 13:40:33.000000000 
-0400
@@ -0,0 +1,66 @@
+/*
+  Copyright (c) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.rmi.rmic;
+
+/**
+ * Thrown by the underlying compiler used by RMIC when it fails to compile a 
file.
+ *
+ * @author Dalibor Topic <address@hidden>
+ */
+
+public class RMICException extends Exception {
+       /**
+        * Create an exception with a message. The cause remains uninitialized.
+        *
+        * @param s the message string
+        * @see #initCause(Throwable)
+        */
+       public RMICException(String message) {
+               super(message);
+       }
+
+       /**
+        * Create an exception with a message and a cause.
+        *
+        * @param s the message string
+        * @param cause the cause of this exception
+        */
+       public RMICException(String message, Throwable cause) {
+               super(message, cause);
+       }
+}
diff -urN -x CVS -x '*.am' -x '.*' 
/home/topic/CVS/classpath/gnu/java/rmi/rmic/RMIC.java 
gnu/java/rmi/rmic/RMIC.java
--- /home/topic/CVS/classpath/gnu/java/rmi/rmic/RMIC.java       2003-08-12 
15:58:20.000000000 -0400
+++ gnu/java/rmi/rmic/RMIC.java 2003-08-18 13:40:33.000000000 -0400
@@ -47,6 +47,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Arrays;
+import java.util.Set;
 
 import gnu.java.rmi.server.RMIHashes;
 
@@ -61,7 +62,7 @@
 private boolean need12Stubs = true;
 private boolean compile = true;
 private boolean verbose;
-private String destination = "";
+private String destination;
 
 private PrintWriter out;
 private TabbedWriter ctrl;
@@ -102,7 +103,7 @@
                        if (verbose) {
                                System.out.println("[Processing class " + 
args[i] + ".class]");
                        }
-                       processClass(args[i]);
+                       processClass(args[i].replace(File.separatorChar, '.'));
                }
                catch (Exception e) {
                        exception = e;
@@ -123,15 +124,15 @@
                generateSkel();
        }
        if (compile) {
-               compile(stubname + ".java");
+               compile(stubname.replace('.', File.separatorChar) + ".java");
                if (need11Stubs) {
-                       compile(skelname + ".java");
+                       compile(skelname.replace('.', File.separatorChar) + 
".java");
                }
        }
        if (!keep) {
-               (new File(stubname + ".java")).delete();
+               (new File(stubname.replace('.', File.separatorChar) + 
".java")).delete();
                if (need11Stubs) {
-                       (new File(skelname + ".java")).delete();
+                       (new File(skelname.replace('.', File.separatorChar) + 
".java")).delete();
                }
        }
        return (true);
@@ -194,12 +195,15 @@
 }
 
 private void findClass() throws ClassNotFoundException {
-       clazz = Class.forName(fullclassname);
+       clazz = Class.forName(fullclassname, true, 
ClassLoader.getSystemClassLoader());
 }
 
 private void generateStub() throws IOException {
-       stubname = classname + "_Stub";
-       ctrl = new TabbedWriter(new FileWriter(destination + File.separator + 
stubname + ".java"));
+       stubname = fullclassname + "_Stub";
+       String stubclassname = classname + "_Stub";
+       ctrl = new TabbedWriter(new FileWriter((destination == null ? "" : 
destination + File.separator)
+                                              + stubname.replace('.', 
File.separatorChar)
+                                              + ".java"));
        out = new PrintWriter(ctrl);
 
        if (verbose) {
@@ -214,20 +218,32 @@
                out.println();
        }
 
-       out.print("public final class " + stubname);
+       out.print("public final class " + stubclassname);
        ctrl.indent();
        out.println("extends java.rmi.server.RemoteStub");
        
-       // Output interfaces we implement
+       // Output interfaces we implement
        out.print("implements ");
-       Class[] ifaces = clazz.getInterfaces(); 
-       for (int i = 0; i < ifaces.length; i++) {
-               out.print(ifaces[i].getName());
-               if (i+1 < ifaces.length) {
+       /* Scan implemented interfaces, and only print remote interfaces. */ 
+        Class[] ifaces = clazz.getInterfaces(); 
+       Set remoteIfaces = new HashSet();
+        for (int i = 0; i < ifaces.length; i++) {
+               Class iface = ifaces[i];
+               if (java.rmi.Remote.class.isAssignableFrom(iface)) {
+                       remoteIfaces.add(iface);
+               }
+       }
+       Iterator iter = remoteIfaces.iterator();
+       while (iter.hasNext()) {
+               /* Print remote interface. */
+               Class iface = (Class) iter.next();
+               out.print(iface.getName());
+
+               /* Print ", " if more remote interfaces follow. */
+               if (iter.hasNext()) {
                        out.print(", ");
                }
        }
-
        ctrl.unindent();
        out.print("{");
        ctrl.indent();
@@ -330,7 +346,7 @@
 
        // Constructors
        if (need11Stubs) {
-               out.print("public " + stubname + "() {");
+               out.print("public " + stubclassname + "() {");
                ctrl.indent();
                out.print("super();");
                ctrl.unindent();
@@ -338,7 +354,7 @@
        }
 
        if (need12Stubs) {
-               out.print("public " + stubname + "(java.rmi.server.RemoteRef 
ref) {");
+               out.print("public " + stubclassname + 
"(java.rmi.server.RemoteRef ref) {");
                ctrl.indent();
                out.print("super(ref);");
                ctrl.unindent();
@@ -619,8 +635,11 @@
 }
 
 private void generateSkel() throws IOException {
-       skelname = classname + "_Skel";
-       ctrl = new TabbedWriter(new FileWriter(destination + File.separator + 
skelname + ".java"));
+       skelname = fullclassname + "_Skel";
+       String skelclassname = classname + "_Skel";
+       ctrl = new TabbedWriter(new FileWriter((destination == null ? "" : 
destination + File.separator)
+                                              + skelname.replace('.', 
File.separatorChar)
+                                              + ".java"));
        out = new PrintWriter(ctrl);
 
        if (verbose) {
@@ -635,7 +654,7 @@
                out.println();
        }
 
-       out.print("public final class " + skelname);
+       out.print("public final class " + skelclassname);
        ctrl.indent();
        
        // Output interfaces we implement

reply via email to

[Prev in Thread] Current Thread [Next in Thread]