1
0
mirror of https://github.com/jht5945/buildj.git synced 2025-12-27 09:20:03 +08:00

feat: update version and using simple_error

This commit is contained in:
2021-02-06 11:01:08 +08:00
parent 7248796b2e
commit 186c08a8f5
8 changed files with 382 additions and 871 deletions

1190
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
[package]
name = "buildj"
version = "0.1.7"
version = "0.1.8"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
homepage = "https://buildj.ruststack.org/"
@@ -8,11 +8,11 @@ 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"

View File

@@ -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())
}

View File

@@ -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()?)
}

View File

@@ -3,7 +3,7 @@ use std::path::Path;
use std::process::Command;
use std::fs::{self, File};
use std::io::{Read, ErrorKind};
use rust_util::{XResult, new_box_ioerror};
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}};
@@ -19,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] {
@@ -27,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 {
@@ -67,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!"),
}
}
@@ -95,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(())

View File

@@ -52,6 +52,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;

View File

@@ -1,6 +1,5 @@
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");
@@ -40,6 +39,7 @@ Official website: {}https://buildj.ruststack.org/{}
}
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))
}

View File

@@ -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);