diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15df9cb..ad77e1c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,8 @@ jobs: - name: Smoke Test shell: bash run: | - mkdir .jgrab - cp ./jgrab-runner/build/libs/jgrab.jar ./.jgrab/jgrab.jar + export JGRAB_HOME="$(pwd)/.jgrab" + mkdir $JGRAB_HOME + cp ./jgrab-runner/build/libs/jgrab.jar $JGRAB_HOME/jgrab.jar + ls -al $JGRAB_HOME ./jgrab-client/target/debug/jgrab-client -e "2 + 2" diff --git a/jgrab-client/Cargo.lock b/jgrab-client/Cargo.lock index 4811cda..c540526 100644 --- a/jgrab-client/Cargo.lock +++ b/jgrab-client/Cargo.lock @@ -2,18 +2,145 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "jgrab-client" version = "0.6.0" dependencies = [ + "dirs", "wait-timeout", ] [[package]] name = "libc" -version = "0.2.22" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "option-ext" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_users" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "syn" +version = "2.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "wait-timeout" @@ -23,3 +150,75 @@ checksum = "b9f3bf741a801531993db6478b95682117471f76916f5e690dd8d45395b09349" dependencies = [ "libc", ] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/jgrab-client/Cargo.toml b/jgrab-client/Cargo.toml index e0c9d24..af778ce 100644 --- a/jgrab-client/Cargo.toml +++ b/jgrab-client/Cargo.toml @@ -5,9 +5,10 @@ version = "0.6.0" authors = [ "Renato Athaydes" ] [dependencies] +dirs = "5.0.1" wait-timeout = "0.1.5" [profile.release] lto = true -panic = 'abort' \ No newline at end of file +panic = 'abort' diff --git a/jgrab-client/src/main.rs b/jgrab-client/src/main.rs index b891620..cc4cd71 100644 --- a/jgrab-client/src/main.rs +++ b/jgrab-client/src/main.rs @@ -1,3 +1,4 @@ +use dirs::home_dir; use std::env; use std::fs::File; use std::io::{stdin, stdout, Cursor, Error, Read, Result, Stdin, Write}; @@ -12,6 +13,7 @@ use std::time::Duration; use wait_timeout::ChildExt; use Input::*; +extern crate dirs; extern crate wait_timeout; const MAX_RETRIES: usize = 5; @@ -213,15 +215,24 @@ fn send_message(reader: &mut R, is_retry: bool) -> Option { } } +fn find_jgrab_jar() -> PathBuf { + let jgrab_home = env::var("JGRAB_HOME"); + let mut path: PathBuf = if let Ok(home) = jgrab_home { + home.into() + } else { + let mut path = home_dir() + .unwrap_or_else(|| env::current_dir().expect("must be able to access current dir!")); + path.push(".jgrab"); + path + }; + path.push("jgrab.jar"); + path +} + fn start_daemon() -> Child { log("Starting daemon"); - let user_home = env::home_dir() - .unwrap_or_else(|| env::current_dir().expect("must be able to access current dir!")); - let mut jgrab_jar: PathBuf = user_home; - jgrab_jar.push(".jgrab"); - jgrab_jar.push("jgrab.jar"); - + let jgrab_jar: PathBuf = find_jgrab_jar(); if jgrab_jar.as_path().is_file() { let cmd = Command::new("java") .arg("-jar") @@ -237,6 +248,10 @@ fn start_daemon() -> Child { Err(err) => error(&err.to_string()), } } else { + log(&format!( + "JGrab jar does not exist: {}", + jgrab_jar.as_path().display() + )); error( "The JGrab jar is not installed! Please install it as explained \ in https://github.com/renatoathaydes/jgrab",