From f02e673038ae1d96034b31974331c20f87d43cf6 Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Sat, 1 Sep 2012 20:06:47 +0100 Subject: [PATCH] Added install feature with gvm implementation. --- bin/gvm | 53 ++++++++++++++++--- .../cucumber/gvm/command_line_interop.feature | 4 -- src/test/cucumber/gvm/initialisation.feature | 2 +- src/test/cucumber/gvm/installation.feature | 16 ++++++ .../resources/gvm/installation_steps.groovy | 7 +++ 5 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/test/cucumber/gvm/installation.feature create mode 100644 src/test/resources/gvm/installation_steps.groovy diff --git a/bin/gvm b/bin/gvm index 1a0cd260..91eebe89 100755 --- a/bin/gvm +++ b/bin/gvm @@ -1,6 +1,7 @@ #!/bin/bash GVM_DIR="$HOME/.gvm" +GVM_SERVICE="http://localhost:8080/gvm-service" if [ ! -d "$GVM_DIR" ]; then mkdir "$GVM_DIR" @@ -9,20 +10,58 @@ if [ ! -d "$GVM_DIR" ]; then echo "" fi -if [ "$1" == "help" -o -z "$1" -o -z "$2" ]; then - echo "Usage: gvm [version]" - echo " commands: install, uninstall, list, use or help" - echo " candidate: groovy, grails, griffon or gradle" - echo " version: defaults to latest stable if not provided" +if [ ! $(which curl) ]; then + echo "Please install curl through your package manager before using this tool." exit 0 fi +if [ "$1" == "help" -o -z "$1" -o -z "$2" ]; then + echo "Usage: gvm [version]" + echo "" + echo " commands : install, uninstall, list, use or help" + echo " candidate : groovy, grails, griffon or gradle" + echo " version : defaults to latest stable if not provided" + echo "" + echo "eg: gvm install grails 2.1.0" + exit 0 +fi + +function download { + CANDIDATE="$1" + VERSION="$2" + echo "Downloading $CANDIDATE $VERSION" + curl -L "$GVM_SERVICE/$CANDIDATE/download/$VERSION" >> "/tmp/$CANDIDATE-$VERSION.zip" +} + function gvm-install { - echo Installing: "$1" + CANDIDATE="$1" + if [ -z "$2" ]; then + VERSION=$(curl "$GVM_SERVICE/$CANDIDATE/version") + else + VERSION=$(curl "$GVM_SERVICE/$CANDIDATE/version/$2") + fi + + if [ -z "$VERSION" ]; then + echo "" + echo "Stop! $2 is not a valid grails version." + exit 0 + fi + + echo "Downloading: $CANDIDATE $VERSION" + download "$CANDIDATE" "$VERSION" + echo "Installing: $CANDIDATE $VERSION" + mkdir -p "$GVM_DIR/$CANDIDATE" + unzip -q "/tmp/$CANDIDATE-$VERSION.zip" -d "/tmp/" + mv -v "/tmp/$CANDIDATE-$VERSION" "$GVM_DIR/$CANDIDATE/$VERSION" + rm "/tmp/$CANDIDATE-$VERSION.zip" + echo "Done installing!" + echo "" + echo "Start using $CANDIDATE $VERSION by issuing the following command:" + echo " gvm use $CANDIDATE $VERSION" } function gvm-use { echo Using: "$1" } -gvm-"$1" "$2" +gvm-"$1" "$2" "$3" diff --git a/src/test/cucumber/gvm/command_line_interop.feature b/src/test/cucumber/gvm/command_line_interop.feature index c759aa33..0e6fbd48 100644 --- a/src/test/cucumber/gvm/command_line_interop.feature +++ b/src/test/cucumber/gvm/command_line_interop.feature @@ -15,10 +15,6 @@ Feature: Command Line Interop When I enter "gvm install" Then I see "Usage: gvm [version]" - Scenario: Install a Candidate - When I enter "gvm install grails" - Then I see "Installing: grails" - Scenario: Use without providing a Candidate When I enter "gvm use" Then I see "Usage: gvm [version]" diff --git a/src/test/cucumber/gvm/initialisation.feature b/src/test/cucumber/gvm/initialisation.feature index cf2b7115..d1b81cfd 100644 --- a/src/test/cucumber/gvm/initialisation.feature +++ b/src/test/cucumber/gvm/initialisation.feature @@ -10,4 +10,4 @@ Feature: Initialisation Given an initialised system When I enter "gvm" Then I see "Usage: gvm [version]" - And the ".gvm" folder exists in user home + And the ".gvm" folder exists in user home \ No newline at end of file diff --git a/src/test/cucumber/gvm/installation.feature b/src/test/cucumber/gvm/installation.feature new file mode 100644 index 00000000..17a7f775 --- /dev/null +++ b/src/test/cucumber/gvm/installation.feature @@ -0,0 +1,16 @@ +Feature: Installation + + Scenario: Install a default Candidate + Given the default "grails" candidate is "2.1.0" + When I enter "gvm install grails" + Then the candidate "grails" version "2.1.0" is installed + And I see "Done installing!" + + Scenario: Install a specific Candidate + When I enter "gvm install grails 1.3.9" + Then the candidate "grails" version "1.3.9" is installed + And I see "Done installing!" + + Scenario: Install a Candidate version that does not exist + When I enter "gvm install grails 1.4.4" + Then I see "Stop! 1.4.4 is not a valid grails version." diff --git a/src/test/resources/gvm/installation_steps.groovy b/src/test/resources/gvm/installation_steps.groovy new file mode 100644 index 00000000..3e104626 --- /dev/null +++ b/src/test/resources/gvm/installation_steps.groovy @@ -0,0 +1,7 @@ +import static cucumber.runtime.groovy.EN.* +import cucumber.runtime.PendingException + +Then(~'^the candidate can be found at "([^"]*)"$') { String path -> + def file = new File(path) + assert file.exists(), "$path does not exist!" +} \ No newline at end of file