changeset 14914:a6bd486b1b44

Extend JavaConfig bootclasspath detection to detect extdirs and endorseddirs
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 01 Apr 2014 16:21:49 +0200
parents 2d1cc640512c
children 32121774dfea
files mxtool/ClasspathDump.java mxtool/mx.py
diffstat 2 files changed, 32 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mxtool/ClasspathDump.java	Tue Apr 01 16:21:49 2014 +0200
@@ -0,0 +1,9 @@
+public class ClasspathDump {
+    public static void main(String[] args) {
+        System.out.print(System.getProperty("sun.boot.class.path"));
+        System.out.print("|");
+        System.out.print(System.getProperty("java.ext.dirs"));
+        System.out.print("|");
+        System.out.print(System.getProperty("java.endorsed.dirs"));
+    }
+}
\ No newline at end of file
--- a/mxtool/mx.py	Fri Mar 28 10:46:48 2014 +0100
+++ b/mxtool/mx.py	Tue Apr 01 16:21:49 2014 +0200
@@ -1422,6 +1422,16 @@
         if self.debug_port is not None:
             self.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(self.debug_port)]
 
+    def _init_classpaths(self):
+        myDir = dirname(__file__)
+        javaSource = join(myDir, 'ClasspathDump.java')
+        javaClass = join(myDir, 'ClasspathDump.class')
+        if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
+            subprocess.check_call([self.javac, '-d', myDir, javaSource])
+        self._bootclasspath, self._extdirs, self._endorseddirs = [x if x != 'null' else None for x in subprocess.check_output([self.java, '-cp', myDir, 'ClasspathDump']).split('|')]
+        if not self._bootclasspath or not self._extdirs or not self._endorseddirs:
+            warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'")
+
     def __hash__(self):
         return hash(self.jdk)
 
@@ -1441,25 +1451,19 @@
 
     def bootclasspath(self):
         if self._bootclasspath is None:
-            tmpDir = tempfile.mkdtemp()
-            try:
-                src = join(tmpDir, 'bootclasspath.java')
-                with open(src, 'w') as fp:
-                    print >> fp, """
-public class bootclasspath {
-    public static void main(String[] args) {
-        String s = System.getProperty("sun.boot.class.path");
-        if (s != null) {
-            System.out.println(s);
-        }
-    }
-}"""
-                subprocess.check_call([self.javac, '-d', tmpDir, src])
-                self._bootclasspath = subprocess.check_output([self.java, '-cp', tmpDir, 'bootclasspath'])
-            finally:
-                shutil.rmtree(tmpDir)
+            self._init_classpaths()
         return self._bootclasspath
 
+    def extdirs(self):
+        if self._extdirs is None:
+            self._init_classpaths()
+        return self._extdirs
+
+    def endorseddirs(self):
+        if self._endorseddirs is None:
+            self._init_classpaths()
+        return self._endorseddirs
+
 def check_get_env(key):
     """
     Gets an environment variable, aborting with a useful message if it is not set.
@@ -1573,10 +1577,10 @@
     if d != '' and not exists(d):
         os.makedirs(d)
 
-    # Try it with the Java tool first since it can show a progress counter
-    myDir = dirname(__file__)
 
     if not path.endswith(os.sep):
+        # Try it with the Java tool first since it can show a progress counter
+        myDir = dirname(__file__)
         javaSource = join(myDir, 'URLConnectionDownload.java')
         javaClass = join(myDir, 'URLConnectionDownload.class')
         if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):