Skip to content
Browse files

Merge pull request #338 from travis-ci/ha-bug-jdk_switcher-path-manip…

…ulation

Prevent jdk_switcher from resetting PATH
  • Loading branch information...
2 parents 763fcf5 + 7bbb123 commit 5c9bec6657bfc718c7b9aaa175ece4921e4f29b6 @joshk joshk committed
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

0 comments on commit 5c9bec6

Please sign in to comment.
Something went wrong with that request. Please try again.