-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConfigAnnotationGrailsPlugin.groovy
78 lines (62 loc) · 2.73 KB
/
ConfigAnnotationGrailsPlugin.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
import ru.grails.config.GrailsConfigAnnotationHandler
import ru.grails.config.GrailsConfigBeanPostProcessor
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class ConfigAnnotationGrailsPlugin {
private static final Logger LOG = LoggerFactory.getLogger("ru.grails.config.GrailsConfigAnnotationGrailsPlugin")
def version = "1.0"
def grailsVersion = "2.0 > *"
def pluginExcludes = [
"grails-app/controllers/ru/grails/config/test/MainController.groovy",
"grails-app/services/ru/grails/config/test/TransactionalService.groovy",
"grails-app/services/ru/grails/config/test/SimpleService.groovy",
"src/groovy/ru/grails/config/test/UsersBean.groovy"
]
def license = 'APACHE'
def title = "Grails Config Annotation Plugin"
def author = "fedor.belov"
def authorEmail = "[email protected]"
def description = '''\
This plugin adds `@GrailsConfig` annotation that gives you simple way to
inject config value into your beans (services, controllers, tagLibs and etc.)
'''
//watch for all scss file changes
def watchedResources = [
'file:./grails-app/**/*.groovy',
'file:./src/**/*.groovy'
]
def documentation = "https://github.com/fedotxxl/grails-config-annotation/blob/master/README.md"
def scm = [url: 'https://github.com/fedotxxl/grails-config-annotation']
def issueManagement = [system: "GITHUB", url: "https://github.com/fedotxxl/grails-config-annotation/issues"]
private GrailsConfigAnnotationHandler handler = GrailsConfigAnnotationHandler.instance
def doWithSpring = {
grailsConfigBeanPostProcessor(GrailsConfigBeanPostProcessor)
}
def onChange = { event ->
try {
Class clazz
if(event.source instanceof Class) {
clazz = event.source
} else {
LOG.debug "@GrailsConfig: skip change event - ${event.source}"
}
if (clazz) {
LOG.trace "@GrailsConfig: updating beans config values of class ${event.source}"
handler.resetClass(clazz)
handler.initClass(clazz, application)
LOG.trace "@GrailsConfig: onChange completed"
}
} catch (Throwable e) {
LOG.error "@GrailsConfig: exception on processing change event: ${event} - ${e}", e
}
}
def onConfigChange = { event ->
LOG.trace "@GrailsConfig: processing config change event"
//I think we can save beans and update beans
//But this is safer approach
handler.annotatedClasses.each { clazz ->
handler.initClass(clazz, application)
}
LOG.trace "@GrailsConfig: completed processing config change event"
}
}