changeset 3730:4e3851bab8d0

Added mechanism for downloading a JDK 7 if the JDK7 environment variable is not set. This only works on Linux as only it has a single tar.gz version of the JDK available from the Oracle JDK download website.
author Doug Simon <doug.simon@oracle.com>
date Fri, 16 Dec 2011 21:56:00 +0100
parents c83fdc80e217
children 71f1f6fd32f7
files mx/commands.py
diffstat 1 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mx/commands.py	Fri Dec 16 20:02:38 2011 +0100
+++ b/mx/commands.py	Fri Dec 16 21:56:00 2011 +0100
@@ -26,7 +26,7 @@
 #
 # ----------------------------------------------------------------------------------------------------
 
-import os, sys, shutil
+import os, sys, shutil, tarfile
 from os.path import join, exists, dirname, isfile, isdir
 
 graal_home = dirname(dirname(__file__))
@@ -145,8 +145,40 @@
                         jtt('threads'), 
                         jtt('hotspot')])
 
+
+def _download_and_extract_targz_jdk7(env, url, dst):
+    assert url.endswith('.tar.gz')
+    dl = join(graal_home, 'jdk7.tar.gz')
+    try:
+        if not exists(dl):
+            env.download(dl, [url])
+        tmp = join(graal_home, 'tmp')
+        if not exists(tmp):
+            os.mkdir(tmp)
+        with tarfile.open(dl, mode='r:gz') as f:
+            env.log('Extracting ' + dl)
+            f.extractall(path=tmp)
+        jdk = os.listdir(tmp)[0]
+        shutil.move(join(tmp, jdk), dst)
+        os.rmdir(tmp)
+        os.remove(dl)
+    except SystemExit:
+        env.abort('Could not download JDK7 from http://www.oracle.com/technetwork/java/javase/downloads/index.html.\n' + 
+                  'Please do this manually and install it at ' + dst + ' or set the JDK7 environment variable to the install location.')
+    
+
 def _jdk7(env, build='product', create=False):
-    jdk7 = env.check_get_env('JDK7')
+    jdk7 = os.environ.get('JDK7')
+    if jdk7 is None:
+        jdk7 = join(graal_home, 'jdk7')
+        if not exists(jdk7):
+            # Try to download it
+            if env.os == 'linux':
+                _download_and_extract_targz_jdk7(env, 'http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-x64.tar.gz', jdk7)
+            else:
+                env.abort('Download JDK7 from http://www.oracle.com/technetwork/java/javase/downloads/index.html\n' + 
+                          'and install it at ' + jdk7 + ' or set the JDK7 environment variable to the JDK7 install location.')
+        
     jre = join(jdk7, 'jre')
     if not exists(jre) or not isdir(jre):
         env.abort(jdk7 + ' does not appear to be a valid JDK directory ("jre" sub-directory is missing)')