forked from apache/aurora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
524 lines (469 loc) · 16.5 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
/*
* 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.
*/
plugins {
id 'com.eriwen.gradle.js' version '1.12.1'
id 'com.github.ben-manes.versions' version '0.5'
id 'com.github.hierynomus.license' version '0.11.0'
}
apply plugin: 'application'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'pmd'
apply plugin: 'project-report'
buildDir = 'dist'
def generatedDir = "$buildDir/generated-src"
def generatedJavaDir = "$generatedDir/gen-java"
def generatedJSDir = "$generatedDir/gen-js"
def generatedResourceDir = "$generatedDir/resources"
def httpAssetsPath = 'scheduler/assets'
def thriftVersion = '0.9.1'
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
tasks.withType(JavaCompile).matching { it.name != 'compileGeneratedJava' }.all {
options.compilerArgs << '-Werror'
options.compilerArgs << '-Xlint:all'
// Don't fail for annotations not claimed by annotation processors.
options.compilerArgs << '-Xlint:-processing'
// Don't fail for serialVersionUID warnings.
options.compilerArgs << '-Xlint:-serial'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
group 'org.apache.aurora'
version = file('.auroraversion').text.trim().toUpperCase()
publishing {
publications {
maven(MavenPublication) {
artifactId 'aurora-scheduler'
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
if (project.hasProperty('internalMavenUrl')) {
repositories {
maven {
credentials {
username = internalMavenUser
password = internalMavenPass
}
url internalMavenUrl
}
}
}
}
repositories {
mavenCentral()
maven {
url 'http://maven.twttr.com/'
}
}
sourceSets {
test {
resources {
srcDir 'src/main/resources'
srcDir 'src/test/resources'
srcDir '3rdparty/javascript'
srcDir generatedJSDir
srcDir generatedResourceDir
}
}
generated {
java.srcDirs = [generatedDir]
}
main {
compileClasspath += sourceSets.generated.output
resources {
srcDir '3rdparty/javascript'
srcDir generatedJSDir
srcDir generatedResourceDir
}
}
test {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
}
/* A note on libthrift: All of com.twitter.common depends on libthrift 0.5.x. We depend on
libthrift 0.9.x. There are binary incompatibilities between the two versions and resolving
them involved forking com.twitter.common classes into Aurora to use the new libthrift API. Be
very cautious when either upgrading libthrift or com.twitter.common dependencies!!!
*/
jar {
from sourceSets.generated.output
manifest {
attributes('Created-By': 'Gradle')
attributes('Main-Class': 'org.apache.aurora.scheduler.app.SchedulerMain')
}
}
dependencies {
def guiceRev = '3.0'
def jerseyRev = '1.18.1'
def log4jRev = '1.2.17'
def slf4jRev = '1.6.1'
def junitRev = '4.11'
def gsonDep = 'com.google.code.gson:gson:2.2.4'
def guavaDep = 'com.google.guava:guava:16.0'
// NOTE: We are using the jetty 7.x series due to a large number of dependencies impacted
// by 8.x and later resulting from using newer javax.servlet servlet-api.
def jettyDep = '7.6.15.v20140411'
def thriftLib = "org.apache.thrift:libthrift:${thriftVersion}"
compile 'aopalliance:aopalliance:1.0'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile gsonDep
compile guavaDep
compile "com.google.inject:guice:${guiceRev}"
compile "com.google.inject.extensions:guice-assistedinject:${guiceRev}"
compile 'com.google.protobuf:protobuf-java:2.5.0'
compile 'com.h2database:h2:1.4.177'
compile "com.sun.jersey:jersey-core:${jerseyRev}"
compile "com.sun.jersey:jersey-json:${jerseyRev}"
compile "com.sun.jersey:jersey-server:${jerseyRev}"
compile "com.sun.jersey:jersey-servlet:${jerseyRev}"
compile "com.sun.jersey.contribs:jersey-guice:${jerseyRev}"
compile 'commons-lang:commons-lang:2.6'
compile 'javax.inject:javax.inject:1'
compile 'javax.servlet:servlet-api:2.5'
compile "log4j:log4j:${log4jRev}"
compile 'org.antlr:stringtemplate:3.2.1'
compile 'org.apache.mesos:mesos:0.20.1'
compile thriftLib
compile 'org.apache.zookeeper:zookeeper:3.3.4'
compile "org.eclipse.jetty:jetty-rewrite:${jettyDep}"
compile "org.eclipse.jetty:jetty-server:${jettyDep}"
compile "org.eclipse.jetty:jetty-servlet:${jettyDep}"
compile "org.eclipse.jetty:jetty-servlets:${jettyDep}"
compile 'org.mybatis:mybatis:3.2.7'
compile 'org.mybatis:mybatis-guice:3.6'
compile 'org.quartz-scheduler:quartz:2.2.1'
compile "org.slf4j:slf4j-api:${slf4jRev}"
compile "org.slf4j:slf4j-jdk14:${slf4jRev}"
compile 'com.twitter.common.logging:log4j:0.0.7'
compile 'com.twitter.common.zookeeper.guice:client-flagged:0.0.5'
compile 'com.twitter.common.zookeeper.guice:client:0.0.5'
compile 'com.twitter.common.zookeeper:candidate:0.0.64'
compile 'com.twitter.common.zookeeper:client:0.0.56'
compile 'com.twitter.common.zookeeper:group:0.0.69'
compile 'com.twitter.common.zookeeper:server-set:1.0.74'
compile 'com.twitter.common.zookeeper:singleton-service:0.0.85'
compile 'com.twitter.common:application-module-applauncher:0.0.51'
compile 'com.twitter.common:application-module-lifecycle:0.0.48'
compile 'com.twitter.common:application-module-stats:0.0.44'
compile 'com.twitter.common:application:0.0.73'
compile 'com.twitter.common:args:0.2.9'
compile 'com.twitter.common:base:0.0.87'
compile 'com.twitter.common:collections:0.0.74'
compile 'com.twitter.common:dynamic-host-set:0.0.44'
compile 'com.twitter.common:inject-timed:0.0.11'
compile 'com.twitter.common:inject:0.0.35'
compile 'com.twitter.common:jdk-logging:0.0.44'
compile 'com.twitter.common:logging:0.0.61'
compile 'com.twitter.common:net-http-handlers-time-series:0.0.51'
compile 'com.twitter.common:net-util:0.0.80'
compile 'com.twitter.common:quantity:0.0.71'
compile 'com.twitter.common:stats:0.0.91'
compile 'com.twitter.common:thrift:0.0.68'
compile 'com.twitter.common:util-executor-service-shutdown:0.0.49'
compile 'com.twitter.common:util-templating:0.0.25'
compile 'com.twitter.common:util-testing:0.0.10'
compile 'com.twitter.common:util:0.0.94'
testCompile "com.sun.jersey:jersey-client:${jerseyRev}"
testCompile 'com.twitter.common:testing-easymock:0.0.4'
testCompile 'com.twitter.common:util-system-mocks:0.0.72'
testCompile 'com.twitter.common:zookeeper-testing:0.0.45'
testCompile "junit:junit:${junitRev}"
generatedCompile gsonDep
generatedCompile guavaDep
generatedCompile thriftLib
configurations.compile {
exclude module: 'junit-dep'
resolutionStrategy {
failOnVersionConflict()
def forceDepVersions = [
// Force versions based on the dependencies we use from above
'com.google.code.gson:gson': '2.2.4',
'org.slf4j:slf4j-api' : slf4jRev,
'log4j:log4j' : log4jRev,
'org.apache.thrift:libthrift' : thriftVersion,
'junit:junit' : junitRev,
// Force versions based on inter-dependency collisions
'org.hamcrest:hamcrest-core' : '1.3',
]
force forceDepVersions.collect { dep, ver -> "$dep:$ver" }
}
}
}
// For normal developer builds, avoid running the often-time-consuming code quality checks.
// Jenkins will always run these, and developers are encouraged to run these before posting diffs
// and pushing to master.
def runCodeQuality = project.hasProperty('q')
def codeQualityTasks = [
Checkstyle,
FindBugs,
nl.javadude.gradle.plugins.license.License,
Pmd
]
codeQualityTasks.each {
tasks.withType(it) {
enabled = runCodeQuality
}
}
checkstyle {
sourceSets = [ sourceSets.main , sourceSets.test]
}
tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
excludeFilter = rootProject.file('config/findbugs/excludeFilter.xml')
}
pmd {
sourceSets = [sourceSets.main]
// PMD rule set names match XML files stored in the PMD jar. For example, with 5.11 you can
// see all the rules included with:
// $ find ~/.gradle -name pmd-5.1.1.jar | xargs zipinfo -1 | egrep java/.*.xml | head -n 5
// rulesets/java/clone.xml
// rulesets/java/basic.xml
// rulesets/java/strings.xml
// rulesets/java/sunsecure.xml
// rulesets/java/codesize.xml
// The format is straightforward: 'java-basic' refers to rulesets/java/basic.xml.
ruleSets = [
'java-basic',
'java-braces',
'java-empty',
'java-junit',
'java-typeresolution',
'java-unnecessary',
'java-unusedcode']
ruleSetFiles = fileTree('config/pmd/')
consoleOutput = true
}
task checkPython() {
def py_versions = ['python2.7', 'python2.6', 'python']
project.ext.set('py', '')
py_versions.each { python_exe ->
if (project.py.isEmpty()) {
// Look for the first version of python listed in py_versions greater than 2.6.
// Execute will throw an exception if that python command does not exist,
// and set project.py to be empty
try {
def check = "import sys; sys.stdout.write(str(sys.version_info > (2,6) and sys.version_info < (3,)))"
def cmd = [python_exe, "-c", check].execute()
def output = cmd.in.text.trim()
if(output.toLowerCase() == 'true') {
project.py = python_exe
}
} catch (Exception e) {
project.py = ''
}
}
}
doLast {
if (project.py.isEmpty()) {
throw new GradleException('Build requires Python 2.6 or Python 2.7')
}
}
}
/**
* There is a jshint target recommended in the README for gradle-js-plugin
* but it does not work. This workaround from here:
* https://github.com/eriwen/gradle-js-plugin/issues/73
*/
task jsHint(type:com.eriwen.gradle.js.tasks.JsHintTask) {
source = fileTree("src/main/resources/$httpAssetsPath/js/")
dest file("${buildDir}/jshint.out")
// Set this to false once JS code complies with JSHint.
ignoreExitCode false
outputToStdOut true
jshint.options = [
// See: http://www.jshint.com/docs/options/ for explanation.
browser: true,
camelcase: true,
curly: true,
eqeqeq: true,
indent: 2,
maxlen: 100,
quotmark: true,
trailing: true,
undef: true,
unused: 'vars',
white: true
]
jshint.predef = [
'_': true,
'angular': true,
'moment': true,
'Thrift': true
]
}
tasks.checkstyleMain.dependsOn(jsHint)
/**
* Check if Apache Thrift is all ready installed and is the same version as we
* depend on, otherwise compile the version in build-support. project.thrift will
* contain the path to the thrift executable when finished
*/
task bootstrapThrift {
logging.captureStandardOutput LogLevel.INFO
project.ext.set('thrift', '')
try {
// Attempt to run thrift and get the version string back. if no version of thrift is available
// execute will throw an exception, catch and set project.thrift as empty to build the local version
def output = "thrift --version".execute().text.trim()
if(output == "Thrift version ${thriftVersion}") {
project.thrift = 'thrift'
}
} catch (IOException e) {
project.thrift = ''
}
// If thrift was not found or was the wrong version build our local copy
if (project.thrift.isEmpty()) {
project.thrift = "build-support/thrift/thrift-${thriftVersion}/compiler/cpp/thrift"
inputs.file file(project.thrift)
outputs.dir file(project.thrift)
doLast {
exec {
executable = 'make'
args = ['-C', 'build-support/thrift']
}
}
}
}
// TODO(wfarner): Extract this into a task under buildSrc/
task generateSources(dependsOn: ['bootstrapThrift', 'checkPython']) {
ext.thriftDir = 'src/main/thrift/org/apache/aurora/gen'
def thriftFiles = fileTree(dir: thriftDir).matching { include '**/*.thrift' }
def codeGenerator = 'src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py';
ext.inputFiles = thriftFiles + files(codeGenerator)
ext.outputDir = file(generatedDir)
ext.jsOutputDir = file("$generatedJSDir/$httpAssetsPath/js")
inputs.file inputFiles
outputs.dir outputDir
doLast {
outputDir.exists() || outputDir.mkdirs()
thriftFiles.each { File file ->
exec {
executable = project.thrift
args = ['--gen', 'java:hashcode,private-members', '-o', outputDir, file]
}
}
exec {
executable = project.py
args = [codeGenerator,
'src/main/thrift/org/apache/aurora/gen/api.thrift',
generatedJavaDir,
"$generatedResourceDir/$httpAssetsPath"]
}
// Generate thrift javascript separately since we don't need all IDLs, and we want to place
// sources in the layout for assets served by the scheduler.
jsOutputDir.exists() || jsOutputDir.mkdirs()
exec {
executable = project.thrift
args = ['--gen', 'js:jquery', '-out', jsOutputDir, "$thriftDir/api.thrift"]
}
}
}
compileGeneratedJava {
dependsOn generateSources
}
compileJava.source sourceSets.main.java
tasks.withType(Test) {
maxParallelForks = Runtime.runtime.availableProcessors()
}
ideaProject.dependsOn generateSources
idea {
module {
def codegenDirs = [file(generatedJavaDir)]
// These directories must exist, else the plugin omits them from the
// generated project. Since this is executed during the configuration
// lifecycle phase, dependency tasks have not yet run and created
// the directories themselves.
codegenDirs.each { File codegenDir ->
codegenDir.mkdirs()
}
// By default, the idea module [1] excludes are set to
// [project.buildDir, project.file('.gradle')]
// This has the side-effect of also excluding our generated sources [2]. Due to the way
// directory exclusion works in idea, you can't exclude a directory and include a child of that
// directory. Clearing the excludes seems to have no ill side-effects, making it preferable to
// other possible approaches.
//
// [1] http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
// [2] http://issues.gradle.org/browse/GRADLE-1174
excludeDirs = [file("$buildDir/reports"), file("$buildDir/test-results")]
sourceDirs += codegenDirs
// For some reason src/main/resources is marked as both a production source and a test source
// directory. In order to run the local scheduler from IntelliJ the resources directory must not
// be marked as test sources, so we make it explicit that it's only a production source.
testSourceDirs -= file("src/main/resources")
}
}
// Configuration parameters for the application plugin.
applicationName = 'aurora-scheduler'
mainClassName = 'org.apache.aurora.scheduler.app.SchedulerMain'
tasks.withType(nl.javadude.gradle.plugins.license.License).each { licenseTask ->
licenseTask.setSource files("$projectDir/src/main/java", "$projectDir/src/test/java")
}
license {
header rootProject.file('config/checkstyle/apache.header')
strictCheck true
skipExistingHeaders true
ext.year = Calendar.getInstance().get(Calendar.YEAR)
}
def reportPath = "$buildDir/reports/jacoco/test"
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
reports {
xml.enabled true
}
doLast {
println "Coverage report generated: file://$reportPath/html/index.html"
}
}
test.finalizedBy jacocoTestReport
task analyzeReport(type: CoverageReportCheck) {
coverageReportFile = "$reportPath/jacocoTestReport.xml"
minInstructionCoverage = 0.87
minBranchCoverage = 0.82
legacyClassesWithoutCoverage = file('config/legacy_untested_classes.txt').readLines()
}
jacocoTestReport.finalizedBy analyzeReport
task FlagSchemaChanges(type: Test) << {
exec {
executable = 'bash'
args = ['src/test/sh/org/apache/aurora/verify_thrift_checksum.sh']
}
}
javadoc {
classpath += sourceSets.generated.output
}
run {
classpath += sourceSets.generated.output
classpath += sourceSets.test.output
main = 'org.apache.aurora.scheduler.app.local.LocalSchedulerMain'
}