forked from LINBIT/linstor-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
537 lines (459 loc) · 16 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
import org.gradle.process.internal.ExecException
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'application'
sourceCompatibility = 1.8
def protobufVersion = '3.8.0'
def protoc = file("${projectDir}/tools/protoc-" + protobufVersion + '/bin/protoc')
def logbackConfig = "logback.xml"
def jvmOpts = ["-Xms32M", "-XX:MinHeapFreeRatio=40", "-XX:MaxHeapFreeRatio=70"]
// workaround to force gradle to download not just the dependencies for --offline use
// but also the plugins
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
if (gradle.startParameter.isOffline()) {
classpath fileTree(dir: "$projectDir/libs/plugins")
}
}
}
subprojects {
apply plugin: 'java'
group 'com.linbit'
sourceCompatibility = 1.8
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
if (gradle.startParameter.isOffline()) {
compile fileTree(dir: "libs/compile")
runtime fileTree(dir: "libs/runtime")
testCompile fileTree(dir: "libs/testCompile")
testRuntime fileTree(dir: "libs/testRuntime")
} else {
compile group: 'com.google.inject', name: 'guice', version: '4.2.2'
compile group: 'com.google.inject.extensions', name: 'guice-assistedinject', version: '4.2.2'
// compile group: 'com.google.protobuf', name: 'protobuf-javalite', version: protobufVersion
compile group: 'com.google.protobuf', name: 'protobuf-java', version: protobufVersion
compile 'info.picocli:picocli:3.9.5'
compile group: 'io.projectreactor', name: 'reactor-core', version: '3.2.9.RELEASE'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile 'org.apache.httpcomponents:httpclient:4.5.7'
compile 'com.fasterxml.jackson.jr:jackson-jr-objects:2.10.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.10.0'
// toml parsing library
compile group: 'com.moandjiezana.toml', name: 'toml4j', version: '0.7.2'
// this needs to be moved to the controller, once we have refactored our interfaces requiring this to be here
compile group: 'com.ibm.etcd', name: 'etcd-java', version: '0.0.13'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
}
}
project(':server') {
apply plugin: 'application'
mainClassName = 'com.linbit.linstor.core.Satellite'
sourceSets {
main {
java {
srcDirs = ["src/main/java", "generated-src"]
}
resources {
srcDirs = ["src/main/resources", "generated-resources"]
}
}
test {
java {
srcDirs = ["src/test/java"]
}
}
}
distributions {
main {
contents {
from(logbackConfig) {
into("lib/conf")
}
}
}
}
/////////////////////////// Version Info ///////////////////////////
task versionInfo() {
String propsFile = "$projectDir/generated-resources/version-info.properties"
outputs.file(propsFile)
if (project.hasProperty('versionOverride')) {
logger.warn("Overriding version with $versionOverride")
version = versionOverride
}
if (!project.hasProperty('versionOverride')) {
File gitFolder = file("$projectDir/../.git")
if (gitFolder.exists())
{
try {
def stdOut = new ByteArrayOutputStream()
def stdErr = new ByteArrayOutputStream()
project.exec {
commandLine 'make', '-C', '..', 'versioninfo'
standardOutput = stdOut
errorOutput = stdErr
}
} catch (ExecException exc) {
throw new RuntimeException("Cannot generate version.", exc)
}
}
Properties props = new Properties()
try {
props.load(new FileInputStream(propsFile))
} catch (Exception exc) {
throw new RuntimeException("Cannot read version.", exc)
}
version = props.get("version")
}
}
/**
* Generates Java sources from common API definitions. This includes the protobuf compilation.
*
* For package builds this task is run in the 'make debrelease' stage, the generated sources are bundled in the package
* tarball, and it is then skipped when the package is finally built.
*/
task generateProto(type:Exec) {
doFirst {
if (!protoc.exists()) {
throw new GradleException("'protoc' binary not found; run the task 'getProtoc' to download the binary")
}
}
commandLine 'make', '-C', "${projectDir}/proto", "PROTOC=" + protoc, 'proto'
inputs.files(fileTree("${projectDir}/proto"))
outputs.dir(file("${projectDir}/generated-src"))
}
task generateJava(type:Exec) {
commandLine 'make', '-C', '../linstor-common', 'java'
inputs.files(fileTree("../linstor-common"))
outputs.files(file("${projectDir}/generated-src/com/linbit/linstor/api/ApiConsts.java"),
"${projectDir}/generated-src/com/linbit/linstor/api/prop/GeneratedPropertyRules.java"
)
dependsOn generateProto
}
task cleanProto(type:Exec) {
commandLine 'make', '-C', "${projectDir}/proto", 'clean-proto'
}
task cleanCommon(type:Exec) {
commandLine 'make', '-C', "../linstor-common", 'cleanjava'
}
processResources.dependsOn versionInfo
compileJava {
dependsOn generateJava
}
clean {
delete "${projectDir}/generated-resources"
dependsOn cleanCommon, cleanProto
}
}
project(':satellite') {
apply plugin: 'application'
dependencies {
compile project(':server')
}
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
resources {
srcDirs = ["src/main/resources"]
}
}
test {
java {
srcDirs = ["src/test/java"]
}
}
}
startScripts.enabled = false
task SatelliteStartup(type: CreateStartScripts) {
mainClassName = 'com.linbit.linstor.core.Satellite'
applicationName = "Satellite"
outputDir = new File(project.buildDir, 'satellite')
classpath = files('conf') + files('*')
defaultJvmOpts = jvmOpts
doLast {
delete windowsScript
}
}
distributions {
main {
contents {
from(SatelliteStartup) {
into("bin")
}
}
}
}
}
version = project(':server').version
project(':controller').version = version
project(':satellite').version = version
project(':controller') {
apply plugin: 'application'
dependencies {
compile project(':server')
testCompile project(':server')
if (gradle.startParameter.isOffline()) {
compile fileTree(dir: "libs/compile")
runtime fileTree(dir: "libs/runtime")
testCompile fileTree(dir: "libs/testCompile")
testRuntime fileTree(dir: "libs/testRuntime")
} else {
// rest libs (grizzly http(s), jersey(rest))
compile 'org.glassfish.grizzly:grizzly-http-server:2.+'
compile 'org.glassfish.jersey.inject:jersey-hk2:2.27'
compile 'org.glassfish.hk2:guice-bridge:2.5.0-b42'
compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.+'
compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-servlet:2.+'
// jdk 11 javax.xml dependency needed by jersey
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.11'
compile group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.2.11'
compile group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.2.11'
compile group: 'javax.activation', name: 'activation', version: '1.1.1'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.6.0'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.6.2'
compile group: 'org.flywaydb', name: 'flyway-core', version: '5.2.4'
runtime group: 'com.h2database', name: 'h2', version: '1.4.197'
// runtime 'org.mariadb.jdbc:mariadb-java-client:2.2.6'
// runtime group: 'org.postgresql', name: 'postgresql', version: '42.2.2'
}
}
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
resources {
srcDirs = ["src/main/resources"]
}
}
test {
java {
srcDirs = ["src/test/java"]
}
}
}
startScripts.enabled = false
task ControllerStartup(type: CreateStartScripts) {
mainClassName = 'com.linbit.linstor.core.Controller'
applicationName = "Controller"
outputDir = new File(project.buildDir, 'controller')
classpath = files('conf') + files('*')
defaultJvmOpts = jvmOpts
doLast {
delete windowsScript
}
}
task LinstorConfigStartup(type: CreateStartScripts) {
mainClassName = 'com.linbit.linstor.core.LinstorConfig'
applicationName = "linstor-config"
outputDir = new File(project.buildDir, 'linstorconfig')
classpath = files('*')
defaultJvmOpts = jvmOpts
doLast {
delete windowsScript
}
}
distributions {
main {
contents {
from(ControllerStartup) {
into("bin")
}
from(LinstorConfigStartup) {
into("bin")
}
}
}
}
}
repositories
{
mavenCentral()
flatDir {
dirs 'libs'
}
}
sourceSets {
test {
java {
srcDirs = ["src/test/java"]
}
}
}
dependencies {
compile project(':controller'), project(':satellite')
testCompile project(':controller'), project(':satellite')
def powerMockVersion = '2.0.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.28.2'
testCompile group: 'org.powermock', name: 'powermock-core', version: powerMockVersion
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: powerMockVersion
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: powerMockVersion
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.9.0'
testCompile group: 'pl.pragmatists', name: 'JUnitParams', version: '1.1.1'
testCompile group: 'com.google.inject.extensions', name: 'guice-testlib', version: '4.2.2'
testCompile group: 'io.projectreactor', name: 'reactor-test', version: '3.2.9.RELEASE'
}
/////////////////////////// Start scripts ///////////////////////////
startScripts.enabled = false
distributions {
main {
contents {
from(project(":controller").ControllerStartup) {
into("bin")
}
from(project(":satellite").SatelliteStartup) {
into("bin")
}
from(project(":controller").LinstorConfigStartup) {
into("bin")
}
from(logbackConfig) {
into("lib/conf")
}
}
}
}
task showMeCache {
doLast {
configurations.compile.each { println it }
configurations.runtime.each { println it }
}
}
task showMeTestCache {
doLast {
configurations.testCompile.each { println it }
}
}
/////////////////////////// Test commands ///////////////////////////
task buildTestCommands(type:Exec) {
workingDir 'test-support'
commandLine 'make'
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
//extension method buildTestCommands.output() can be used to obtain the output:
ext.output = {
return standardOutput.toString()
}
}
task unzip(type: Copy) {
def zipFile = file("tools/protoc-" + protobufVersion + '-linux-x86_64.zip')
def outputDir = file("tools/protoc-" + protobufVersion)
from zipTree(zipFile)
into outputDir
}
task downloadProtoc {
outputs.dir "tools"
def protozip = new File("${projectDir}/tools/protoc-" + protobufVersion + '-linux-x86_64.zip')
outputs.file protozip
doLast {
if (!protozip.exists()) {
mkdir "tools"
println "downloading protoc..."
new URL('https://github.com/google/protobuf/releases/download/v'
+ protobufVersion + '/protoc-' + protobufVersion + '-linux-x86_64.zip')
.withInputStream { i -> protozip.withOutputStream { it << i}}
}
}
}
task getProtoc {
dependsOn downloadProtoc, unzip
}
task cleanTestCommands(type:Exec) {
workingDir 'test-support'
commandLine 'make', 'clean'
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
//extension method buildTestCommands.output() can be used to obtain the output:
ext.output = {
return standardOutput.toString()
}
}
compileTestJava {
dependsOn buildTestCommands
}
clean {
dependsOn cleanTestCommands
}
/////////////////////////// Dependency resolution ///////////////////////////
task resolveDependencies {
doLast {
project.rootProject.allprojects.each { subProject ->
subProject.buildscript.configurations.each { configuration ->
resolveConfiguration(configuration)
}
subProject.configurations.each { configuration ->
resolveConfiguration(configuration)
}
}
}
}
static void resolveConfiguration(configuration) {
def nonResolveableConfigurations =
['apiElements', 'implementation', 'runtimeElements', 'runtimeOnly', 'testImplementation',
'testRuntimeOnly', 'generatedImplementation', 'generatedRuntimeOnly']
if (!nonResolveableConfigurations.contains(configuration.getName())) {
configuration.resolve()
}
}
task deleteLibs(type: Delete) {
doLast {
subprojects.each { prj ->
delete "${prj.name}/libs"
}
delete "${projectDir}/libs"
}
}
task copyToLibs(dependsOn: 'deleteLibs') {
doLast {
['compile', 'runtime'].each { scope ->
copy {
from configurations.getByName(scope).files
into "libs"
}
}
subprojects.each { prj ->
['compile', 'runtime'].each { scope ->
mkdir "${prj.name}/libs/${scope}"
prj.configurations.getByName(scope).files.each { f ->
if (file("libs/" + f.getName()).exists()) {
ant.symlink(resource: "../../../libs/" + f.getName(), link: "${prj.name}/libs/${scope}/${f.getName()}")
}
else {
copy {
from f
into "${prj.name}/libs/${scope}"
}
}
}
}
}
copy {
from buildscript.configurations.classpath
into "${projectDir}/libs/plugins"
}
}
}
// this task is needed for RPM packaging
// it creates a list of dependency jars needed for the server project
task showServerRuntimeLibs() {
doLast {
project(':server').configurations.getByName('runtime').files.each { f ->
print('/usr/share/linstor-server/lib/' + f.getName().toString() + '\n')
}
}
}