-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
570 lines (467 loc) · 20.8 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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'checkstyle'
apply plugin: 'project-report'
apply plugin: 'jacoco'
apply plugin: 'org.asciidoctor.gradle.asciidoctor'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'artifactory'
apply plugin: 'org.flywaydb.flyway'
apply plugin: 'info-broker'
apply plugin: 'info-jar'
apply plugin: 'info-basic'
apply plugin: 'info-java'
/********************************/
/**** Profile configuration ****/
/** Profile scopes/dependencies configuration boilerplate */
configurations {
// additional profile-specific scopes
profileCompile
profileRuntime
// append profile dependencies to the base classpath
compile.extendsFrom profileCompile
runtime.extendsFrom profileRuntime
}
/** Profile loading boilerplate */
def applyProfile(aProfile) {
def profilesDir = relativePath('build-profiles')
println 'Loading profile: ' + aProfile + '.gradle'
apply from: profilesDir + '/' + aProfile + '.gradle'
}
/** usage: gradle build -Pprofile=omero500-ice34 */
ext.profile = hasProperty("profile") ? profile : 'omero520-ice35' // default profile: omero-5.2.0 + ice-3.5.1
applyProfile(profile)
/********************************/
/**** Project configuration ****/
group = 'org.imagopole.omero'
version = '0.6'
description = """OMERO CSV Annotation Tool"""
/********************************/
/**** Custom properties ****/
ext.buildConfig = [
generatedTestResourcesDir : "$buildDir/generated-resources/test"
]
ext.sharedManifest = manifest {
attributes 'Main-Class' : 'org.imagopole.omero.tools.CsvAnnotatorCliMain',
'X-Build-Profile' : profile,
'X-Omero-Version' : omeVersions.omeroRelease,
'X-Omero-Ice-Version' : iceVersions.main
}
/** Full omero server + ice flavor classifier for distribution packages */
ext.omeClassifier = omeVersions.qualifier + '-' + iceVersions.qualifier
ext.versions = [
omero : omeVersions.omeroRelease, //--OMERO: cf. profile
ice : iceVersions.main, //--OMERO: cf. profile
slf4j : '1.7.6', //--OMERO: 1.7.6
logback : '1.1.1', //--OMERO: 1.1.1
testng : '6.8', //--OMERO: n/p (6.8)
unitils : '3.3', //--OMERO: n/a
postgresJdbc : '9.4-1200-jdbc4', //--OMERO: 9.4-1200.jdbc4
guava : '17.0', //--OMERO: 17.0
jsr305 : '1.3.9', //--OMERO: n/a
getopt : '1.0.13', //--OMERO: 1.0.13
commonsCsv : '1.2', //--OMERO: n/a
hibernate : [
core : '3.5.6-Final', //--OMERO: "n/a" (hibernate-3.5.6-4510)
jpa : '1.0.0.Final', //--OMERO: 1.0.0.Final
search : '3.1.1.GA' //--OMERO: 3.1.1.GA
]
]
ext.resourcesFilterTokens = [
'project_version_token' : project.version,
'omero_version_token' : versions.omero,
'ice_version_token' : versions.ice,
'script_version_token' : sprintf("%s [%s-%s]", //eg. 0.3.1-SNAPSHOT [ome508-ice34]
project.version, omeVersions.qualifier, iceVersions.qualifier)
]
ext.integrationTests = [
db : [
schemaLocation : sprintf("classpath:db/schemas/ome%s", omeVersions.baseline), //eg. db/schemas/ome50x
name : omeVersions.qualifier, //eg. ome508
owner : omeVersions.qualifier,
pwd : omeVersions.qualifier,
jdbcUrl : sprintf("jdbc:postgresql://%s:%s/%s", "localhost", "5432", omeVersions.qualifier)
],
resources : [
omeroServerDataDir : sprintf("$buildDir/tmp/%s.data", profile),
omeroServerConfigFileName : sprintf("omero-config.%s.properties", project.name),
unitilsLocalFileName : sprintf("unitils-local.%s.properties", project.name)
]
]
/*********************************/
/**** Builfile configuration ****/
sourceCompatibility = 1.6
targetCompatibility = 1.6
jar {
manifest = sharedManifest
}
repositories {
mavenLocal()
mavenCentral()
maven {
name 'Artifactory OME repo'
url 'http://artifacts.openmicroscopy.org/artifactory/repo'
}
// mirror for artifacts not published in a central repo (eg. OMERO language bindings
// and other dependencies not published in a central repo like Apache Commons CSV)
maven {
name 'Bintray Imagopole repo'
url 'http://dl.bintray.com/imagopole/maven'
}
}
/**
* Reminder: all dependencies should remain in line with OMERO's runtime classpath
**/
dependencies {
compile 'org.slf4j:slf4j-api:' + versions.slf4j
// OMERO 5 Java bindings
// see http://www.openmicroscopy.org/site/support/omero5/developers/Java.html
// http://www.openmicroscopy.org/community/viewtopic.php?f=6&t=7573
compile group: 'omero', name: 'blitz', version: versions.omero, transitive: false
compile 'zeroc:ice:' + versions.ice
compile 'zeroc:ice-glacier2:' + versions.ice
compile 'org.apache.commons:commons-csv:' + versions.commonsCsv
compile 'gnu.getopt:java-getopt:' + versions.getopt
compile 'com.google.guava:guava:' + versions.guava
compile 'com.google.code.findbugs:jsr305:' + versions.jsr305
// required OMERO transitive dependencies
// note: the 'model-psql' jar is actually only required for 'testCompile' and 'runtime' scopes
compile group: 'omero', name: 'model-psql', version: versions.omero, transitive: false
// note: the 'common' jar is actually only required for 'testRuntime' and 'runtime' scopes
compile group: 'omero', name: 'common', version: versions.omero, transitive: false
// logback slf4j binding
runtime 'ch.qos.logback:logback-classic:' + versions.logback
// slf4j bound to logback-classic + redirection of ACL to slf4j
// (ie. slf4j replaces commons-logging - see http://www.slf4j.org/legacy.html)
runtime 'org.slf4j:jcl-over-slf4j:' + versions.slf4j
testCompile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:' + versions.hibernate.jpa
testCompile group: 'org.hibernate', name: 'hibernate-core', version: versions.hibernate.core, transitive: false
testCompile group: 'org.hibernate', name: 'hibernate-annotations', version: versions.hibernate.core, transitive: false
testCompile group: 'org.hibernate', name: 'hibernate-search', version: versions.hibernate.search, transitive: false
testCompile 'org.testng:testng:' + versions.testng
testCompile 'org.unitils:unitils-core:' + versions.unitils
testCompile(group: 'org.unitils', name: 'unitils-testng', version: versions.unitils) {
transitive = false
}
testCompile 'org.unitils:unitils-inject:' + versions.unitils
testCompile 'org.unitils:unitils-mock:' + versions.unitils
testCompile 'org.unitils:unitils-io:' + versions.unitils
testCompile(group: 'org.unitils', name: 'unitils-database', version: versions.unitils) {
exclude group: 'org.slf4j'
exclude group: 'ch.qos.logback'
}
testCompile(group: 'org.unitils', name: 'unitils-dbunit', version: versions.unitils) {
exclude group: 'org.slf4j'
exclude group: 'ch.qos.logback'
}
testRuntime 'org.postgresql:postgresql:' + versions.postgresJdbc
//scriptsRuntime 'org.python:jython-standalone:2.5.3'
}
/** Note: integration tests can be run only after database has been populated with the right
* users/credentials by task "integrationTestDbSetup" */
test {
useTestNG()
//testLogging.showStandardStreams = true
// for integration tests only
// either one or the other:
// - ICE_CONFIG has priority eg. ICE_CONFIG=~/ice-local.config ./gradlew test
// - if not set, then fallback on a default 'ice.config.location' in $buildDir
systemProperty 'ice.config.location', "$sourceSets.test.output.resourcesDir/ice-local.config"
}
sourceSets {
main {
resources {
// include scripts as resources for easier processing/filtering w/o project layout changes
srcDirs += "$projectDir/src/main/scripts"
}
}
test {
// register an output folder on the test SourceSet for inclusion on the classpath
output.dir(buildConfig.generatedTestResourcesDir, builtBy: 'generateTestResources')
}
}
processResources {
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens : resourcesFilterTokens)
}
/********************************/
/**** Plugins configuration ****/
findbugs {
sourceSets = [sourceSets.main]
effort = 'max'
reportLevel = 'high'
ignoreFailures = true
}
findbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
pmd {
sourceSets = [sourceSets.main]
ignoreFailures = true
ruleSetFiles = files("config/pmd/pmd.xml")
}
checkstyle {
sourceSets = [sourceSets.main]
ignoreFailures = true
showViolations = false
}
/** Generate the checkstyle html report */
task checkstyleHtmlReport(dependsOn: checkstyleMain) {
if (file("$reporting.baseDir/checkstyle/main.xml").exists()) {
ant.xslt(
in: "$reporting.baseDir/checkstyle/main.xml",
style: "$projectDir/config/checkstyle/checkstyle-noframes-severity-sorted.xsl",
out: "$reporting.baseDir/checkstyle/main.html"
)
}
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.enabled true
}
// workaround for source code highlighting in coverage report
// see http://www.eclemma.org/jacoco/trunk/doc/faq.html
// http://forums.gradle.org/gradle/topics/_1_6_rc_1_jacoco_plugin_does_not_show_line_numbers
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
}
asciidoctor {
sourceDir = file("$projectDir/src/asciidoc")
backends = [ "html5", "pdf" ]
attributes = [
'pagenums': '' // generate page numbers for PDF backend - see asciidoctor-pdf#41
]
separateOutputDirs = false
resources {
from(sourceDir) {
include 'images/**'
include 'files/**'
}
}
}
shadowJar {
classifier "standalone"
manifest = sharedManifest
exclude 'META-INF/*.txt'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
exclude 'META-INF/*.SF'
}
bintray {
user = project.hasProperty('bintray_user') ? bintray_user : null
key = project.hasProperty('bintray_key') ? bintray_key : null
dryRun = project.hasProperty('bintray_dryRun') ? bintray_dryRun.toBoolean() : true
publish = project.hasProperty('bintray_publish') ? bintray_publish.toBoolean() : false
filesSpec {
from "$distsDir"
into bintray_targetPath
include project.hasProperty('bintray_includeSpec') ? bintray_includeSpec : []
}
pkg {
repo = project.bintray_repo
userOrg = project.hasProperty('bintray_org') ? bintray_org : null
name = project.bintray_pkg
desc = project.description
vcsUrl = project.bintray_vcsUrl
licenses = [ 'GPL-2.0' ]
version.mavenCentralSync.sync = false
}
}
/*********************************************/
/**** Custom tasks/project configuration ****/
task generateTestResources {
/* Generate unitils-local settings for the current profile */
def generateUnitilsProperties = {
def generatedUnitilsProperties = new File(buildConfig.generatedTestResourcesDir,
integrationTests.resources.unitilsLocalFileName)
def sb = new StringBuilder()
sb.append("# ").append(integrationTests.resources.unitilsLocalFileName).append("\n")
sb.append("# Generated by gradlew generateTestResources on ").append(new Date()).append("\n")
sb.append("database.url=").append(integrationTests.db.jdbcUrl).append("\n")
sb.append("database.userName=").append(integrationTests.db.owner).append("\n")
sb.append("database.password=").append(integrationTests.db.pwd).append("\n")
generatedUnitilsProperties.text = sb.toString()
}
/* Generate minimal omero server settings for inclusion via 'bin/omero config load <properties>' */
def generateOmeroServerConfig = {
def generatedOmeroConfig = new File(buildConfig.generatedTestResourcesDir,
integrationTests.resources.omeroServerConfigFileName)
def sb = new StringBuilder()
sb.append("# ").append(integrationTests.resources.omeroServerConfigFileName).append("\n")
sb.append("# Generated by gradlew generateTestResources on ").append(new Date()).append("\n")
sb.append("omero.db.name=").append(integrationTests.db.name).append("\n")
sb.append("omero.db.user=").append(integrationTests.db.owner).append("\n")
sb.append("omero.db.pass=").append(integrationTests.db.pwd).append("\n")
sb.append("omero.data.dir=").append(integrationTests.resources.omeroServerDataDir).append("\n")
generatedOmeroConfig.text = sb.toString()
}
/* A poor man's integration testing man page/script which outputs a bunch of commands for manual execution
* Ideally should be runnable in one fell gradle swoop, with sudo command prompt, etc... */
def generateIntegrationTestInfo = {
def generatedTestInfo = new File(buildConfig.generatedTestResourcesDir, "integration-tests.sh")
def sb = new StringBuilder("#!/bin/bash")
sb.append("\n##############################################################################\n")
sb.append(sprintf("/bin/bash $projectDir/src/test/resources/db/setup-db.sh %s %s %s \n",
integrationTests.db.name, integrationTests.db.owner, integrationTests.db.pwd))
sb.append("./gradlew integrationTestDbMigrate -Pprofile=").append(profile).append("\n")
sb.append(sprintf("\$OMERO_PREFIX/bin/omero config def %s-%s \n", project.name, profile))
sb.append(sprintf("\$OMERO_PREFIX/bin/omero config load -q %s/%s \n",
buildConfig.generatedTestResourcesDir,
integrationTests.resources.omeroServerConfigFileName))
sb.append("mkdir -p ").append(integrationTests.resources.omeroServerDataDir).append("\n")
sb.append("\$OMERO_PREFIX/bin/omero admin start \n")
sb.append("./gradlew test jacocoTestReport -Pprofile=").append(profile).append("\n")
sb.append("\$OMERO_PREFIX/bin/omero admin stop \n")
sb.append("\$OMERO_PREFIX/bin/omero config def default \n")
sb.append(sprintf("/bin/bash $projectDir/src/test/resources/db/teardown-db.sh %s %s \n",
integrationTests.db.name, integrationTests.db.owner))
sb.append("###############################################################################\n")
generatedTestInfo.text = sb.toString()
logger.info(generatedTestInfo.text) // enable logging to console for copy/paste
}
doLast {
new File(buildConfig.generatedTestResourcesDir).mkdirs()
generateUnitilsProperties()
generateOmeroServerConfig()
generateIntegrationTestInfo()
}
}
/** Refresh database state prior to integration tests */
task integrationTestDbSetup(type: Test) {
useTestNG()
include 'org/imagopole/omero/tools/DbUnitInitializerTest*'
}
// make sure database is initialized when running 'gradle test'
test.dependsOn integrationTestDbSetup
/** Convenience wrapper around the flywayClean task, with database properties set */
task integrationTestDbClean() {
finalizedBy flywayClean
doFirst {
project.ext.set('flyway.url', integrationTests.db.jdbcUrl)
project.ext.set('flyway.user', integrationTests.db.owner)
project.ext.set('flyway.password', integrationTests.db.pwd)
}
}
/** Convenience wrapper around the flywayMigrate task, with database properties set */
task integrationTestDbMigrate() {
finalizedBy flywayMigrate
doFirst {
project.ext.set('flyway.url', integrationTests.db.jdbcUrl)
project.ext.set('flyway.user', integrationTests.db.owner)
project.ext.set('flyway.password', integrationTests.db.pwd)
project.ext.set('flyway.locations', integrationTests.db.schemaLocation)
}
}
/** Create a distribution bundle with runtime dependencies + shell scripts included */
task withDepsDistZip(type: Zip) { zipTask ->
dependsOn asciidoctor
classifier = omeClassifier + '-with-dependencies'
into ("lib") {
from configurations.runtime
}
into ("docs") {
from "$buildDir/asciidoc"
}
into ("bin") {
from "$sourceSets.main.output.resourcesDir/cli"
from fileTree("$sourceSets.main.output.resourcesDir/omero").include("*.sh")
}
into ("scripts") {
from fileTree("$sourceSets.main.output.resourcesDir").include("omero/**").exclude("**/*.sh")
}
from configurations.runtime.allArtifacts.files
from fileTree("$projectDir").include(["*.md", "LICENSE.txt", "NOTICE.txt"])
}
/** Create a distribution bundle with a standalone fat jar + shell scripts included */
task standaloneDistZip(type: Zip) { zipTask ->
dependsOn asciidoctor, shadowJar
classifier = omeClassifier + '-standalone'
into ("docs") {
from "$buildDir/asciidoc"
}
into ("bin") {
from "$sourceSets.main.output.resourcesDir/cli"
from fileTree("$sourceSets.main.output.resourcesDir/omero").include("*.sh")
}
into ("scripts") {
from fileTree("$sourceSets.main.output.resourcesDir").include("omero/**").exclude("**/*.sh")
}
from fileTree("$libsDir").include("*-standalone.jar")
from fileTree("$projectDir").include(["*.md", "LICENSE.txt", "NOTICE.txt"])
}
/** Create a documentation only bundle with user manual and CSV files samples */
task docsDistZip(type: Zip) { zipTask ->
dependsOn asciidoctor
classifier = 'docs-with-examples'
from "$buildDir/asciidoc"
from fileTree("$projectDir").include(["*.md", "LICENSE.txt", "NOTICE.txt"])
}
/** Create all distribution bundles */
task distributionZip {
dependsOn standaloneDistZip, withDepsDistZip, docsDistZip
}
artifacts {
archives file(withDepsDistZip.archivePath)
archives file(standaloneDistZip.archivePath)
archives file(docsDistZip.archivePath)
}
/** Upload and publish the released standalone + exploded dependencies binaries distributions.
* Note: SNAPSHOT artifacts bintray uploads are disallowed */
task bintrayDistsUpload() {
finalizedBy bintrayUpload
doFirst {
// hacky way to override the copySpec after buildfile evaluation, so that:
// (i) the com.jfrog.bintray.gradle.Artifact path may be customized/shortened (as MavenPublication or
// Configuration-collected artifacts strictly adhere to a maven repo layout for artifacts paths)
// (ii) packages uploads may be handled by separate tasks with finer granularity (ie. binaries
// and docs), eg. when sequentially publishing artifacts from distinct profiles to a single package version
project.extensions['bintray'].filesSpec.include('**/*-standalone.zip',
'**/*-with-dependencies.zip')
}
}
/** Upload and publish the released docs distribution.
* Note: SNAPSHOT artifacts bintray uploads are disallowed */
task bintrayDocsUpload {
finalizedBy bintrayUpload
doFirst {
// see bintrayDistsPublish comment
project.extensions['bintray'].filesSpec.include('**/*-docs-with-examples.zip')
}
}
/**************************************/
/**** Build plugins configuration ****/
buildscript {
ext.pluginsVersions = [
asciidoctor : '1.5.2',
asciidoctorjPdf : '1.5.0-alpha.6',
shadow : '1.2.2',
artifactory : '2.2.5',
bintray : '1.4',
flyway : '3.2.1',
info : '2.2.0'
]
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:' + pluginsVersions.asciidoctor
classpath 'org.asciidoctor:asciidoctorj-pdf:' + pluginsVersions.asciidoctorjPdf
classpath 'com.github.jengelman.gradle.plugins:shadow:' + pluginsVersions.shadow
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:' + pluginsVersions.artifactory
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:' + pluginsVersions.bintray
classpath 'org.flywaydb:flyway-gradle-plugin:' + pluginsVersions.flyway
classpath 'com.netflix.nebula:gradle-info-plugin:' + pluginsVersions.info
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}