Repository navigation
Expand file tree
/
Copy pathcommons.gradle
More file actions
246 lines (212 loc) · 7.87 KB
/
Copy pathcommons.gradle
File metadata and controls
246 lines (212 loc) · 7.87 KB
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
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Deps
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.ajoberstar.grgit:org.ajoberstar.grgit.gradle.plugin:${project.property('grgit.version')}"
classpath "org.apache.commons:commons-text:${project.property('commons-text.version')}"
classpath "org.apache.commons:commons-lang3:${project.property('commons-lang3.version')}"
}
}
import java.security.MessageDigest
// Helper methods
ext.splash = { ->
System.out.println("\033[38;5;196m")
System.out.println(" ██████╗ ██████╗ █████╗ ███████╗ ████████╗ ███████╗ ██████╗ ██████╗ ███╗ ███╗ ███████╗")
System.out.println("██╔════╝ ██╔══██╗ ██╔══██╗ ██╔════╝ ╚══██╔══╝ ██╔════╝ ██╔══██╗ ██╔════╝ ████╗ ████║ ██╔════╝")
System.out.println("██║ ██████╔╝ ███████║ █████╗ ██║ █████╗ ██████╔╝ ██║ ██╔████╔██║ ███████╗")
System.out.println("██║ ██╔══██╗ ██╔══██║ ██╔══╝ ██║ ██╔══╝ ██╔══██╗ ██║ ██║╚██╔╝██║ ╚════██║")
System.out.println("╚██████╗ ██║ ██║ ██║ ██║ ██║ ██║ ███████╗ ██║ ██║ ╚██████╗ ██║ ╚═╝ ██║ ███████║")
System.out.println(" ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝")
System.out.println("\033[0m")
}
// Settings
ext {
cmsDir = "${projectDir}/craftercms"
commandTimeout = getPropertySafelyWithDefaults("commandTimeout", 1000000).toInteger()
}
ext.execCommand = { command, dir ->
def cmd = "";
command.each { fragment ->
cmd += fragment
if (fragment != command.last()) {
cmd += " "
}
}
// System.out.println("Executing command \"" + dir + ":" + cmd + "\"")
def proc = cmd.execute(null, file(dir))
proc.consumeProcessOutput(System.out, System.err)
proc.waitForOrKill(commandTimeout)
if (proc.exitValue() != 0) {
throw new GradleException("$cmd failed.")
}
}
ext.copyFile = { workingDir, source, destination ->
def command = ["cp", source, destination]
try {
execCommand(command, workingDir)
} catch (e) {
logger.error("Failed to copy file workingDir: {}, source: {}, destination: {}")
throw new GradleException("Failed to copy file.", e)
}
}
ext.syncFolder = { workingDir, source, destination, exclude, overwriteChangedFiles, deleteNonExisting ->
def command = ["rsync", "-ar"]
if (!overwriteChangedFiles) {
command += ["--update"]
}
if (deleteNonExisting) {
command += ["--delete"]
}
if (!exclude.isEmpty()) {
command += ["--exclude", exclude]
}
// Make sure the destination exists
file(destination).mkdirs()
// Rsync the source to the destination
command += [source, destination]
try {
execCommand(command, workingDir)
} catch (e) {
logger.error("Failed to sync folders workingDir: {}, source: {}, destination: {}," +
"exclude: {}, overwriteChangedFiles: {}, exception: {}", workingDir, source,
destination, exclude, overwriteChangedFiles, e)
throw new GradleException("Failed to sync folders.", e)
}
}
// Build methods
ext.gradleModules = [
'groovy-sandbox': ':groovy-sandbox',
'script-security-plugin': ':script-security-plugin',
'commons': [
':commons:utilities',
':commons:security',
':commons:audit',
':commons:git',
':commons:entitlements',
':commons:validation',
':commons:plugin',
':commons:upgrade-manager'
],
'core': ':core',
'search': [
':search:commons',
':search:batch-indexer',
':search:opensearch'
],
'engine': ':engine',
'studio-ui': ':studio-ui',
'studio': ':studio',
'deployer': ':deployer',
'cli': ':cli'
]
// This is used to run external tasks: bomGenerate, publishMavenPublicationToGitHubPackagesRepository
ext.runGradleModuleTask = { module, task, extraArgs = [] ->
def projects = gradleModules[module]
if (projects == null) {
return false
}
def gradleArgs = ["./gradlew"]
if (extraArgs) {
gradleArgs.addAll(extraArgs as List)
}
if (projects instanceof List) {
projects.each { gradleArgs += "${it}:${task}" }
} else {
gradleArgs += "${projects}:${task}"
}
execCommand(gradleArgs, projectDir)
return true
}
ext.buildBom = { module ->
if (runGradleModuleTask(module, 'bomGenerate')) {
return
}
println "Skipping BOM generation for $module (no Gradle bomGenerate task configured)"
}
ext.aggregateBoms = { dir ->
try {
execCommand(["./aggregate-boms.sh"], dir)
} catch (e) {
logger.error("Failed to aggregate BOMs, exception: {}", e)
throw new GradleException("Failed to aggregate BOMs.", e)
}
}
ext.checksumFile = { filePath, algorithm ->
// Set your algorithm
// "MD2","MD5","SHA","SHA-1","SHA-256","SHA-384","SHA-512"
MessageDigest md = MessageDigest.getInstance(algorithm);
FileInputStream fis = new FileInputStream(new File(filePath));
byte[] dataBytes = new byte[1024];
int nread = 0;
while ((nread = fis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
}
byte[] mdbytes = md.digest();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
}
ext.bundleEnvironment = { env, bundlesDir /*, fresh*/ ->
/*
// TODO: add support for a fresh env before bundling
if (fresh) {
// Create a temporary folder and do a fresh build
// Set the source to the fresh build
}
*/
// Tar and package
def bundleFilename = "crafter-cms-${env}-${project.version}-${currentPlatform}-${currentArch}.tar.gz"
def bundlePath = "${bundlesDir}/" + bundleFilename
def source = "./crafter"
if (!file(bundlePath).exists()) {
if (env == "authoring") {
file("${authoringEnvDir}").renameTo(source)
} else if (env == "delivery") {
file("${deliveryEnvDir}").renameTo(source)
} else {
throw new GradleException("Unknown environment " + env)
}
file(bundlesDir).mkdir()
try {
execCommand(["tar", "czf", bundlePath, source], "${projectDir}")
def md5sum = checksumFile(bundlePath, "MD5")
def sha512sum = checksumFile(bundlePath, "SHA-512")
new File(bundlePath + ".md5").withWriter('utf-8') {
writer -> writer.writeLine md5sum + " " + bundleFilename
}
new File(bundlePath + ".sha512").withWriter('utf-8') {
writer -> writer.writeLine sha512sum + " " + bundleFilename
}
} catch (e) {
logger.error("Failed to create bundle for env: {}, bundlesDir: {}", env, bundlesDir, e)
throw new GradleException("Failed to create bundle.", e)
} finally {
if (env == "authoring") {
file(source).renameTo("${authoringEnvDir}")
} else if (env == "delivery") {
file(source).renameTo("${deliveryEnvDir}")
} else {
throw new GradleException("Unknown environment " + env)
}
}
}
}