-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
215 lines (185 loc) · 6.76 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
/// Why doesn't this work on Travis under Java 7?
/// The same text does in Randoop's build.gradle file.
plugins {
// Plugin that applies Google-Java-format to the Java files in the project.
// https://github.com/sherter/google-java-format-gradle-plugin
// id 'com.github.sherter.google-java-format' version '0.6'
id 'com.github.johnrengelman.shadow' version '2.0.4'
}
apply plugin: 'java'
ext {
jsr308 = System.getenv('JSR308') ?: file(new File("..")).absolutePath
cfPath = "${jsr308}/checker-framework"
jsr308langtoolsPath = "${jsr308}/jsr308-langtools"
afu = "${jsr308}/annotation-tools/annotation-file-utilities"
castPath = "${jsr308}/cast-checker"
}
println '==================================='
println ' Cast Checker '
println '==================================='
println ''
println '-------------------------------'
println 'Important Environment Variables'
println '-------------------------------'
println 'JSR308: ' + jsr308
println 'CF: ' + cfPath
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(dir: "${cfPath}/checker/dist", include: "checker.jar")
// CF test lib dependency
testCompile fileTree(dir: "${cfPath}/framework-test/build/libs", include: "framework-test-*.jar")
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDirs = ["src"]
}
resources {
srcDirs += ['src']
exclude "**/*.java"
}
}
test {
java {
// TODO: we shouldn't need source level dependency on CFITest
srcDirs = ["tests"]
}
}
}
compileJava {
options.compilerArgs = [
'-implicit:class',
'-Awarns',
'-Xmaxwarns', '10000',
]
}
afterEvaluate {
// Create a task for each JUnit test class whose name is the same as the JUnit class name.
sourceSets.test.allJava.filter { it.path.contains("${castPath}/tests") }.forEach { file ->
String junitClassName = file.name.replaceAll(".java", "")
String testName = junitClassName.replaceAll("Test", "")
tasks.create(name: "${junitClassName}", type: Test) {
description "Run ${testName} tests."
include "**/${name}.class"
}
}
// Configure JUnit tests
tasks.withType(Test) {
group 'Verification'
systemProperties 'path.afu.scripts': "${afu}/scripts",
JDK_JAR: "${cfPath}/checker/dist/jdk8.jar"
environment "external_checker_classpath", "${castPath}/build/classes/java/main:${castPath}/build/libs/cast-checker.jar"
jvmArgs "-Xbootclasspath/p:${cfPath}/dist/javac.jar"
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// The following prints out each time a test is passed.
events "passed", "skipped", "failed", "standardOut", "standardError"
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
showExceptions true
showCauses true
showStackTraces true
showStandardStreams true
}
// After each test, print a summary.
afterSuite { desc, result ->
if (desc.getClassName() != null) {
long mils = result.getEndTime() - result.getStartTime()
double seconds = mils / 1000.0
println "Testsuite: ${desc.getClassName()}\n" +
"Tests run: ${result.testCount}, " +
"Failures: ${result.failedTestCount}, " +
"Skipped: ${result.skippedTestCount}, " +
"Time elapsed: ${seconds} sec\n"
}
}
}
}
tasks.clean {
delete += "build"
delete += "dist"
delete += "testdata"
}
/* Configuration for formatting */
/* Copy from https://github.com/randoop/randoop/blob/master/build.gradle */
task getCodeFormatScripts {
description "Obtain the run-google-java-format scripts"
doLast {
if (! new File("$projectDir/build/utils/.run-google-java-format").exists()) {
Grgit.clone(dir: "$projectDir/build/utils/.run-google-java-format", uri: 'https://github.com/plume-lib/run-google-java-format.git')
} else {
def rgjfGit = Grgit.open(dir: "$projectDir/build/utils/.run-google-java-format")
rgjfGit.pull()
}
}
}
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 "testinput/**" exclude "testdata/**" exclude "build/**"
} as List
def pythonArgs = javaFiles.clone()
pythonArgs.add(0, "$projectDir/build/utils/.run-google-java-format/check-google-java-format.py")
pythonArgs.add(1, "--aosp") // 4 space indentation
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 "src/**/*.java" exclude "testinput/**" exclude "testdata/**" exclude "build/**"
} as List
def pythonArgs = javaFiles.clone()
pythonArgs.add(0, "$projectDir/build/utils/.run-google-java-format/run-google-java-format.py")
pythonArgs.add(1, "--aosp") // 4 space indentation
commandLine "python"
args pythonArgs
}
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
// Commented out because plugins section is commented out
/* Configuration for formatting */
/*
googleJavaFormat {
// toolVersion '1.3'
options style: 'AOSP'
}
tasks.googleJavaFormat {
group 'Formatting'
description = "Reformat Java source code with Google-Java-format"
exclude 'testing'
exclude 'testdata'
exclude 'annotated'
exclude 'worked-benchmarks'
}
tasks.verifyGoogleJavaFormat {
group 'Formatting'
description = "Check Java source code is in Google-Java-format"
exclude 'testing'
exclude 'testdata'
exclude 'annotated'
exclude 'worked-benchmarks'
}
*/