-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
416 lines (351 loc) · 11.1 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
/*
* Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission
* to use, copy, modify, and distribute this software and its documentation for
* educational, research, and not-for-profit purposes, without fee and without a
* signed licensing agreement.
*
* IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE CLARA SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY,
* PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO PROVIDE
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* This software was developed under the United States Government license.
* For more information contact author at [email protected]
* Department of Experimental Nuclear Physics, Jefferson Lab.
*/
plugins {
id 'java-library'
id 'maven-publish'
id 'checkstyle'
id 'com.github.spotbugs' version '5.2.5'
id 'eclipse'
id 'idea'
}
group = 'org.jlab.coda'
version = '4.3-SNAPSHOT'
base {
archivesName = 'jclara'
}
defaultTasks 'build'
configurations {
all {
resolutionStrategy.cacheChangingModulesFor 30, 'minutes'
}
deployerJars
}
sourceSets {
main {
java {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
exclude "resources/**"
}
resources {
srcDir 'test/resources'
}
}
}
repositories {
maven {
url 'https://clasweb.jlab.org/clas12maven/'
}
mavenCentral()
}
dependencies {
api 'org.jlab.coda:xmsg:2.3'
implementation 'org.yaml:snakeyaml:1.18'
api 'org.json:json:20160810'
api 'org.jline:jline:3.1.3'
implementation 'org.apache.commons:commons-exec:1.3'
implementation 'org.freemarker:freemarker:2.3.26-incubating'
implementation 'net.sf.jopt-simple:jopt-simple:4.9'
implementation 'com.google.code.findbugs:jsr305:3.0.1'
implementation 'org.jlab.coda:jinflux:1.0-SNAPSHOT'
implementation 'junit:junit:4.12'
deployerJars 'org.apache.maven.wagon:wagon-ssh-external:2.12'
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.4.2'
testImplementation 'org.hamcrest:hamcrest-library:1.3'
testImplementation 'org.mockito:mockito-junit-jupiter:2.28.2'
}
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
compileJava {
options.release = 17
}
javadoc {
options.charSet = 'utf8'
options.encoding = 'utf8'
options.docEncoding = 'utf8'
options.addStringOption('Xdoclint:none', '-quiet')
include "org/jlab/clara/base/**"
include "org/jlab/clara/engine/**"
include "org/jlab/clara/std/**"
include "org/jlab/clara/sys/**"
exclude "org/jlab/clara/base/core/**"
exclude "org/jlab/clara/sys/ccc/**"
}
publishing {
publications {
maven(MavenPublication) {
// repositories {
// mavenDeployer {
// configuration = configurations.deployerJars
// repository(url: 'scpexe://[email protected]/group/clas/www/clasweb/html/clas12maven') {
// authentication(userName: 'clas12')
// }
// }
// }
groupId = 'org.jalb.coda.clara'
artifactId = 'library'
version = '1.1'
from components.java
}
}
}
test {
useJUnitPlatform {
excludeTags 'integration'
}
testLogging {
exceptionFormat = 'full'
}
}
tasks.register('integrationTest', Test) {
useJUnitPlatform {
includeTags 'integration'
}
testLogging {
exceptionFormat = 'full'
}
testClassesDirs = testing.suites.test.sources.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath
outputs.upToDateWhen { false }
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:deprecation"
}
//////////////////////////////////////////////////////////////////////////////
// version information
//////////////////////////////////////////////////////////////////////////////
def runGit(cmd) {
rootProject.file('.git').exists() ? cmd.execute().text.trim() : ''
}
ext {
gitBranch = properties['gitBranch'] ?: runGit('git rev-parse --abbrev-ref HEAD')
gitRev = properties['gitRev'] ?: runGit('git rev-parse --short=10 HEAD')
gitDescribe = properties['gitDescribe'] ?: runGit('git describe --match=v[0-9]* --abbrev=10 HEAD')
}
tasks.register('generateVersionProperties') {
def propertiesFile = file("${buildDir}/resources/main/META-INF/version.properties")
inputs.property 'version', project.version
inputs.property 'groupId', project.group
inputs.property 'artifactId', project.base.archivesName
inputs.property 'gitBranch', gitBranch
inputs.property 'gitRev', gitRev
inputs.property 'gitDescribe', gitDescribe
outputs.file propertiesFile
doLast {
propertiesFile.write "version=${project.version}\n"
propertiesFile.append "groupId=${project.group}\n"
propertiesFile.append "artifactId=${project.base.archivesName}\n"
propertiesFile.append "builtBy=${System.getProperty('user.name')}\n"
propertiesFile.append "builtJDK=${System.getProperty('java.version')}\n"
if (gitBranch) {
propertiesFile.append "git.branch=${gitBranch}\n"
}
if (gitRev) {
propertiesFile.append "git.revision=${gitRev}\n"
}
if (gitDescribe) {
propertiesFile.append "git.describe=${gitDescribe}\n"
}
}
}
classes.dependsOn generateVersionProperties
//////////////////////////////////////////////////////////////////////////////
// deployment
//////////////////////////////////////////////////////////////////////////////
def deploySpec = copySpec {
into ('lib') {
from configurations.runtimeClasspath
from jar
}
from ('scripts/unix') {
into 'bin'
fileMode 0755
}
from ('scripts/lib') {
into 'lib/clara'
fileMode 0755
}
// trick Gradle to "create" empty directories
def tempDir = "${buildDir}/distributions/clara_home"
file("${tempDir}/log").mkdirs()
file("${tempDir}/plugins").mkdirs()
from tempDir
}
tasks.register('distSources', Tar) {
archiveExtension = 'tar.gz'
archiveClassifier = 'src'
compression = Compression.GZIP
into "${archiveBaseName.get()}-${archiveVersion.get()}-${archiveClassifier.get()}"
from 'README.md'
from 'build.gradle'
from 'settings.gradle'
from 'gradlew'
from 'gradlew.bat'
def sourceDirs = [
'config',
'gradle',
'scripts',
'src',
'test',
]
sourceDirs.each { dir ->
from ("${dir}") { into "${dir}" }
}
dependsOn build
}
tasks.register('distBinaries', Tar) {
archiveExtension = 'tar.gz'
compression = Compression.GZIP
into "${archiveBaseName.get()}-${archiveVersion.get()}"
with deploySpec
dependsOn build
}
tasks.register('deploy', Copy) {
def dest = "$System.env.CLARA_HOME"
into dest
with deploySpec
doFirst {
if (dest == 'null') {
throw new GradleException('CLARA_HOME not set')
}
}
dependsOn jar
}
//////////////////////////////////////////////////////////////////////////////
// development scripts
//////////////////////////////////////////////////////////////////////////////
ext {
// used by scripts in `scripts/dev/*` through `scripts/exec-class`
classPathCache = file("${buildDir}/tmp/classpath")
testClassPathCache = file("${buildDir}/tmp/test_classpath")
}
tasks.register('cacheClasspath') {
inputs.files sourceSets.main.runtimeClasspath
inputs.files sourceSets.test.runtimeClasspath
outputs.files classPathCache
outputs.files testClassPathCache
doLast {
classPathCache.write sourceSets.main.runtimeClasspath.asPath
testClassPathCache.write sourceSets.test.runtimeClasspath.asPath
}
}
tasks.register('printClasspath') {
doLast {
println classPathCache.text.replace(':', '\n')
}
dependsOn cacheClasspath
}
assemble.dependsOn cacheClasspath
//////////////////////////////////////////////////////////////////////////////
// quality check
//////////////////////////////////////////////////////////////////////////////
ext {
ciMode = properties['ciMode'] ?: 'false'
}
checkstyle {
toolVersion = '10.15.0'
configFile = file('config/quality/checkstyle.xml')
configProperties['samedir'] = file('config/quality')
}
spotbugs {
toolVersion = '4.8.3'
ignoreFailures = true
effort = 'max'
reportLevel = 'medium'
excludeFilter = file('config/quality/findbugs-exclude.xml')
}
tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
def useXml = ciMode.toBoolean()
reports {
xml.enabled = useXml
html.enabled = !useXml
}
}
tasks.register('checkSpotBugsResults') {
doLast {
def bugsFound = 0
[spotbugsMain, spotbugsTest].each {
try {
bugsFound += printSpotBugs it.reports.getByName('xml').destination
} catch (FileNotFoundException e) {
logger.info e.message
}
}
if (bugsFound > 0) {
throw new GradleException("$bugsFound SpotBugs rule violations were found.")
}
}
}
def printSpotBugs(File xml) {
def slurped = new XmlSlurper().parse(xml)
def bugs = slurped.BugInstance
bugs.each { bug ->
def line = bug.SourceLine
logger.error "[SpotBugs] ${line.@sourcepath}:${line.@start}:${line.@end} [${bug.@type}]"
}
bugs.size()
}
tasks.register('spotbugs') {
group = 'Verification'
description = 'Marker task to enable SpotBugs.'
mustRunAfter spotbugsMain, spotbugsTest
if (ciMode.toBoolean()) {
finalizedBy checkSpotBugsResults
}
}
gradle.taskGraph.whenReady { taskGraph ->
tasks.spotbugsMain.onlyIf {
taskGraph.hasTask(tasks.spotbugs)
}
tasks.spotbugsTest.onlyIf {
taskGraph.hasTask(tasks.spotbugs)
}
tasks.checkSpotBugsResults.onlyIf {
taskGraph.hasTask(tasks.spotbugs)
}
}
//////////////////////////////////////////////////////////////////////////////
// IDE configuration
//////////////////////////////////////////////////////////////////////////////
eclipse {
classpath {
file {
defaultOutputDir = file("${buildDir}/eclipse")
whenMerged { classpath ->
classpath.entries.each { source ->
if (source.kind == 'src' && source.hasProperty('output')) {
source.output = "${buildDir.getName()}/eclipse"
}
}
}
}
}
}