forked from apache/cassandra-sidecar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
316 lines (269 loc) · 10.4 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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 com.github.spotbugs.snom.SpotBugsTask
import org.nosphere.apache.rat.RatTask
import java.nio.file.Files
import java.nio.file.Paths
buildscript {
dependencies {
// findBugs needs a newer version of Guava in the buildscript.
// otherwise it throws an exception
classpath "com.google.guava:guava:28.2-jre"
}
}
plugins {
id 'idea'
id 'java'
id 'application'
// since we're using a specific version here, we delay applying the plugin till the all projects
id "com.github.spotbugs" version "6.0.20" apply false
// https://github.com/nebula-plugins/gradle-ospackage-plugin/wiki
id "com.netflix.nebula.ospackage" version "11.10.0"
id 'com.netflix.nebula.ospackage-application' version "11.10.0"
id 'org.asciidoctor.jvm.convert' version '3.3.2'
// Release Audit Tool (RAT) plugin for checking project licenses
id("org.nosphere.apache.rat") version "0.8.0"
id 'jacoco'
}
// Force checkstyle, rat, and spotBugs to run before test tasks for faster feedback
def codeCheckTasks = task("codeCheckTasks")
allprojects {
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: "com.github.spotbugs"
repositories {
mavenCentral()
// for dtest jar
mavenLocal()
}
checkstyle {
toolVersion '7.8.1'
configFile file("${project.rootDir}/checkstyle.xml")
}
spotbugs {
toolVersion = '4.2.3'
excludeFilter = file("${project.rootDir}/spotbugs-exclude.xml")
}
codeCheckTasks.dependsOn(tasks.withType(Checkstyle))
codeCheckTasks.dependsOn(tasks.withType(RatTask))
codeCheckTasks.dependsOn(tasks.withType(SpotBugsTask))
tasks.withType(Test) {
shouldRunAfter(codeCheckTasks)
shouldRunAfter(tasks.withType(Checkstyle))
shouldRunAfter(tasks.withType(RatTask))
shouldRunAfter(tasks.withType(SpotBugsTask))
}
}
group 'org.apache.cassandra'
version project.version
sourceCompatibility = 1.8
application {
// Take the application out once we're running via Cassandra
mainClassName = "org.apache.cassandra.sidecar.CassandraSidecarDaemon"
applicationName = 'cassandra-sidecar'
applicationDefaultJvmArgs = ["PLACEHOLDER"]
}
startScripts {
doLast {
// Config file location should be in file:/// format for local files,
def confFile = "file:" + File.separator + File.separator + "\${APP_HOME}/conf/sidecar.yaml"
// As of Gradle version 7.2, the generated bin/cassandra-sidecar file by default is configured to not allow
// shell fragments. Thus, variables like APP_HOME are treated as literals, which prevents us from being able to
// start up cassandra-sidecar. See this comment on bin/cassandra-sidecar (line 208):
//
// # Collect all arguments for the java command:
// # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
// # and any embedded shellness will be escaped.
// # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
// # treated as '${Hostname}' itself on the command line.
//
// Replacing the placeholder after the script has been generated will preserve the semantics from Gradle < 7.2.
// See this Gradle issue for more context: https://github.com/gradle/gradle/issues/18170.
def defaultJvmOpts = ["-Dsidecar.logdir=./logs",
"-Dsidecar.config=" + confFile,
"-Dlogback.configurationFile=./conf/logback.xml",
"-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory",
"-javaagent:\${APP_HOME}/agents/jolokia-jvm-1.6.0-agent.jar=port=7777,host=localhost"]
unixScript.text = unixScript.text.replace("DEFAULT_JVM_OPTS='\"PLACEHOLDER\"'",
"DEFAULT_JVM_OPTS=\"${defaultJvmOpts.join(" ")}\"")
windowsScript.delete()
}
}
run {
def confFile = System.getProperty("sidecar.config", "file:" + File.separator + File.separator + "$projectDir/conf/sidecar.yaml")
println "Sidecar configuration file $confFile"
jvmArgs = ["-Dsidecar.logdir=./logs",
"-Dsidecar.config=" + confFile,
"-Dlogback.configurationFile=./conf/logback.xml",
"-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory",
"-javaagent:$projectDir/agents/jolokia-jvm-1.6.0-agent.jar=port=7777,host=localhost"]
}
distributions {
main {
contents {
from 'LICENSE.txt'
// Include the "agents" directory in the distribution
from('agents') {
into('agents')
}
// Include the "conf" directory in the distribution
from('conf') {
into('conf')
}
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
}
}
configurations {
jolokia
runtime.exclude(group: "com.google.code.findbugs", module: "jsr305")
runtime.exclude(group: "org.codehaus.mojo", module: "animal-sniffer-annotations")
runtime.exclude(group: "com.google.guava", module: "listenablefuture")
runtime.exclude(group: "org.checkerframework", module: "checker-qual")
runtime.exclude(group: "com.google.errorprone", module: "error_prone_annotations")
runtime.exclude(group: 'com.github.jnr', module: 'jnr-ffi')
runtime.exclude(group: 'com.github.jnr', module: 'jnr-posix')
}
dependencies {
runtimeOnly(project(':server'))
jolokia 'org.jolokia:jolokia-jvm:1.6.0:agent'
}
jar {
doFirst {
// Store current Cassandra Sidecar build version in an embedded resource file;
// the file is either created or overwritten, and ignored by Git source control
Files.createDirectories(Paths.get("$projectDir/server-common/src/main/resources"))
new File("$projectDir/server-common/src/main/resources/sidecar.version").text = version
}
}
tasks.register('copyIdeaSettings', Copy) {
from "ide/idea"
into ".idea"
}
tasks.named('idea').configure {
dependsOn copyIdeaSettings
}
tasks.register('copyJolokia') {
doLast {
copy {
into "$projectDir"
into("agents") {
from configurations.jolokia
}
}
}
}
// Lets clean distribution directories along with default build directories.
clean.doLast {
["agents"].each {
println "Deleting directory $projectDir/$it"
delete "$projectDir/$it"
}
println "Deleting generated docs $projectDir/server/src/main/resources/docs"
delete "$projectDir/server/src/main/resources/docs"
}
subprojects {
jacocoTestReport {
reports {
xml.setRequired(true)
html.setRequired(true)
csv.setRequired(false)
}
}
test {
jvmArgs "-XX:-MaxFDLimit"
finalizedBy jacocoTestReport // report is always generated after tests run
}
}
// copy the user documentation to the final build
tasks.register('copyDocs', Copy) {
dependsOn ':docs:asciidoctor'
from(tasks.getByPath(":docs:asciidoctor").outputs) {
include "**/*.html"
}
into "build/docs/"
exclude "tmp"
}
/**
* General configuration for linux packages.
* Can be overridden in the buildRpm and buildDeb configuration
* We can put dependencies here, such as java, but unfortunately since java is distributed
* in an inconsistent manner depending on the version you want (8 vs 11) we can't include Java
* as a requirement without the install breaking if you want to use a different version
*/
ospackage {
packageName = "cassandra-sidecar"
version = project.version
// ospackage puts packages into /opt/[package] by default
// which is _technically_ the right spot for packages
link("/usr/local/bin/cassandra-sidecar", "/opt/cassandra-sidecar/bin/cassandra-sidecar")
license "Apache License 2.0"
description "Sidecar Management Tool for Apache Cassandra"
os = LINUX
user "root"
}
buildRpm {
group = "build"
}
buildDeb {
group = "build"
}
tasks.register('buildIgnoreRatList', Exec) {
description 'Builds a list of ignored files for the rat task from the unversioned git files'
commandLine 'bash', '-c', "git clean --force -d --dry-run -x | cut -c 14-"
doFirst {
mkdir(buildDir)
standardOutput new FileOutputStream("${buildDir}/.rat-excludes.txt")
}
// allows task to fail when git/cut commands are unavailable or fail
ignoreExitValue = true
}
rat {
doFirst {
def excludeFilePath = Paths.get("${buildDir}/.rat-excludes.txt")
def excludeLines = Files.readAllLines(excludeFilePath)
excludeLines.each { line ->
if (line.endsWith("/")) {
excludes.add("**/" + line + "**")
} else {
excludes.add(line)
}
}
}
// List of Gradle exclude directives, defaults to ['**/.gradle/**']
excludes.add("**/build/**")
excludes.add("CHANGES.txt")
// Documentation files
excludes.add("**/docs/src/**")
// gradle files
excludes.add("gradle/**")
excludes.add("gradlew")
excludes.add("gradlew.bat")
// resource files for test
excludes.add("**/test**/resources/**")
// XML, TXT and HTML reports directory, defaults to 'build/reports/rat'
reportDir.set(file("build/reports/rat"))
}
installDist.dependsOn copyJolokia
check.dependsOn codeCheckTasks
build.dependsOn copyJolokia, copyDocs
run.dependsOn build
tasks.named('rat').configure {
dependsOn(buildIgnoreRatList)
}