-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.openfire-plugin.gradle
257 lines (239 loc) · 9.78 KB
/
build.openfire-plugin.gradle
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import org.apache.tools.ant.filters.ReplaceTokens
import java.time.Duration
import java.time.Instant
repositories {
mavenCentral()
maven {
url 'https://maven.atlassian.com/repository/public'
}
maven {
url 'https://igniterealtime.org/archiva/repository/maven/'
}
}
dependencies {
compileOnly "org.igniterealtime.openfire:xmppserver:${minOpenfireVersion}"
testImplementation "org.igniterealtime.openfire:xmppserver:${minOpenfireVersion}"
}
def canonicalName = project.name.replaceAll('\\W', '').toLowerCase()
task confirmChangeLog() {
group = 'verification'
description = 'Checks the changelog contains the current date - but only if this is not a SNAPSHOT version'
def changelog = new File('src/plugin/changelog.html')
inputs.file(changelog)
def expectedDate = new Date().format("MMMM d, yyyy")
doFirst {
if (!changelog.text.contains(expectedDate)) {
throw new Exception("The changelog at ${changelog} does not contain todays date (${expectedDate}) - remember to update it!")
}
}
}
tasks.confirmChangeLog.onlyIf { !(project.version as String).contains("SNAPSHOT") }
tasks.check.dependsOn tasks.confirmChangeLog
task jspcLoggingProperties(type: WriteProperties) {
outputFile = file("$buildDir/jspc-log4j/log4j2.properties")
property('appender.console.type', 'Console')
property('appender.console.name', 'STDOUT')
property('appender.console.layout.type', 'PatternLayout')
property('appender.console.layout.pattern', '%m%n')
}
def jspCompile(File srcDir, File destDir, File mergedWebXml, String javaPackage) {
def xmlFragment = file("${destDir}/web.xml.fragment")
// Create the target WEB-INF folder so the JspC can create the web.xml.partial
xmlFragment.getParentFile().mkdirs()
javaexec {
classpath = files(sourceSets.main.compileClasspath, tasks.jspcLoggingProperties.outputFile.parent)
main = 'org.apache.jasper.JspC'
args = ['-webapp', srcDir.absolutePath,
'-d', file("${destDir}/java").absolutePath,
'-p', javaPackage,
'-failFast',
'-l',
'-die',
'-source', java.sourceCompatibility.toString(),
'-target', java.targetCompatibility.toString(),
'-webxmlencoding', 'UTF-8',
'-webinc', xmlFragment.absolutePath
]
}
def webXmlOriginal = file("${srcDir}/WEB-INF/web.xml")
if (webXmlOriginal.exists() && xmlFragment.exists()) {
// Merge the partial XML with the original
String originalXML = webXmlOriginal.text
String xmlToMerge = xmlFragment.text
String mergedXML = originalXML.replaceFirst('(?s)(<web-app.*?>)', '$1' + xmlToMerge)
mergedWebXml.text = mergedXML
}
}
task jspcAdmin(dependsOn: [jspcLoggingProperties]) {
ext.inputDir = file('src/main/webapp-admin')
ext.outputDir = file("${buildDir}/generated/sources/jsp-admin")
ext.webXml = file("$outputDir/web.xml")
inputs.dir inputDir
outputs.dir outputDir
doFirst {
jspCompile(inputDir as File, outputDir as File, webXml as File,
"org.jivesoftware.openfire.plugin.${canonicalName}.jsp.admin")
}
}
tasks.jspcAdmin.onlyIf { !tasks.jspcAdmin.inputs.files.empty }
tasks.compileJava.dependsOn tasks.jspcAdmin
sourceSets.main.java.srcDirs file("${jspcAdmin.outputDir}/java").absolutePath
task jspcClient(dependsOn: [jspcLoggingProperties]) {
ext.inputDir = file('src/main/webapp-client')
ext.outputDir = file("${buildDir}/generated/sources/jsp-client")
ext.webXml = file("$outputDir/web.xml")
inputs.dir inputDir
outputs.dir outputDir
doFirst {
jspCompile(inputDir as File, outputDir as File, webXml as File,
"org.jivesoftware.openfire.plugin.${canonicalName}.jsp.client")
}
}
tasks.jspcClient.onlyIf { !tasks.jspcClient.inputs.files.empty }
tasks.compileJava.dependsOn tasks.jspcClient
sourceSets.main.java.srcDirs file("${jspcClient.outputDir}/java").absolutePath
task openfirePluginAssembly(type: Jar, dependsOn: [jar]) {
dependsOn configurations.runtimeClasspath
group = 'build'
description = 'Assembles the Openfire-specific plugin JAR file'
mustRunAfter(tasks.confirmChangeLog)
archiveClassifier.set 'openfire-plugin-assembly'
from(jar.archiveFile) {
into 'lib'
}
from(configurations.runtimeClasspath) {
into 'lib'
}
from('src/main/resources') {
into 'classes'
}
from('src/plugin') {
filesMatching('plugin.xml') {
filter(ReplaceTokens, tokens: [
name : project.pluginName,
description : project.description,
version : project.version,
releaseDate : new Date().format("yyyy-MM-dd"),
minOpenfireVersion: minOpenfireVersion,
javaVersion : java.targetCompatibility as String
])
}
}
from('src/main/webapp-admin') {
into 'web'
exclude('**/*.jsp*')
exclude('**/*.tld')
exclude('WEB-INF/web.xml')
}
from(tasks.jspcAdmin.webXml as File) {
into 'web/WEB-INF'
}
from('src/main/webapp-client') {
into 'web-client'
exclude('**/*.jsp*')
exclude('**/*.tld')
exclude('WEB-INF/web.xml')
}
from(tasks.jspcClient.webXml as File) {
into 'web-client/WEB-INF'
}
}
assemble.dependsOn(openfirePluginAssembly)
// Runtime resources are added to the WAR file by openfirePluginAssembly, so skip that stage
tasks.processResources.enabled = false
// But ensure runtime resources are added to the test runtime
sourceSets.test.resources.srcDir 'src/main/resources'
task deleteOldPluginInOpenfire(type: Delete) {
group = 'deploy'
description = 'Deletes the current plugin JAR file in the Openfire plugins directory. ' +
'Requires the OPENFIRE_HOME environment variable to bet set appropriately.'
doFirst {
if (System.env.OPENFIRE_HOME == null) {
throw new Exception('Unable to delete existing plugin JAR file; OPENFIRE_HOME environment variable is not set')
}
def pluginDir = new File("${System.env.OPENFIRE_HOME}/plugins")
if (!pluginDir.exists() || !pluginDir.isDirectory()) {
throw new Exception('Unable to deploy; OPENFIRE_HOME is not set to an Openfire folder')
}
}
delete "${System.env.OPENFIRE_HOME}/plugins/${canonicalName}.jar"
}
task waitForOpenfireToUnloadPlugin(dependsOn: [deleteOldPluginInOpenfire]) {
group = 'deploy'
description = 'Waits for Openfire to unload the current plugin. Note that the Jetty bug at ' +
'https://github.com/eclipse/jetty.project/issues/1425 means plugins cannot always be unloaded without restarting Openfire.'
doFirst {
if (System.env.OPENFIRE_HOME == null) {
throw new Exception('Unable to wait for existing plugin to unload; OPENFIRE_HOME environment variable is not set')
}
def startTime = Instant.now()
def pluginFolder = new File("${System.env.OPENFIRE_HOME}/plugins/${canonicalName}")
print "Waiting for Openfire to unload old ${canonicalName}.jar "
while (pluginFolder.exists() && (startTime + Duration.ofMinutes(1)) > Instant.now()) {
print '.'
sleep(1000)
}
if (pluginFolder.exists()) {
throw new Exception('Timeout waiting for Openfire to unload old plugin; either Openfire is not running or the plugin cannot unload cleanly')
} else {
println(' unloaded')
}
}
}
tasks.waitForOpenfireToUnloadPlugin.mustRunAfter(tasks.check)
task copyNewPlugin(type: Copy, dependsOn: [openfirePluginAssembly, waitForOpenfireToUnloadPlugin]) {
group = 'deploy'
description = "Copies the plugin to the Openfire plugins directory."
from openfirePluginAssembly.archiveFile
into "${System.env.OPENFIRE_HOME}/plugins"
rename ".*", "${canonicalName}.jar"
doFirst {
if (System.env.OPENFIRE_HOME == null) {
throw new Exception('Unable to copy the new plugin; OPENFIRE_HOME environment variable is not set')
}
}
}
task deploy(dependsOn: [copyNewPlugin]) {
group = 'deploy'
description = 'Waits for Openfire to load the new plugin.'
doFirst {
if (System.env.OPENFIRE_HOME == null) {
throw new Exception('Unable to install new plugin; OPENFIRE_HOME environment variable is not set')
}
def startTime = Instant.now()
def pluginFolder = new File("${System.env.OPENFIRE_HOME}/plugins/${canonicalName}")
print "Waiting for Openfire to install new ${canonicalName}.jar "
while (!pluginFolder.exists() && (startTime + Duration.ofMinutes(1)) > Instant.now()) {
print '.'
sleep(1000)
}
if (!pluginFolder.exists()) {
throw new Exception('Timeout waiting for Openfire to install the plugin; either Openfire is not running or the plugin cannot be installed')
} else {
println(' installed')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact source: openfirePluginAssembly
pom {
name = project.name
description = project.description
url = 'https://igniterealtime.org/projects/openfire/plugin-archive.jsp?plugin=' + project.name
}
}
}
repositories {
maven {
credentials {
username System.getenv("IGNITE_REALTIME_MAVEN_USERNAME")
password System.getenv("IGNITE_REALTIME_MAVEN_PASSWORD")
}
url 'https://igniterealtime.org/archiva/repository/maven/'
}
}
}
tasks.publish.dependsOn check