forked from Consensys/orion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
544 lines (465 loc) · 15.3 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
538
539
540
541
542
543
544
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed 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 net.ltgt.gradle.errorprone.CheckSeverity
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
buildscript {
repositories { jcenter() }
dependencies {
classpath 'org.apache.openjpa:openjpa:3.1.0'
classpath 'com.radcortez.gradle:openjpa-gradle-plugin:3.0.0'
}
}
plugins {
id "com.diffplug.gradle.spotless" version "3.10.0"
id 'com.github.ben-manes.versions' version '0.20.0'
id "com.github.hierynomus.license" version "0.14.0"
id "com.jfrog.bintray" version "1.8.4"
id 'net.ltgt.errorprone' version '0.8'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
}
apply plugin: 'java-library'
apply plugin: "scala"
apply plugin: "jacoco"
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'application'
apply plugin: 'maven-publish'
apply plugin: 'io.spring.dependency-management'
apply from: "gradle/check-licenses.gradle"
apply from: "gradle/versions.gradle"
apply plugin: 'com.jfrog.bintray'
apply plugin: 'openjpa'
version = '1.5.0-SNAPSHOT'
//////
// Default tasks and build aliases
defaultTasks 'checkLicenses', 'assemble', 'javadoc', 'test', 'acceptanceTest'
def buildAliases = ['dev': [
'spotlessApply',
'checkLicenses',
'assemble',
'javadoc',
'test',
'acceptanceTest'
]]
def expandedTaskList = []
gradle.startParameter.taskNames.each {
expandedTaskList << (buildAliases[it] ? buildAliases[it] : it)
}
gradle.startParameter.taskNames = expandedTaskList.flatten()
/////
// Source formatting
spotless {
java {
licenseHeaderFile 'gradle/spotless.license.java'
removeUnusedImports()
eclipse().configFile(rootProject.file('gradle/eclipse-java-consensys-style.xml'))
importOrder 'net.consensys', 'java', ''
endWithNewline()
}
groovyGradle {
target '**/*.gradle'
greclipse().configFile(rootProject.file('gradle/greclipse-gradle-consensys-style.properties'))
endWithNewline()
}
format 'scala', {
target '**/*.scala'
licenseHeaderFile 'gradle/spotless.license.java', 'package'
paddedCell()
}
format 'build-gradle', {
target '/build.gradle'
licenseHeaderFile 'gradle/spotless.license.java', 'import'
paddedCell()
}
}
license { exclude "**/*" }
//////
// Compiler arguments
tasks.withType(JavaCompile) {
options.compilerArgs += [
'-proc:none',
'-Xlint:unchecked',
'-Xlint:cast',
'-Xlint:rawtypes',
'-Xlint:overloads',
'-Xlint:divzero',
'-Xlint:finally',
'-Xlint:static',
'-Werror',
]
options.errorprone {
check('FutureReturnValueIgnored', CheckSeverity.OFF)
check('FutureReturnValueIgnored', CheckSeverity.OFF)
check('EqualsGetClass', CheckSeverity.OFF)
check('InsecureCryptoUsage', CheckSeverity.WARN)
check('FieldCanBeFinal', CheckSeverity.WARN)
check('WildcardImport', CheckSeverity.WARN)
check('TestExceptionChecker', CheckSeverity.WARN)
// This check is broken in Java 12. See https://github.com/google/error-prone/issues/1257
if ((JavaVersion.current().majorVersion as Integer) > 11) {
check('Finally', CheckSeverity.OFF)
}
}
}
//////
// Additional source sets (acceptance and performance tests)
test { useJUnitPlatform() }
sourceSets {
acceptance {
java.srcDir file('src/acceptance-test/java')
resources.srcDir file('src/acceptance-test/resources')
compileClasspath += main.runtimeClasspath + test.runtimeClasspath
runtimeClasspath += main.runtimeClasspath + test.runtimeClasspath
}
performance {
scala.srcDir file('src/performance-test/scala')
resources.srcDir file('src/performance-test/resources')
compileClasspath += main.runtimeClasspath
runtimeClasspath += main.runtimeClasspath
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
task acceptanceTest(type: Test) {
description = 'Runs the acceptance tests'
group = 'verification'
useJUnitPlatform()
setTestClassesDirs(sourceSets.acceptance.output.getClassesDirs())
classpath = sourceSets.acceptance.runtimeClasspath
}
static def gatlingURL() {
def appUrl = System.getProperty('gatlingURL')
appUrl ?: 'http://localhost:8295'
}
task startOrion {
dependsOn installDist
doLast {
copy {
from "$projectDir/src/performance-test/resources"
into "$buildDir/install/orion"
include '*'
}
ext.process1 = new ProcessBuilder()
.directory(new File("$buildDir/install/orion"))
.command('bin/orion', 'config-8081.txt')
.start()
ext.process2 = new ProcessBuilder()
.directory(new File("$buildDir/install/orion"))
.command('bin/orion', 'config-8083.txt')
.start()
ext.process3 = new ProcessBuilder()
.directory(new File("$buildDir/install/orion"))
.command('bin/orion', 'config-8085.txt')
.start()
}
}
task stopOrion {
doLast {
if (tasks.startOrion.process1 != null) {
tasks.startOrion.process1.destroy()
}
if (tasks.startOrion.process2 != null) {
tasks.startOrion.process2.destroy()
}
if (tasks.startOrion.process3 != null) {
tasks.startOrion.process3.destroy()
}
}
}
task performanceTest(type: JavaExec) {
description = 'Runs the performance tests'
group = 'verification'
dependsOn startOrion
finalizedBy stopOrion
main = 'io.gatling.app.Gatling'
classpath = sourceSets.performance.runtimeClasspath
args = [
'--simulation',
'net.consensys.orion.load.LoadSimulation',
'--results-folder',
file('build/reports/performance').absolutePath,
'--mute'
]
environment = ['appUrl': gatlingURL()]
systemProperties = ['gatling.core.directory.binaries': sourceSets.test.output.classesDirs]
}
openjpa {
// only use the jpa entity classes defined the in the persistence.xml
excludes = ['**/*.class']
}
//////
// Dependencies
repositories {
jcenter()
maven { url "https://repo1.maven.org/maven2/" }
maven { url "https://consensys.bintray.com/consensys" }
}
dependencies {
compile 'org.apache.tuweni:tuweni-bytes'
compile 'org.apache.tuweni:tuweni-config'
compile 'org.apache.tuweni:tuweni-crypto'
compile 'org.apache.tuweni:tuweni-io'
compile 'org.apache.tuweni:tuweni-kv'
compile 'org.apache.tuweni:tuweni-net'
compile 'org.apache.tuweni:tuweni-rlp'
// vertx
compile 'io.vertx:vertx-core'
compile 'io.vertx:vertx-web'
// crypto
compile 'org.bouncycastle:bcprov-jdk15on'
compile 'org.bouncycastle:bcpkix-jdk15on'
compile 'com.github.jnr:jnr-ffi'
// http client
testCompile 'com.squareup.okhttp3:okhttp'
// storage
compile 'org.fusesource.leveldbjni:leveldbjni-all'
compile('org.mapdb:mapdb') {
exclude group: 'net.jpountz.lz4', module: 'lz4'
}
compile 'org.lz4:lz4-java'
compile 'com.jolbox:bonecp'
compile 'org.apache.openjpa:openjpa'
compile 'org.postgresql:postgresql'
// serialization
compile 'com.moandjiezana.toml:toml4j'
compile 'com.fasterxml.jackson.core:jackson-databind'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
// logging
compile 'org.apache.logging.log4j:log4j-api'
compile 'org.apache.logging.log4j:log4j-core'
compile 'org.apache.logging.log4j:log4j-slf4j-impl'
// XML
compile 'javax.xml.bind:jaxb-api'
//Oracle JDBC
compile('com.oracle.ojdbc:ojdbc10')
// testing
testCompile 'org.apache.tuweni:tuweni-junit'
testCompile 'com.h2database:h2'
testCompile 'org.junit.jupiter:junit-jupiter-api'
testCompile 'org.junit.jupiter:junit-jupiter-params'
testRuntime 'org.junit.jupiter:junit-jupiter-engine'
testCompile 'org.mockito:mockito-all'
testCompile 'org.awaitility:awaitility'
// mock http server (unit test purposes)
testCompile 'com.squareup.okhttp3:mockwebserver'
testCompile 'org.assertj:assertj-core'
testCompile 'io.vertx:vertx-unit'
testCompile 'io.vertx:vertx-junit5'
// performance testing
performanceCompile 'org.scala-lang:scala-library'
performanceCompile 'org.scalatest:scalatest_2.12'
performanceCompile 'io.gatling:gatling-core'
performanceCompile 'io.gatling:gatling-http'
performanceCompile 'io.gatling:gatling-app'
performanceCompile 'io.gatling.highcharts:gatling-charts-highcharts'
errorprone 'com.google.errorprone:error_prone_core'
if (JavaVersion.current().isJava8()) {
errorproneJavac("com.google.errorprone:javac")
}
}
//////
// Packaging
mainClassName = 'net.consensys.orion.cmd.Orion'
group = 'net.consensys'
jar {
doFirst {
delete fileTree(dir:'build/libs', include: '*.jar')
delete "$projectDir/src/main/resources/version.txt"
delete "$buildDir/resources/main/version.txt"
new File("$buildDir/resources/main/version.txt").text = """Application-name: $project.name
Version: $version
"""
new File("$buildDir/version").text = """$version"""
}
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': version,
'Main-Class': mainClassName
)
}
}
distributions {
main {
contents {
from("./LICENSE") { into "." }
from("build/reports/license/license-dependency.html") { into "." }
from("./database") { into "database" }
}
}
}
installDist { dependsOn checkLicenses }
distTar {
dependsOn checkLicenses
doFirst {
delete fileTree(dir:'build/distributions', include: '*.tar.gz')
}
compression = Compression.GZIP
archiveExtension = 'tar.gz'
}
distZip {
dependsOn checkLicenses
doFirst {
delete fileTree(dir:'build/distributions', include: '*.zip')
}
}
// rename the top level dir from orion-<version> to orion and this makes it really
// simple for use in docker
tasks.register("dockerDistUntar") {
dependsOn distTar
dependsOn distZip
def dockerBuildDir = "build/docker-orion/"
def distTarFile = distTar.outputs.files.singleFile
def distTarFileName = distTar.outputs.files.singleFile.name.replace(".tar.gz", "")
doFirst {
new File(dockerBuildDir).mkdir()
copy {
from tarTree(distTarFile)
into(dockerBuildDir)
}
file("${dockerBuildDir}/${distTarFileName}").renameTo("${dockerBuildDir}/orion")
}
}
task distDocker(type: Exec) {
dependsOn dockerDistUntar
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def imageName = "pegasyseng/orion"
def image = project.hasProperty('release.releaseVersion') ? "${imageName}:" + project.property('release.releaseVersion') : "${imageName}:${project.version}"
def dockerBuildDir = "build/docker-orion/"
workingDir "${dockerBuildDir}"
doFirst {
copy {
from file("${projectDir}/docker/Dockerfile")
into(workingDir)
}
}
executable "sh"
args "-c", "docker build --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${getCheckedOutGitCommitHash()} -t ${image} ."
}
task testDocker(type: Exec) {
dependsOn distDocker
def dockerReportsDir = "docker/reports/"
def imageName = "pegasyseng/orion"
def image = project.hasProperty('release.releaseVersion') ? "${imageName}:" + project.property('release.releaseVersion') : "${imageName}:${project.version}"
workingDir "docker"
doFirst {
new File(dockerReportsDir).mkdir()
}
executable "sh"
args "-c", "bash test.sh ${image}"
}
task dockerUpload(type: Exec) {
dependsOn distDocker
def imageName = "pegasyseng/orion"
def image = project.hasProperty('release.releaseVersion') ? "${imageName}:" + project.property('release.releaseVersion') : "${imageName}:${project.version}"
def cmd = "docker push '${image}'"
def additionalTags = []
if (project.hasProperty('branch') && project.property('branch') == 'master') {
additionalTags.add('develop')
}
if (!(version ==~ /.*-SNAPSHOT/)) {
additionalTags.add('latest')
additionalTags.add(version.split(/\./)[0..1].join('.'))
}
additionalTags.each { tag -> cmd += " && docker tag '${image}' '${imageName}:${tag.trim()}' && docker push '${imageName}:${tag.trim()}'" }
executable "sh"
args "-c", cmd
}
// http://label-schema.org/rc1/
// using the RFC3339 format "2016-04-12T23:20:50.52Z"
def buildTime() {
return OffsetDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"))
}
def getCheckedOutGitCommitHash() {
def gitFolder = "$projectDir/.git/"
if (!file(gitFolder).isDirectory()) {
// We are in a submodule. The file's contents are `gitdir: <gitFolder>\n`.
// Read the file, cut off the front, and trim the whitespace.
gitFolder = file(gitFolder).text.substring(8).trim() + "/"
}
def takeFromHash = 8
/*
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
*/
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
if(isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb
def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master
refHead.text.trim().take takeFromHash
}
//////
// Runtime
applicationDefaultJvmArgs = [
"-Dvertx.disableFileCPResolving=true",
"-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4j2LogDelegateFactory"
]
run {
description = 'Run Orion. Use -Pargs="" to pass arguments'
standardInput = System.in
if (project.hasProperty("args")) {
args project.getProperty('args').split()
}
}
//////
// Publishing & release
publishing {
publications {
mavenArtifact(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name 'Orion'
description 'A java implementation of a Enterprise Ethereum Private Transaction Manager.'
url 'https://github.com/pegasyseng/orion'
scm { url 'https://github.com/pegasyseng/orion' }
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/license/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}
}
}
}
task deploy() {}
deploy.dependsOn bintrayUpload
bintray {
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_KEY')
publications = ['mavenArtifact']
override = true
publish = true
pkg {
repo = "pegasys-repo"
name = "orion"
userOrg = "consensys"
licenses = ["Apache-2.0"]
vcsUrl = "https://github.com/pegasyseng/orion"
version { name = project.version }
}
}