diff options
Diffstat (limited to 'tools/gnu/classpath/tools/giop')
-rw-r--r-- | tools/gnu/classpath/tools/giop/GRMIC.java | 23 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/giop/GRMIC.txt | 24 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java | 94 |
3 files changed, 113 insertions, 28 deletions
diff --git a/tools/gnu/classpath/tools/giop/GRMIC.java b/tools/gnu/classpath/tools/giop/GRMIC.java index a372cfd66..c910d7083 100644 --- a/tools/gnu/classpath/tools/giop/GRMIC.java +++ b/tools/gnu/classpath/tools/giop/GRMIC.java @@ -104,6 +104,17 @@ public class GRMIC else HelpPrinter.printHelpAndExit(HelpPath); } + else if (c.equals("-classpath")) + { + int f = i + 1; + if (f < args.length) + { + compiler.setClassPath(args[f]); + i++; + } + else + HelpPrinter.printHelpAndExit(HelpPath); + } else if (c.charAt(0) != '-') // No more options - start of class list. { @@ -124,17 +135,7 @@ public class GRMIC if (args[i].charAt(0) != '-') { compiler.reset(); - Class c = null; - try - { - c = Thread.currentThread().getContextClassLoader().loadClass( - args[i]); - } - catch (ClassNotFoundException e) - { - System.err.println(args[i] + " class not found."); - System.exit(1); - } + Class c = compiler.loadClass(args[i]); compiler.compile(c); String packag = compiler.getPackageName().replace('.', '/'); diff --git a/tools/gnu/classpath/tools/giop/GRMIC.txt b/tools/gnu/classpath/tools/giop/GRMIC.txt index 08aaf148f..875bcdbcf 100644 --- a/tools/gnu/classpath/tools/giop/GRMIC.txt +++ b/tools/gnu/classpath/tools/giop/GRMIC.txt @@ -9,18 +9,20 @@ Please report bugs at http://www.gnu.org/software/classpath/bugs.html Usage: grmic <options> <class names> where <options> includes: - -poa Generate the Servant based ties (default) - -impl Generate the obsoleted ObjectImpl based ties - (for backward compatibility) - -nowarn Show no warnings - -nowrite Do not write any files (check for errors only) - -d <folder> Place generated files into the given folder + -poa Generate the Servant based ties (default) + -impl Generate the obsoleted ObjectImpl based ties + (for backward compatibility) + -nowarn Show no warnings + -nowrite Do not write any files (check for errors only) + -d <folder> Place generated files into the given folder + -classpath <path> Specifies the path, where to find the classes being + compiled - -help Print this help text - -v Print version - -verbose Verbose output - -force Try to generate code even if the input classes seem not - consistent with RMI specification. + -help Print this help text + -v Print version + -verbose Verbose output + -force Try to generate code even if the input classes seem not + consistent with RMI specification. and <class names> can include one or more non abstract classes that implement diff --git a/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java b/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java index 4beba1c9f..6d895a14c 100644 --- a/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java +++ b/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java @@ -23,7 +23,11 @@ package gnu.classpath.tools.giop.grmic; import gnu.classpath.tools.AbstractMethodGenerator; +import java.io.File; import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; import java.rmi.Remote; import java.rmi.RemoteException; import java.util.ArrayList; @@ -33,6 +37,7 @@ import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.Properties; +import java.util.StringTokenizer; import java.util.TreeSet; /** @@ -104,6 +109,11 @@ public class GiopRmicCompiler * Force mode - do not check the exceptions */ protected boolean force = false; + + /** + * The class loader to load the class being compiled. + */ + ClassLoader classLoader; /** * Clear data, preparing for the next compilation. @@ -116,6 +126,78 @@ public class GiopRmicCompiler methods.clear(); vars.clear(); } + + /** + * Set the class path (handle the -classpath key) + * + * @param classPath the class path to set. + */ + public void setClassPath(String classPath) + { + classLoader = Thread.currentThread().getContextClassLoader(); + StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator, + true); + ArrayList urls = new ArrayList(tok.countTokens()); + String s = null; + try + { + while (tok.hasMoreTokens()) + { + s = tok.nextToken(); + if (s.equals(File.pathSeparator)) + urls.add(new File(".").toURL()); + else + { + urls.add(new File(s).toURL()); + if (tok.hasMoreTokens()) + { + // Skip the separator. + tok.nextToken(); + // If the classpath ended with a separator, + // append the current directory. + if (! tok.hasMoreTokens()) + urls.add(new File(".").toURL()); + } + } + } + } + catch (MalformedURLException ex) + { + System.err.println("Malformed path '" + s + "' in classpath '" + + classPath + "'"); + System.exit(1); + } + URL[] u = new URL[urls.size()]; + for (int i = 0; i < u.length; i++) + { + u[i] = (URL) urls.get(i); + } + + classLoader = new URLClassLoader(u, classLoader); + } + + /** + * Loads the class with the given name (uses class path, if applicable) + * + * @param name the name of the class. + */ + public Class loadClass(String name) + { + ClassLoader loader = classLoader; + if (loader == null) + loader = Thread.currentThread().getContextClassLoader(); + try + { + return loader.loadClass(name); + } + catch (ClassNotFoundException e) + { + System.err.println(name+" not found on "+loader); + System.exit(1); + // Unreacheable code. + return null; + } + } /** * Compile the given class (the instance of Remote), generating the stub and @@ -193,12 +275,12 @@ public class GiopRmicCompiler remEx = true; break; } - if (! remEx && !force) - throw new CompilationError(m[i].getName() + ", defined in " - + c.getName() - + ", does not throw " - + RemoteException.class.getName()); - } + } + if (! remEx && !force) + throw new CompilationError(m[i].getName() + ", defined in " + + c.getName() + + ", does not throw " + + RemoteException.class.getName()); AbstractMethodGenerator mm = createMethodGenerator(m[i]); methods.add(mm); } |