Skip to content

Commit

Permalink
move code in PluginInfo to PluginResolveEngine and populate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Nov 14, 2011
1 parent c568384 commit e8955f6
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 74 deletions.
Expand Up @@ -47,6 +47,95 @@ final class PluginResolveEngine {
dependencyManager.createCopy(settings)
}

/**
* Renders plugin info to the target writer
*
* @param pluginName The plugin name
* @param pluginVersion The plugin version
* @param output The target writer
*/
GPathResult renderPluginInfo(String pluginName, String pluginVersion, OutputStream outputStream) {
renderPluginInfo(pluginName, pluginVersion, new OutputStreamWriter(outputStream))
}
/**
* Renders plugin info to the target writer
*
* @param pluginName The plugin name
* @param pluginVersion The plugin version
* @param output The target writer
*/
GPathResult renderPluginInfo(String pluginName, String pluginVersion, Writer writer) {
def pluginXml = resolvePluginMetadata(pluginName, pluginVersion)

if(pluginXml != null) {
def output = new PrintWriter(writer)
def line = "Name: ${pluginName}"
line += "\t| Latest release: ${pluginXml.@version}"
output.println getPluginInfoHeader()
output.println line
output.println '--------------------------------------------------------------------------'
def release = pluginXml
if (release) {
if (release.'title'.text()) {
output.println "${release.'title'.text()}"
}
else {
output.println "No info about this plugin available"
}
output.println '--------------------------------------------------------------------------'
if (release.'author'.text()) {
output.println "Author: ${release.'author'.text()}"
output.println '--------------------------------------------------------------------------'
}
if (release.'authorEmail'.text()) {
output.println "Author's e-mail: ${release.'authorEmail'.text()}"
output.println '--------------------------------------------------------------------------'
}
if (release.'documentation'.text()) {
output.println "Find more info here: ${release.'documentation'.text()}"
output.println '--------------------------------------------------------------------------'
}
if (release.'description'.text()) {
output.println "${release.'description'.text()}"
output.println '--------------------------------------------------------------------------'
}


}
else {
output.println "<release not found for this plugin>"
output.println '--------------------------------------------------------------------------'
}

output.println getPluginInfoFooter()
output.flush()
}

return pluginXml
}

protected String getPluginInfoHeader() {
'''
--------------------------------------------------------------------------
Information about Grails plugin
--------------------------------------------------------------------------\
'''
}

protected String getPluginInfoFooter() {
'''
To get info about specific release of plugin 'grails plugin-info [NAME] [VERSION]'
To get list of all plugins type 'grails list-plugins'
To install latest version of plugin type 'grails install-plugin [NAME]'
To install specific version of plugin type 'grails install-plugin [NAME] [VERSION]'
For further info visit http://grails.org/Plugins
'''
}

/**
* Resolves a list of plugins and produces a ResolveReport
*
Expand Down
Expand Up @@ -26,6 +26,22 @@ class PluginResolveEngineSpec extends Specification{
metadata.title.text() == 'Render RSS/Atom feeds with a simple builder'
}

def "Test rendering plugin-info"() {
given:"An instance of the resolve engine"
def resolveEngine = systemUnderTest()

when:"We resolve the 'feeds' plugin"
def sw = new StringWriter()
resolveEngine.renderPluginInfo("feeds", "1.5", System.out)
resolveEngine.renderPluginInfo("feeds", "1.5", sw)
def info = sw.toString()

then:"The correct metadata is obtained"
info.contains 'Name: feeds | Latest release: 1.5'
info.contains 'Render RSS/Atom feeds with a simple builder'
info.contains 'Author: Marc Palmer'
}

PluginResolveEngine systemUnderTest() {
def settings = new BuildSettings()
def dependencyManager = new IvyDependencyManager("test", "0.1", settings)
Expand Down
75 changes: 1 addition & 74 deletions scripts/PluginInfo_.groovy
Expand Up @@ -27,95 +27,22 @@ import org.codehaus.groovy.grails.resolve.PluginResolveEngine

includeTargets << grailsScript("_GrailsPlugins")

def displayHeader = {
'''
--------------------------------------------------------------------------
Information about Grails plugin
--------------------------------------------------------------------------\
'''
}

def displayPluginInfo = { pluginName, version ->

BuildSettings settings = grailsSettings
def pluginResolveEngine = new PluginResolveEngine(settings.dependencyManager, settings)
pluginXml = pluginResolveEngine.resolvePluginMetadata(pluginName, version)
if (!pluginXml) {
event("StatusError", ["Plugin with name '${pluginName}' was not found in the configured repositories"])
exit 1
}

def plugin = pluginXml
if (plugin == null) {
event("StatusError", ["Plugin with name '${pluginName}' was not found in the configured repositories"])
exit 1
}

def line = "Name: ${pluginName}"
line += "\t| Latest release: ${plugin.@version}"
def sw = new StringWriter()
def output = new PrintWriter(sw)
output.println displayHeader()
output.println line
output.println '--------------------------------------------------------------------------'
def release = pluginXml
if (release) {
if (release.'title'.text()) {
output.println "${release.'title'.text()}"
}
else {
output.println "No info about this plugin available"
}
output.println '--------------------------------------------------------------------------'
if (release.'author'.text()) {
output.println "Author: ${release.'author'.text()}"
output.println '--------------------------------------------------------------------------'
}
if (release.'authorEmail'.text()) {
output.println "Author's e-mail: ${release.'authorEmail'.text()}"
output.println '--------------------------------------------------------------------------'
}
if (release.'documentation'.text()) {
output.println "Find more info here: ${release.'documentation'.text()}"
output.println '--------------------------------------------------------------------------'
}
if (release.'description'.text()) {
output.println "${release.'description'.text()}"
output.println '--------------------------------------------------------------------------'
}
}
else {
output.println "<release ${releaseVersion} not found for this plugin>"
output.println '--------------------------------------------------------------------------'
}

println sw.toString()
pluginXml = pluginResolveEngine.renderPluginInfo(pluginName, version, System.out)
}

def displayFooter = {
println '''
To get info about specific release of plugin 'grails plugin-info [NAME] [VERSION]'
To get list of all plugins type 'grails list-plugins'
To install latest version of plugin type 'grails install-plugin [NAME]'
To install specific version of plugin type 'grails install-plugin [NAME] [VERSION]'
For further info visit http://grails.org/Plugins
'''
}

target(pluginInfo:"Implementation target") {
depends(parseArguments)

if (argsMap.params) {
displayHeader()
def pluginName = argsMap.params[0]
def version = argsMap.params.size() > 1 ? argsMap.params[1] : null

displayPluginInfo(pluginName, version)
displayFooter()
}
else {
event("StatusError", ["Usage: grails plugin-info <plugin-name> [version]"])
Expand Down

0 comments on commit e8955f6

Please sign in to comment.