forked from aalmiray/grails-jalarms
/
JalarmsGrailsPlugin.groovy
97 lines (84 loc) · 3.17 KB
/
JalarmsGrailsPlugin.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
/*
* grails-jalarms: JAlarms Grails plugin
* Copyright 2010 and beyond, Hackergarten
*
* This library 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 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
import com.solab.alarms.AlarmChannel
import com.solab.alarms.AlarmSender
import org.codehaus.groovy.grails.commons.ApplicationHolder
import org.codehaus.groovy.grails.commons.ConfigurationHolder
/**
* @author Hackergarten
*/
class JalarmsGrailsPlugin {
def groupId = 'com.solab.grails'
// the plugin version
def version = "0.3"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.5 > *"
// the other plugins this plugin depends on
def dependsOn = [:]
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp"
]
def author = "Enrique Zamudio, Hector Cuesta, Andres Almiray"
def authorEmail = "chochos@users.sourceforge.net, aalmiray@users.sourceforge.net"
def title = "JAlarms plugin for Grails"
def description = '''\\
This plugin enables Grails applications to send alarms with a multitude of configurable channels.
Relies on JAlarms http://jalarms.sourceforge.net
'''
def observe = ['controllers', 'services']
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/jalarms"
def doWithDynamicMethods = { ctx ->
processArtifacts()
}
def onChange = { event ->
processArtifacts()
}
def onConfigChange = { event ->
processArtifacts()
}
private processArtifacts() {
def config = ConfigurationHolder.config
def application = ApplicationHolder.application
def types = config.grails?.jalarms?.injectInto ?: ["Controller", "Service"]
types.each { type ->
application.getArtefacts(type).each{ klass ->
klass.metaClass.sendAlarm = sendAlarm
}
}
}
private sendAlarm = {String... args ->
ApplicationHolder.application.mainContext.alarmer.sendAlarm(*args)
}
def doWithSpring = {
alarmer(AlarmSender) { bean ->
bean.scope = 'singleton'
bean.autowire = 'byName'
}
}
def doWithApplicationContext = { applicationContext ->
Map<String, AlarmChannel> channels = applicationContext.getBeansOfType(AlarmChannel)
if(channels) {
List<AlarmChannel> chnls = []
chnls.addAll(channels.values())
applicationContext.alarmer.alarmChannels = chnls
}
}
}