diff --git a/Cargo.lock b/Cargo.lock index dcdc1a0..262a81c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,6 +80,7 @@ version = "0.1.2" dependencies = [ "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "json 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.19 (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)", diff --git a/Cargo.toml b/Cargo.toml index 811d5ef..1a31189 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,5 @@ reqwest = "0.9.18" urlencoding = "1.0.0" dirs = "2.0.1" rust-crypto = "0.2.36" +lazy_static = "1.3.0" rust_util = { git = "https://github.com/jht5945/rust_util" } diff --git a/build.rs b/build.rs index b596729..7ffdd60 100644 --- a/build.rs +++ b/build.rs @@ -3,4 +3,7 @@ fn main() { let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap(); println!("cargo:rustc-env=GIT_HASH={}", git_hash); + let date_output = Command::new("date").output().unwrap(); + let date = String::from_utf8(date_output.stdout).unwrap(); + println!("cargo:rustc-env=BUILD_DATE={}", date); } diff --git a/src/http.rs b/src/http.rs index 15d7fc6..e62b48f 100644 --- a/src/http.rs +++ b/src/http.rs @@ -11,11 +11,12 @@ use rust_util::{ XResult, }; -use super::misc::*; +use super::misc::{ + VERBOSE, +}; pub fn download_url(url: &str, dest: &mut File) -> XResult<()> { - let verbose = is_verbose(); - if verbose { + if *VERBOSE { print_message(MessageType::DEBUG, &format!("Download URL: {}", url)); } let mut response = reqwest::get(url)?; @@ -23,7 +24,7 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> { None => -1, Some(len_value) => len_value.to_str().unwrap().parse::().unwrap(), }; - if verbose { + if *VERBOSE { print_message(MessageType::DEBUG, &format!("Content-Length: {}", header_content_length)); } copy_io(&mut response, dest, header_content_length)?; @@ -31,7 +32,7 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> { } pub fn get_url(url: &str) -> XResult { - if is_verbose() { + if *VERBOSE { print_message(MessageType::DEBUG, &format!("Get URL: {}", url)); } Ok(reqwest::get(url)?.text()?) diff --git a/src/main.rs b/src/main.rs index c947d68..76810af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,8 @@ extern crate dirs; extern crate crypto; extern crate urlencoding; extern crate rust_util; +#[macro_use] +extern crate lazy_static; pub mod jdk; pub mod local_util; @@ -33,6 +35,7 @@ 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: &Vec) { @@ -137,6 +140,11 @@ fn do_with_buildin_args(args: &Vec) { fn main() { print_message(MessageType::INFO, &format!("{} - version {} - {}", BUILDJ, BUDERJ_VER, &GIT_HASH[0..7])); + if *VERBOSE { + print_message(MessageType::DEBUG, &format!("Full GIT_HASH: {}", GIT_HASH)); + print_message(MessageType::DEBUG, &format!("Binary build date: {}", BUILD_DATE)); + } + let args = local_util::get_args_as_vec(); print_message(MessageType::INFO, &format!("Arguments: {:?}", args)); diff --git a/src/misc.rs b/src/misc.rs index ef58f30..339a5df 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -1,15 +1,24 @@ use std::env; +lazy_static! { + pub static ref VERBOSE: bool = is_verbose(); +} + pub fn print_usage() { print!(r#" buildj ::: - print this message buildj :::help - print this message buildj :::create --java --maven - create java-version, maven-version project + e.g. buildj :::create --java1.8 --maven3.5.2 buildj :::create --java --gradle - create java-version, gradle-version project -buildj :::java [-version] - run java with assigned version, e.g. buildj :::java1.8 -version -buildj :::maven [--java] - run maven with assigned version and java version, e.g. buildj :::maven3.5.2 --java1.8 ARGS -buildj :::gradle [--java] - run gradle with assigned version and java version, e.g. buildj :::gradle3.5.1 --java1.8 ARGS + e.g. buildj :::create --java1.8 --gradle3.5.1 +buildj :::java [-version] - run java with assigned version + e.g. buildj :::java1.8 -version +buildj :::maven [--java] - run maven with assigned version and java version + e.g. buildj :::maven3.5.2 --java1.8 ARGS +buildj :::gradle [--java] - run gradle with assigned version and java version + e.g. buildj :::gradle3.5.1 --java1.8 ARGS buildj - run build, run assigned version builder tool "#); }