You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/01/03 11:46:16 UTC

svn commit: r492098 - /harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javac/Compiler.java

Author: tellison
Date: Wed Jan  3 02:46:15 2007
New Revision: 492098

URL: http://svn.apache.org/viewvc?view=rev&rev=492098
Log:
Search for the ECJ jar alongside the tools.jar if it is not in the local dir.

Modified:
    harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javac/Compiler.java

Modified: harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javac/Compiler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javac/Compiler.java?view=diff&rev=492098&r1=492097&r2=492098
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javac/Compiler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/javac/Compiler.java Wed Jan  3 02:46:15 2007
@@ -88,10 +88,6 @@
      * Initialize our local variables. Called during type construction.
      */
     protected void initialize() {
-        if (!new File(ECJ_JAR_FILE).exists()) {
-            System.err.println("javac requires the compiler jar \""
-                    + ECJ_JAR_FILE + "\" to run");
-        }
         try {
             initializeMainClass();
             initializeInstance();
@@ -139,9 +135,35 @@
             IllegalArgumentException, InstantiationException,
             IllegalAccessException, InvocationTargetException {
 
+        URLClassLoader loader;
+
+        // Find the ECJ JAR file
+        if (new File(ECJ_JAR_FILE).exists()) {
+            // It is in the working directory
+            URL ecjURL = new URL("file:" + ECJ_JAR_FILE);
+            loader = new URLClassLoader(new URL[] { ecjURL });
+        } else {
+            // Assume it is next to the tools.jar
+            URLClassLoader bogusLoader = new URLClassLoader(new URL[] {});
+            URLClassLoader parentLoader = (URLClassLoader) bogusLoader
+                    .getParent();
+            URL[] uls = parentLoader.getURLs();
+            URL ecjURL = null;
+            for (int i = 0; i < uls.length; i++) {
+                URL l = uls[i];
+                String filename = new File(l.getFile()).getName();
+                if (filename.equals("tools.jar")) {
+                    ecjURL = new URL(l, ECJ_JAR_FILE);
+                    break;
+                }
+            }
+            if (ecjURL == null) {
+                throw new RuntimeException("Cannot find file " + ECJ_JAR_FILE);
+            }
+            loader = new URLClassLoader(new URL[] { ecjURL });
+        }
+
         // Load the ECJ main class
-        URL ecjURL = new URL("file:" + ECJ_JAR_FILE);
-        URLClassLoader loader = new URLClassLoader(new URL[] { ecjURL });
         ecjCompilerClass = loader.loadClass(MAIN_CLASS_NAME);
     }
 
@@ -153,7 +175,8 @@
             NoSuchMethodException {
         staticMainMth = ecjCompilerClass.getMethod("main",
                 new Class[] { String[].class });
-        printUsageMth = ecjCompilerClass.getMethod("printUsage", (Class[])null);
+        printUsageMth = ecjCompilerClass
+                .getMethod("printUsage", (Class[]) null);
     }
 
     /**