Browse files

Add list functionality for local candidate versions.

  • Loading branch information...
1 parent 8d69e63 commit e8b8c96b8abd9d8a0c82c51463dbd5d3c645c901 @marc0der marc0der committed Jan 20, 2013
View
3 src/main/resources/server.groovy
@@ -119,7 +119,8 @@ rm.get("/candidates/:candidate/list") { req ->
def cmd = [action:"find", collection:"versions", matcher:[candidate:candidate], keys:["version":1], sort:["version":-1]]
vertx.eventBus.send("mongo-persistor", cmd){ msg ->
def available = msg.body.results.collect { it.version }
- def binding = [candidate:candidate, available:available, current:current, installed:installed]
+ def local = installed.findAll { ! available.contains(it) }
+ def binding = [candidate:candidate, available:available, current:current, installed:installed, local:local]
def template = templateEngine.createTemplate(gtplFile).make(binding)
addPlainTextHeader req
req.response.end template.toString()
View
29 src/main/resources/templates/list.gtpl
@@ -1,21 +1,30 @@
-------------------------------------------------------------
+============================================================
Available ${candidate.capitalize()} Versions
-------------------------------------------------------------
+============================================================
<%
+ if(local){
+ local.each { version ->
+ if(current == version) {
+ println " > + ${version}"
+ } else {
+ println " + ${version}"
+ }
+ }
+ println '------------------------------------------------------------'
+ }
available.each { version ->
- print "\n"
- if(current == version) {
- print ' > '
+ if(current == version) {
+ println " > * ${version}"
} else if(installed.contains(version)){
- print ' * '
+ println " * ${version}"
} else {
- print ' '
+ println " ${version}"
}
- print version
}
%>
-------------------------------------------------------------
+============================================================
++ - local version
* - installed
> - currently in use
-------------------------------------------------------------
+============================================================
View
33 src/test/cucumber/gvm/list_candidates.feature
@@ -3,18 +3,35 @@ Feature: List Candidates
Background:
Given the internet is reachable
- Scenario: List all available Versions for an installed Candidate
+ Scenario: List an uninstalled available Version
+ Given I do not have a "grails" candidate installed
+ When I enter "gvm list grails"
+ Then I see "Available Grails Versions"
+ And I see " 2.1.0"
+
+ Scenario: List an installed available Version not in use
+ Given the candidate "grails" version "2.1.0" is already installed but not default
+ When I enter "gvm list grails"
+ Then I see "Available Grails Versions"
+ And I see " * 2.1.0"
+
+ Scenario: List an installed available Version in use
Given the candidate "grails" version "2.1.0" is already installed and default
- And the candidate "grails" version "1.3.9" is already installed but not default
When I enter "gvm list grails"
Then I see "Available Grails Versions"
- And I see "> 2.1.0"
- And I see "* 1.3.9"
+ And I see " > * 2.1.0"
- Scenario: List all available Versions without a Candidate installed
- Given I do not have a "grails" candidate installed
+ Scenario: List an installed local version not in use
+ Given I have a local candidate "grails" version "2.3-SNAPSHOT" at "/tmp/grails-core"
+ And the candidate "grails" version "2.3-SNAPSHOT" is already linked to "/tmp/grails-core"
When I enter "gvm list grails"
Then I see "Available Grails Versions"
- And I see " 2.1.0"
- And I see " 1.3.9"
+ And I see " + 2.3-SNAPSHOT"
+ Scenario: List an installed local Version in use
+ Given I have a local candidate "grails" version "2.3-SNAPSHOT" at "/tmp/grails-core"
+ And the candidate "grails" version "2.3-SNAPSHOT" is already linked to "/tmp/grails-core"
+ And the candidate "grails" version "2.3-SNAPSHOT" is the default
+ When I enter "gvm list grails"
+ Then I see "Available Grails Versions"
+ And I see " > + 2.3-SNAPSHOT"
View
8 src/test/groovy/gvm/VertxUtils.groovy
@@ -59,10 +59,12 @@ class VertxUtils {
rm.get("/candidates/:candidate/list") { req ->
def candidate = req.params['candidate']
+ def available = candidates[candidate]
def current = req.params['current']
- def installed = req.params['installed']
- def gtplFile = new File('build/templates/list.gtpl')
- def binding = [candidate:candidate, available:candidates[candidate], current:current, installed:installed]
+ def installed = req.params['installed'].tokenize(',')
+ def local = installed.findAll { ! available.contains(it) }
+ def gtplFile = 'build/templates/list.gtpl' as File
+ def binding = [candidate:candidate, available:available, current:current, installed:installed, local:local]
def template = templateEngine.createTemplate(gtplFile).make(binding)
req.response.end template.toString()
}
View
16 src/test/resources/gvm/installation_steps.groovy
@@ -1,5 +1,7 @@
package gvm
+import cucumber.runtime.PendingException
+
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
@@ -29,14 +31,20 @@ When(~'^the candidate "([^"]*)" version "([^"]*)" is already installed and defau
Files.createSymbolicLink currentLink, candidateVersion
}
+And(~'^the candidate "([^"]*)" version "([^"]*)" is the default$') { String candidate, String version ->
+ def localVersion = FileSystems.default.getPath("$gvmDir/$candidate/$version")
+ def currentLink = FileSystems.default.getPath("$gvmDir/$candidate/current")
+ Files.createSymbolicLink currentLink, localVersion
+}
+
When(~'^the candidate "([^"]*)" version "([^"]*)" is already installed but not default$') { String candidate, String version ->
prepareCandidateFolder "$gvmDir", candidate, version
}
Given(~'^I do not have a "([^"]*)" candidate installed$') { String candidate ->
- def file = new File("${gvmDir}/${candidate}")
- file.delete()
- assert ! file.exists()
+ def candidateDir = FileSystems.default.getPath("${gvmDir}/${candidate}")
+ Files.createDirectory(candidateDir)
+ assert ! candidateDir.toFile().listFiles()
}
Given(~'^the candidate "([^"]*)" version "([^"]*)" does not exist$') { String candidate, String version ->
@@ -95,4 +103,4 @@ private prepareCandidateExecutable(Path binFolder, String candidate, String vers
def candidateFile = new File("$binFolder/$candidate")
candidateFile.write "echo ${candidate.capitalize()} Version: ${version}"
candidateFile.executable = true
-}
+}

0 comments on commit e8b8c96

Please sign in to comment.