mirror of
https://github.com/jht5945/buildj.git
synced 2025-12-29 10:20:04 +08:00
chore: code style
This commit is contained in:
@@ -106,17 +106,17 @@ pub fn find_build_json_in_parents() -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_build_json() -> Option<String> {
|
pub fn find_build_json() -> Option<String> {
|
||||||
match find_build_json_in_current() {
|
if let Some(p) = find_build_json_in_current() {
|
||||||
Some(p) => Some(p),
|
return Some(p);
|
||||||
None => match find_build_json_in_parents() {
|
}
|
||||||
Some(p) => {
|
match find_build_json_in_parents() {
|
||||||
warning!("Cannot find {} in current dir, find: {}", BUILD_JSON, p);
|
Some(p) => {
|
||||||
Some(p)
|
warning!("Cannot find {} in current dir, find: {}", BUILD_JSON, p);
|
||||||
},
|
Some(p)
|
||||||
None => {
|
},
|
||||||
failure!("Cannot find {}", BUILD_JSON);
|
None => {
|
||||||
None
|
failure!("Cannot find {}", BUILD_JSON);
|
||||||
},
|
None
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/http.rs
20
src/http.rs
@@ -10,18 +10,14 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
|
|||||||
let mut response = reqwest::get(url)?;
|
let mut response = reqwest::get(url)?;
|
||||||
let header_content_length: i64 = match response.headers().get("content-length") {
|
let header_content_length: i64 = match response.headers().get("content-length") {
|
||||||
None => -1_i64, Some(len_value) => {
|
None => -1_i64, Some(len_value) => {
|
||||||
let len_str = match len_value.to_str() {
|
let len_str = len_value.to_str().unwrap_or_else(|err| {
|
||||||
Ok(len_str) => len_str, Err(err) => {
|
warning!("Get content length for {:?}, error: {}", len_value, err);
|
||||||
warning!("Get content length for {:?}, error: {}", len_value, err);
|
"-1"
|
||||||
"-1"
|
});
|
||||||
},
|
len_str.parse::<i64>().unwrap_or_else(|err| {
|
||||||
};
|
warning!("Get content length for {:?}, error: {}", len_value, err);
|
||||||
match len_str.parse::<i64>() {
|
-1
|
||||||
Ok(len) => len, Err(err) => {
|
})
|
||||||
warning!("Get content length for {:?}, error: {}", len_value, err);
|
|
||||||
-1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if *VERBOSE {
|
if *VERBOSE {
|
||||||
|
|||||||
21
src/jdk.rs
21
src/jdk.rs
@@ -1,13 +1,6 @@
|
|||||||
use std::{
|
use std::{ collections::HashMap, env, fs, str, path::Path, process::Command };
|
||||||
collections::HashMap,
|
use rust_util::util_os;
|
||||||
env,
|
use crate::{ local_util, tool, misc::{ VERBOSE } };
|
||||||
fs,
|
|
||||||
str,
|
|
||||||
path::Path,
|
|
||||||
process::Command,
|
|
||||||
};
|
|
||||||
use rust_util::util_os::*;
|
|
||||||
use crate::{ local_util, tool, misc::* };
|
|
||||||
|
|
||||||
const PATH: &str = "PATH";
|
const PATH: &str = "PATH";
|
||||||
const JAVA_HOME: &str = "JAVA_HOME";
|
const JAVA_HOME: &str = "JAVA_HOME";
|
||||||
@@ -34,13 +27,13 @@ pub fn get_java_home(version: &str) -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cloud_java(version: &str) -> bool {
|
pub fn get_cloud_java(version: &str) -> bool {
|
||||||
if ! is_macos_or_linux() {
|
if ! util_os::is_macos_or_linux() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let cloud_java_names = match &*BUILDJ_JAVA_NAME {
|
let cloud_java_names = match &*BUILDJ_JAVA_NAME {
|
||||||
None => if is_macos() {
|
None => if util_os::is_macos() {
|
||||||
vec![OPENJDK_MACOS]
|
vec![OPENJDK_MACOS]
|
||||||
} else if is_linux() {
|
} else if util_os::is_linux() {
|
||||||
vec![JDK_LINUX, OPENJDK_LINUX]
|
vec![JDK_LINUX, OPENJDK_LINUX]
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
@@ -60,7 +53,7 @@ pub fn get_cloud_java(version: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_macos_java_home(version: &str) -> Option<String> {
|
pub fn get_macos_java_home(version: &str) -> Option<String> {
|
||||||
if ! is_macos() {
|
if ! util_os::is_macos() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let output = Command::new(MACOS_LIBEXEC_JAVAHOME).arg("-version").arg(version).output().ok()?;
|
let output = Command::new(MACOS_LIBEXEC_JAVAHOME).arg("-version").arg(version).output().ok()?;
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
use std::{
|
use std::{ env, fs::{ self, File }, io::{ Read, ErrorKind }, path::Path, process::Command };
|
||||||
env,
|
use rust_util::{ XResult, new_box_ioerror, util_io::{ self, DEFAULT_BUF_SIZE, PrintStatusContext } };
|
||||||
fs::{ self, File },
|
use crypto::{ digest::Digest, md5::Md5, sha1::Sha1, sha2::{ Sha256, Sha512 } };
|
||||||
io::{ Read, ErrorKind },
|
|
||||||
path::Path,
|
|
||||||
process::Command,
|
|
||||||
};
|
|
||||||
use rust_util::{ XResult, new_box_ioerror, util_io::* };
|
|
||||||
use crypto::{
|
|
||||||
digest::Digest,
|
|
||||||
md5::Md5,
|
|
||||||
sha1::Sha1,
|
|
||||||
sha2::{ Sha256, Sha512 },
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn get_args_as_vec() -> Vec<String> {
|
pub fn get_args_as_vec() -> Vec<String> {
|
||||||
env::args().collect::<Vec<String>>()
|
env::args().collect::<Vec<String>>()
|
||||||
@@ -65,7 +54,7 @@ pub fn calc_file_digest(digest: &mut dyn Digest, digest_alg: &str, file_name: &s
|
|||||||
};
|
};
|
||||||
digest.input(&buf[..len]);
|
digest.input(&buf[..len]);
|
||||||
written += len as i64;
|
written += len as i64;
|
||||||
print_status_last_line(&format!("Calc {}", digest_alg), file_len, written, &mut print_status_context);
|
util_io::print_status_last_line(&format!("Calc {}", digest_alg), file_len, written, &mut print_status_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
src/main.rs
26
src/main.rs
@@ -302,23 +302,17 @@ fn read_build_json_object() -> Option<json::JsonValue> {
|
|||||||
return Some(o);
|
return Some(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
let build_json = match find_build_json() {
|
let build_json = find_build_json()?;
|
||||||
Some(p) => p, None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
success!("Find {} @ {}", BUILD_JSON, build_json);
|
success!("Find {} @ {}", BUILD_JSON, build_json);
|
||||||
let build_json_content = match fs::read_to_string(build_json) {
|
|
||||||
Ok(content) => content, Err(err) => {
|
let build_json_content = fs::read_to_string(build_json).map_err(|err| {
|
||||||
failure!("Read {} failed: {}", BUILD_JSON, err);
|
failure!("Read {} failed: {}", BUILD_JSON, err);
|
||||||
return None;
|
err
|
||||||
},
|
}).ok()?;
|
||||||
};
|
json::parse(&build_json_content).map_err(|err| {
|
||||||
match json::parse(&build_json_content) {
|
failure!("Parse JSON failed: {}", err);
|
||||||
Ok(object) => Some(object), Err(err) => {
|
err
|
||||||
failure!("Parse JSON failed: {}", err);
|
}).ok()
|
||||||
None
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
12
src/misc.rs
12
src/misc.rs
@@ -1,12 +1,12 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use rust_util::util_env::*;
|
use rust_util::util_env;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref VERBOSE: bool = is_env_on("BUILDJ_VERBOSE");
|
pub static ref VERBOSE: bool = util_env::is_env_on("BUILDJ_VERBOSE");
|
||||||
pub static ref NOAUTH: bool = is_env_on("BUILDJ_NOAUTH");
|
pub static ref NOAUTH: bool = util_env::is_env_on("BUILDJ_NOAUTH");
|
||||||
pub static ref NOBUILDIN: bool = is_env_on("BUILDJ_NOBUILDIN");
|
pub static ref NOBUILDIN: bool = util_env::is_env_on("BUILDJ_NOBUILDIN");
|
||||||
pub static ref AUTH_TOKEN: Option<String> = env::var("BUILDJ_AUTH_TOKEN").ok();
|
pub static ref AUTH_TOKEN: Option<String> = env::var("BUILDJ_AUTH_TOKEN").ok();
|
||||||
pub static ref JAVA_VERSION: Option<String> = env::var("BUILDJ_JAVA").ok();
|
pub static ref JAVA_VERSION: Option<String> = env::var("BUILDJ_JAVA").ok();
|
||||||
pub static ref BUILDER_VERSION: Option<String> = env::var("BUILDJ_BUILDER").ok();
|
pub static ref BUILDER_VERSION: Option<String> = env::var("BUILDJ_BUILDER").ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
src/tool.rs
31
src/tool.rs
@@ -1,17 +1,6 @@
|
|||||||
use std::{
|
use std::{ fs::{ self, File }, path::Path };
|
||||||
fs::{ self, File },
|
use rust_util::{ XResult, new_box_ioerror, util_os };
|
||||||
path::Path,
|
use crate::{ http, local_util, misc::{ AUTH_TOKEN, VERBOSE, NOAUTH } };
|
||||||
};
|
|
||||||
use rust_util::{
|
|
||||||
XResult,
|
|
||||||
new_box_ioerror,
|
|
||||||
util_os::is_macos_or_linux,
|
|
||||||
};
|
|
||||||
use crate::{
|
|
||||||
http::{ download_url, get_url_content },
|
|
||||||
local_util::{ self, * },
|
|
||||||
misc::*,
|
|
||||||
};
|
|
||||||
|
|
||||||
const M2_HOME: &str = "M2_HOME";
|
const M2_HOME: &str = "M2_HOME";
|
||||||
const MAVEN_HOME: &str = "MAVEN_HOME";
|
const MAVEN_HOME: &str = "MAVEN_HOME";
|
||||||
@@ -54,7 +43,7 @@ impl BuilderDesc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_builder_home(builder: &str, version: &str) -> Option<BuilderDesc> {
|
pub fn get_builder_home(builder: &str, version: &str) -> Option<BuilderDesc> {
|
||||||
let local_builder_home_base_dir = match get_user_home_dir(LOCAL_BUILDER_HOME_BASE_DIR) {
|
let local_builder_home_base_dir = match local_util::get_user_home_dir(LOCAL_BUILDER_HOME_BASE_DIR) {
|
||||||
Ok(o) => o, Err(_) => return None,
|
Ok(o) => o, Err(_) => return None,
|
||||||
};
|
};
|
||||||
let builder_name = match builder {
|
let builder_name = match builder {
|
||||||
@@ -75,7 +64,7 @@ pub fn get_builder_home(builder: &str, version: &str) -> Option<BuilderDesc> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cloud_builder(builder: &str, version: &str) -> bool {
|
pub fn get_cloud_builder(builder: &str, version: &str) -> bool {
|
||||||
if ! is_macos_or_linux() {
|
if ! util_os::is_macos_or_linux() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let local_builder_home_base_dir = match local_util::get_user_home_dir(LOCAL_BUILDER_HOME_BASE_DIR) {
|
let local_builder_home_base_dir = match local_util::get_user_home_dir(LOCAL_BUILDER_HOME_BASE_DIR) {
|
||||||
@@ -119,7 +108,7 @@ pub fn get_tool_package_secret() -> XResult<String> {
|
|||||||
return Ok((*AUTH_TOKEN).as_ref().unwrap().clone());
|
return Ok((*AUTH_TOKEN).as_ref().unwrap().clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let standard_config_file = get_user_home_dir(STANDARD_CONFIG_JSON)?;
|
let standard_config_file = local_util::get_user_home_dir(STANDARD_CONFIG_JSON)?;
|
||||||
let standard_config_json = fs::read_to_string(&standard_config_file)?;
|
let standard_config_json = fs::read_to_string(&standard_config_file)?;
|
||||||
let standard_config_object = json::parse(&standard_config_json)?;
|
let standard_config_object = json::parse(&standard_config_json)?;
|
||||||
|
|
||||||
@@ -133,7 +122,7 @@ pub fn get_tool_package_secret() -> XResult<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_tool_package_secret(secret: &str) -> XResult<()> {
|
pub fn set_tool_package_secret(secret: &str) -> XResult<()> {
|
||||||
let standard_config_file = get_user_home_dir(STANDARD_CONFIG_JSON)?;
|
let standard_config_file = local_util::get_user_home_dir(STANDARD_CONFIG_JSON)?;
|
||||||
|
|
||||||
match fs::metadata(&standard_config_file) {
|
match fs::metadata(&standard_config_file) {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@@ -196,7 +185,7 @@ pub fn get_tool_package_detail(name: &str, version: &str) -> XResult<String> {
|
|||||||
url.push_str(&urlencoding::encode(name));
|
url.push_str(&urlencoding::encode(name));
|
||||||
url.push_str("&ver=");
|
url.push_str("&ver=");
|
||||||
url.push_str(&urlencoding::encode(version));
|
url.push_str(&urlencoding::encode(version));
|
||||||
Ok(get_url_content(url.as_str())?)
|
Ok(http::get_url_content(url.as_str())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_and_extract_tool_package(base_dir: &str, dir_with_name: bool, name: &str, version: &str, extract_match: bool) -> XResult<bool> {
|
pub fn get_and_extract_tool_package(base_dir: &str, dir_with_name: bool, name: &str, version: &str, extract_match: bool) -> XResult<bool> {
|
||||||
@@ -228,11 +217,11 @@ pub fn get_and_extract_tool_package(base_dir: &str, dir_with_name: bool, name: &
|
|||||||
target_base_dir.push_str("/");
|
target_base_dir.push_str("/");
|
||||||
target_base_dir.push_str(&format!("{}-{}", n, v));
|
target_base_dir.push_str(&format!("{}-{}", n, v));
|
||||||
}
|
}
|
||||||
init_dir(&target_base_dir);
|
local_util::init_dir(&target_base_dir);
|
||||||
let target_file_name = format!("{}/{}", &target_base_dir, name.to_string());
|
let target_file_name = format!("{}/{}", &target_base_dir, name.to_string());
|
||||||
|
|
||||||
information!("Start download: {} -> {}", &url.to_string(), &target_file_name);
|
information!("Start download: {} -> {}", &url.to_string(), &target_file_name);
|
||||||
download_url(&url.to_string(), &mut File::create(&target_file_name)?)?;
|
http::download_url(&url.to_string(), &mut File::create(&target_file_name)?)?;
|
||||||
|
|
||||||
information!("Start verify integrity: {} ...", &target_file_name);
|
information!("Start verify integrity: {} ...", &target_file_name);
|
||||||
if local_util::verify_file_integrity(&integrity.to_string(), &target_file_name)? {
|
if local_util::verify_file_integrity(&integrity.to_string(), &target_file_name)? {
|
||||||
|
|||||||
Reference in New Issue
Block a user