diff --git a/.ci/install.sh b/.ci/install.sh new file mode 100644 index 0000000..6e71480 --- /dev/null +++ b/.ci/install.sh @@ -0,0 +1,171 @@ +#!/bin/bash + +INSTALL_DIR="$HOME/.jvc" +RELEASE="latest" +OS="$(uname -s)" + +# Parse Flags +parse_args() { + while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -d | --install-dir) + INSTALL_DIR="$2" + shift # past argument + shift # past value + ;; + -s | --skip-shell) + SKIP_SHELL="true" + shift # past argument + ;; + -r | --release) + RELEASE="$2" + shift # past release argument + shift # past release value + ;; + *) + echo "Unrecognized argument $key" + exit 1 + ;; + esac + done +} + +set_filename() { + if [ "$OS" == "Linux" ]; then + FILENAME="jvc-linux-amd64" + elif [ "$OS" == "Darwin" ]; then + FILENAME="jvc-macos-amd64" + echo "Downloading the latest jvc binary from GitHub..." + else + echo "OS $OS is not supported." + exit 1 + fi +} + +download_jvc() { + if [ "$RELEASE" == "latest" ]; then + URL="https://github.com/neculai-stanciu/jvc/releases/latest/download/$FILENAME" + else + URL="https://github.com/neculai-stanciu/jvc/releases/download/$RELEASE/$FILENAME" + fi + + DOWNLOAD_DIR=$(mktemp -d) + + echo "Downloading $URL..." + + mkdir -p "$INSTALL_DIR" &>/dev/null + + if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME"; then + echo "Download failed. Check that the release/filename are correct." + exit 1 + fi + + if [ -f "$DOWNLOAD_DIR/$FILENAME" ]; then + mv "$DOWNLOAD_DIR/$FILENAME" "$INSTALL_DIR/jvc" + else + echo "Cannot find $FILENAME in path $DOWNLOAD_DIR" + exit 2 + fi + + chmod u+x "$INSTALL_DIR/jvc" +} + +check_dependencies() { + echo "Checking dependencies for the installation script..." + + echo -n "Checking availability of curl... " + if hash curl 2>/dev/null; then + echo "OK!" + else + echo "Missing!" + SHOULD_EXIT="true" + fi + + echo -n "Checking availability of unzip... " + if hash unzip 2>/dev/null; then + echo "OK!" + else + echo "Missing!" + SHOULD_EXIT="true" + fi + + if [ "$USE_HOMEBREW" = "true" ]; then + echo -n "Checking availability of Homebrew (brew)... " + if hash brew 2>/dev/null; then + echo "OK!" + else + echo "Missing!" + SHOULD_EXIT="true" + fi + fi + + if [ "$SHOULD_EXIT" = "true" ]; then + exit 1 + fi +} + +ensure_containing_dir_exists() { + local CONTAINING_DIR + CONTAINING_DIR="$(dirname "$1")" + if [ ! -d "$CONTAINING_DIR" ]; then + echo " >> Creating directory $CONTAINING_DIR" + mkdir -p "$CONTAINING_DIR" + fi +} + +setup_shell() { + CURRENT_SHELL="$(basename "$SHELL")" + + if [ "$CURRENT_SHELL" == "zsh" ]; then + CONF_FILE=${ZDOTDIR:-$HOME}/.zshrc + ensure_containing_dir_exists "$CONF_FILE" + echo "Installing for Zsh. Appending the following to $CONF_FILE:" + echo "" + echo ' # jvc' + echo ' export PATH='"$INSTALL_DIR"':$PATH' + echo ' eval "`jvc env`"' + + echo '' >>$CONF_FILE + echo '# jvc' >>$CONF_FILE + echo 'export PATH='$INSTALL_DIR':$PATH' >>$CONF_FILE + echo 'eval "`jvc env`"' >>$CONF_FILE + + elif [ "$CURRENT_SHELL" == "bash" ]; then + if [ "$OS" == "Darwin" ]; then + CONF_FILE=$HOME/.profile + else + CONF_FILE=$HOME/.bashrc + fi + ensure_containing_dir_exists "$CONF_FILE" + echo "Installing for Bash. Appending the following to $CONF_FILE:" + echo "" + echo ' # jvc' + echo ' export PATH='"$INSTALL_DIR"':$PATH' + echo ' eval "`jvc env`"' + + echo '' >>$CONF_FILE + echo '# jvc' >>$CONF_FILE + echo 'export PATH='"$INSTALL_DIR"':$PATH' >>$CONF_FILE + echo 'eval "`jvc env`"' >>$CONF_FILE + + else + echo "Could not infer shell type. Please set up manually." + echo "Current shell is $CURRENT_SHELL" + exit 1 + fi + + echo "" + echo "In order to apply the changes, open a new terminal or run the following command:" + echo "" + echo " source $CONF_FILE" +} + +parse_args "$@" +set_filename +check_dependencies +download_jvc +if [ "$SKIP_SHELL" != "true" ]; then + setup_shell +fi diff --git a/.github/workflows/create_new_tag.yml b/.github/workflows/create_new_tag.yml index a4589e1..fde2c3e 100644 --- a/.github/workflows/create_new_tag.yml +++ b/.github/workflows/create_new_tag.yml @@ -1,4 +1,4 @@ -name: Bump version, create new tag and release point +name: create-tag on: push: diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 8f9b142..1a3f264 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -1,4 +1,4 @@ -name: "Build and upload binaries to release jvc" +name: release-jvc on: repository_dispatch: diff --git a/.gitignore b/.gitignore index db56b21..a7d1311 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ todo.md 0 maven.http -/.ci diff --git a/Cargo.lock b/Cargo.lock index fd417f2..0763e69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -610,15 +610,6 @@ dependencies = [ "regex", ] -[[package]] -name = "instant" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "ipnet" version = "2.3.0" @@ -642,7 +633,7 @@ dependencies = [ [[package]] name = "jvc" -version = "0.1.20" +version = "0.1.12" dependencies = [ "anyhow", "async-trait", @@ -679,15 +670,6 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" -[[package]] -name = "lock_api" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.14" @@ -793,28 +775,12 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "number_prefix" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" -[[package]] -name = "once_cell" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" - [[package]] name = "openssl" version = "0.10.32" @@ -848,31 +814,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "parking_lot" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272" -dependencies = [ - "cfg-if 1.0.0", - "instant", - "libc", - "redox_syscall 0.1.57", - "smallvec", - "winapi", -] - [[package]] name = "percent-encoding" version = "2.1.0" @@ -1187,12 +1128,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "security-framework" version = "2.0.0" @@ -1238,9 +1173,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" +checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486" dependencies = [ "itoa", "ryu", @@ -1259,27 +1194,12 @@ dependencies = [ "serde", ] -[[package]] -name = "signal-hook-registry" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -[[package]] -name = "smallvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0" - [[package]] name = "socket2" version = "0.3.19" @@ -1458,29 +1378,24 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6714d663090b6b0acb0fa85841c6d66233d150cdb2602c8f9b8abb03370beb3f" +checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" dependencies = [ "autocfg", "bytes 1.0.0", "libc", "memchr", "mio", - "num_cpus", - "once_cell", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "tokio-macros", - "winapi", ] [[package]] name = "tokio-macros" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index f4bc0b7..e3a4675 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,11 @@ [package] name = "jvc" -version = "0.1.20" +version = "0.1.12" authors = ["Stanciu Neculai "] edition = "2018" +description = "A simple tool that help with java versions." +license = "MIT" +repository= "https://github.com/neculai-stanciu/jvc" [[bin]] name = "jvc" @@ -18,7 +21,7 @@ path = "src/jvc-init.rs" structopt = "0.3.21" # async runtime -tokio = { version = "1.1.1", features = ["full"] } +tokio = { version = "1.2.0", features = ["macros", "rt", "net", "io-util", "fs"] } async-trait = "0.1.42" # error handling @@ -33,7 +36,7 @@ reqwest = { version = "0.11", features = ["json"] } colored = "2.0.0" # json serialization serde = { version = "1.0.123", features = ["derive"] } -serde_json = "1.0.61" +serde_json = "1.0.62" chrono = { version = "0.4.19", features = ["serde"] } # temp dir tempdir = "0.3.7" @@ -53,7 +56,6 @@ dirs = "3.0.1" csv = "1.1.5" winreg= "0.8.0" - [profile.dev] opt-level = 0 debug = true diff --git a/README.md b/README.md index 8c88c16..65d1f06 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ -# jvc: Java versions controller -## Documentation +# jvc: java versions controller -A tool to handle java versions. +![Amount of downloads](https://img.shields.io/github/downloads/neculai-stanciu/jvc/total.svg?style=flat) +![Issues opened](https://img.shields.io/github/issues/neculai-stanciu/jvc) +A tool to handle java versions. - +## Installation +## Supported shells diff --git a/src/commands/windows/mod.rs b/src/commands/windows/mod.rs index dd4147e..d8aab6f 100644 --- a/src/commands/windows/mod.rs +++ b/src/commands/windows/mod.rs @@ -74,6 +74,9 @@ impl Executor for Setup { let shell_path_as_str = shell_path .to_str() .ok_or(anyhow!("Cannot set shell path."))?; + + debug!("Create a JVC_SHELL_PATH {}", shell_path_as_str); + let base_dir = config.get_base_dir_or_default(); let jvc_dir_as_str = base_dir .to_str() diff --git a/src/jvc-init.rs b/src/jvc-init.rs index f4e38ba..e0cc333 100644 --- a/src/jvc-init.rs +++ b/src/jvc-init.rs @@ -216,7 +216,7 @@ async fn set_persistent_path(value: &str) -> Result<()> { Ok(()) } -#[tokio::main] +#[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { let start_time = Instant::now(); let args: Cli = Cli::from_args(); diff --git a/src/main.rs b/src/main.rs index b3e9983..601d16d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ fn init_logging(log_level: &LogLevel) { .init(); } -#[tokio::main] +#[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { let start_time = Instant::now();