This repository has been archived by the owner on Nov 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
401 lines (355 loc) · 14.7 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
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
//apply plugin: 'antlr4'
group = 'com.vzome.core'
version = '0.16.0'
ext.gitCommit = System.getenv( "GIT_COMMIT" ) ?: 'HEAD'
description = "vzome-core"
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext.antlr4 = [
antlrSource: "src/main/antlr",
// Simplify multiple IDE integration by putting destinationDir under src/main/java
// Some IDEs don't corectly read multiple source folders from build.gradle.
destinationDir: "src/main/java/com/vzome/core/antlr/generated",
grammarpackage: "com.vzome.core.antlr.generated"
]
repositories {
mavenCentral()
ivy { // not really an Ivy repo, but this pattern lets us automate the bare JAR download for java3d/vecmath
url "http://jogamp.org/deployment"
layout "pattern", {
artifact "[organization]/[revision]/[artifact].[ext]"
}
}
}
configurations {
antlr4 {
description = "ANTLR4"
}
}
// Support for decoupled "regression" task
sourceSets {
regression {
java.srcDir file('src/regression/java')
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.1' //version required
}
task recordBuildProperties {
def propsFile = file( "$buildDir/buildPropsResource/vzome-core-build.properties" )
ext.outputDir = propsFile .getParentFile()
doFirst {
writeProjectProperties( [ 'version', 'gitCommit' ], propsFile )
}
println 'recorded build properties'
}
processResources {
dependsOn recordBuildProperties
from recordBuildProperties.outputDir
}
dependencies {
compile group: 'org.antlr', name: 'antlr4', version:'4.5'
compile group: 'java3d', name: 'vecmath', version:'1.6.0-pre12'
compile group: 'org.python', name: 'jython', version:'2.7-b4'
runtime group: 'org.python', name: 'jython', version:'2.7-b4'
runtime group: 'java3d', name: 'vecmath', version:'1.6.0-pre12'
testCompile group: 'antlr', name: 'antlr', version:'2.7.7'
testCompile group: 'junit', name: 'junit', version:'4.12'
testCompile group: 'xom', name: 'xom', version:'1.2.5'
antlr4 group: 'org.antlr', name: 'antlr4', version: '4.5'
regressionCompile sourceSets.main.output
regressionCompile configurations.testCompile
regressionCompile sourceSets.test.output
regressionRuntime configurations.testRuntime
}
// These options apply to all java projects
// More info at http://www.javaworld.com/article/2073587/javac-s--xlint-options.html
// I'm turning on most of the warnings
// ...except that the test project ignores deprecation
// and they all ignore serial for now.
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs \
<< "-Xdiags:verbose" \
<< "-Xlint:all" \
<< "-Xlint:cast" \
<< "-Xlint:divzero" \
<< "-Xlint:empty" \
<< "-Xlint:fallthrough" \
<< "-Xlint:finally" \
<< "-Xlint:overrides" \
<< "-Xlint:path" \
<< "-Xlint:rawtypes" \
<< "-Xlint:unchecked" \
<< "-Xlint:-serial"
// TODO: Enable the serial warning and look into fixing the ~11 issues.
// Most of them are classes which extend a generic Collection or Exception.
}
}
// It seems that the settings below are the starting point
// and that the ones above override them, so only put
// settings above if they are identical in all projects.
// This applies only to the primary 'compile' java project
compileJava {
options.compilerArgs \
<< "-Xlint:deprecation" \
}
// This applies only to the 'test' java project
compileTestJava {
// These warnings exist in the older legacy zomic code
// which we don't plan to maintain
// except for regression and backward compatibility testing.
options.compilerArgs \
<< "-Xlint:-deprecation" /* A minus sign following the colon removes that check. */
}
// Successive runs of 'test' tasks will not be executed
// unless the results of the previous run are 'cleaned'.
//
// Individual tests or a group of tests based on method name patterns
// can be run from the gradle command line.
//
// The method name(s) of individual tests or groups of tests to be run
// can be specified by specifying a pattern matching the fully qualified name of the test class method
// or with appropriate wildcards.
// Note that the patterns are CaSe SeNsItIve.
// For example, a pattern to execute the three tests:
// testOK_RedAliases, testOK_BlueAliases and testOK_YellowAliases
// would be *testOK_*Aliases
//
// Standard Output and Standard Error are not displayed by default for gradle tests.
// Use -P"testLogging.showStandardStreams" in the command line to enable them as shown below.
//
// To execute the same test or group of tests repeatedly,
// use a gradle command line like this:
//
// gradle cleanTest test --tests *testOK_*Aliases
//
// ... or with standard streams displayed to the console:
// gradle cleanTest test --tests *testOK_*Aliases -P"testLogging.showStandardStreams"
//
test {
def loggingProperties = new File ('src/test/java/logging.properties')
if(loggingProperties.exists()) {
jvmArgs "-Djava.util.logging.config.file=${loggingProperties.absolutePath}"
}
doLast {
if(loggingProperties.exists()) {
println("Tests used java.util.logging.config.file: ${loggingProperties.absolutePath}")
}
}
testLogging {
// Only set showStandardStreams=true from the gradle command line.
// using -P"testLogging.showStandardStreams"
// Otherwise, it normally defaults to false which is correct for the NetBeans IDE.
if( project.hasProperty( 'testLogging.showStandardStreams' ) ) {
// Make sure output from standard out or error is shown in Gradle output.
showStandardStreams = true
// Or we use events method:
// events 'standard_out', 'standard_error' // ,'started', 'passed'
// Or set property events:
// events = ['standard_out', 'standard_error']
// Instead of string values we can use enum values:
// events org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT,
// org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR,
}
}
}
task makeAntlrOutputDir {
outputs.dir antlr4.destinationDir
doLast() {
// Be sure to wrap this inside doLast().
// Otherwise it will run during the initialization or configuration phase, even when an unrelated task is is run.
//println 'Making Antlr Output Directory: ' + antlr4.destinationDir
file(antlr4.destinationDir).mkdirs()
}
}
// This is a start in case we ever want to put each language into its own folder.
// It got messy to do with separate Lexer and Parser grammars so I dumped them all in the same folder for now
// We may eventually remove this part if we don't use it.
//task makeAntlrOutputDirTree << {
// String pkg = antlr4.grammarpackage.replaceAll("\\.", "/")
// String srcRoot = antlr4.antlrSource + "/" + pkg'
// String dstRoot = antlr4.destinationDir + "/" + pkg
// def tree = fileTree(srcRoot).include('**/*.g4')
// tree.visit {element ->
// // this will only build the dstPath folder if there is a .g4 file under the srcRoot folder
// if (!element.isDirectory()) {
// String dstPath = dstRoot + "/" + element.relativePath
// //println "dstPath = " + dstPath
// // strip filename from dstPath so only folders remain
// dstPath = dstPath.substring(0, dstPath.lastIndexOf("/"))
// //println "DstPath = " + dstPath
// file(dstPath).mkdirs()
// }
// }
//}
// According to https://gradle.org/docs/current/userguide/more_about_tasks.html...
// A task with no defined outputs will never be considered up-to-date.
// A task with only outputs (no inputs) defined will be considered up-to-date if those outputs are unchanged since the previous build.
task compileAntlrGrammars(type: JavaExec , dependsOn: makeAntlrOutputDir) {
// Grammars are conveniently sorted alphabetically. I assume that will remain true.
// That ensures that files named *Lexer.g4 are listed and therefore processed before the corresponding *Parser.g4
// It matters because the Lexer must be processed first since the Parser needs the .tokens file from the Lexer.
// Also note that the output file naming convention for combined grammars is slightly different from separate Lexer and Parser grammars.
// Also, changing the args when invoking Antlr will change the files it generates which affects the outputs collection.
def grammars = fileTree(antlr4.antlrSource).include('**/*.g4')
//def pkg = antlr4.grammarpackage.replaceAll("\\.", "/")
def target = file("${antlr4.destinationDir}") ///${pkg}")
inputs.files grammars
outputs.dir target
main = 'org.antlr.v4.Tool'
classpath = configurations.antlr4
// Antlr command line args are at https://theantlrguy.atlassian.net/wiki/display/ANTLR4/ANTLR+Tool+Command+Line+Options
args = ["-o", target,
"-lib", target,
//"-listener", //"-listener" is the default
//"-no-visitor", //"-no-visitor" is the default
"-package", antlr4.grammarpackage,
grammars.files //grammars.collect{ relativePath(it) } // may want to do something with relative paths so leave this sample code here for now
].flatten()
//println args
// include optional description and group (shown by ./gradlew tasks command)
description = 'Generates Java sources from ANTLR4 grammars.'
group = 'Build'
}
compileJava {
dependsOn compileAntlrGrammars
// this net line isn't technically needed unless the antlr4.destinationDir is not under buildDir, but it doesn't hurt either
source antlr4.destinationDir
}
task cleanAntlr {
doLast() {
// Be sure to wrap this inside doLast().
// Otherwise it will run during the initialization or configuration phase, even when an unrelated task is is run.
// It would also run when the NetBeas IDE first loaded the project.
//println 'Deleting Antlr Directory: ' + antlr4.destinationDir
delete antlr4.destinationDir
}
}
clean.dependsOn cleanAntlr
// These tasks are used to run the vZome regression test suite
def regressionOutputDir = new File(buildDir.toString() + '/test-results/regression')
task makeRegressionOutputDir {
outputs.dir regressionOutputDir
doLast() {
// Be sure to wrap this inside doLast().
// Otherwise it will run during the initialization or configuration phase, even when an unrelated task is is run.
println 'Making Regression Output Directory: ' + regressionOutputDir
regressionOutputDir.mkdirs()
}
}
task regression(type: JavaExec, dependsOn: check) {
group = 'Verification'
description = """Run regression testing
command-line options:
-PregressionHome=src/regression/files (default shown, value can be absolute or relative)
-PregressionFile=sniff-test.vZome-files (default shown, relative to regressionHome)
If the regressionFile is a ".vZome-files" file, it can contain paths that are
resolved relative to regressionHome.
"""
def testHome = 'src/regression/files'
if( project .hasProperty( "regressionHome" ) ){
testHome = regressionHome
println "testHome is $testHome"
}
def testFile = 'sniff-test.vZome-files'
if( project .hasProperty( "regressionFile" ) ){
testFile = regressionFile
println "testFile is $testFile"
}
def testOut = 'build/test-results/regression/TEST-output.xml'
if( project .hasProperty( "regressionOutput" ) ){
testOut = regressionOutput
println "testOut is $testOut"
}
classpath = sourceSets.regression.runtimeClasspath
main = 'com.vzome.core.regression.TestVZomeFiles'
args( testHome, testFile, testOut )
jvmArgs( '-Xmx3048M' )
jvmArgs( '-Djava.util.logging.config.file=regression-logging.properties' )
}
regression.dependsOn makeRegressionOutputDir
[ '01-Jan', '02-Feb', '03-Mar', '04-Apr', '05-May', '06-Jun', '07-Jul', '08-Aug', '09-Sep', '10-Oct', '11-Nov', '12-Dec' ]
.each { def month ->
task "regression-$month"( dependsOn: [check, makeRegressionOutputDir], type: JavaExec ) {
def testHome = 'src/regression/files'
if( project .hasProperty( "regressionHome" ) ){
testHome = regressionHome
}
def testYear = '2015'
if( project .hasProperty( "regressionYear" ) ){
testYear = regressionYear
}
def testFile = "${testYear}/${month}"
def testOut = "build/test-results/regression/TEST-${testYear}-${month}.xml"
if( project .hasProperty( "regressionOutput" ) ){
testOut = regressionOutput
}
classpath = sourceSets.regression.runtimeClasspath
main = 'com.vzome.core.regression.TestVZomeFiles'
args( testHome, testFile, testOut )
jvmArgs( '-Xmx3048M' )
}
}
task regressionYear( dependsOn: tasks.matching { Task task -> task.name.startsWith( "regression-" ) } )
task zomicPP( type: JavaExec, dependsOn: build) {
def theFile = 'src/regression/files/Zomic/yellowAxisSaddleWeb/yellowAxisSaddleWeb.zomic'
if( project.hasProperty( 'zomicFile' ) ){
theFile = zomicFile
}
classpath = sourceSets.test.runtimeClasspath
main = 'com.vzome.core.zomic.program.PrintVisitor'
args( theFile )
group = 'Verification'
description = """Pretty-Prints the specified Zomic file
command-line options:
-PzomicFile="$theFile" (default shown, value can be absolute or relative)
Prints the file using the ORIGINAL zomic parser.
-P-new
Prints the file using the NEW Antlr4 zomic compiler.
Sample Usage:
gradle zomicPP -PzomicFile="$theFile"
gradle zomicPP -PzomicFile="$theFile" -P-new
The output should be identical to $theFile-pp
"""
doLast { // doFirst and doLast are executed only during the execution phase, not during the initialization or configuration phases.
if( !project.hasProperty( 'zomicFile' ) ){
println ""
println "No zomic file was specified. Using default: $theFile"
println description
println ""
}
}
}
jar {
manifest {
attributes 'Implementation-Title': 'vzome-core',
'Implementation-Version': version
}
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
def writeProjectProperties( keys, propsFile )
{
def outputDir = propsFile .getParentFile()
outputDir.exists() || outputDir.mkdirs()
def buildProps = new Properties()
project.properties.findAll( { it.key in keys } ) .each {
buildProps .put( it.key, it.value.toString() )
}
def writer = new FileWriter( propsFile )
try {
buildProps .store( writer, null )
writer.flush()
} finally {
writer.close()
}
}