1
0
mirror of https://github.com/jht5945/buildj.git synced 2025-12-29 18:30:05 +08:00

support jdk and openjdk download, update version

This commit is contained in:
2019-07-28 23:32:48 +08:00
parent 7397db60bc
commit 02686e514d
3 changed files with 15 additions and 12 deletions

2
Cargo.lock generated
View File

@@ -79,7 +79,7 @@ dependencies = [
[[package]] [[package]]
name = "buildj" name = "buildj"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"dirs 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"json 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)", "json 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "buildj" name = "buildj"
version = "0.1.0" version = "0.1.1"
authors = ["Hatter Jiang <jht5945@gmail.com>"] authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018" edition = "2018"

View File

@@ -20,6 +20,7 @@ use super::{
}; };
const OPENJDK_MACOS: &str = "openjdk-osx"; const OPENJDK_MACOS: &str = "openjdk-osx";
const JDK_LINUX: &str = "jdk-linux";
const OPENJDK_LINUX: &str = "openjdk-linux"; const OPENJDK_LINUX: &str = "openjdk-linux";
pub const LOCAL_JAVA_HOME_BASE_DIR: &str = ".jssp/jdks"; pub const LOCAL_JAVA_HOME_BASE_DIR: &str = ".jssp/jdks";
@@ -41,25 +42,27 @@ pub fn get_cloud_java(version: &str) -> bool {
if ! is_macos_or_linux() { if ! is_macos_or_linux() {
return false; return false;
} }
let cloud_java_name = if is_macos() { let cloud_java_names = if is_macos() {
OPENJDK_MACOS vec![OPENJDK_MACOS]
} else if is_linux() { } else if is_linux() {
OPENJDK_LINUX vec![JDK_LINUX, OPENJDK_LINUX]
} else { } else {
"" vec![]
}; };
let local_java_home_base_dir = match local_util::get_user_home_dir(LOCAL_JAVA_HOME_BASE_DIR) { let local_java_home_base_dir = match local_util::get_user_home_dir(LOCAL_JAVA_HOME_BASE_DIR) {
Err(_) => return false, Err(_) => return false,
Ok(o) => o, Ok(o) => o,
}; };
for i in 0..cloud_java_names.len() {
let cloud_java_name = cloud_java_names[i];
match tool::get_and_extract_tool_package(&local_java_home_base_dir, false, cloud_java_name, version, false) { match tool::get_and_extract_tool_package(&local_java_home_base_dir, false, cloud_java_name, version, false) {
Err(err) => { Err(_) => (),
print_message(MessageType::ERROR, &format!("Get java failed, version: {}, error: {}", version, err)); Ok(_) => return true,
return false;
},
Ok(_) => true,
} }
} }
print_message(MessageType::ERROR, &format!("Get java failed, version: {}", version));
false
}
pub fn get_macos_java_home(version: &str) -> Option<String> { pub fn get_macos_java_home(version: &str) -> Option<String> {
if ! is_macos() { if ! is_macos() {