-
Notifications
You must be signed in to change notification settings - Fork 951
/
ListPluginUpdates.groovy
110 lines (102 loc) · 4.05 KB
/
ListPluginUpdates.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright 2004-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import groovy.xml.dom.DOMCategory
import org.codehaus.groovy.grails.resolve.GrailsRepoResolver
import org.codehaus.groovy.grails.resolve.IvyDependencyManager
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_PluginDependencies")
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
}
eachRepository = { Closure callable ->
def dependencyManager = grailsSettings.dependencyManager
if (dependencyManager instanceof IvyDependencyManager) {
for (resolver in dependencyManager.chainResolver.resolvers) {
if (resolver instanceof GrailsRepoResolver) {
pluginsList = resolver.getPluginList(new File(grailsWorkDir, "plugins-list-${resolver.name}.xml"))
if (pluginsList != null) {
callable(resolver.name, resolver.repositoryRoot)
} else {
grailsConsole.error "An error occurred resolving plugin list from resolver [${resolver.name} - ${resolver.repositoryRoot}]."
}
}
}
}
else {
pluginsList = dependencyManager.downloadPluginList(new File(grailsWorkDir, "plugins-list-grailsCentral.xml"))
dependencyManager.repositories.each { r ->
callable.call(r.id, r.url)
}
}
}
def getInstalledPluginVersions = {
def plugins = [:]
for (p in readAllPluginXmlMetadata()) {
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(resolveDependencies)
def availablePluginVersions = getAvailablePluginVersions()
def installedPluginVersions = getInstalledPluginVersions()
boolean headerDisplayed = false
if (installedPluginVersions) {
installedPluginVersions.each {name, version ->
def availableVersion = availablePluginVersions."$name"
if (availableVersion != version && availableVersion != null) {
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."
}
}