Permalink
Browse files

Merge pull request #117 from dsyer/feature/unhardcode

Remove hard-coded references to candidates
  • Loading branch information...
2 parents 38afc71 + d316ec7 commit 19072c7e169e839813184ffacab0a30b7384cda8 @marc0der marc0der committed Feb 4, 2013
@@ -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
@@ -32,14 +32,38 @@ case "`uname`" in
;;
esac
-
-if [ -z "${GVM_SERVICE}" ]; then
- export GVM_SERVICE="@GVM_SERVICE@"
-fi
+GVM_SERVICE_DEFAULT="@GVM_SERVICE@"
+GVM_CANDIDATES_DEFAULT=("groovy" "grails" "griffon" "gradle" "vertx")
if [ -z "${GVM_DIR}" ]; then
export GVM_DIR="$HOME/.gvm"
fi
+mkdir -p $GVM_DIR/var/candidates
+
+if [ -z "${GVM_SERVICE}" ]; then
+ if [ -f "${GVM_DIR}/var/service" ]; then
+ GVM_SERVICE=$(cat "${GVM_DIR}/var/service")
+ else
+ GVM_SERVICE=${GVM_SERVICE_DEFAULT}
+ fi
+fi
+export GVM_SERVICE
+echo -n ${GVM_SERVICE} > "${GVM_DIR}/var/service"
+
+# check cached candidates first
+candidate_cache="${GVM_DIR}/var/candidates/$(echo ${GVM_SERVICE} | tr ':/' '_')"
+if [ -f "${candidate_cache}" -a "${*/--flush/}" == "${*}" ]; then
+ GVM_CANDIDATES=($(cat "${candidate_cache}"))
+else
+ GVM_CANDIDATES=($(curl -s "${GVM_SERVICE}/candidates" | sed -e 's/,//g'))
+ if [[ "${#GVM_CANDIDATES[@]}" == "0" ]]; then
+ GVM_CANDIDATES=(${GVM_CANDIDATES_DEFAULT[@]})
+ else
+ # only cache the candidates if derived from online service
+ echo -n ${GVM_CANDIDATES[@]} > "${candidate_cache}"
+ fi
+fi
+export GVM_CANDIDATES
OFFLINE_BROADCAST=$( cat << EOF
==== BROADCAST =============================================
@@ -60,18 +84,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}"
@@ -39,8 +39,13 @@ 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
+ export PATH=${GVM_DIR}/${CANDIDATE}/${VERSION}/bin:$PATH
+ fi
echo ""
echo Using "${CANDIDATE}" version "${VERSION} in this shell."
@@ -5,12 +5,14 @@ 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")
}
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")
}

0 comments on commit 19072c7

Please sign in to comment.