Skip to content

Loading…

Prevent jdk_switcher from resetting PATH #338

Merged
merged 4 commits into from

3 participants

@BanzaiMan
Travis CI member

Since /etc/profile.d/load_jdk_switcher.sh always sources
$HOME/.jdk_switcher_rc, jdk_switcher reverting to the original $PATH
causes problems when other stuff (such as PostgreSQL service)
starts a login shell after manipulating $PATH and subshell is expected
to find stuff in the modified $PATH.

@BanzaiMan BanzaiMan Prevent jdk_switcher from resetting PATH
Since /etc/profile.d/load_jdk_switcher.sh always sources
$HOME/.jdk_switcher_rc, jdk_switcher reverting to the original PATH
causes problems when other stuff (such as PostgreSQL service)
starts a login shell after manipulating PATH and subshell is expected
to find stuff in the modified PATH.
a6f3e65
@joshk joshk was assigned by BanzaiMan
BanzaiMan added some commits
@henrikhodne henrikhodne commented on an outdated diff
ci_environment/java/templates/ubuntu/jdk_switcher.sh.erb
@@ -108,6 +103,14 @@ warn_gcj_user () {
echo "We do not support GCJ." >&2
}
+remove_dir_from_path() {
+ local target=$(echo $1 | sed -e 's:/*$::') # remove all occurrences of / at the end
+ PATH=:$(echo $PATH: | sed -e 's_/*:_:_g'):
@henrikhodne Travis CI member
$ PATH=foo:bar/
$ echo :$(echo $PATH: | sed -e 's_/*:_:_g'):
:foo:bar::

I think this'll work better:

PATH="$(echo :$PATH: | sed -e 's_/*:_:_g')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@joshk joshk merged commit 5c9bec6 into master

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
@joshk joshk deleted the ha-bug-jdk_switcher-path-manipulation branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 30, 2014
  1. @BanzaiMan

    Prevent jdk_switcher from resetting PATH

    BanzaiMan committed
    Since /etc/profile.d/load_jdk_switcher.sh always sources
    $HOME/.jdk_switcher_rc, jdk_switcher reverting to the original PATH
    causes problems when other stuff (such as PostgreSQL service)
    starts a login shell after manipulating PATH and subshell is expected
    to find stuff in the modified PATH.
  2. @BanzaiMan
  3. @BanzaiMan

    Append : to $PATH in remove_dir_from_path

    BanzaiMan committed
    : at the end is necessary in case the last PATH element has
    trailing slashes
  4. @BanzaiMan

    Tweak PATH manipulation

    BanzaiMan committed
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 13 deletions.
  1. +16 −13 ci_environment/java/templates/ubuntu/jdk_switcher.sh.erb
View
29 ci_environment/java/templates/ubuntu/jdk_switcher.sh.erb
@@ -4,15 +4,6 @@
# JDK switcher based on https://github.com/michaelklishin/jdk_switcher
#
-# first time we run, save PATH
-ORIG_PATH_FILE=$HOME/.orig.path
-if [ -f $ORIG_PATH_FILE ]; then
- ORIG_PATH=$(cat $ORIG_PATH_FILE)
-else
- ORIG_PATH=$PATH
- echo $ORIG_PATH > $ORIG_PATH_FILE
-fi
-
if uname -a | grep x86_64 >/dev/null ; then
ARCH_SUFFIX=amd64
else
@@ -58,26 +49,30 @@ fi
switch_to_openjdk6 () {
echo "Switching to OpenJDK6 ($OPENJDK6_UJA_ALIAS), JAVA_HOME will be set to $OPENJDK6_JAVA_HOME"
+ remove_dir_from_path $JAVA_HOME/bin
export JAVA_HOME="$OPENJDK6_JAVA_HOME"
- export PATH=$JAVA_HOME/bin:$ORIG_PATH
+ export PATH=$JAVA_HOME/bin:$PATH
}
switch_to_openjdk7 () {
echo "Switching to OpenJDK7 ($OPENJDK7_UJA_ALIAS), JAVA_HOME will be set to $OPENJDK7_JAVA_HOME"
+ remove_dir_from_path $JAVA_HOME/bin
export JAVA_HOME="$OPENJDK7_JAVA_HOME"
- export PATH=$JAVA_HOME/bin:$ORIG_PATH
+ export PATH=$JAVA_HOME/bin:$PATH
}
switch_to_oraclejdk7 () {
echo "Switching to Oracle JDK7 ($ORACLEJDK7_UJA_ALIAS), JAVA_HOME will be set to $ORACLEJDK7_JAVA_HOME"
+ remove_dir_from_path $JAVA_HOME/bin
export JAVA_HOME="$ORACLEJDK7_JAVA_HOME"
- export PATH=$JAVA_HOME/bin:$ORIG_PATH
+ export PATH=$JAVA_HOME/bin:$PATH
}
switch_to_oraclejdk8 () {
echo "Switching to Oracle JDK8 ($ORACLEJDK8_UJA_ALIAS), JAVA_HOME will be set to $ORACLEJDK8_JAVA_HOME"
+ remove_dir_from_path $JAVA_HOME/bin
export JAVA_HOME="$ORACLEJDK8_JAVA_HOME"
- export PATH=$JAVA_HOME/bin:$ORIG_PATH
+ export PATH=$JAVA_HOME/bin:$PATH
}
print_home_of_openjdk6 () {
@@ -108,6 +103,14 @@ warn_gcj_user () {
echo "We do not support GCJ." >&2
}
+remove_dir_from_path() {
+ local target=$(echo $1 | sed -e 's:/*$::') # remove all occurrences of / at the end
+ PATH="$(echo :$PATH: | sed -e 's_/*:_:_g')"
+ PATH="${PATH//:$target:/:}"
+ PATH="${PATH#:}"
+ PATH="${PATH%:}"
+}
+
switch_jdk()
{
case "${1:-default}" in
Something went wrong with that request. Please try again.