From cb180d9c01f41081d480c365c3f2698cf5ec3d56 Mon Sep 17 00:00:00 2001 From: Elton Lika Date: Thu, 13 Jun 2019 12:19:47 +0200 Subject: [PATCH] Implemented support for SDKMAN! updates and upgrades (#167) --- src/config.rs | 3 +++ src/main.rs | 12 +++++++++++ src/steps/os/unix.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/src/config.rs b/src/config.rs index da7fc6d3..0bf5df6d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,7 @@ lazy_static! { m.insert("vim", Step::Vim); m.insert("emacs", Step::Emacs); m.insert("gem", Step::Gem); + m.insert("sdkman", Step::Sdkman); #[cfg(windows)] m.insert("powershell", Step::Powershell); @@ -43,6 +44,8 @@ pub enum Step { Emacs, /// Don't upgrade ruby gems Gem, + /// Don't upgrade SDKMAN! and its packages + Sdkman, #[cfg(windows)] /// Don't update Powershell modules diff --git a/src/main.rs b/src/main.rs index 247dd0ff..a26cb111 100644 --- a/src/main.rs +++ b/src/main.rs @@ -468,6 +468,18 @@ fn run() -> Result<(), Error> { } } + #[cfg(unix)] + { + if config.should_run(Step::Sdkman) { + execute( + &mut report, + "SDKMAN!", + || unix::run_sdkman(&base_dirs, config.cleanup(), run_type), + config.no_retry(), + )?; + } + } + if !report.data().is_empty() { print_separator("Summary"); diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 671218ee..a0d6cb6f 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -84,3 +84,51 @@ pub fn run_pearl(run_type: RunType) -> Result<(), Error> { run_type.execute(&pearl).arg("update").check_run() } + +pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Result<(), Error> { + let bash_path = require("bash").map(|p| format!("{}", &p.display()))?; + + let sdkman_init_path = env::var("SDKMAN_DIR") + .map(PathBuf::from) + .unwrap_or_else(|_| base_dirs.home_dir().join(".sdkman")) + .join("bin") + .join("sdkman-init.sh") + .require() + .map(|p| format!("{}", &p.display()))?; + + print_separator("SDKMAN!"); + + let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path); + run_type + .execute(&bash_path) + .args(&["-c", cmd_selfupdate.as_str()]) + .check_run()?; + + let cmd_update = format!("source {} && sdk update", &sdkman_init_path); + run_type + .execute(&bash_path) + .args(&["-c", cmd_update.as_str()]) + .check_run()?; + + let cmd_upgrade = format!("source {} && sdk upgrade", &sdkman_init_path); + run_type + .execute(&bash_path) + .args(&["-c", cmd_upgrade.as_str()]) + .check_run()?; + + if cleanup { + let cmd_flush_archives = format!("source {} && sdk flush archives", &sdkman_init_path); + run_type + .execute(&bash_path) + .args(&["-c", cmd_flush_archives.as_str()]) + .check_run()?; + + let cmd_flush_temp = format!("source {} && sdk flush temp", &sdkman_init_path); + run_type + .execute(&bash_path) + .args(&["-c", cmd_flush_temp.as_str()]) + .check_run()?; + } + + Ok(()) +}