From 9574046bfe0b26177a4fb95795df8319ea382160 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 23 Jan 2013 12:44:59 +0000 Subject: [PATCH 1/3] Add gvm_auto_{install,use} in $GVM_DIR/etc/config Fixes #101. These flags are consulted when gvm is asked to use an uninstalled version or to install an unused version. User is prompted for a response by default but this can be overridden by adding these flags to the confg, e.g. $ echo gvm_auto_install=Y >> $GVM_DIR/etc/config $ echo gvm_auto_use=Y >> $GVM_DIR/etc/config $ gvm use groovy 1.8.8 ... (installs and uses without prompting) --- src/main/resources/scripts/gvm-install.sh | 6 ++++-- src/main/resources/scripts/gvm-use.sh | 6 ++++-- src/test/cucumber/gvm/install_candidate.feature | 8 ++++++++ src/test/cucumber/gvm/use_and_default_candidate.feature | 7 +++++++ src/test/resources/gvm/installation_steps.groovy | 5 +++++ src/test/resources/gvm/use_steps.groovy | 7 ++++++- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/resources/scripts/gvm-install.sh b/src/main/resources/scripts/gvm-install.sh index c2cc3ccc..eeb658a5 100644 --- a/src/main/resources/scripts/gvm-install.sh +++ b/src/main/resources/scripts/gvm-install.sh @@ -31,8 +31,10 @@ function __gvmtool_install { if [[ ${VERSION_VALID} == 'valid' ]]; then __gvmtool_install_candidate_version "${CANDIDATE}" "${VERSION}" || return 1 - echo -n "Do you want ${CANDIDATE} ${VERSION} to be set as default? (Y/n): " - read USE + if [[ -z "${gvm_auto_use}" ]]; then + echo -n "Do you want ${CANDIDATE} ${VERSION} to be set as default? (Y/n): " + read USE + fi if [[ -z "${USE}" || "${USE}" == "y" || "${USE}" == "Y" ]]; then echo "" echo "Setting ${CANDIDATE} ${VERSION} as default." diff --git a/src/main/resources/scripts/gvm-use.sh b/src/main/resources/scripts/gvm-use.sh index 9ec3b403..869bb7cf 100644 --- a/src/main/resources/scripts/gvm-use.sh +++ b/src/main/resources/scripts/gvm-use.sh @@ -24,8 +24,10 @@ function __gvmtool_use { if [[ "${GVM_ONLINE}" == "true" && ! -d "${GVM_DIR}/${CANDIDATE}/${VERSION}" ]]; then echo "" echo "Stop! ${CANDIDATE} ${VERSION} is not installed." - echo -n "Do you want to install it now? (Y/n): " - read INSTALL + if [[ -z "${gvm_auto_install}" ]]; then + echo -n "Do you want to install it now? (Y/n): " + read INSTALL + fi if [[ -z "${INSTALL}" || "${INSTALL}" == "y" || "${INSTALL}" == "Y" ]]; then __gvmtool_install_candidate_version "${CANDIDATE}" "${VERSION}" else diff --git a/src/test/cucumber/gvm/install_candidate.feature b/src/test/cucumber/gvm/install_candidate.feature index 00dea05a..d76cc7f6 100644 --- a/src/test/cucumber/gvm/install_candidate.feature +++ b/src/test/cucumber/gvm/install_candidate.feature @@ -31,6 +31,14 @@ Feature: Install Candidate And I see "Setting grails 2.1.0 as default." Then the candidate "grails" version "2.1.0" should be the default + Scenario: Install a candidate and select to use it automatically + And I have configured autoinstall="Y" and autouse="Y" + When I enter "gvm install grails 2.1.0" + Then the candidate "grails" version "2.1.0" is installed + And I see "Done installing!" + And I see "Setting grails 2.1.0 as default." + Then the candidate "grails" version "2.1.0" should be the default + Scenario: Install a candidate and do not select to use it When I enter "gvm install grails 2.1.0" and answer "n" Then the candidate "grails" version "2.1.0" is installed diff --git a/src/test/cucumber/gvm/use_and_default_candidate.feature b/src/test/cucumber/gvm/use_and_default_candidate.feature index 19422298..d07a50f2 100644 --- a/src/test/cucumber/gvm/use_and_default_candidate.feature +++ b/src/test/cucumber/gvm/use_and_default_candidate.feature @@ -20,6 +20,13 @@ Feature: Use and Default Candidate Then I see "Using groovy version 1.8.8 in this shell." And the candidate "groovy" version "1.8.8" should be in use + Scenario: Use a candidate version that is automatically installed + And I have configured autoinstall="Y" + When I enter "gvm use groovy 1.8.8" + Then I see "Stop! groovy 1.8.8 is not installed." + Then I see "Using groovy version 1.8.8 in this shell." + And the candidate "groovy" version "1.8.8" should be in use + Scenario: Use a candidate version that does not exist When I enter "gvm use groovy 1.9.9" Then I see "Stop! 1.9.9 is not a valid groovy version." diff --git a/src/test/resources/gvm/installation_steps.groovy b/src/test/resources/gvm/installation_steps.groovy index 11533ea9..ac0a0bbe 100644 --- a/src/test/resources/gvm/installation_steps.groovy +++ b/src/test/resources/gvm/installation_steps.groovy @@ -80,6 +80,11 @@ And(~'^the candidate "([^"]*)" version "([^"]*)" is already linked to "([^"]*)"$ Files.createSymbolicLink(link, target) } +And(~'^I have configured autoinstall="([^"]*)"$') { String flag -> + def configFile = new File("$gvmDir/etc/config") + configFile.write "gvm_auto_install=${flag}" +} + private prepareCandidateFolder(String baseDir, String candidate, String version) { def directory = "$baseDir/$candidate/$version" prepareCandidateBinFolder directory, candidate, version diff --git a/src/test/resources/gvm/use_steps.groovy b/src/test/resources/gvm/use_steps.groovy index f3526d24..560e4657 100644 --- a/src/test/resources/gvm/use_steps.groovy +++ b/src/test/resources/gvm/use_steps.groovy @@ -42,4 +42,9 @@ Then(~'^the candidate "([^"]*)" version "([^"]*)" should not be the default$') { Then(~'^the candidate "([^"]*)" is no longer selected$') { String candidate -> def symlink = new File("$gvmDir/$candidate/current") assert ! symlink.exists() -} \ No newline at end of file +} + +And(~'^I have configured autoinstall="([^"]*)" and autouse="([^"]*)"$') { String install,use -> + def configFile = new File("$gvmDir/etc/config") + configFile.write "gvm_auto_install=${install}\ngvm_auto_use=${use}" +} From 93121e907dea4528122659e442a4497290f8bbea Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 23 Jan 2013 13:50:25 +0000 Subject: [PATCH 2/3] Use a single flag 'gvm_auto' instead of separate use/install --- src/main/resources/scripts/gvm-install.sh | 2 +- src/main/resources/scripts/gvm-use.sh | 2 +- src/test/cucumber/gvm/install_candidate.feature | 2 +- src/test/resources/gvm/installation_steps.groovy | 2 +- src/test/resources/gvm/use_steps.groovy | 5 ----- 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/resources/scripts/gvm-install.sh b/src/main/resources/scripts/gvm-install.sh index eeb658a5..787d554a 100644 --- a/src/main/resources/scripts/gvm-install.sh +++ b/src/main/resources/scripts/gvm-install.sh @@ -31,7 +31,7 @@ function __gvmtool_install { if [[ ${VERSION_VALID} == 'valid' ]]; then __gvmtool_install_candidate_version "${CANDIDATE}" "${VERSION}" || return 1 - if [[ -z "${gvm_auto_use}" ]]; then + if [[ -z "${gvm_auto}" ]]; then echo -n "Do you want ${CANDIDATE} ${VERSION} to be set as default? (Y/n): " read USE fi diff --git a/src/main/resources/scripts/gvm-use.sh b/src/main/resources/scripts/gvm-use.sh index 869bb7cf..90125f94 100644 --- a/src/main/resources/scripts/gvm-use.sh +++ b/src/main/resources/scripts/gvm-use.sh @@ -24,7 +24,7 @@ function __gvmtool_use { if [[ "${GVM_ONLINE}" == "true" && ! -d "${GVM_DIR}/${CANDIDATE}/${VERSION}" ]]; then echo "" echo "Stop! ${CANDIDATE} ${VERSION} is not installed." - if [[ -z "${gvm_auto_install}" ]]; then + if [[ -z "${gvm_auto}" ]]; then echo -n "Do you want to install it now? (Y/n): " read INSTALL fi diff --git a/src/test/cucumber/gvm/install_candidate.feature b/src/test/cucumber/gvm/install_candidate.feature index d76cc7f6..a85b8942 100644 --- a/src/test/cucumber/gvm/install_candidate.feature +++ b/src/test/cucumber/gvm/install_candidate.feature @@ -32,7 +32,7 @@ Feature: Install Candidate Then the candidate "grails" version "2.1.0" should be the default Scenario: Install a candidate and select to use it automatically - And I have configured autoinstall="Y" and autouse="Y" + And I have configured autoinstall="Y" When I enter "gvm install grails 2.1.0" Then the candidate "grails" version "2.1.0" is installed And I see "Done installing!" diff --git a/src/test/resources/gvm/installation_steps.groovy b/src/test/resources/gvm/installation_steps.groovy index ac0a0bbe..c7a61004 100644 --- a/src/test/resources/gvm/installation_steps.groovy +++ b/src/test/resources/gvm/installation_steps.groovy @@ -82,7 +82,7 @@ And(~'^the candidate "([^"]*)" version "([^"]*)" is already linked to "([^"]*)"$ And(~'^I have configured autoinstall="([^"]*)"$') { String flag -> def configFile = new File("$gvmDir/etc/config") - configFile.write "gvm_auto_install=${flag}" + configFile.write "gvm_auto=${flag}" } private prepareCandidateFolder(String baseDir, String candidate, String version) { diff --git a/src/test/resources/gvm/use_steps.groovy b/src/test/resources/gvm/use_steps.groovy index 560e4657..471b6b81 100644 --- a/src/test/resources/gvm/use_steps.groovy +++ b/src/test/resources/gvm/use_steps.groovy @@ -43,8 +43,3 @@ Then(~'^the candidate "([^"]*)" is no longer selected$') { String candidate -> def symlink = new File("$gvmDir/$candidate/current") assert ! symlink.exists() } - -And(~'^I have configured autoinstall="([^"]*)" and autouse="([^"]*)"$') { String install,use -> - def configFile = new File("$gvmDir/etc/config") - configFile.write "gvm_auto_install=${install}\ngvm_auto_use=${use}" -} From 0fea0aea4dce16cb74b91f3f34d30e2ee2e9cffb Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 24 Jan 2013 12:26:03 +0000 Subject: [PATCH 3/3] Rename auto var to gvm_auto_answer --- src/main/resources/scripts/gvm-install.sh | 2 +- src/main/resources/scripts/gvm-use.sh | 2 +- src/test/resources/gvm/installation_steps.groovy | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/scripts/gvm-install.sh b/src/main/resources/scripts/gvm-install.sh index 787d554a..230c2bb2 100644 --- a/src/main/resources/scripts/gvm-install.sh +++ b/src/main/resources/scripts/gvm-install.sh @@ -31,7 +31,7 @@ function __gvmtool_install { if [[ ${VERSION_VALID} == 'valid' ]]; then __gvmtool_install_candidate_version "${CANDIDATE}" "${VERSION}" || return 1 - if [[ -z "${gvm_auto}" ]]; then + if [[ -z "${gvm_auto_answer}" ]]; then echo -n "Do you want ${CANDIDATE} ${VERSION} to be set as default? (Y/n): " read USE fi diff --git a/src/main/resources/scripts/gvm-use.sh b/src/main/resources/scripts/gvm-use.sh index 90125f94..c5a9978d 100644 --- a/src/main/resources/scripts/gvm-use.sh +++ b/src/main/resources/scripts/gvm-use.sh @@ -24,7 +24,7 @@ function __gvmtool_use { if [[ "${GVM_ONLINE}" == "true" && ! -d "${GVM_DIR}/${CANDIDATE}/${VERSION}" ]]; then echo "" echo "Stop! ${CANDIDATE} ${VERSION} is not installed." - if [[ -z "${gvm_auto}" ]]; then + if [[ -z "${gvm_auto_answer}" ]]; then echo -n "Do you want to install it now? (Y/n): " read INSTALL fi diff --git a/src/test/resources/gvm/installation_steps.groovy b/src/test/resources/gvm/installation_steps.groovy index c7a61004..bf18cd91 100644 --- a/src/test/resources/gvm/installation_steps.groovy +++ b/src/test/resources/gvm/installation_steps.groovy @@ -82,7 +82,7 @@ And(~'^the candidate "([^"]*)" version "([^"]*)" is already linked to "([^"]*)"$ And(~'^I have configured autoinstall="([^"]*)"$') { String flag -> def configFile = new File("$gvmDir/etc/config") - configFile.write "gvm_auto=${flag}" + configFile.write "gvm_auto_answer=${flag}" } private prepareCandidateFolder(String baseDir, String candidate, String version) {