forked from smaldini/grails-events-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventsPushGrailsPlugin.groovy
127 lines (109 loc) · 4.92 KB
/
EventsPushGrailsPlugin.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* Copyright 2011-2012 the original author or authors:
*
* Marc Palmer (marc@grailsrocks.com)
* Stéphane Maldini (stephane.maldini@gmail.com)
*
* 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 org.atmosphere.cpr.ApplicationConfig
import org.atmosphere.cpr.MeteorServlet
import org.grails.plugin.platform.events.push.EventsPushHandler
import org.grails.plugin.platform.events.push.GrailsMeteorServlet
import org.springframework.util.ClassUtils
class EventsPushGrailsPlugin {
// the plugin version
def version = "1.0.M3"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.0 > *"
// the other plugins this plugin depends on
def loadAfter = ['platformCore']
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp",
"grails-app/views/index.gsp",
"grails-app/conf/Test*.groovy",
"grails-app/domain/**/Test*.groovy",
"grails-app/services/**/Test*.groovy",
"web-app/css/**",
"web-app/images/**",
"web-app/js/application.js",
"web-app/WEB-INF/**"
]
def observe = ['platformCore']
def title = "Events Push Plugin" // Headline display name of the plugin
def author = "Stephane Maldini"
def authorEmail = "smaldini@vmware.com"
def description = '''\
This is a client-side event bus based on the portable push library [Atmosphere|https://github.com/Atmosphere/atmosphere]\
that propagates events from the server-side event bus provided by the [Platform Core|http://grails.org/plugin/platform-core]\
to the browser. It allows your client Javascript code to both send events and listen for them.
For security, events-push is a white-list broadcaster so that you can control exactly which events are propagated from\
the server to the browser.
'''
// URL to the plugin's documentation
def documentation = "https://github.com/smaldini/grails-events-push/blob/master/README.md"
// Extra (optional) plugin metadata
// License: one of 'APACHE', 'GPL2', 'GPL3'
def license = "APACHE"
// Details of company behind the plugin (if there is one)
// def organization = [ name: "My Company", url: "http://www.my-company.com/" ]
// Any additional developers beyond the author specified above.
// def developers = [ [ name: "Joe Bloggs", email: "joe@bloggs.net" ]]
// Location of the plugin's issue tracker.
def issueManagement = [ system: "GITHUB", url: "https://github.com/smaldini/grails-events-push/issues" ]
// Online location of the plugin's browseable source code.
def scm = [url: "https://github.com/smaldini/grails-events-push"]
def doWithWebDescriptor = { xml ->
def servlets = xml.'servlet'
def config = application.config?.events?.push
servlets[servlets.size() - 1] + {
'servlet' {
'description'('MeteorServlet')
'servlet-name'('MeteorServlet')
'servlet-class'(MeteorServlet.name)
'init-param' {
'param-name'(ApplicationConfig.SERVLET_CLASS)
'param-value'(EventsPushHandler.name)
}
if (!config?.servlet?.initParams?."$ApplicationConfig.WEBSOCKET_SUPPORT") {
'init-param' {
'param-name'(ApplicationConfig.WEBSOCKET_SUPPORT)
'param-value'(true)
}
}
if (ClassUtils.isPresent("javax.servlet.AsyncContext", Thread.currentThread().getContextClassLoader())) {
'async-supported'(true)
}
config?.servlet?.initParams.each { initParam ->
'init-param' {
'param-name'(initParam.key)
'param-value'(initParam.value)
}
}
'load-on-startup'('0')
}
}
def mappings = xml.'servlet-mapping'
mappings[mappings.size() - 1] + {
'servlet-mapping' {
'servlet-name'('MeteorServlet')
'url-pattern'(config?.servlet?.urlPattern ?: '/g-eventsbus/*')
}
}
}
def onChange = { event ->
if (application.isArtefactOfType('Events', event.source)) {
EventsPushHandler.registerTopics(event.ctx.grailsEventsRegistry, event.ctx.grailsEvents)
}
}
}