Remove hard-coded references to candidates

It seems wrong to hard-code the candidate names when they are
available from the server.  It also makes it hard to add new
candidates.  The scripts pretty much work with a really small
change to gvm-use.sh, but the tests also rely on the PATH being
set, so there is a change to the tests as well to make them pass.
This commit is contained in:
Dave Syer
2013-01-23 08:41:40 +00:00
parent 38afc71f14
commit 342b813d77
4 changed files with 18 additions and 13 deletions

View File

@@ -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 {

View File

@@ -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}"

View File

@@ -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."

View File

@@ -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")
}