-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathtomcat.gradle
221 lines (190 loc) · 7.3 KB
/
tomcat.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
repositories {
mavenLocal()
mavenCentral()
}
configurations {
tomcat
shared
}
dependencies {
tomcat "org.apache.tomcat:tomcat:${tomcatVersion}@tar.gz"
shared "javax.ccpp:ccpp:${ccppVersion}"
shared "org.apache.portals.pluto:pluto-container-api:${plutoVersion}"
shared "org.apache.portals.pluto:pluto-container-driver-api:${plutoVersion}"
shared "org.apache.portals.pluto:pluto-taglib:${plutoVersion}"
shared "org.apereo.service.persondir:person-directory-api:${personDirectoryVersion}"
shared "${portletApiDependency}"
}
/*
* Used by tasks in this file to avoid trying to start the Tomcat service twice, etc.
*/
private boolean verifyTomcatState(Project project, boolean verifyRunning) {
project.ant {
condition(property: 'tomcatIsRunning', value: true, else: false) {
socket(server: 'localhost', port: 8080)
}
if (Boolean.valueOf(tomcatIsRunning) != verifyRunning) {
logger.lifecycle("The embedded Tomcat servlet container ${verifyRunning ? 'is not currently' : 'is already'} running; nothing to do")
throw new StopExecutionException()
}
}
}
task tomcatInstall() {
group 'Tomcat'
description 'Downloads the Apache Tomcat servlet container and performs the necessary configuration steps'
dependsOn ':portalProperties'
doLast {
String serverHome = rootProject.ext['buildProperties'].getProperty('server.home')
logger.lifecycle("Installing Tomcat servlet container version ${tomcatVersion} to location ${serverHome}")
File tomcatTmpDir = new File('build/tmp/tomcat')
// Clear & reset the tomcat directory
tomcatTmpDir.deleteDir()
tomcatTmpDir.mkdirs()
File tomcatTarFile = new File("${tomcatTmpDir}/tomcat-gunziped.tar")
// Gunzip the Tomcat binaries
File tomcatTarGz = configurations.tomcat.files.iterator().next()
ant.gunzip(src: tomcatTarGz, dest: tomcatTarFile.getPath())
// Un-archive the tar file
copy {
from tarTree(tomcatTarFile.getPath())
into tomcatTmpDir
}
// Clear any previous copy of Tomcat
file(serverHome).deleteDir()
// Copy to the final location
copy {
from "${tomcatTmpDir}/apache-tomcat-${tomcatVersion}"
into serverHome
}
// Configure our settings by overlaying etc/tomcat
copy {
from 'etc/tomcat'
into serverHome
}
// Add shared.loader dependencies
copy {
from configurations.shared
into "${serverHome}/shared/lib"
}
/*
* Create & initialize the folder that is the default location of {portal.home]. (If
* another location has been specified, we don't want to mess with that.)
*/
String portalHomeDir = "${serverHome}/portal"
file(portalHomeDir).mkdirs()
copy {
from 'etc/portal'
into portalHomeDir
}
}
}
task tomcatStart() {
group 'Tomcat'
description 'Start the embedded Tomcat servlet container'
dependsOn ':portalProperties'
/*
* When we chain tasks together -- which is often convenient -- there are some other tasks that
* may potentially be included in the Task Graph that really need to complete before we start
* this one.
*/
mustRunAfter ':tomcatInstall'
mustRunAfter allprojects.collect { it.tasks.matching { it.name.equals('tomcatDeploy') } }
mustRunAfter ':deployPortletApp'
mustRunAfter ':hsqlStart'
mustRunAfter allprojects.collect { it.tasks.matching { it.name.equals('dataInit') } }
doLast {
verifyTomcatState(project, false)
String serverHome = rootProject.ext['buildProperties'].getProperty('server.home')
String portalHome = rootProject.ext['buildProperties'].getProperty('portal.home')
logger.lifecycle("Starting Tomcat servlet container in ${serverHome}")
String executable = isWindows ? 'cmd' : './catalina.sh'
ant.exec(dir: "${serverHome}/bin", executable: executable, spawn: true) {
env(key: "PORTAL_HOME", value: new File(portalHome).getCanonicalPath()) // Must be absolute
if (isWindows) {
arg(value: '/c')
arg(value: 'catalina.bat')
}
if (project.hasProperty('with-jpda')) {
arg(value: 'jpda')
}
arg(value: 'start')
}
ant.waitfor() {
http(url: 'http://localhost:8080/uPortal', followRedirects: false)
}
logger.lifecycle('Tomcat has finished loading webapps, local uPortal server is live')
}
}
task tomcatStop() {
group 'Tomcat'
description 'Stop the embedded Tomcat servlet container'
dependsOn ':portalProperties'
doLast {
verifyTomcatState(project, true)
String serverHome = rootProject.ext['buildProperties'].getProperty('server.home')
logger.lifecycle("Stopping Tomcat servlet container in ${serverHome}")
String executable = isWindows ? 'cmd' : './shutdown.sh'
ant.exec(dir: "${serverHome}/bin", executable: executable, spawn: true) {
if (isWindows) {
arg(value: '/c')
arg(value: 'shutdown.bat')
}
}
ant.waitfor() {
not() {
http(url: 'http://localhost:8080/uPortal', followRedirects: false)
}
}
}
}
task tomcatClearLogs(type: Delete) {
group 'Tomcat'
description 'Delete all log files within Tomcat'
dependsOn ':portalProperties'
doFirst {
String serverBase = rootProject.ext['buildProperties'].getProperty('server.base')
FileTree logsFolder = fileTree("${serverBase}/logs")
if (logsFolder.isEmpty()) {
logger.lifecycle('The Tomcat logs directory is empty; there is noting to delete')
} else {
logsFolder.visit { FileVisitDetails details ->
logger.lifecycle("Deleting ${details.name}")
delete details.file
}
}
}
}
task tomcatZip {
group 'Tomcat'
description 'Create a zip file of Tomcat (base) with uPortal and portlets'
dependsOn ':portalProperties'
mustRunAfter ':tomcatInstall'
mustRunAfter allprojects.collect { it.tasks.matching { it.name.equals('tomcatDeploy') } }
doLast {
String serverBase = rootProject.ext.buildProperties.getProperty('server.base')
ant.zip(destfile: 'tomcat-uportal.zip') {
zipfileset (
dir: "${serverBase}",
prefix: 'tomcat',
excludes: 'logs/**/*, temp/**/*, work/**/*'
)
}
}
}
task tomcatTar {
group 'Tomcat'
description 'Create a .tar.gz file of Tomcat (base) with uPortal and portlets'
dependsOn ':portalProperties'
mustRunAfter ':tomcatInstall'
mustRunAfter allprojects.collect { it.tasks.matching { it.name.equals('tomcatDeploy') } }
doLast {
String serverBase = rootProject.ext.buildProperties.getProperty('server.base')
ant.tar(destfile: 'tomcat-uportal.tgz', compression: 'gzip', longfile: 'gnu') {
tarfileset (
dir: "${serverBase}",
prefix: 'tomcat',
excludes: 'logs/**/*, temp/**/*, work/**/*'
)
}
}
}