mirror of
https://github.com/jht5945/buildj.git
synced 2026-01-14 01:00:04 +08:00
Compare commits
5 Commits
1e933bde6b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
ec27eaa877
|
|||
| 26de9ddcc6 | |||
| 0a02a56d57 | |||
| 186c08a8f5 | |||
| 7248796b2e |
1585
Cargo.lock
generated
1585
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
19
Cargo.toml
19
Cargo.toml
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "buildj"
|
||||
version = "0.1.6"
|
||||
version = "0.1.10"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
homepage = "https://buildj.ruststack.org/"
|
||||
@@ -8,11 +8,12 @@ license = "MIT"
|
||||
description = "A java build tool"
|
||||
|
||||
[dependencies]
|
||||
json = "0.12.4"
|
||||
term = "0.6.1"
|
||||
reqwest = "0.9.18"
|
||||
urlencoding = "1.1.1"
|
||||
dirs = "3.0.1"
|
||||
rust-crypto = "0.2.36"
|
||||
lazy_static = "1.4.0"
|
||||
rust_util = "0.6.22"
|
||||
json = "0.12"
|
||||
term = "0.7"
|
||||
reqwest = { version = "0.11", features = [ "blocking" ] }
|
||||
urlencoding = "1.1"
|
||||
dirs = "3.0"
|
||||
rust-crypto = "0.2"
|
||||
lazy_static = "1.4"
|
||||
rust_util = "0.6"
|
||||
plist = "1.1"
|
||||
|
||||
5
build.rs
5
build.rs
@@ -2,10 +2,7 @@ use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap();
|
||||
let mut git_hash = String::from_utf8(output.stdout).unwrap();
|
||||
if git_hash.is_empty() {
|
||||
git_hash = "0000000000000000000000000000000000000000".to_string();
|
||||
}
|
||||
let git_hash = String::from_utf8(output.stdout).unwrap();
|
||||
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
|
||||
let date_output = Command::new("date").args(&["+%Y-%m-%dT%H:%M:%S%z"]).output().unwrap();
|
||||
let date = String::from_utf8(date_output.stdout).unwrap();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{fs, path::Path};
|
||||
use rust_util::{XResult, new_box_ioerror};
|
||||
use rust_util::XResult;
|
||||
|
||||
use crate::http::get_url_content;
|
||||
use crate::misc::VERBOSE;
|
||||
@@ -24,7 +24,7 @@ pub fn get_archive_version(gid: &str, aid: &str) -> XResult<String> {
|
||||
}
|
||||
let version_result_object = json::parse(&version_result)?;
|
||||
if version_result_object["status"] != 200 {
|
||||
Err(new_box_ioerror(&format!("Get archive info version failed: {}", version_result)))
|
||||
simple_error!("Get archive info version failed: {}", version_result)
|
||||
} else {
|
||||
Ok(version_result_object["data"].to_string())
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
|
||||
if *VERBOSE {
|
||||
debugging!("Start download URL: {}", url);
|
||||
}
|
||||
let mut response = reqwest::get(url)?;
|
||||
let mut response = reqwest::blocking::get(url)?;
|
||||
let header_content_length: i64 = match response.headers().get("content-length") {
|
||||
None => -1_i64, Some(len_value) => {
|
||||
let len_str = len_value.to_str().unwrap_or_else(|err| {
|
||||
@@ -31,5 +31,5 @@ pub fn get_url_content(url: &str) -> XResult<String> {
|
||||
if *VERBOSE {
|
||||
debugging!("Get URL: {}", url);
|
||||
}
|
||||
Ok(reqwest::get(url)?.text()?)
|
||||
Ok(reqwest::blocking::get(url)?.text()?)
|
||||
}
|
||||
|
||||
56
src/jdk.rs
56
src/jdk.rs
@@ -1,6 +1,8 @@
|
||||
use std::{collections::HashMap, env, fs, str, path::Path, process::Command};
|
||||
use rust_util::util_os;
|
||||
use rust_util::util_env;
|
||||
use crate::{local_util, tool, misc::VERBOSE};
|
||||
use plist::Value;
|
||||
|
||||
const PATH: &str = "PATH";
|
||||
const JAVA_HOME: &str = "JAVA_HOME";
|
||||
@@ -19,7 +21,8 @@ lazy_static! {
|
||||
|
||||
pub fn get_java_home(version: &str) -> Option<String> {
|
||||
match get_macos_java_home(version) {
|
||||
Some(j) => Some(j), None => match get_local_java_home(version) {
|
||||
Some(j) => Some(j),
|
||||
None => match get_local_java_home(version) {
|
||||
Some(j) => Some(j),
|
||||
None => iff!(get_cloud_java(version), get_local_java_home(version), None),
|
||||
},
|
||||
@@ -27,7 +30,7 @@ pub fn get_java_home(version: &str) -> Option<String> {
|
||||
}
|
||||
|
||||
pub fn get_cloud_java(version: &str) -> bool {
|
||||
if ! util_os::is_macos_or_linux() {
|
||||
if !util_os::is_macos_or_linux() {
|
||||
return false;
|
||||
}
|
||||
let cloud_java_names = match &*BUILDJ_JAVA_NAME {
|
||||
@@ -41,7 +44,8 @@ pub fn get_cloud_java(version: &str) -> bool {
|
||||
Some(buildj_java_name) => vec![buildj_java_name.as_str()],
|
||||
};
|
||||
let local_java_home_base_dir = match local_util::get_user_home_dir(LOCAL_JAVA_HOME_BASE_DIR) {
|
||||
Ok(o) => o, Err(_) => return false,
|
||||
Ok(o) => o,
|
||||
Err(_) => return false,
|
||||
};
|
||||
for cloud_java_name in cloud_java_names {
|
||||
if tool::get_and_extract_tool_package(&local_java_home_base_dir, false, cloud_java_name, version, false).is_ok() {
|
||||
@@ -53,19 +57,39 @@ pub fn get_cloud_java(version: &str) -> bool {
|
||||
}
|
||||
|
||||
pub fn get_macos_java_home(version: &str) -> Option<String> {
|
||||
if ! util_os::is_macos() {
|
||||
if !util_os::is_macos() || util_env::is_env_on("SKIP_CHECK_JAVA_HOME") {
|
||||
return None;
|
||||
}
|
||||
let output = Command::new(MACOS_LIBEXEC_JAVAHOME).arg("-version").arg(version).output().ok()?;
|
||||
let output_in_utf8 = str::from_utf8(&output.stderr).ok()?;
|
||||
if *VERBOSE {
|
||||
debugging!("java_home outputs: {}", output_in_utf8);
|
||||
}
|
||||
if output_in_utf8.contains("Unable to find any JVMs") {
|
||||
None
|
||||
} else {
|
||||
Some(str::from_utf8(&output.stdout).ok()?.trim().to_string())
|
||||
let java_home_x = Command::new(MACOS_LIBEXEC_JAVAHOME).arg("-x").output().ok()?;
|
||||
let java_home_plist_value = match Value::from_reader_xml(&*java_home_x.stdout) {
|
||||
Err(e) => {
|
||||
debugging!("Parse java_home outputs failed: {}", e);
|
||||
return None;
|
||||
}
|
||||
Ok(val) => val,
|
||||
};
|
||||
let java_home_plist_value_array = match java_home_plist_value.as_array() {
|
||||
None => {
|
||||
debugging!("Covert java_home plist output to array failed: {:?}", java_home_plist_value);
|
||||
return None;
|
||||
}
|
||||
Some(val) => val,
|
||||
};
|
||||
for java_home_plist_item in java_home_plist_value_array {
|
||||
debugging!("Checking: {:?}", java_home_plist_item);
|
||||
if let Some(jvm_item) = java_home_plist_item.as_dictionary() {
|
||||
let jvm_version_value = jvm_item.get("JVMVersion");
|
||||
let jvm_home_path_value = jvm_item.get("JVMHomePath");
|
||||
if let (Some(Value::String(jvm_version)), Some(Value::String(jvm_path))) = (jvm_version_value, jvm_home_path_value) {
|
||||
debugging!("Check version: {} vs {}", jvm_version, version);
|
||||
if jvm_version.starts_with(version) {
|
||||
debugging!("Check version success: {} -> {}", jvm_version, jvm_path);
|
||||
return Some(jvm_path.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_local_java_home(version: &str) -> Option<String> {
|
||||
@@ -73,7 +97,7 @@ pub fn get_local_java_home(version: &str) -> Option<String> {
|
||||
let paths = fs::read_dir(Path::new(&local_java_home_base_dir)).ok()?;
|
||||
for path in paths {
|
||||
if let Ok(dir_entry) = path {
|
||||
if let Some(p)= dir_entry.path().to_str() {
|
||||
if let Some(p) = dir_entry.path().to_str() {
|
||||
if *VERBOSE {
|
||||
debugging!("Try match path: {}", p);
|
||||
}
|
||||
@@ -82,7 +106,7 @@ pub fn get_local_java_home(version: &str) -> Option<String> {
|
||||
path_name = &path_name[..path_name.len() - 1]
|
||||
}
|
||||
if let Some(i) = path_name.rfind('/') {
|
||||
path_name = &path_name[i+1..];
|
||||
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)) {
|
||||
@@ -98,7 +122,7 @@ pub fn get_local_java_home(version: &str) -> Option<String> {
|
||||
Some(format!("{}/{}", matched_path, "Contents/Home"))
|
||||
} else {
|
||||
Some(matched_path.to_string())
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
use std::{env, fs::{self, File}, io::{Read, ErrorKind}, path::Path, process::Command};
|
||||
use rust_util::{XResult, new_box_ioerror, util_io::{self, DEFAULT_BUF_SIZE, PrintStatusContext}};
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{Read, ErrorKind};
|
||||
use rust_util::XResult;
|
||||
use rust_util::util_io::{self, DEFAULT_BUF_SIZE, PrintStatusContext};
|
||||
use crypto::{digest::Digest, md5::Md5, sha1::Sha1, sha2::{Sha256, Sha512}};
|
||||
|
||||
pub fn get_args_as_vec() -> Vec<String> {
|
||||
@@ -14,7 +19,7 @@ pub fn is_buildin_args(args: &[String]) -> bool {
|
||||
|
||||
pub fn verify_file_integrity(integrity: &str, file_name: &str) -> XResult<bool> {
|
||||
match integrity.find('-') {
|
||||
None => Err(new_box_ioerror(&format!("Not supported integrigty: {}", integrity))),
|
||||
None => simple_error!("Not supported integrigty: {}", integrity),
|
||||
Some(index) => {
|
||||
let digest_hex = &integrity[index+1..];
|
||||
let calc_digest_hex = match &integrity[0..index] {
|
||||
@@ -22,7 +27,7 @@ pub fn verify_file_integrity(integrity: &str, file_name: &str) -> XResult<bool>
|
||||
"sha512:hex" => calc_file_digest(&mut Sha512::new(), "SHA512", file_name)?,
|
||||
"sha1:hex" => calc_file_digest(&mut Sha1::new(), "SHA1", file_name)?,
|
||||
"md5:hex" => calc_file_digest(&mut Md5::new(), "MD5", file_name)?,
|
||||
_ => return Err(new_box_ioerror(&format!("Not supported integrigty: {}", integrity))),
|
||||
_ => return simple_error!("Not supported integrigty: {}", integrity),
|
||||
};
|
||||
let integrity_verify_result = digest_hex == calc_digest_hex.as_str();
|
||||
if ! integrity_verify_result {
|
||||
@@ -40,7 +45,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> {
|
||||
let mut buf: [u8; DEFAULT_BUF_SIZE] = [0u8; DEFAULT_BUF_SIZE];
|
||||
let mut buf = [0u8; DEFAULT_BUF_SIZE];
|
||||
let mut f = File::open(file_name)?;
|
||||
let file_len = f.metadata().map(|md| md.len() as i64).unwrap_or(-1_i64);
|
||||
let mut print_status_context = PrintStatusContext::default();
|
||||
@@ -62,9 +67,9 @@ pub fn get_user_home() -> XResult<String> {
|
||||
match dirs::home_dir() {
|
||||
Some(home_dir_o) => match home_dir_o.to_str() {
|
||||
Some(home_dir_str) => Ok(home_dir_str.to_string()),
|
||||
None => Err(new_box_ioerror("Home dir not found!")),
|
||||
None => simple_error!("Home dir not found!"),
|
||||
},
|
||||
None => Err(new_box_ioerror("Home dir not found!")),
|
||||
None => simple_error!("Home dir not found!"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +95,7 @@ pub fn extract_package_and_wait(dir: &str, file_name: &str) -> XResult<()> {
|
||||
cmd = Command::new("tar");
|
||||
cmd.arg("-xzvf");
|
||||
} else {
|
||||
return Err(new_box_ioerror(&format!("Unknown file type: {}", file_name)));
|
||||
return simple_error!("Unknown file type: {}", file_name);
|
||||
}
|
||||
cmd.arg(file_name).current_dir(dir).spawn()?.wait()?;
|
||||
Ok(())
|
||||
|
||||
80
src/main.rs
80
src/main.rs
@@ -1,9 +1,6 @@
|
||||
#[macro_use]
|
||||
extern crate json;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate rust_util;
|
||||
#[macro_use] extern crate json;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
#[macro_use] extern crate rust_util;
|
||||
|
||||
use std::fs;
|
||||
use std::collections::HashMap;
|
||||
@@ -16,35 +13,41 @@ pub mod tool;
|
||||
pub mod build_json;
|
||||
pub mod misc;
|
||||
|
||||
use rust_util::util_cmd::run_command_and_wait;
|
||||
use rust_util::util_cmd;
|
||||
use tool::*;
|
||||
use jdk::*;
|
||||
use build_json::*;
|
||||
use misc::*;
|
||||
|
||||
const BUILDJ: &str = "buildj";
|
||||
const BUDERJ_VER: &str = env!("CARGO_PKG_VERSION");
|
||||
const GIT_HASH: &str = env!("GIT_HASH");
|
||||
const BUILD_DATE: &str = env!("BUILD_DATE");
|
||||
|
||||
|
||||
fn do_with_buildin_arg_java(first_arg: &str, args: &[String]) {
|
||||
let ver = &first_arg[7..];
|
||||
if ver.is_empty() {
|
||||
failure!("Java version is not assigned!");
|
||||
return;
|
||||
}
|
||||
fn do_with_buildin_arg_java_cmd(first_arg: &str, args: &[String]) {
|
||||
let first_num_pos = first_arg.chars().position(|c| c >= '0' && c <= '9');
|
||||
let (cmd, ver) = match first_num_pos {
|
||||
None => {
|
||||
failure!("Java command version is not assigned!");
|
||||
return;
|
||||
},
|
||||
Some(pos) => {
|
||||
(&first_arg[3..pos], &first_arg[pos..])
|
||||
},
|
||||
};
|
||||
match get_java_home(ver) {
|
||||
None => failure!("Assigned java version not found: {}", ver),
|
||||
Some(java_home) => {
|
||||
success!("Find java home: {}", java_home);
|
||||
let java_bin = &format!("{}/bin/java", java_home);
|
||||
let java_bin = &format!("{}/bin/{}", java_home, cmd);
|
||||
if fs::metadata(java_bin).is_ok() {
|
||||
success!("Command found: {}", java_bin);
|
||||
} else {
|
||||
failure!("Command {} not exists", java_bin);
|
||||
return;
|
||||
}
|
||||
let mut cmd = Command::new(java_bin);
|
||||
cmd.envs(&get_env_with_java_home(&java_home));
|
||||
if args.len() > 2 {
|
||||
cmd.args(&args[2..]);
|
||||
}
|
||||
if let Err(err) = run_command_and_wait(&mut cmd) {
|
||||
if let Err(err) = util_cmd::run_command_and_wait(&mut cmd) {
|
||||
failure!("Exec java failed: {}", err);
|
||||
}
|
||||
},
|
||||
@@ -60,6 +63,7 @@ fn do_with_buildin_arg_gradle(first_arg: &str, args: &[String]) {
|
||||
}
|
||||
|
||||
fn do_with_buildin_arg_config(_first_arg: &str, args: &[String]) {
|
||||
information!("Current config file: ~/{}", tool::STANDARD_CONFIG_JSON);
|
||||
if args.len() <= 2 {
|
||||
failure!("No arguments, get or set.");
|
||||
return;
|
||||
@@ -125,7 +129,7 @@ fn do_with_buildin_arg_builder(first_arg: &str, args: &[String], builder_name: &
|
||||
for arg in args.iter().skip(from_index) {
|
||||
cmd.arg(&arg);
|
||||
}
|
||||
if let Err(err) = run_command_and_wait(&mut cmd) {
|
||||
if let Err(err) = util_cmd::run_command_and_wait(&mut cmd) {
|
||||
failure!("Run build command failed: {}", err);
|
||||
}
|
||||
}
|
||||
@@ -158,7 +162,7 @@ fn do_with_buildin_arg_ddd(first_arg: &str, args: &[String]) {
|
||||
if *VERBOSE {
|
||||
debugging!("Running cmd: {}, args: {:?}", &cmd_name, cmd_args);
|
||||
}
|
||||
if let Err(err) = run_command_and_wait(&mut cmd) {
|
||||
if let Err(err) = util_cmd::run_command_and_wait(&mut cmd) {
|
||||
failure!("Run xRun command failed: {}", err);
|
||||
}
|
||||
}
|
||||
@@ -170,10 +174,23 @@ fn do_with_buildin_args(args: &[String]) {
|
||||
":::version" => print_version(),
|
||||
":::create" => create_build_json(args),
|
||||
":::config" => do_with_buildin_arg_config(first_arg, args),
|
||||
a if a.starts_with(":::java") => do_with_buildin_arg_java (a, args),
|
||||
a if a.starts_with(":::maven") => do_with_buildin_arg_maven (a, args),
|
||||
a if a.starts_with(":::gradle") => do_with_buildin_arg_gradle(a, args),
|
||||
a if a.starts_with("...") => do_with_buildin_arg_ddd (a, args),
|
||||
a if a.starts_with(":::jar") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::java") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jinfo") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jlink") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::keytool")=> do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jaotc") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jcmd") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jconsole")=> do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jdb") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jmap") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jps") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jstack") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jstat") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::jimage") => do_with_buildin_arg_java_cmd(a, args),
|
||||
a if a.starts_with(":::maven") => do_with_buildin_arg_maven (a, args),
|
||||
a if a.starts_with(":::gradle") => do_with_buildin_arg_gradle (a, args),
|
||||
a if a.starts_with("...") => do_with_buildin_arg_ddd (a, args),
|
||||
_ => failure!("Unknown args: {:?}", &args),
|
||||
}
|
||||
}
|
||||
@@ -315,10 +332,15 @@ fn read_build_json_object() -> Option<json::JsonValue> {
|
||||
|
||||
|
||||
fn main() {
|
||||
information!("{} - version {} - {}", BUILDJ, BUDERJ_VER, &GIT_HASH[0..7]);
|
||||
match get_short_git_hash() {
|
||||
None => information!("{} - version {}", BUILDJ, BUDERJ_VER),
|
||||
Some(shot_git_hash) => information!("{} - version {} - {}", BUILDJ, BUDERJ_VER, &shot_git_hash),
|
||||
}
|
||||
|
||||
if *VERBOSE {
|
||||
debugging!("Full GIT_HASH: {}", GIT_HASH);
|
||||
if let Some(full_git_hash) = get_full_git_hash() {
|
||||
debugging!("Full GIT_HASH: {}", full_git_hash);
|
||||
}
|
||||
debugging!("Build date: {}", BUILD_DATE);
|
||||
}
|
||||
|
||||
@@ -374,7 +396,7 @@ fn main() {
|
||||
}
|
||||
debugging!("-----END ENVIRONMENT VARIABLES-----");
|
||||
}
|
||||
let exit_status = run_command_and_wait(&mut cmd).unwrap_or_else(|err| {
|
||||
let exit_status = util_cmd::run_command_and_wait(&mut cmd).unwrap_or_else(|err| {
|
||||
failure!("Run build command failed: {}", err);
|
||||
process::exit(-1);
|
||||
});
|
||||
|
||||
28
src/misc.rs
28
src/misc.rs
@@ -1,6 +1,11 @@
|
||||
use std::env;
|
||||
use rust_util::util_env;
|
||||
use rust_util::util_term;
|
||||
use rust_util::{util_env, util_term};
|
||||
|
||||
pub const BUILDJ: &str = "buildj";
|
||||
pub const BUDERJ_VER: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const BUILD_DATE: &str = env!("BUILD_DATE");
|
||||
const GIT_HASH: &str = env!("GIT_HASH");
|
||||
|
||||
|
||||
lazy_static! {
|
||||
pub static ref VERBOSE: bool = util_env::is_env_on("BUILDJ_VERBOSE");
|
||||
@@ -17,18 +22,27 @@ pub fn print_usage() {
|
||||
}
|
||||
|
||||
pub fn print_version() {
|
||||
println!(r#"buildj {} - {}
|
||||
Full git commit hash: {}{}{}
|
||||
println!(r#"buildj {}{}{}
|
||||
Build date: {}
|
||||
|
||||
Copyright (C) 2019-{} Hatter Jiang.
|
||||
License MIT <{}https://opensource.org/licenses/MIT{}>
|
||||
|
||||
Official website: {}https://buildj.ruststack.org/{}
|
||||
"#, super::BUDERJ_VER,
|
||||
&super::GIT_HASH[0..7],
|
||||
util_term::BOLD, &super::GIT_HASH, util_term::END,
|
||||
"#, BUDERJ_VER,
|
||||
get_short_git_hash().map(|h| format!(" - {}", h)).unwrap_or("".into()),
|
||||
get_full_git_hash().map(|h| format!("\nFull git commit hash: {}{}{}", util_term::BOLD, h, util_term::END)).unwrap_or("".into()),
|
||||
BUILD_DATE,
|
||||
*BUILD_YEAR,
|
||||
util_term::UNDER, util_term::END,
|
||||
util_term::UNDER, util_term::END);
|
||||
}
|
||||
|
||||
pub fn get_full_git_hash() -> Option<&'static str> {
|
||||
// build from crates, git hash is empty
|
||||
iff!(GIT_HASH.is_empty(), None, Some(GIT_HASH))
|
||||
}
|
||||
|
||||
pub fn get_short_git_hash() -> Option<&'static str> {
|
||||
get_full_git_hash().map(|h| &h[0..7])
|
||||
}
|
||||
|
||||
20
src/tool.rs
20
src/tool.rs
@@ -1,5 +1,5 @@
|
||||
use std::{fs::{self, File}, path::Path};
|
||||
use rust_util::{ XResult, new_box_ioerror, util_os};
|
||||
use rust_util::{ XResult, util_os};
|
||||
use crate::{http, local_util, misc::{AUTH_TOKEN, VERBOSE, NOAUTH}};
|
||||
|
||||
const M2_HOME: &str = "M2_HOME";
|
||||
@@ -7,7 +7,7 @@ const MAVEN_HOME: &str = "MAVEN_HOME";
|
||||
const GRADLE_HOME: &str = "GRADLE_HOME";
|
||||
|
||||
pub const LOCAL_BUILDER_HOME_BASE_DIR: &str = ".jssp/builder";
|
||||
const STANDARD_CONFIG_JSON: &str = ".standard_config.json";
|
||||
pub const STANDARD_CONFIG_JSON: &str = ".standard_config.json";
|
||||
const TOOL_PACKAGE_DETAIL_URL: &str = "https://hatter.ink/tool/query_tool_by_name_version.json";
|
||||
const TOOL_PACKAGE_DETAIL_URL_WITHOUT_AUTH: &str = "https://hatter.ink/tool/query_tool_by_name_version_without_auth.json";
|
||||
|
||||
@@ -115,7 +115,7 @@ pub fn get_tool_package_secret() -> XResult<String> {
|
||||
let build_js_auth_token = &standard_config_object["build.js"]["auth_token"];
|
||||
|
||||
if build_js_auth_token.is_null() {
|
||||
Err(new_box_ioerror("Standard json#build.js#auth_token is null."))
|
||||
simple_error!("Standard json#build.js#auth_token is null.")
|
||||
} else {
|
||||
Ok(build_js_auth_token.to_string())
|
||||
}
|
||||
@@ -131,12 +131,12 @@ pub fn set_tool_package_secret(secret: &str) -> XResult<()> {
|
||||
"auth_token" => secret, }
|
||||
}, 4)) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(new_box_ioerror(&format!("Write config failed: {}, error message: {}", standard_config_file, err))),
|
||||
Err(err) => simple_error!("Write config failed: {}, error message: {}", standard_config_file, err),
|
||||
}
|
||||
},
|
||||
Ok(f) => {
|
||||
if ! f.is_file() {
|
||||
return Err(new_box_ioerror(&format!("Config is not a file: {}", standard_config_file)));
|
||||
return simple_error!("Config is not a file: {}", standard_config_file);
|
||||
}
|
||||
let standard_config_json = fs::read_to_string(&standard_config_file)?;
|
||||
let mut standard_config_object = json::parse(&standard_config_json)?;
|
||||
@@ -149,7 +149,7 @@ pub fn set_tool_package_secret(secret: &str) -> XResult<()> {
|
||||
}
|
||||
match fs::write(&standard_config_file, json::stringify_pretty(standard_config_object, 4)) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(new_box_ioerror(&format!("Write config failed: {}, error message: {}", &standard_config_file, err))),
|
||||
Err(err) => simple_error!("Write config failed: {}, error message: {}", &standard_config_file, err),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,20 +195,20 @@ pub fn get_and_extract_tool_package(base_dir: &str, dir_with_name: bool, name: &
|
||||
debugging!("Get tool {}:{}, result JSON: {}", name, version, json::stringify_pretty(build_json_object.clone(), 4));
|
||||
}
|
||||
if build_json_object["status"] != 200 {
|
||||
return Err(new_box_ioerror(&format!("Error in get tool package detail: {}", build_json_object["message"])));
|
||||
return simple_error!("Error in get tool package detail: {}", build_json_object["message"]);
|
||||
}
|
||||
let data = &build_json_object["data"];
|
||||
let integrity = &data["integrity"];
|
||||
let url = &data["url"];
|
||||
let name = &data["name"];
|
||||
if integrity.is_null() || url.is_null() || name.is_null() {
|
||||
return Err(new_box_ioerror(&format!("Parse tool package detail failed: {}", tool_package_detail)));
|
||||
return simple_error!("Parse tool package detail failed: {}", tool_package_detail);
|
||||
}
|
||||
let n = data["n"].to_string();
|
||||
let v = data["v"].to_string();
|
||||
|
||||
if extract_match && version != v {
|
||||
return Err(new_box_ioerror(&format!("Required version not match, {}: {} vs {}", name, version, &v)));
|
||||
return simple_error!("Required version not match, {}: {} vs {}", name, version, &v);
|
||||
}
|
||||
|
||||
let mut target_base_dir = String::with_capacity(512);
|
||||
@@ -227,7 +227,7 @@ pub fn get_and_extract_tool_package(base_dir: &str, dir_with_name: bool, name: &
|
||||
if local_util::verify_file_integrity(&integrity.to_string(), &target_file_name)? {
|
||||
success!("Verify integrity success.");
|
||||
} else {
|
||||
return Err(new_box_ioerror("Verify integrity failed!"));
|
||||
return simple_error!("Verify integrity failed!");
|
||||
}
|
||||
|
||||
success!("Start extract file: {}", &target_file_name);
|
||||
|
||||
Reference in New Issue
Block a user