diff --git a/README.md b/README.md index 8285d87..e644f47 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ version control. ## Support -javaenv currently only support Mac OS X. Linux will be supported. Support for -Windows should be doable. +javaenv supports Linux and Mac OS X. Support for Windows should be doable but +is not on my roadmap. ## Installation @@ -106,7 +106,7 @@ List all versions available for installation. Print the value for `JAVA_HOME` for the active version. The version can either be provided to the command, or read from a `.javaversion file`. The command is -useful when setting `JAVA_HOME` for tools using it, e.g. Maven. +useful for tools using `JAVA_HOME`, e.g. Maven. ``` export JAVA_HOME=$(javaenv home) @@ -122,6 +122,5 @@ so this requires you to trust your javaenv installation. * Add support for automatically shimming Java command line tools * Add all released and still available versions -* Add support for Linux * Add support for building Docker images * Add direct support for setting Java version for Maven diff --git a/javaenv b/javaenv index 80dc4fb..6f3a98d 100755 --- a/javaenv +++ b/javaenv @@ -18,42 +18,92 @@ JAVAENV_HOME = os.environ.get("JAVAENV_HOME", os.path.expanduser("~/.javaenv/")) VERSIONS_DIR = os.path.join(JAVAENV_HOME, "versions/") DEFAULT_VERSION_FILE = os.path.join(JAVAENV_HOME, "version") +OS = sys.platform VERSIONS = { "adoptopenjdk-8u222": { - "url": "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u222-b10/OpenJDK8U-jdk_x64_mac_hotspot_8u222b10.tar.gz", - "home_dir": "jdk8u222-b10/Contents/Home/", - "sha256": "9605fd00d2960934422437f601c7a9a1c5537309b9199d5bc75f84f20cd29a76" + "darwin": { + "url": "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u222-b10/OpenJDK8U-jdk_x64_mac_hotspot_8u222b10.tar.gz", + "home_dir": "jdk8u222-b10/Contents/Home", + "sha256": "9605fd00d2960934422437f601c7a9a1c5537309b9199d5bc75f84f20cd29a76" + }, + "linux": { + "url": "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u222-b10/OpenJDK8U-jdk_x64_linux_hotspot_8u222b10.tar.gz", + "home_dir": "jdk8u222-b10", + "sha256": "37356281345b93feb4212e6267109b4409b55b06f107619dde4960e402bafa77" + }, }, "corretto-11.0.4.11.1": { - "url": "https://d3pxv6yz143wms.cloudfront.net/11.0.4.11.1/amazon-corretto-11.0.4.11.1-macosx-x64.tar.gz", - "home_dir": "amazon-corretto-11.jdk/Contents/Home/", - "md5": "44bb1e1e6368e1b0f994f5e899b0adc9" + "darwin": { + "url": "https://d3pxv6yz143wms.cloudfront.net/11.0.4.11.1/amazon-corretto-11.0.4.11.1-macosx-x64.tar.gz", + "home_dir": "amazon-corretto-11.jdk/Contents/Home", + "md5": "44bb1e1e6368e1b0f994f5e899b0adc9" + }, + "linux": { + "url": "https://d3pxv6yz143wms.cloudfront.net/11.0.4.11.1/amazon-corretto-11.0.4.11.1-linux-x64.tar.gz", + "home_dir": "amazon-corretto-11.0.4.11.1-linux-x64", + "md5": "4bbcd5e6d721fef56e46b3bfa8631c1c" + } }, "openjdk-9.0.4": { - "url": "https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_osx-x64_bin.tar.gz", - "home_dir": "jdk-9.0.4.jdk/Contents/Home/", - "sha256": "66415406716fc42cff36e2d74ae991d46c42b3cf317b0425c7bf67697c616716" + "darwin": { + "url": "https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_osx-x64_bin.tar.gz", + "home_dir": "jdk-9.0.4.jdk/Contents/Home", + "sha256": "66415406716fc42cff36e2d74ae991d46c42b3cf317b0425c7bf67697c616716" + }, + "linux": { + "url": "https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz", + "home_dir": "jdk-9.0.4", + "sha256": "39362fb9bfb341fcc802e55e8ea59f4664ca58fd821ce956d48e1aa4fb3d2dec" + } }, "openjdk-11.0.1": { - "url": "https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_osx-x64_bin.tar.gz", - "home_dir": "jdk-11.0.1.jdk/Contents/Home/", - "sha256": "fa07eee08fa0f3de541ee1770de0cdca2ae3876f3bd78c329f27e85c287cd070" + "darwin": { + "url": "https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_osx-x64_bin.tar.gz", + "home_dir": "jdk-11.0.1.jdk/Contents/Home", + "sha256": "fa07eee08fa0f3de541ee1770de0cdca2ae3876f3bd78c329f27e85c287cd070" + }, + "linux": { + "url": "https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz", + "home_dir": "jdk-11.0.1", + "sha256": "7a6bb980b9c91c478421f865087ad2d69086a0583aeeb9e69204785e8e97dcfd" + } }, "openjdk-11.0.2": { - "url": "https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz", - "home_dir": "jdk-11.0.2.jdk/Contents/Home/", - "sha256": "f365750d4be6111be8a62feda24e265d97536712bc51783162982b8ad96a70ee" + "darwin": { + "url": "https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz", + "home_dir": "jdk-11.0.2.jdk/Contents/Home", + "sha256": "f365750d4be6111be8a62feda24e265d97536712bc51783162982b8ad96a70ee" + }, + "linux": { + "url": "https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz", + "home_dir": "jdk-11.0.2", + "sha256": "99be79935354f5c0df1ad293620ea36d13f48ec3ea870c838f20c504c9668b57" + } }, "openjdk-12": { - "url": "https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_osx-x64_bin.tar.gz", - "home_dir": "jdk-12.jdk/Contents/Home/", - "sha256": "52164a04db4d3fdfe128cfc7b868bc4dae52d969f03d53ae9d4239fe783e1a3a" + "darwin": { + "url": "https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_osx-x64_bin.tar.gz", + "home_dir": "jdk-12.jdk/Contents/Home", + "sha256": "52164a04db4d3fdfe128cfc7b868bc4dae52d969f03d53ae9d4239fe783e1a3a" + }, + "linux": { + "url": "https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_linux-x64_bin.tar.gz", + "home_dir": "jdk-12", + "sha256": "b43bc15f4934f6d321170419f2c24451486bc848a2179af5e49d10721438dd56" + } }, - "oracle-12.0.1": { - "url": "https://download.oracle.com/java/GA/jdk12.0.1/69cfe15208a647278a19ef0990eea691/12/GPL/openjdk-12.0.1_osx-x64_bin.tar.gz", - "home_dir": "jdk-12.0.1.jdk/Contents/Home/", - "sha256": "cba6f42f82496f62c51fb544e243d440984d442bdc906550a30428d8be6189e5" + "oracle-12.0.2": { + "darwin": { + "url": "https://download.oracle.com/java/GA/jdk12.0.2/e482c34c86bd4bf8b56c0b35558996b9/10/GPL/openjdk-12.0.2_osx-x64_bin.tar.gz", + "home_dir": "jdk-12.0.2.jdk/Contents/Home", + "sha256": "675a739ab89b28a8db89510f87cb2ec3206ec6662fb4b4996264c16c72cdd2a1" + }, + "linux": { + "url": "https://download.oracle.com/java/GA/jdk12.0.2/e482c34c86bd4bf8b56c0b35558996b9/10/GPL/openjdk-12.0.2_linux-x64_bin.tar.gz", + "home_dir": "jdk-12.0.2", + "sha256": "75998a6ebf477467aa5fb68227a67733f0e77e01f737d4dfbc01e617e59106ed" + } }, } # yapf: disable @@ -67,6 +117,9 @@ def debug(msg): eprint(msg) +def get_version_blob(version): + return VERSIONS[version][OS] + def make_versions_dir(): if not os.path.exists(VERSIONS_DIR): os.makedirs(VERSIONS_DIR) @@ -94,7 +147,7 @@ def get_installed_versions(): def get_download_url(version): debug("getting download url for " + version) - return VERSIONS[version]["url"] + return get_version_blob(version)["url"] def is_version_installed(version): @@ -104,18 +157,19 @@ def is_version_installed(version): def get_java_home(version): if is_version_installed(version): - return make_version_dir(version) + VERSIONS[version]["home_dir"] + return os.path.join(make_version_dir(version), get_version_blob(version)["home_dir"]) else: raise Exception("No installed versions of Java matched " + version) def verify_hash(version, path): - if "sha256" in VERSIONS[version]: + blob = get_version_blob(version) + if "sha256" in blob: hash = hashlib.sha256() - expected_hash = VERSIONS[version]["sha256"] + expected_hash = blob["sha256"] else: hash = hashlib.md5() - expected_hash = VERSIONS[version]["md5"] + expected_hash = blob["md5"] with open(path, 'rb') as f: while True: @@ -266,7 +320,7 @@ if __name__ == "__main__": if bn == "javaenv": javaenv() else: - cmd = get_java_home(get_version(None)) + "bin/" + bn + cmd = os.path.join(get_java_home(get_version(None)), "bin/", bn) args = [cmd] + sys.argv[1:] p = subprocess.run(args) sys.exit(p.returncode)