From e4298045be855c12f19678388db4e2521db93bbb Mon Sep 17 00:00:00 2001 From: Anusikh <56106489+anusikh@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:14:50 +0530 Subject: [PATCH] feat: added graalvm support (#13) * added graalvm support * macos fix for graalvm * patch upgrade --------- Co-authored-by: Anusikh Panda --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands/usev.rs | 19 +++++++++---- src/constants/versions.rs | 56 ++++++++++++++++++++++++++++++++++----- src/utils/file_utils.rs | 7 +++++ 5 files changed, 73 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55915b0..a1df872 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -187,7 +187,7 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "jvem" -version = "0.2.0" +version = "0.2.2" dependencies = [ "clap", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 4c45305..e983108 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jvem" -version = "0.2.1" +version = "0.2.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/commands/usev.rs b/src/commands/usev.rs index bc702e4..5e6a6b5 100644 --- a/src/commands/usev.rs +++ b/src/commands/usev.rs @@ -86,17 +86,26 @@ pub async fn usev_util(name: String) { #[cfg(target_os = "macos")] pub async fn usev_util(name: String) { + use crate::utils::file_utils::check_path_exists; + let _ = run_command("rm", vec!["-rf", &format!("{}/.jvem/java", get_home_dir())]); + // check if Contents folder present inside extracted files (required for Graal VM support) + let con_path = format!("{}/Contents", get_installation_dir(&name)); + let if_contents_exists = check_path_exists(&con_path); + let final_path; + + if if_contents_exists == true { + final_path = format!("{}/Contents/Home", get_installation_dir(&name)); + } else { + final_path = format!("{}/Home", get_installation_dir(&name)); + }; + let output = run_command( "sh", vec![ "-c", - &format!( - "ln -s {} {}/.jvem/java", - format!("{}/Contents/Home", get_installation_dir(&name)), - get_home_dir() - ), + &format!("ln -s {} {}/.jvem/java", final_path, get_home_dir()), ], ); diff --git a/src/constants/versions.rs b/src/constants/versions.rs index 733d111..e6e7122 100644 --- a/src/constants/versions.rs +++ b/src/constants/versions.rs @@ -1,8 +1,9 @@ pub mod constants { pub const LINUX_ARTIFACT: &str = "jvem.tar.gz"; pub const WINDOWS_ARTIFACT: &str = "jvem.zip"; - pub const AVAILABLE_VERSIONS: &str = "ZULU8,ZULU11,ZULU17,ZULU21,OPENJDK11,OPENJDK17,OPENJDK21"; - + pub const AVAILABLE_VERSIONS: &str = + "ZULU8,ZULU11,ZULU17,ZULU21,OPENJDK11,OPENJDK17,OPENJDK21,GRAAL17,GRAAL21,GRAAL22"; + // zulu jdk's pub const ZULU21_LINUX: &str = "https://cdn.azul.com/zulu/bin/zulu21.32.17-ca-jdk21.0.2-linux_x64.tar.gz"; @@ -24,7 +25,7 @@ pub mod constants { pub const ZULU8_WINDOWS: &str ="https://cdn.azul.com/zulu/bin/zulu8.76.0.17-ca-jdk8.0.402-win_x64.zip?_gl=1*i45ppb*_ga*MTg0NTAyMjU0LjE3MDg3MDUwMzU.*_ga_42DEGWGYD5*MTcwODcwNTAzNS4xLjEuMTcwODcwNTIxMy4xNy4wLjA."; pub const ZULU8_MACOS_AARCH64: &str = "https://cdn.azul.com/zulu/bin/zulu8.76.0.17-ca-jdk8.0.402-macosx_aarch64.tar.gz?_gl=1*18knssl*_ga*MTU1MDc4NTgxMS4xNzA5NzU3MDc2*_ga_42DEGWGYD5*MTcwOTc1NzA3NS4xLjEuMTcwOTc1ODA1MS41MC4wLjA."; pub const ZULU8_MACOS_X86_64: &str = "https://cdn.azul.com/zulu/bin/zulu8.76.0.17-ca-jdk8.0.402-macosx_x64.tar.gz?_gl=1*18knssl*_ga*MTU1MDc4NTgxMS4xNzA5NzU3MDc2*_ga_42DEGWGYD5*MTcwOTc1NzA3NS4xLjEuMTcwOTc1ODA1MS41MC4wLjA."; - + // openjdk jdk's pub const OPENJDK21_LINUX: &str = "https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_linux-x64_bin.tar.gz"; pub const OPENJDK21_WINDOWS: &str = "https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_windows-x64_bin.zip"; @@ -34,9 +35,38 @@ pub mod constants { pub const OPENJDK17_WINDOWS: &str = "https://download.java.net/java/GA/jdk17.0.1/2a2082e5a09d4267845be086888add4f/12/GPL/openjdk-17.0.1_windows-x64_bin.zip"; pub const OPENJDK17_MACOS_AARCH64: &str = "https://download.java.net/java/GA/jdk17.0.1/2a2082e5a09d4267845be086888add4f/12/GPL/openjdk-17.0.1_macos-aarch64_bin.tar.gz"; pub const OPENJDK17_MACOS_X86_64: &str = "https://download.java.net/java/GA/jdk17.0.1/2a2082e5a09d4267845be086888add4f/12/GPL/openjdk-17.0.1_macos-x64_bin.tar.gz"; - pub const OPENJDK11_LINUX: &str = "https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz"; - pub const OPENJDK11_WINDOWS: &str = "https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_windows-x64_bin.zip"; - pub const OPENJDK11_MACOS_X86_64: &str = "https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz"; + pub const OPENJDK11_LINUX: &str = + "https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz"; + pub const OPENJDK11_WINDOWS: &str = + "https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_windows-x64_bin.zip"; + pub const OPENJDK11_MACOS_X86_64: &str = + "https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz"; + + // graalvm jdk's + pub const GRAAL22_LINUX: &str = + "https://download.oracle.com/graalvm/22/latest/graalvm-jdk-22_linux-x64_bin.tar.gz"; + pub const GRAAL22_WINDOWS: &str = + "https://download.oracle.com/graalvm/22/latest/graalvm-jdk-22_windows-x64_bin.zip"; + pub const GRAAL22_MACOS_AARCH64: &str = + "https://download.oracle.com/graalvm/22/latest/graalvm-jdk-22_macos-aarch64_bin.tar.gz"; + pub const GRAAL22_MACOS_X86_64: &str = + "https://download.oracle.com/graalvm/22/latest/graalvm-jdk-22_macos-x64_bin.tar.gz"; + pub const GRAAL21_LINUX: &str = + "https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-x64_bin.tar.gz"; + pub const GRAAL21_WINDOWS: &str = + "https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_windows-x64_bin.zip"; + pub const GRAAL21_MACOS_AARCH64: &str = + "https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_macos-aarch64_bin.tar.gz"; + pub const GRAAL21_MACOS_X86_64: &str = + "https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_macos-x64_bin.tar.gz"; + pub const GRAAL17_LINUX: &str = + "https://download.oracle.com/graalvm/17/latest/graalvm-jdk-17_linux-x64_bin.tar.gz"; + pub const GRAAL17_WINDOWS: &str = + "https://download.oracle.com/graalvm/17/latest/graalvm-jdk-17_windows-x64_bin.zip"; + pub const GRAAL17_MACOS_AARCH64: &str = + "https://download.oracle.com/graalvm/17/latest/graalvm-jdk-17_macos-aarch64_bin.tar.gz"; + pub const GRAAL17_MACOS_X86_64: &str = + "https://download.oracle.com/graalvm/17/latest/graalvm-jdk-17_macos-x64_bin.tar.gz"; pub fn get_constant(key: &str) -> Option<&'static str> { match key { @@ -75,6 +105,20 @@ pub mod constants { "OPENJDK11_WINDOWS" => Some(OPENJDK11_WINDOWS), "OPENJDK11_MACOS_X86_64" => Some(OPENJDK11_MACOS_X86_64), + // graalvm jdk's + "GRAAL22_LINUX" => Some(GRAAL22_LINUX), + "GRAAL22_WINDOWS" => Some(GRAAL22_WINDOWS), + "GRAAL22_MACOS_AARCH64" => Some(GRAAL22_MACOS_AARCH64), + "GRAAL22_MACOS_X86_64" => Some(GRAAL22_MACOS_X86_64), + "GRAAL21_LINUX" => Some(GRAAL21_LINUX), + "GRAAL21_WINDOWS" => Some(GRAAL21_WINDOWS), + "GRAAL21_MACOS_AARCH64" => Some(GRAAL21_MACOS_AARCH64), + "GRAAL21_MACOS_X86_64" => Some(GRAAL21_MACOS_X86_64), + "GRAAL17_LINUX" => Some(GRAAL17_LINUX), + "GRAAL17_WINDOWS" => Some(GRAAL17_WINDOWS), + "GRAAL17_MACOS_AARCH64" => Some(GRAAL17_MACOS_AARCH64), + "GRAAL17_MACOS_X86_64" => Some(GRAAL17_MACOS_X86_64), + _ => None, } } diff --git a/src/utils/file_utils.rs b/src/utils/file_utils.rs index fccdb3e..a45bb20 100644 --- a/src/utils/file_utils.rs +++ b/src/utils/file_utils.rs @@ -60,6 +60,13 @@ pub fn check_jdk_exists(name: &str) -> bool { } } +pub fn check_path_exists(path: &str) -> bool { + match Path::new(&path).exists() { + true => true, + false => false, + } +} + pub fn create_java_dir(name: &str) { let new_dir_path = format!("{}/.jvem/{}", *HOME_DIR, name); fs::create_dir_all(new_dir_path).unwrap();