forked from randoop/randoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
971 lines (853 loc) · 31.9 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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
/*
* build.gradle for Randoop
*
* Quick instructions: in project directory run with command
* ./gradlew build
*/
plugins {
id 'com.github.johnrengelman.shadow' version '5.0.0'
id 'java'
id 'eclipse'
id 'idea'
id 'jacoco'
/*
* Plugin that applies Google's Error Prone linter (http://errorprone.info/).
* https://github.com/tbroyer/gradle-errorprone-plugin
* Elsewhere this file excludes src/testInput from directories examined by Error Prone.
* To run Error Prone, do: ./gradlew compileJava
* There is no separate target to just run Error Prone.
*/
id "net.ltgt.errorprone-base" version "0.0.16"
// To update version numbers of dependencies in this file, run: ./gradlew useLatestVersions
id 'se.patrikerdes.use-latest-versions' version '0.2.9'
id 'com.github.ben-manes.versions' version '0.21.0'
}
// For Checker Framework pluggable type-checking, run: ./gradlew checkTypes
// It is not run in the main build because the Checker Framework is incompatible with Error Prone.
// TODO: Uncomment
// apply from: "checkerframework.gradle"
/* Common build configuration for Randoop and agents */
allprojects {
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = 1.8
targetCompatibility = 1.8
/* Use Maven Central when have external dependencies */
repositories {
mavenCentral()
jcenter()
}
/* Randoop version number - added to generated jar files */
version = '4.1.1'
configurations {
// A collection of all plumelib dependencies required, so that all
// sub-projects use the same versions.
plumelib
}
dependencies {
implementation "org.checkerframework:checker-qual:2.7.0"
// https://mvnrepository.com/artifact/org.plumelib/bcel-util
plumelib 'org.plumelib:bcel-util:1.1.4'
// To use a local version comment out line above and uncomment line below.
// plumelib files("${rootDir}/libs/bcel-util-all.jar")
// https://mvnrepository.com/artifact/org.plumelib/options
plumelib 'org.plumelib:options:1.0.1'
// https://mvnrepository.com/artifact/org.plumelib/plume-util
plumelib 'org.plumelib:plume-util:1.0.6'
// https://mvnrepository.com/artifact/org.plumelib/reflection-util
plumelib 'org.plumelib:reflection-util:0.0.2'
}
}
/******
* Configuration specific to Randoop and not agents.
* Configuration for agent FOO appears in agents/FOO/FOO.gradle .
******/
description = "Randoop automated test generation"
/* Root for working directories for system test generated files */
def workingDirectories = "$buildDir/working-directories"
sourceSets {
/* JUnit tests that must be run with -javaagent */
/* JUnit tests are run in nondeterministic order, but system tests are
run in deterministic order. */
coveredTest
replacecallTest
/* system tests */
systemTest {
resources {
srcDir 'src/testInput/resources'
}
output.dir(workingDirectories, builtBy: 'generateWorkingDirs')
}
/* Code sets used by system tests. There are no actual tests here. */
testInput
test {
resources {
srcDir 'src/testInput/resources'
}
}
}
configurations {
/*
* Used to manage javaagent jar file
*/
jacocoagent
junit
/*
* The agent tests are JUnit tests run with the covered-class-agent, so
* borrow from unit test configurations.
*/
coveredTestImplementation.extendsFrom testImplementation
coveredTestRuntimeOnly.extendsFrom testRuntimeOnly
replacecallTestImplementation.extendsFrom testImplementation
replacecallTestRuntimeOnly.extendsFrom testRuntimeOnly
}
dependencies {
junit group: 'junit', name: 'junit', version: '4.+'
implementation configurations.plumelib
implementation 'org.apache.commons:commons-exec:1.3'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
implementation configurations.junit.dependencies
implementation files(project(':replacecall').sourceSets.main.output)
/* JavaParser 2.4.0 is the most recent version available with JDK7 jar files.
* TODO: Update now that we no longer support JDK7.
* Note that updating will require code changes due to JavaParser API changes. */
implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '2.4.0'
/* Jacoco measures coverage of classes and methods under test. */
implementation group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.3'
implementation group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.8.3', classifier: 'runtime'
/* sourceSet test uses JUnit and some use testInput source set */
testImplementation group: 'commons-codec', name: 'commons-codec', version: '1.12'
testImplementation configurations.junit.dependencies
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testImplementation group: 'org.checkerframework', name: 'checker-qual', version: '2.7.0'
testImplementation sourceSets.testInput.output
/*
* sourceSet coveredTest uses output from main sourceSet, and agent projects.
* (Also, see configuration block.)
*/
coveredTestImplementation sourceSets.main.output
coveredTestImplementation sourceSets.test.output
coveredTestRuntimeOnly project(':covered-class')
replacecallTestImplementation files(project(':replacecall').sourceSets.main.output)
jacocoagent group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.8.3'
/*
* source set systemTest
*/
systemTestImplementation configurations.plumelib
systemTestImplementation group: 'commons-io', name: 'commons-io', version: '2.6'
systemTestImplementation 'org.apache.commons:commons-exec:1.3'
systemTestImplementation configurations.junit.dependencies
systemTestImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
systemTestImplementation group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.3'
systemTestImplementation group: 'org.jacoco', name: 'org.jacoco.report', version: '0.8.3'
systemTestImplementation group: 'org.checkerframework', name: 'checker-qual', version: '2.7.0'
systemTestRuntimeOnly sourceSets.testInput.output
/*
* sourceSet testInput depends on output of main.
* Also, src/testInput/java/ps1/RatPolyTest.java uses JUnit
*/
testInputImplementation sourceSets.main.output
testInputImplementation configurations.junit.dependencies
errorprone group: 'com.google.errorprone', name: 'error_prone_core', version: '2.3.3'
}
/*
* Configuration for compilation.
*/
compileJava.options.compilerArgs = ['-Xlint','-g','-Xlint:-classfile']
compileTestJava.options.compilerArgs = ['-g','-Xlint:-classfile']
compileCoveredTestJava.options.compilerArgs = ['-g','-Xlint:-classfile']
compileReplacecallTestJava.options.compilerArgs = ['-g','-Xlint:-classfile']
compileSystemTestJava.options.compilerArgs = ['-g','-Xlint:-classfile']
compileTestInputJava.options.compilerArgs = ['-nowarn','-g','-Xlint:-classfile', '-XDenableSunApiLintControl', '-Xlint:-sunapi']
task compileAll() {
dependsOn compileJava
dependsOn compileTestJava
dependsOn ':covered-class:compileJava'
dependsOn ':covered-class:compileTestJava'
dependsOn ':replacecall:compileJava'
dependsOn ':covered-class:compileTestJava'
dependsOn compileCoveredTestJava
dependsOn compileReplacecallTestJava
dependsOn compileSystemTestJava
}
// This isn't working; maybe I need to make it run first.
// Get early notification of any compilation failures, before running any tests
build.dependsOn compileAll
/*
* Configuration for using Error Prone linter.
*/
import net.ltgt.gradle.errorprone.ErrorProneToolChain
tasks.withType(JavaCompile).each { t ->
if (!t.name.equals("compileTestInputJava") && !t.name.startsWith("checkTypes")) {
t.toolChain ErrorProneToolChain.create(project)
t.options.compilerArgs += [
// Maybe NamedParameters is no longer supported?
// // undocumented, and suggestion seems bad
// '-Xep:NamedParameters:OFF',
// Is always a false positive in my experience.
'-Xep:StringSplitter:OFF'
// TODO: uncomment once we run the Interning Checker on Randoop
// '-Xep:ReferenceEquality:OFF'
]
}
}
/*
* Configuration for formatting
*/
task getCodeFormatScripts {
description "Obtain the run-google-java-format scripts"
doLast {
def rgjfDir = "$buildDir/utils/run-google-java-format"
if ( ! new File(rgjfDir).exists() ) {
exec {
commandLine 'git', 'clone', '--depth', '1', "https://github.com/plume-lib/run-google-java-format.git", rgjfDir
}
} else {
// Ignore exit value so this does not halt the build when not connected to the Internet.
exec {
workingDir rgjfDir
ignoreExitValue true
commandLine 'git', 'pull', '-q'
}
}
}
}
task pythonIsInstalled(type: Exec) {
description "Check that the python executable is installed."
executable = "python"
args "--version"
}
task checkFormat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled], group: 'Formatting') {
description "Check whether the Java source code is properly formatted"
def javaFiles = fileTree("$projectDir").matching{
include "**/*.java" exclude "src/testInput/**" exclude "build/**" exclude "**/CloneVisitor.java"
} as List
def pythonArgs = javaFiles.clone()
pythonArgs.add(0, "$projectDir/build/utils/run-google-java-format/check-google-java-format.py")
commandLine "python"
args pythonArgs
ignoreExitValue true
doLast {
if (execResult.exitValue != 0) {
throw new GradleException("Found improper formatting, try running: ./gradlew reformat")
}
}
}
task reformat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled], group: 'Formatting') {
description "Format the Java source code according to the Google Java Format style"
def javaFiles = fileTree("$projectDir").matching{
include "**/*.java" exclude "src/testInput/**" exclude "build/**" exclude "**/CloneVisitor.java"
} as List
def pythonArgs = javaFiles.clone()
pythonArgs.add(0, "$projectDir/build/utils/run-google-java-format/run-google-java-format.py")
commandLine "python"
args pythonArgs
}
/*
* Configuration for clean
*/
clean.dependsOn ':replacecall:clean'
clean.dependsOn ':covered-class:clean'
/*
* Configuration for testing.
* In terms of build, we have two kinds of tests, both using JUnit.
* * Those in src/coveredTest require the covered-class Java agent.
* * Those in src/test are run without the agent.
* This second group includes tests that run the full Randoop over
* classes that (mostly) are located in src/testInput.
*/
/*
* Configuration of test task from Java plugin.
* Runs all tests in test sourceSet except those excluded below.
*/
test {
/*
* Set the working directory for JUnit tests to the resources directory
* instead of the project directory.
*/
workingDir = file("$buildDir/resources")
/*
* Show as much as possible to console.
*/
testLogging {
events 'started', 'passed'
showStandardStreams = true
exceptionFormat = 'full'
}
/* Turn off HTML reports -- handled by testReport task */
reports.html.enabled = false
/*
* Temporary exclusion b/c script file uses generics as raw types and conflicts with
* other uses of parsing.
*/
exclude '**/randoop/test/SequenceTests.*'
/*
* Temporary exclusion b/c incomplete.
*/
exclude '**/randoop/output/JUnitCreatorTest.*'
/*
* Problematic tests excluded during Gradle setup that need to be evaluated.
* Unless otherwise noted, these are tests that were not previously run by
* Makefile. However, some included tests were also not run, but are not
* failing.
*/
exclude 'randoop/test/NonterminatingInputTest.*'
exclude 'randoop/test/EmptyTest.*'
exclude 'randoop/test/RandoopPerformanceTest.*' /* had target but not run */
exclude 'randoop/test/ForwardExplorerPerformanceTest.*'
exclude 'randoop/test/ForwardExplorerTests2.*' /* sporadic heap space issue */
exclude 'randoop/test/Test_SomeDuplicates.*'
exclude 'randoop/test/Test_SomePass.*'
exclude 'randoop/operation/OperationParserTests.*'
}
task coveredTest(type: Test, dependsOn: ['copyJars', 'compileTestJava']) {
/*
* Set the working directory for JUnit tests to the resources directory
* instead of the project directory.
*/
workingDir = sourceSets.coveredTest.output.resourcesDir
testClassesDirs = sourceSets.coveredTest.output.classesDirs
classpath = sourceSets.coveredTest.runtimeClasspath
jvmArgs "-javaagent:$buildDir/libs/covered-class-${version}.jar"
/*
* Show as much as possible to console.
*/
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
/* Turn off HTML reports -- handled by testReport task */
reports.html.enabled = false
}
/*
* Link the coveredTest task into project check task. Includes agent tests into
* the project build task.
*/
check.dependsOn coveredTest
task replacecallTest(type: Test, dependsOn: 'copyJars') {
workingDir = sourceSets.replacecallTest.output.resourcesDir
testClassesDirs = sourceSets.replacecallTest.output.classesDirs
classpath = sourceSets.replacecallTest.runtimeClasspath + files("$buildDir/libs/replacecall-${version}.jar")
// use the replacecall agent using the exclusions file from replacecallTest/resources
jvmArgs "-javaagent:$buildDir/libs/replacecall-${version}.jar=--dont-transform=replacecall-exclusions.txt,--debug"
jvmArgs "-Xbootclasspath/a:$buildDir/libs/replacecall-${version}.jar"
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
/* Turn off HTML reports -- handled by testReport task */
reports.html.enabled = false
}
check.dependsOn replacecallTest
jacocoTestReport {
group 'Report'
reports {
xml.enabled = true
html.enabled = true
}
}
// Expects these files to exist in build/javcoco/:
// agentTest.exec
// coveredTest.exec
// systemTest.exec
// test.exec
// What is creating the agentTest.exec files, and how do I create it?
// test.exec is the default, though it it also greated by "gradle test".
// jacocoTestReport.dependsOn agentTest
jacocoTestReport.dependsOn coveredTest
jacocoTestReport.dependsOn test
check.dependsOn jacocoTestReport
/*
* Task to build the root directory of working directories used by the
* JUnit tests in the systemTest task.
* If the directory exists then cleans out the contents.
*/
task generateWorkingDirs {
doLast {
def generated = file(workingDirectories)
if (! generated.exists()) {
generated.mkdir()
} else {
def workingFiles = fileTree(workingDirectories) {
include '**/*.java'
include '**/*.class'
include '**/*.exec'
include '**/*.txt'
}
delete workingFiles
}
}
}
/*
* Extracts JaCoCo javaagent into build/jacocoagent
*/
task extractJacocoAgent(type: Copy) {
from {
configurations.jacocoagent.collect { zipTree(it) }
}
into "$buildDir/jacocoagent/"
}
/*
* Runs JUnit over all classes in systemTest sourceSet.
* JUnit tests assume that working directories can be found in the build directory.
*/
task systemTest(type: Test, dependsOn: [ 'extractJacocoAgent', 'generateWorkingDirs', 'assemble' ]) {
/*
* Set system properties for jar paths, used by randoop.main.SystemTestEnvironment
*/
doFirst {
systemProperty 'jar.randoop', shadowJar.archivePath
systemProperty 'jar.replacecall.agent', project(':replacecall').shadowJar.archivePath
systemProperty 'jar.covered.class.agent', project(':covered-class').shadowJar.archivePath
}
workingDir = file("$buildDir")
testClassesDirs = sourceSets.systemTest.output.classesDirs
classpath = sourceSets.systemTest.runtimeClasspath
/*
* Show as much as possible to console.
*/
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
/* Turn off HTML reports -- handled by testReport task */
reports.html.enabled = false
}
systemTest.dependsOn shadowJar
/*
* Link the systemTest task into the project check task.
* Includes system tests into the project build task.
*/
check.dependsOn systemTest
jacocoTestReport.dependsOn systemTest
tasks.withType(Test) {
/*
* Set the destination directory for JUnit XML output files
*/
reports.junitXml.destination = file("$buildDir/test-results/${name}")
/*
* Set the heap size and GC for running tests.
*/
jvmArgs '-Xmx384m', '-XX:+UseG1GC', '-XX:SoftRefLRUPolicyMSPerMB=250'
/*
* Pass along any system properties that begin with "randoop."
* Used by randoop.main.RandoopOptions in systemTest.
*/
System.properties.each { k,v->
if (k.startsWith("randoop.")) {
systemProperty k, v
}
}
}
/*
* Write HTML reports into build/reports/allTests for all tests.
* [
* Note that this may not work correctly if different Test tasks use the same
* test classes. Fine here because sourceSets use different packages for test
* classes.
* ]
*/
task testReport(type: TestReport) {
group 'Report'
description "Creates HTML reports for tests results"
destinationDir = file("$buildDir/reports/allTests")
reportOn tasks.withType(Test)
}
task printJunitJarPath {
description "Print the path to junit.jar"
doFirst { println configurations.junit.asPath }
}
//****************** Building distribution *****************
/*
* Only want the jar file to include class files from main source set.
* (Task part of build by default.)
*/
jar {
from sourceSets.main.output
}
// want to archive locally
uploadArchives {
repositories {
flatDir {
dirs 'dist'
}
}
}
task copyJars(type: Copy, dependsOn: [':covered-class:jar', ':replacecall:jar']) {
from subprojects.collect { it.tasks.withType(Jar) }
into "$buildDir/libs"
}
assemble.dependsOn copyJars
shadowJar {
// The jar file name is randoop-all-$version.jar
baseName = 'randoop-all'
classifier = null
exclude '**/pom.*'
exclude '**/default-*.txt'
// don't include either mocks or agent classes
// otherwise creates problems for replacement creation of replacecall agent
exclude '**/randoop/mock/*'
exclude '**/randoop/instrument/*'
relocate 'com.github.javaparser', 'randoop.com.github.javaparser'
relocate 'com.google', 'randoop.com.google'
relocate 'com.jcraft.jsch', 'randoop.com.jcraft.jsch'
relocate 'com.sun.javadoc', 'randoop.com.sun.javadoc'
relocate 'com.sun.jna', 'randoop.com.sun.jna'
relocate 'com.trilead.ssh2', 'randoop.com.trilead.ssh2'
relocate 'de.regnis.q.sequence', 'randoop.de.regnis.q.sequence'
relocate 'net.fortuna.ical4j', 'randoop.net.fortuna.ical4j'
relocate 'nu.xom', 'randoop.nu.xom'
relocate 'org.antlr', 'randoop.org.antlr'
relocate 'org.apache', 'randoop.org.apache'
relocate 'org.ccil.cowan.tagsoup', 'randoop.org.ccil.cowan.tagsoup'
relocate 'org.checkerframework', 'randoop.org.checkerframework'
relocate 'org.ini4j', 'randoop.org.ini4j'
relocate 'org.plumelib', 'randoop.org.plumelib'
relocate 'org.slf4j', 'randoop.org.slf4j'
relocate 'org.tigris.subversion', 'randoop.org.tigris.subversion'
relocate 'org.tmatesoft', 'randoop.org.tmatesoft'
}
assemble.dependsOn shadowJar
task distributionZip (type: Zip , dependsOn: ['shadowJar', 'copyJars', 'manual']) {
group 'Publishing'
description "Assemble a zip file with jar files and user documentation"
def dirName = "$baseName-$version"
from 'build/libs/'
from ('build/docs/manual/index.html') {
into 'doc'
}
from ('build/docs/manual/stylesheets') {
into 'doc/manual/stylesheets'
}
from 'src/distribution/resources/README.txt'
into (dirName)
exclude { details -> details.file.name.contains('randoop') && ! details.file.name.contains('-all-') }
}
/********************* Building manual *******************/
/*
* The "manual" gradle target creates the contents of the manual directory
* within src/, which will eventually be moved to the gh-pages branch.
*
* Has structure:
* src/
* docs/
* api/ - contains javadoc for main source set
* manual/
* dev.html - developer documentation
* index.html - user documentation
* *example.txt - example configuration files for user manual
* stylesheets/ - contains css file for web pages
*/
/*
* Clone or update repositories containing executable scripts.
*
* Grgit has too many limitations. Use exec instead.
*/
task cloneLibs( dependsOn: [ 'cloneChecklink', 'cloneHtmlTools', 'clonePlumeScripts' ]) { }
task cloneChecklink {
doLast {
if ( ! file("$buildDir/utils/checklink").exists() ) {
exec {
commandLine 'git', 'clone', '--depth', '1', "https://github.com/plume-lib/checklink.git", "$buildDir/utils/checklink"
}
} else {
// Ignore exit value so this does not halt the build when not connected to the Internet.
exec {
workingDir "$buildDir/utils/checklink"
ignoreExitValue true
commandLine 'git', 'pull', '-q'
}
}
}
}
task cloneHtmlTools {
doLast {
if ( ! file("$buildDir/utils/html-tools").exists() ) {
exec {
commandLine 'git', 'clone', '--depth', '1', "https://github.com/plume-lib/html-tools.git", "$buildDir/utils/html-tools"
}
} else {
// Ignore exit value so this does not halt the build when not connected to the Internet.
exec {
workingDir "$buildDir/utils/html-tools"
ignoreExitValue true
commandLine 'git', 'pull', '-q'
}
}
}
}
task clonePlumeScripts {
doLast {
if ( ! file("$buildDir/utils/plume-scripts").exists() ) {
exec {
commandLine 'git', 'clone', '--depth', '1', "https://github.com/plume-lib/plume-scripts.git", "$buildDir/utils/plume-scripts"
}
} else {
// Ignore exit value so this does not halt the build when not connected to the Internet.
exec {
workingDir "$buildDir/utils/plume-scripts"
ignoreExitValue true
commandLine 'git', 'pull', '-q'
}
}
}
}
/*
* Set destination directory to build/docs/api, and restrict to classes in
* main sourceSet.
*/
javadoc {
destinationDir = file("${buildDir}/docs/api")
source sourceSets.main.allJava
options.memberLevel = JavadocMemberLevel.PRIVATE
options.addStringOption("stylesheetfile", "${projectDir}/src/javadoc/resources/stylesheets/javadocstyle.css")
// Use of Javadoc's -linkoffline command-line option makes Javadoc generation
// much faster, especially on Travis.
options.with {
linksOffline 'https://docs.oracle.com/javase/8/docs/api/', 'https://docs.oracle.com/javase/8/docs/api/'
}
failOnError = true // does not fail on warnings
}
// Make Javadoc fail on warnings
// From https://stackoverflow.com/a/49544352/173852
tasks.withType(Javadoc) {
// The '-quiet' as second argument is actually a hack,
// since the one paramater addStringOption doesn't seem to
// work, we extra add '-quiet', which is added anyway by
// gradle. See https://github.com/gradle/gradle/issues/2354
// See JDK-8200363 (https://bugs.openjdk.java.net/browse/JDK-8200363)
// for information about the -Xwerror option.
options.addStringOption('Xwerror', '-quiet')
}
configurations {
requireJavadoc
}
dependencies {
implementation group: 'org.plumelib', name: 'require-javadoc', version: '0.1.0'
}
task requireJavadoc(type: Javadoc) {
description = 'Ensures that all Java elements have Javadoc documentation.'
destinationDir.deleteDir()
source = sourceSets.main.allJava
classpath = project.sourceSets.main.compileClasspath
// options.memberLevel = JavadocMemberLevel.PRIVATE
options.docletpath = project.sourceSets.main.compileClasspath as List
options.doclet = "org.plumelib.javadoc.RequireJavadoc"
// options.addStringOption('skip', 'ClassNotToCheck|OtherClass')
}
task requireJavadocPrivate(type: Javadoc) {
description = 'Ensures that all (even private) Java elements have Javadoc documentation.'
destinationDir.deleteDir()
source = sourceSets.main.allJava
classpath = project.sourceSets.main.compileClasspath
options.memberLevel = JavadocMemberLevel.PRIVATE
options.docletpath = project.sourceSets.main.compileClasspath as List
options.doclet = "org.plumelib.javadoc.RequireJavadoc"
// options.addStringOption('skip', 'ClassNotToCheck|OtherClass')
}
// needed for javadoc.doLast
javadoc.dependsOn cloneLibs
javadoc.doLast {
def preplace = file("$buildDir/utils/plume-scripts/preplace")
// Work around Javadoc bug
exec {
commandLine preplace, "<dt><span class=\"memberNameLink\"><a href=\".*\\(\\)</a></span> - Constructor for enum [a-zA-Z0-9_.]*<a href=\".*</a></dt>", "", "build/docs/api/index-all.html"
}
// Reduce size of diffs (when it's copied over to gh-pages branch whech is under
// version control). Note that build/docs/api/ is the same as src/docs/api/.
exec {
commandLine preplace, "^<!-- Generated by javadoc \\(.* -->\$", "", "build/docs/api/"
}
exec {
commandLine preplace, "^<meta name=\"date\" content=\"[-0-9]+\">\$", "", "build/docs/api/"
}
}
/*
* Make sure that build runs the same tasks as the script in .travis.yml
*/
build.dependsOn javadoc
/* Update the table-of-contents for the user documentation. */
task updateUserTOC( type:Exec, dependsOn: [ 'cloneLibs' ]) {
executable file("$buildDir/utils/html-tools/html-update-toc")
args file("${projectDir}/src/docs/manual/index.html")
environment PATH: "$System.env.PATH:$buildDir/utils/html-tools"
}
/* Update table of contents in developer documentation. */
task updateDevTOC( type:Exec, dependsOn: ['cloneLibs' ]) {
executable file("$buildDir/utils/html-tools/html-update-toc")
args file("${projectDir}/src/docs/manual/dev.html")
environment PATH: "$System.env.PATH:$buildDir/utils/html-tools"
}
// TODO: Why isn't this a Javadoc task? That is, why does it call javadoc
// from the command line?
/*
* Applies OptionsDoclet to src/docs/manual/index.html to add
* command-line arguments extracted from the given @Option annotated classes.
* Applied in-place.
*/
task updateUserOptions(dependsOn: 'assemble') {
description "Runs OptionsDoclet on src/docs/manual/index.html"
def classpath = sourceSets.main.runtimeClasspath.asPath
def docFile = file("${projectDir}/src/docs/manual/index.html")
def options = [
"-classpath", classpath,
"-docletpath", classpath, // doclet loads class files from the documented classes
"-doclet", "org.plumelib.options.OptionsDoclet",
"-docfile", docFile,
"-i",
]
def fileList = [
file("${projectDir}/src/main/java/randoop/main/GenInputsAbstract.java"),
file("${projectDir}/src/main/java/randoop/generation/AbstractGenerator.java"),
file("${projectDir}/src/main/java/randoop/util/ReflectionExecutor.java"),
file("${projectDir}/src/main/java/randoop/main/Minimize.java")
]
doLast {
project.exec {
commandLine = [ "javadoc" ] + options + fileList
}
}
}
/* Requires that the html5validator program is installed */
task html5validatorExists {
doLast {
def result = exec {
def command = "command -v html5validator"
ignoreExitValue = true
executable "bash" args "-l", "-c", command
}
if (result.getExitValue() != 0) {
ant.fail('html5validator is not installed. See https://randoop.github.io/randoop/manual/dev.html#prerequisites .')
}
}
}
/*
* Generate/update and move documentation into build/docs directory.
*/
task manual(type: DefaultTask, dependsOn: [ 'updateUserOptions', 'updateUserTOC', 'updateDevTOC', 'html5validatorExists']) {
group 'Documentation'
description "Adds options and TOC to documentation in src/docs"
doLast {
exec {
environment PATH: "$System.env.PATH"
commandLine "html5validator", "--root", file("${projectDir}/src/docs/manual")
}
}
}
build.dependsOn manual
/*
* Applies HTML5 validator to API javadoc.
*/
task validateAPI(type: Exec, dependsOn: ['javadoc', 'html5validatorExists']) {
group 'Documentation'
description "Run html5validator to find HTML errors in API documentation"
// Prior to Java 9, javadoc does not comply with HTML5.
if (JavaVersion.current().isJava9Compatible()) {
environment PATH: "$System.env.PATH"
commandLine "html5validator", "--root", file("${buildDir}/docs/api")
} else {
commandLine "echo", "WARNING: HTML validation of API is only run in Java 9+."
}
}
/*
* WARNING: do not run this task unless you mean to wipe out the project pages
* directory. It can be repopulated by publishSite, but the contents will be
* based on changes to the files in src/docs and the Javadoc in the source.
*/
task cleanSite {
group=null
description 'Removes all files from the project pages directory (CAUTION!)'
def siteDir = file("${projectDir}/../randoop-branch-gh-pages")
def oldSiteFiles = fileTree(siteDir) {
exclude 'README.md'
}
doLast {
delete oldSiteFiles
}
}
/*
* Publishes changes to the project documentation to the project pages directory
* (gh-pages branch). This task ensures that all old site files are removed, new API
* documentation is generated, the manual is updated, and the HTML has been
* validated.
*
* Note that the contents of any subdirectory of build/docs will be included in
* the site. Currently, this is only the api directory generated by the javadoc
* task.
*
* All site files will be read-only.
*/
task publishSite (dependsOn: ['cleanSite', 'javadoc', 'validateAPI', 'manual']) {
group 'Publishing'
description 'Publish changes to site files and javadoc to the project pages directory'
def siteDir = file("${projectDir}/../randoop-branch-gh-pages")
def buildDocsDir = file("${buildDir}/docs") // include any built docs (e.g., api)
def newSiteFiles = fileTree("${projectDir}/src/docs") {
exclude 'README.md'
exclude 'api'
}
doLast {
copy {
from (buildDocsDir) //copy api
from (newSiteFiles)
into siteDir
fileMode = Integer.parseInt("444", 8)
}
}
}
/*
* Applies HTML5 validator to project site HTML, including the manual
*/
task validateSite(dependsOn: 'html5validatorExists') {
description "Run html5validator to find HTML errors in site files (excludes manual and api)"
if (JavaVersion.current().isJava9Compatible()) {
exec {
environment PATH: "$System.env.PATH"
commandLine "html5validator", "--root", "src/docs/"
}
} else if (JavaVersion.current().isJava8Compatible()) {
// Before JDK9, Javadoc did not create proper HTML 5.
exec {
environment PATH: "$System.env.PATH"
commandLine "html5validator", "--root", "src/docs/", "--ignore", "src/docs/api"
}
} else {
commandLine "echo", "WARNING: HTML validation of API documentation is only run in Java 9+."
}
}
task buildRelease(type: DefaultTask, dependsOn: [ 'assemble', 'check', 'publishSite', 'validateSite', 'distributionZip' ]) {
group 'Publishing'
description "Builds system and documentation, validates HTML, and publishes site"
}
/*************** Other tool configs *************/
/* Make Emacs TAGS table */
task tags(type: Exec, dependsOn: 'cloneLibs') {
group 'Emacs'
description "Run etags to create an Emacs TAGS table"
commandLine "bash", "-c", "find src/ agent/covered-class/src/ agent/replacecall/src/ -name '*.java' | grep -v src/testInput | $buildDir/utils/plume-scripts/sort-directory-order | xargs etags"
}
/* Make Emacs TAGS table, with only Randoop code (not test code) */
task tagsNoTests(type: Exec, dependsOn: 'cloneLibs') {
group 'Emacs'
description "Run etags to create an Emacs TAGS table"
commandLine "bash", "-c", "find src/ -name *.java | $buildDir/utils/plume-scripts/sort-directory-order | grep -v /testInput/ | xargs etags"
}
/* Run checklink */
task checklink(type: Exec, dependsOn: 'cloneLibs') {
group 'Validation'
description "Run checklink on randoop.github.io/randoop/ and write output to checklink-log.txt"
environment PATH: "$System.env.PATH:$buildDir/utils/checklink"
commandLine 'bash', '-c', """
checklink -q -r `grep -v '^#' build/utils/checklink/checklink-args.txt` https://randoop.github.io/randoop/ &> checklink-log.txt
"""
}
task installGitHooks(type: Copy) {
group=null
description "Installs git hooks for pre-commit"
from 'scripts/'
into '.git/hooks'
}
/* Always run this task. */
gradle.startParameter.taskNames = [":installGitHooks"] + gradle.startParameter.taskNames