forked from moqui/moqui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
184 lines (165 loc) · 8.78 KB
/
build.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
/*
* This software is in the public domain under CC0 1.0 Universal plus a
* Grant of Patent License.
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software (see the LICENSE.md file). If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
allprojects { version = '1.6.0' }
defaultTasks 'build'
def tomcatHome = '../apache-tomcat-8.0.21'
def warName = 'moqui-' + version + '.war'
def plusRuntimeName = 'moqui-plus-runtime.war'
def execTempDir = 'execwartmp'
def moquiRuntime = 'runtime'
def moquiConfDev = 'conf/MoquiDevConf.xml'
def moquiConfProduction = 'conf/MoquiProductionConf.xml'
def allCleanTasks = getTasksByName('clean', true)
def allBuildTasks = getTasksByName('build', true)
// ========== clean tasks ==========
task clean(type: Delete) { delete file(warName); delete file(execTempDir) }
task cleanTempDir(type: Delete) { delete file(execTempDir) }
task cleanDb(type: Delete) { delete files(file(moquiRuntime+'/db/derby').listFiles()) - files(moquiRuntime+'/db/derby/derby.properties'); delete file(moquiRuntime+'/db/h2') }
task cleanOrientDb(type: Delete) { delete file(moquiRuntime+'/db/orientdb/databases') }
task cleanElasticSearch(type: Delete) { delete file(moquiRuntime+'/elasticsearch/data') }
task cleanLog(type: Delete) { delete fileTree(dir: moquiRuntime+'/log', include: '*') }
task cleanTxLog(type: Delete) { delete fileTree(dir: moquiRuntime+'/txlog', include: '*') }
task cleanLoadSave(type: Delete) { delete file('SaveH2.zip'); delete file('SaveDEFAULT.zip'); delete file('SaveTenant.zip');
delete file('SaveTransactional.zip'); delete file('SaveAnalytical.zip'); delete file('SaveOrientDb.zip'); delete file('SaveElasticSearch.zip') }
task cleanPlusRuntime(type: Delete) { delete file(plusRuntimeName) }
task cleanOther(type: Delete) { delete fileTree(dir: '.', includes: ['**/.nbattrs', '**/*~', '**/.#*', '**/.DS_Store', '**/*.rej', '**/*.orig']) }
task cleanAll {
dependsOn clean
dependsOn allCleanTasks
dependsOn cleanDb
dependsOn cleanOrientDb
dependsOn cleanElasticSearch
dependsOn cleanTxLog
dependsOn cleanLog
dependsOn cleanLoadSave
dependsOn cleanPlusRuntime
dependsOn cleanOther
}
// ========== run tasks ==========
task run(type: JavaExec) {
dependsOn allBuildTasks
dependsOn cleanTempDir
workingDir = '.'; jvmArgs = ['-server', '-XX:MaxPermSize=192m', '-XX:-OmitStackTraceInFastThrow']; maxHeapSize = '256M'
systemProperties = ['moqui.conf':moquiConfDev, 'moqui.runtime':moquiRuntime]
// NOTE: this is a hack, using -jar instead of a class name, and then the first argument is the name of the jar file
main = '-jar'; args = [warName]
}
task runStaging(type: JavaExec) {
dependsOn allBuildTasks
dependsOn cleanTempDir
workingDir = '.'; jvmArgs = ['-server', '-XX:MaxPermSize=192m', '-Xms512M']; maxHeapSize = '512M'
systemProperties = ['moqui.conf':'conf/MoquiStagingConf.xml', 'moqui.runtime':moquiRuntime]
main = '-jar'; args = [warName]
}
task runProduction(type: JavaExec) {
dependsOn allBuildTasks
dependsOn cleanTempDir
workingDir = '.'; jvmArgs = ['-server', '-XX:MaxPermSize=192m', '-Xms1024M']; maxHeapSize = '1024M'
systemProperties = ['moqui.conf':moquiConfProduction, 'moqui.runtime':moquiRuntime]
main = '-jar'; args = [warName]
}
// use user-specified command line args like: "gradle load -Ptypes=seed -PtenantId=EXAMPLE1"
task load(type: JavaExec) {
dependsOn allBuildTasks
workingDir = '.'; jvmArgs = ['-server', '-XX:MaxPermSize=192m']; maxHeapSize = '512M'
systemProperties = ['moqui.conf':moquiConfDev, 'moqui.runtime':moquiRuntime]
main = '-jar'
def argList = [warName, '-load']
if (project.properties.containsKey('types')) argList.add("-types=${types}")
if (project.properties.containsKey('tenantId')) argList.add("-tenantId=${tenantId}")
args = argList
}
task loadProduction(type: JavaExec) {
dependsOn allBuildTasks
workingDir = '.'; jvmArgs = ['-server', '-XX:MaxPermSize=192m']; maxHeapSize = '512M'
systemProperties = ['moqui.conf':moquiConfProduction, 'moqui.runtime':moquiRuntime]
main = '-jar'
def argList = [warName, '-load']
if (project.properties.containsKey('types')) argList.add("-types=${types}")
if (project.properties.containsKey('tenantId')) argList.add("-tenantId=${tenantId}")
args = argList
}
task loadSaveExec << {
if (file(moquiRuntime+'/db/derby/MoquiDEFAULT').exists()) ant.zip(destfile: 'SaveDEFAULT.zip') { fileset(dir: moquiRuntime+'/db/derby/MoquiDEFAULT') { include(name: '**/*') } }
if (file(moquiRuntime+'/db/derby/MoquiTenant').exists()) ant.zip(destfile: 'SaveTenant.zip') { fileset(dir: moquiRuntime+'/db/derby/MoquiTenant') { include(name: '**/*') } }
if (file(moquiRuntime+'/db/h2').exists()) ant.zip(destfile: 'SaveH2.zip') { fileset(dir: moquiRuntime+'/db/h2') { include(name: '**/*') } }
if (file(moquiRuntime+'/db/orientdb/databases').exists()) ant.zip(destfile: 'SaveOrientDb.zip') { fileset(dir: moquiRuntime+'/db/orientdb/databases') { include(name: '**/*') } }
if (file(moquiRuntime+'/elasticsearch/data').exists()) ant.zip(destfile: 'SaveElasticSearch.zip') { fileset(dir: moquiRuntime+'/elasticsearch/data') { include(name: '**/*') } }
}
task loadSave {
dependsOn cleanAll
dependsOn load
dependsOn loadSaveExec
}
task reloadSaveExec << {
if (file('SaveDEFAULT.zip').exists()) copy { from zipTree('SaveDEFAULT.zip'); into file(moquiRuntime+'/db/derby/MoquiDEFAULT') }
if (file('SaveTenant.zip').exists()) copy { from zipTree('SaveTenant.zip'); into file(moquiRuntime+'/db/derby/MoquiTenant') }
if (file('SaveH2.zip').exists()) copy { from zipTree('SaveH2.zip'); into file(moquiRuntime+'/db/h2') }
if (file('SaveOrientDb.zip').exists()) copy { from zipTree('SaveOrientDb.zip'); into file(moquiRuntime+'/db/orientdb/databases') }
if (file('SaveElasticSearch.zip').exists()) copy { from zipTree('SaveElasticSearch.zip'); into file(moquiRuntime+'/elasticsearch/data') }
}
task reloadSave {
// dependsOn cleanAll
dependsOn cleanTempDir
dependsOn cleanDb
dependsOn cleanOrientDb
dependsOn cleanElasticSearch
dependsOn cleanTxLog
dependsOn cleanLog
dependsOn allBuildTasks
dependsOn reloadSaveExec
}
// ========== deploy tasks ==========
task deployTomcat << {
// remove runtime directory, may have been added for logs/etc
delete file(tomcatHome + '/runtime')
// remove ROOT directory and war to avoid conflicts
delete file(tomcatHome + '/webapps/ROOT')
delete file(tomcatHome + '/webapps/ROOT.war')
// copy the war file to ROOT.war
copy { from file(warName); into file(tomcatHome + '/webapps'); rename(warName, 'ROOT.war') }
}
task addRuntime << {
// unzip the "moqui-${version}.war" file to the wartemp directory
//directory { dir = file('wartemp') }
copy { from zipTree(warName); into file('wartemp') }
// copy runtime directory (with a few exceptions) into a runtime directory in the war
copy {
from fileTree(dir: '.', include: moquiRuntime+'/**', excludes: ['**/*.jar', moquiRuntime+'/classes/**', moquiRuntime+'/lib/**', moquiRuntime+'/log/**'])
into file('wartemp')
}
// copy the jar files from runtime/lib
copy { from fileTree(dir: moquiRuntime+'/lib', include: '**/*.jar').files; into 'wartemp/WEB-INF/lib' }
// copy the classpath resource files from runtime/classes
copy { from fileTree(dir: moquiRuntime+'/classes', include: '**/*'); into 'wartemp/WEB-INF/classes' }
// copy the jar files from components
copy { from fileTree(dir: moquiRuntime+'/component-lib', include: '**/*.jar').files; into 'wartemp/WEB-INF/lib' }
copy { from fileTree(dir: moquiRuntime+'/component', include: '**/*.jar').files; into 'wartemp/WEB-INF/lib' }
// add MoquiInit.properties fresh copy, just in case it was changed
copy { from file('MoquiInit.properties'); into 'wartemp/WEB-INF/classes' }
// zip it up again
ant.zip(destfile: plusRuntimeName) { fileset(dir: 'wartemp') { include(name: '**/*') } }
// alternative once supported: zip { archiveName plusRuntimeName; from fileTree(dir: 'wartemp', include: '**/*') }
// clean up the temporary directory
delete file('wartemp')
}
// don't use this task directly, use addRuntimeTomcat which calls this
task deployTomcatRuntime << {
delete file(tomcatHome + '/runtime'); delete file(tomcatHome + '/webapps/ROOT'); delete file(tomcatHome + '/webapps/ROOT.war')
copy { from file(plusRuntimeName); into file(tomcatHome + '/webapps'); rename(plusRuntimeName, 'ROOT.war') }
}
task addRuntimeTomcat {
dependsOn addRuntime
dependsOn deployTomcatRuntime
}