diff --git a/src/main/resources/scripts/gvm-common.sh b/src/main/resources/scripts/gvm-common.sh index 15df0bbe..d7476bac 100644 --- a/src/main/resources/scripts/gvm-common.sh +++ b/src/main/resources/scripts/gvm-common.sh @@ -75,7 +75,7 @@ function __gvmtool_determine_version { function __gvmtool_build_version_csv { CANDIDATE="$1" CSV="" - for version in $(ls -1 "${GVM_DIR}/${CANDIDATE}"); do + for version in $(ls -1 "${GVM_DIR}/${CANDIDATE}" 2> /dev/null); do if [ ${version} != 'current' ]; then CSV="${version},${CSV}" fi @@ -134,6 +134,11 @@ function __gvmtool_default_environment_variables { if [ ! "${GVM_DIR}" ]; then GVM_DIR="$HOME/.gvm" fi + + GVM_CANDIDATES=($(curl -s "${GVM_SERVICE}/candidates" | sed -e 's/,//g')) + if [[ "${#GVM_CANDIDATES[@]}" == "0" ]]; then + GVM_CANDIDATES=("groovy" "grails" "griffon" "gradle" "vertx") + fi } function __gvmtool_check_upgrade_available { diff --git a/src/main/resources/scripts/gvm-init.sh b/src/main/resources/scripts/gvm-init.sh index bc04df9a..35047f00 100755 --- a/src/main/resources/scripts/gvm-init.sh +++ b/src/main/resources/scripts/gvm-init.sh @@ -60,18 +60,8 @@ EOF ) OFFLINE_MESSAGE="This command is not available in aeroplane mode." -GVM_CANDIDATES=("groovy" "grails" "griffon" "gradle" "vertx") - PATH="${GVM_DIR}/bin:${GVM_DIR}/ext:$PATH" -GROOVY_HOME="${GVM_DIR}/groovy/current" -GRAILS_HOME="${GVM_DIR}/grails/current" -GRIFFON_HOME="${GVM_DIR}/griffon/current" -GRADLE_HOME="${GVM_DIR}/gradle/current" -VERTX_HOME="${GVM_DIR}/vertx/current" - -export PATH="${GROOVY_HOME}/bin:${GRAILS_HOME}/bin:${GRIFFON_HOME}/bin:${GRADLE_HOME}/bin:${VERTX_HOME}/bin:$PATH" - # Source gvm module scripts. for f in $(find "${GVM_DIR}/src" -type f -name 'gvm-*'); do source "${f}" diff --git a/src/main/resources/scripts/gvm-use.sh b/src/main/resources/scripts/gvm-use.sh index 8cf4aead..ddece964 100644 --- a/src/main/resources/scripts/gvm-use.sh +++ b/src/main/resources/scripts/gvm-use.sh @@ -39,8 +39,16 @@ function __gvmtool_use { UPPER_CANDIDATE=`echo "${CANDIDATE}" | tr '[:lower:]' '[:upper:]'` export "${UPPER_CANDIDATE}_HOME"="${GVM_DIR}/${CANDIDATE}/${VERSION}" - # Replace the current path for the candidate with the selected version. - export PATH=`echo $PATH | sed -E "s!${GVM_DIR}/${CANDIDATE}/([^/]+)!${GVM_DIR}/${CANDIDATE}/${VERSION}!g"` + # if PATH already has this candidate + if [ $PATH != "${PATH/${GVM_DIR}\/${CANDIDATE}/}" ]; then + # Replace the current path for the candidate with the selected version. + export PATH=`echo $PATH | sed -E "s!${GVM_DIR}/${CANDIDATE}/([^/]+)!${GVM_DIR}/${CANDIDATE}/${VERSION}!g"` + else + if [ $PATH == "${PATH/${GVM_DIR}\/${CANDIDATE}/}" ]; then + export PATH=${GVM_DIR}/${CANDIDATE}/current/bin:$PATH + fi + export PATH=${GVM_DIR}/${CANDIDATE}/${VERSION}/bin:$PATH + fi echo "" echo Using "${CANDIDATE}" version "${VERSION} in this shell." diff --git a/src/test/resources/gvm/aeroplane_mode_steps.groovy b/src/test/resources/gvm/aeroplane_mode_steps.groovy index 0ad40849..5cf7628c 100644 --- a/src/test/resources/gvm/aeroplane_mode_steps.groovy +++ b/src/test/resources/gvm/aeroplane_mode_steps.groovy @@ -5,6 +5,7 @@ import static cucumber.api.groovy.EN.* Given(~'^the internet is not reachable$') {-> bash = new BashEnv(baseDir, [GVM_DIR: gvmDirEnv, GVM_SERVICE: "http://localhost:0"]) bash.start() + bash.execute('export PATH=${GVM_DIR}/groovy/current/bin:${GVM_DIR}/grails/current/bin:$PATH') bash.execute("source $binDir/gvm-init.sh") } @@ -12,5 +13,6 @@ Given(~'^the internet is not reachable$') {-> And(~'^the internet is reachable$') {-> bash = new BashEnv(baseDir, [GVM_DIR: gvmDirEnv, GVM_SERVICE: serviceUrlEnv]) bash.start() + bash.execute('export PATH=${GVM_DIR}/groovy/current/bin:${GVM_DIR}/grails/current/bin:$PATH') bash.execute("source $binDir/gvm-init.sh") } \ No newline at end of file