Created
June 15, 2009 10:19
-
-
Save robfletcher/130031 to your computer and use it in GitHub Desktop.
Grails script that checks the versions of plugins you have installed and notifies you when newer versions are available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.xml.dom.DOMCategory | |
includeTargets << grailsScript("_GrailsInit") | |
includeTargets << grailsScript("_GrailsPlugins") | |
def getAvailablePluginVersions = { | |
def plugins = [:] | |
eachRepository {repo, url -> | |
use(DOMCategory) { | |
pluginsList.'plugin'.each {plugin -> | |
def name = plugin.'@name' | |
def version | |
if (plugin.'@latest-release') { | |
version = plugin.'@latest-release' | |
} | |
else if (plugin.'release'.size() > 0) { | |
// determine latest release by comparing version names in lexicografic order | |
version = plugin.'release'[0].'@version' | |
plugin.'release'.each { | |
if (!"${it.'@version'}".endsWith("SNAPSHOT") && "${it.'@version'}" > version) version = "${it.'@version'}" | |
} | |
} | |
plugins."$name" = version | |
} | |
} | |
} | |
return plugins | |
} | |
def getInstalledPluginVersions = { | |
def plugins = [:] | |
def pluginXmls = readAllPluginXmlMetadata() | |
for (p in pluginXmls) { | |
def name = p.@name.text() | |
def version = p.@version.text() | |
plugins."$name" = version | |
} | |
return plugins | |
} | |
target('default': "Checks installed plugin versions against latest releases on repositories") { | |
depends(updatePluginsList) | |
def availablePluginVersions = getAvailablePluginVersions() | |
def installedPluginVersions = getInstalledPluginVersions() | |
boolean headerDisplayed = false | |
if (installedPluginVersions) { | |
installedPluginVersions.each { name, version -> | |
def availableVersion = availablePluginVersions."$name" | |
if (availableVersion != version) { | |
if (!headerDisplayed) { | |
println """ | |
Plugins with available updates are listed below: | |
------------------------------------------------------------- | |
<Plugin> <Current> <Available>""" | |
headerDisplayed = true | |
} | |
println "${name.padRight(20, " ")}${version.padRight(16, " ")} ${availableVersion}" | |
} | |
} | |
if (!headerDisplayed) { | |
println "\nAll plugins are up to date." | |
} | |
} else { | |
println "\nYou do not have any plugins installed." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment