mirror of
https://github.com/jht5945/buildj.git
synced 2025-12-29 18:30:05 +08:00
update buildj
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -72,7 +72,7 @@ dependencies = [
|
|||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rust_util 0.1.0 (git+https://github.com/jht5945/rust_util)",
|
"rust_util 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"urlencoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"urlencoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
@@ -1008,8 +1008,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust_util"
|
name = "rust_util"
|
||||||
version = "0.1.0"
|
version = "0.2.1"
|
||||||
source = "git+https://github.com/jht5945/rust_util#9c1bed76d1408467ff09a97a2783848751de8ba0"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -1602,7 +1602,7 @@ dependencies = [
|
|||||||
"checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650"
|
"checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650"
|
||||||
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
|
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
|
||||||
"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
|
"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
|
||||||
"checksum rust_util 0.1.0 (git+https://github.com/jht5945/rust_util)" = "<none>"
|
"checksum rust_util 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "35700070bf50662d748fb06926d16d24c1f7d6cfd62ba556dc58541d3c96d436"
|
||||||
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
|
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
|
||||||
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
||||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ urlencoding = "1.0.0"
|
|||||||
dirs = "2.0.1"
|
dirs = "2.0.1"
|
||||||
rust-crypto = "0.2.36"
|
rust-crypto = "0.2.36"
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.3.0"
|
||||||
rust_util = { git = "https://github.com/jht5945/rust_util" }
|
rust_util = "0.2.1"
|
||||||
|
|||||||
@@ -125,9 +125,7 @@ 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() {
|
match find_build_json_in_current() {
|
||||||
Some(p) => {
|
Some(p) => Some(p),
|
||||||
Some(p)
|
|
||||||
},
|
|
||||||
None => match find_build_json_in_parents() {
|
None => match find_build_json_in_parents() {
|
||||||
Some(p) => {
|
Some(p) => {
|
||||||
print_message(MessageType::WARN, &format!("Cannot find {} in current dir, find: {}", BUILD_JSON, p));
|
print_message(MessageType::WARN, &format!("Cannot find {} in current dir, find: {}", BUILD_JSON, p));
|
||||||
|
|||||||
74
src/jdk.rs
74
src/jdk.rs
@@ -9,6 +9,7 @@ use std::{
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
rust_util::{
|
rust_util::{
|
||||||
|
iff,
|
||||||
util_os::*,
|
util_os::*,
|
||||||
util_msg::*,
|
util_msg::*,
|
||||||
},
|
},
|
||||||
@@ -37,11 +38,7 @@ pub fn get_java_home(version: &str) -> Option<String> {
|
|||||||
Some(j) => Some(j),
|
Some(j) => Some(j),
|
||||||
None => match get_local_java_home(version) {
|
None => match get_local_java_home(version) {
|
||||||
Some(j) => Some(j),
|
Some(j) => Some(j),
|
||||||
None => if get_cloud_java(version) {
|
None => iff!(get_cloud_java(version), get_local_java_home(version), None),
|
||||||
get_local_java_home(version)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,53 +90,46 @@ pub fn get_local_java_home(version: &str) -> Option<String> {
|
|||||||
let local_java_home_base_dir = local_util::get_user_home_dir(LOCAL_JAVA_HOME_BASE_DIR).ok()?;
|
let local_java_home_base_dir = local_util::get_user_home_dir(LOCAL_JAVA_HOME_BASE_DIR).ok()?;
|
||||||
let paths = fs::read_dir(Path::new(&local_java_home_base_dir)).ok()?;
|
let paths = fs::read_dir(Path::new(&local_java_home_base_dir)).ok()?;
|
||||||
for path in paths {
|
for path in paths {
|
||||||
match path {
|
if let Ok(dir_entry) = path {
|
||||||
Err(_) => (),
|
if let Some(p)= dir_entry.path().to_str() {
|
||||||
Ok(dir_entry) => match dir_entry.path().to_str() {
|
if *VERBOSE {
|
||||||
None => (),
|
print_message(MessageType::DEBUG, &format!("Try match path: {}", p));
|
||||||
Some(p) => {
|
}
|
||||||
|
let mut path_name = p;
|
||||||
|
if p.ends_with('/') {
|
||||||
|
path_name = &path_name[..path_name.len() - 1]
|
||||||
|
}
|
||||||
|
if let Some(i) = path_name.rfind('/') {
|
||||||
|
path_name = &path_name[i+1..];
|
||||||
|
}
|
||||||
|
let matched_path_opt = if (path_name.starts_with("jdk-") && (&path_name[4..]).starts_with(version))
|
||||||
|
|| (path_name.starts_with("jdk") && (&path_name[3..]).starts_with(version)) {
|
||||||
|
Some(p)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
if let Some(matched_path) = matched_path_opt {
|
||||||
if *VERBOSE {
|
if *VERBOSE {
|
||||||
print_message(MessageType::DEBUG, &format!("Try match path: {}", p));
|
print_message(MessageType::DEBUG, &format!("Matched JDK path found: {}", matched_path));
|
||||||
}
|
}
|
||||||
let mut path_name = p;
|
if local_util::is_path_exists(matched_path, "Contents/Home") {
|
||||||
if p.ends_with('/') {
|
return Some(format!("{}/{}", matched_path, "Contents/Home"));
|
||||||
path_name = &path_name[..path_name.len() - 1]
|
|
||||||
}
|
|
||||||
let last_index_of_slash = path_name.rfind('/');
|
|
||||||
match last_index_of_slash {
|
|
||||||
None => (),
|
|
||||||
Some(i) => path_name = &path_name[i+1..],
|
|
||||||
};
|
|
||||||
let matched_path = if (path_name.starts_with("jdk-") && (&path_name[4..]).starts_with(version))
|
|
||||||
|| (path_name.starts_with("jdk") && (&path_name[3..]).starts_with(version)) {
|
|
||||||
p
|
|
||||||
} else {
|
} else {
|
||||||
""
|
return Some(matched_path.to_string());
|
||||||
};
|
|
||||||
if !matched_path.is_empty() {
|
|
||||||
if *VERBOSE {
|
|
||||||
print_message(MessageType::DEBUG, &format!("Matched JDK path found: {}", matched_path));
|
|
||||||
}
|
|
||||||
if local_util::is_path_exists(matched_path, "Contents/Home") {
|
|
||||||
return Some(format!("{}/{}", matched_path, "Contents/Home"));
|
|
||||||
} else {
|
|
||||||
return Some(matched_path.to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extract_jdk_and_wait(file_name: &str) {
|
pub fn extract_jdk_and_wait(file_name: &str) {
|
||||||
match local_util::get_user_home_dir(LOCAL_JAVA_HOME_BASE_DIR) {
|
if let Ok(local_java_home_base_dir) = local_util::get_user_home_dir(LOCAL_JAVA_HOME_BASE_DIR) {
|
||||||
Err(_) => (),
|
local_util::extract_package_and_wait(&local_java_home_base_dir, file_name).unwrap_or_else(|err| {
|
||||||
Ok(local_java_home_base_dir) => local_util::extract_package_and_wait(&local_java_home_base_dir, file_name).unwrap_or_else(|err| {
|
|
||||||
print_message(MessageType::ERROR, &format!("Extract file: {}, failed: {}", file_name, err));
|
print_message(MessageType::ERROR, &format!("Extract file: {}, failed: {}", file_name, err));
|
||||||
}),
|
});
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_env() -> HashMap<String, String> {
|
pub fn get_env() -> HashMap<String, String> {
|
||||||
|
|||||||
@@ -71,10 +71,7 @@ pub fn calc_sha256(d: &[u8]) -> String {
|
|||||||
pub fn calc_file_digest(digest: &mut dyn Digest, digest_alg: &str, file_name: &str) -> XResult<String> {
|
pub fn calc_file_digest(digest: &mut dyn Digest, digest_alg: &str, file_name: &str) -> XResult<String> {
|
||||||
let mut buf: [u8; DEFAULT_BUF_SIZE] = [0u8; DEFAULT_BUF_SIZE];
|
let mut buf: [u8; DEFAULT_BUF_SIZE] = [0u8; DEFAULT_BUF_SIZE];
|
||||||
let mut f = File::open(file_name)?;
|
let mut f = File::open(file_name)?;
|
||||||
let file_len = match f.metadata() {
|
let file_len = f.metadata().map(|md| md.len() as i64).unwrap_or(-1_i64);
|
||||||
Err(_) => -1_i64,
|
|
||||||
Ok(meta_data) => meta_data.len() as i64,
|
|
||||||
};
|
|
||||||
let start = SystemTime::now();
|
let start = SystemTime::now();
|
||||||
let mut written = 0_i64;
|
let mut written = 0_i64;
|
||||||
loop {
|
loop {
|
||||||
@@ -130,10 +127,9 @@ pub fn extract_package_and_wait(dir: &str, file_name: &str) -> XResult<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_home_dir(home_sub_dir: &str) {
|
pub fn init_home_dir(home_sub_dir: &str) {
|
||||||
match get_user_home_dir(home_sub_dir) {
|
if let Ok(user_home_dir) = get_user_home_dir(home_sub_dir) {
|
||||||
Err(_) => (),
|
init_dir(&user_home_dir);
|
||||||
Ok(user_home_dir) => init_dir(&user_home_dir),
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_dir(dir: &str) {
|
pub fn init_dir(dir: &str) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ const BUILD_DATE: &str = env!("BUILD_DATE");
|
|||||||
|
|
||||||
fn do_with_buildin_arg_java(first_arg: &str, args: &[String]) {
|
fn do_with_buildin_arg_java(first_arg: &str, args: &[String]) {
|
||||||
let ver = &first_arg[7..];
|
let ver = &first_arg[7..];
|
||||||
if ver == "" {
|
if ver.is_empty() {
|
||||||
print_message(MessageType::ERROR, "Java version is not assigned!");
|
print_message(MessageType::ERROR, "Java version is not assigned!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/tool.rs
25
src/tool.rs
@@ -50,11 +50,9 @@ impl BuilderDesc {
|
|||||||
pub fn get_builder_bin(&self) -> String {
|
pub fn get_builder_bin(&self) -> String {
|
||||||
match &self.bin {
|
match &self.bin {
|
||||||
Some(b) => b.clone(),
|
Some(b) => b.clone(),
|
||||||
None => {
|
None => match self.name {
|
||||||
match self.name {
|
BuilderName::Maven => format!("{}/bin/mvn", self.home.clone()),
|
||||||
BuilderName::Maven => format!("{}/bin/mvn", self.home.clone()),
|
BuilderName::Gradle => format!("{}/bin/gradle", self.home.clone()),
|
||||||
BuilderName::Gradle => format!("{}/bin/gradle", self.home.clone()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,23 +103,18 @@ pub fn get_local_builder_home_sub(builder_name: BuilderName, local_builder_home_
|
|||||||
print_message(MessageType::ERROR, &format!("Cannot find builder home in: {}", local_builder_home_dir));
|
print_message(MessageType::ERROR, &format!("Cannot find builder home in: {}", local_builder_home_dir));
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
Some(p) => {
|
Some(p) => Some(BuilderDesc{name: builder_name, home: p, bin: None}),
|
||||||
Some(BuilderDesc{name: builder_name, home: p, bin: None})
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_local_builder_home_sub_first_sub_dir(local_builder_home_dir: &str) -> Option<String> {
|
pub fn get_local_builder_home_sub_first_sub_dir(local_builder_home_dir: &str) -> Option<String> {
|
||||||
let paths = fs::read_dir(Path::new(&local_builder_home_dir)).ok()?;
|
let paths = fs::read_dir(Path::new(&local_builder_home_dir)).ok()?;
|
||||||
for path in paths {
|
for path in paths {
|
||||||
match path {
|
if let Ok(p) = path {
|
||||||
Err(_) => (),
|
if p.path().is_dir() {
|
||||||
Ok(p) => {
|
return Some(p.path().to_str()?.to_string());
|
||||||
if p.path().is_dir() {
|
}
|
||||||
return Some(p.path().to_str()?.to_string());
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user