-
Notifications
You must be signed in to change notification settings - Fork 7
/
EntryPointsGrailsPlugin.groovy
94 lines (83 loc) · 3.3 KB
/
EntryPointsGrailsPlugin.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
/*
* Copyright (c) 2011 Vincent Barrier.
*
*
* entry-points is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* entry-points is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with iceScrum. If not, see <http://www.gnu.org/licenses/>.
*
*/
import org.icescrum.plugins.entryPoints.artefacts.EntryPointsArtefactHandler
import org.icescrum.plugins.entryPoints.services.EntryPointsService
class EntryPointsGrailsPlugin {
def groupId = 'org.icescrum'
def version = "1.4.2"
def grailsVersion = "2.5 > *"
def dependsOn = [:]
def pluginExcludes = [
"grails-app/views/error.gsp"
]
def artefacts = [new EntryPointsArtefactHandler()]
def watchedResources = [
"file:./grails-app/*/*EntryPoints.groovy",
"file:./plugins/*/grails-app/*/*EntryPoints.groovy",
]
def loadAfter = ['controllers']
def author = "Vincent Barrier"
def authorEmail = "[email protected]"
def title = "Entry points for your grails app (entry points inside gsp & controllers)"
def description = '''
used in iceScrum -> http://www.icescrum.org
'''
def documentation = "http://www.icescrum.org/plugin/entry-points"
def doWithDynamicMethods = { ctx ->
EntryPointsService service = ctx.getBean('entryPointsService')
application.controllerClasses.each {
addEntryPointsMethods(it, service)
}
}
def doWithApplicationContext = { applicationContext ->
applicationContext.entryPointsService.reload()
}
def onChange = { event ->
def type = EntryPointsArtefactHandler.TYPE
if (application.isArtefactOfType(type, event.source)) {
log.debug("reloading $event.source.name ($type)")
def oldClass = application.getArtefact(type, event.source.name)
application.addArtefact(type, event.source)
application.getArtefacts(type).each {
if (it.clazz != event.source && oldClass.clazz.isAssignableFrom(it.clazz)) {
def newClass = application.classLoader.reloadClass(it.clazz.name)
application.addArtefact(type, newClass)
}
}
event.application.mainContext.entryPointsService.reload()
}
}
def onConfigChange = { event ->
event.application.mainContext.entryPointsService.reload()
}
private addEntryPointsMethods(it, service) {
it.clazz.metaClass {
entryPoints { String ref, Map model = null ->
assert ref
if (model instanceof Map) {
model.each { request."${it.key}" = it.value }
} else {
request.model = model
}
service.getEntriesToChain(ref)?.each {
forward(action: it.form?.action ?: it.action, controller: it.form?.controller ?: it.controller)
}
}
}
}
}