From 53c75758fa87d2ae711adb91263157f03f0a9035 Mon Sep 17 00:00:00 2001 From: Gildas Cuisinier Date: Sun, 27 Jan 2013 10:51:41 +0100 Subject: [PATCH] prepare exec hook --- libexec/jenv | 45 ++++++++++++++++--- libexec/jenv-add | 11 +---- libexec/jenv-exec | 1 + libexec/jenv-remove | 19 +++----- .../maven/etc/jenv.d/exec/maven-before.bash | 1 + plugins/maven/etc/jenv.d/rehash/maven.bash | 45 ++++++++++++++++++- 6 files changed, 90 insertions(+), 32 deletions(-) create mode 100644 plugins/maven/etc/jenv.d/exec/maven-before.bash diff --git a/libexec/jenv b/libexec/jenv index 790c90e..bce3577 100755 --- a/libexec/jenv +++ b/libexec/jenv @@ -20,6 +20,24 @@ abs_dirname() { cd "$cwd" } +resolvepath() { + local cwd="$(pwd)" + cd $1 + echo "$(pwd)" + cd "$cwd" +} + +samedir() { + local path1="$(resolvepath $1)" + local path2="$(resolvepath $2)" + + if [ $path1 == $path2 ]; then + return 0; + else + return 1; + fi +} + if [ -z "${JENV_ROOT}" ]; then JENV_ROOT="${HOME}/.jenv" else @@ -45,6 +63,8 @@ shopt -s nullglob bin_path="$(abs_dirname "$0")" + + @@ -52,20 +72,31 @@ for plugin_bin in "${JENV_ROOT}/plugins/"*/bin; do bin_path="${bin_path}:${plugin_bin}" done -for plugin_bin in "$bin_path/../plugins/"*/bin; do - bin_path="${bin_path}:${plugin_bin}" -done +# If jenv is not installed in $HOME/.jenv, look for plugin in installation directory +if ! samedir "${JENV_ROOT}" "$bin_path/../" ; then + for plugin_bin in "$bin_path/../plugins/"*/bin; do + bin_path="${bin_path}:${plugin_bin}" + done +fi + + + +export PATH="${bin_path}:${PATH}" + -export PATH="${bin_path}:${PATH}" hook_path="${JENV_HOOK_PATH}" for plugin_hook in "${JENV_ROOT}/plugins/"*/etc/jenv.d; do hook_path="${hook_path}:${plugin_hook}" done -for plugin_hook in "$bin_path/../plugins/"*/etc/jenv.d; do - hook_path="${hook_path}:${plugin_hook}" -done +# If jenv is not installed in $HOME/.jenv, look for plugin in installation directory +if ! samedir "${JENV_ROOT}" "$bin_path/../" ; then + for plugin_hook in "$bin_path/../plugins/"*/etc/jenv.d; do + hook_path="${hook_path}:${plugin_hook}" + done +fi + export JENV_HOOK_PATH=$hook_path diff --git a/libexec/jenv-add b/libexec/jenv-add index bd3c497..b895a70 100755 --- a/libexec/jenv-add +++ b/libexec/jenv-add @@ -2,21 +2,12 @@ set -e [ -n "$JENV_DEBUG" ] && set -x -# Provide jenv completions -if [ "$1" = "--complete" ]; then - echo --unset - echo system - exec jenv-versions --bare -fi + JENV_VERSION="$1" JENV_JAVAPATH="$2" JENV_VERSION_FILE=".jenv-version" - -echo $JENV_VERSION -echo $JENV_JAVAPATH - if [ -f "$JENV_JAVAPATH/bin/java" ]; then diff --git a/libexec/jenv-exec b/libexec/jenv-exec index 2338efb..a7631dd 100755 --- a/libexec/jenv-exec +++ b/libexec/jenv-exec @@ -34,6 +34,7 @@ fi JENV_COMMAND_PATH="$(jenv-which "$JENV_COMMAND")" JENV_BIN_PATH="${JENV_COMMAND_PATH%/*}" + for script in $(jenv-hooks exec); do source "$script" done diff --git a/libexec/jenv-remove b/libexec/jenv-remove index bd3c497..bb06322 100755 --- a/libexec/jenv-remove +++ b/libexec/jenv-remove @@ -4,24 +4,17 @@ set -e # Provide jenv completions if [ "$1" = "--complete" ]; then - echo --unset - echo system exec jenv-versions --bare fi JENV_VERSION="$1" -JENV_JAVAPATH="$2" -JENV_VERSION_FILE=".jenv-version" -echo $JENV_VERSION -echo $JENV_JAVAPATH - - -if [ -f "$JENV_JAVAPATH/bin/java" ]; -then - ln -s "$JENV_JAVAPATH" "${JENV_ROOT}/versions/$JENV_VERSION" - $(jenv-rehash) +if [ -L " " ]; +then + rm -f $JENV_ROOT/versions/$JENV_VERSION + $(jenv-rehash) + else - echo "$JENV_JAVAPATH is not a valid path to java installation" + echo "$JENV_VERSION is not a managed version of Java " fi diff --git a/plugins/maven/etc/jenv.d/exec/maven-before.bash b/plugins/maven/etc/jenv.d/exec/maven-before.bash new file mode 100644 index 0000000..e616483 --- /dev/null +++ b/plugins/maven/etc/jenv.d/exec/maven-before.bash @@ -0,0 +1 @@ +echo "Before execute $1 $2" \ No newline at end of file diff --git a/plugins/maven/etc/jenv.d/rehash/maven.bash b/plugins/maven/etc/jenv.d/rehash/maven.bash index 3623bed..adaf5a8 100644 --- a/plugins/maven/etc/jenv.d/rehash/maven.bash +++ b/plugins/maven/etc/jenv.d/rehash/maven.bash @@ -1,2 +1,43 @@ -bin_path="/usr/share/maven/bin/*" -make_shims "$bin_path" \ No newline at end of file +remove_from_path() { + local path_to_remove="$(expand_path "$1")" + local result="" + + if [ -z "$path_to_remove" ]; then + echo "${PATH}" + return + fi + + local paths + IFS=: paths=($PATH) + + for path in "${paths[@]}"; do + path="$(expand_path "$path" || true)" + if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then + result="${result}${path}:" + fi + done + + echo "${result%:}" +} + +expand_path() { + if [ ! -d "$1" ]; then + return 1 + fi + + local cwd="$(pwd)" + cd "$1" + pwd + cd "$cwd" +} + +backuppath=$PATH + +PATH="$(remove_from_path "${JENV_ROOT}/shims")" +MAVEN_BIN="$(command -v "mvn" || true)" + +PATH=$backuppath + +#echo "make shims $MAVEN_BIN" +make_shims "$MAVEN_BIN" +