c2db9bc257ccfe0da29e0bf5fc4166d8ac92ac67
[jpf-core.git] / build.gradle
1 plugins {
2     id "com.gradle.build-scan" version "1.14"
3     id "java"
4     id "jacoco"
5 }
6
7 sourceCompatibility = 1.8
8 targetCompatibility = 1.8
9
10 ext.manifestCommonAttrbutes = manifest {
11     attributes(
12         "Built-By": System.getProperty("user.name"),
13         "Implementation-Vendor": "NASA Ames Research Center",
14         "Implementation-Version": "1234" // FIXME
15     )
16 }
17
18 buildScan {
19     termsOfServiceUrl = 'https://gradle.com/terms-of-service'
20     termsOfServiceAgree = 'yes'
21 }
22
23 jacocoTestReport {
24     reports {
25         xml.enabled = true
26         html.enabled = false
27     }
28 }
29
30 repositories {
31     mavenCentral()
32 }
33
34 dependencies {
35     testImplementation "junit:junit:4.12"
36 }
37
38 sourceSets {
39     annotations {
40         java.srcDirs = ["src/annotations"]
41         java.outputDir = file("${buildDir}/annotations")
42     }
43     main {
44         java.srcDirs = ["src/main"]
45         java.outputDir = file("${buildDir}/main")
46         compileClasspath += sourceSets.annotations.output
47     }
48     examples {
49         java.srcDirs = ["src/examples"]
50         java.outputDir = file("${buildDir}/examples")
51         compileClasspath += sourceSets.main.output
52     }
53     classes {
54         java.srcDirs = ["src/classes"]
55         java.outputDir = file("${buildDir}/classes")
56         compileClasspath += sourceSets.main.output + sourceSets.annotations.output
57     }
58     peers {
59         java.srcDirs = ["src/peers"]
60         java.outputDir = file("${buildDir}/peers")
61         compileClasspath += sourceSets.main.output + sourceSets.annotations.output
62     }
63     test {
64         java.srcDirs = ["src/tests"]
65         java.outputDir = file("${buildDir}/tests")
66         compileClasspath += sourceSets.annotations.output + sourceSets.classes.output + sourceSets.peers.output
67         runtimeClasspath += compileClasspath
68     }
69 }
70
71 task generateVersion {
72     group = "JPF Build Resources"
73     description = "Generates the .version file with the current revision hash"
74     doLast {
75         def revision = "git rev-parse HEAD".execute().text
76         new File(".version").withWriter("utf-8") { writer ->
77             writer.writeLine revision
78         }
79     }
80 }
81
82 task generateBuildInfo {
83     group = "JPF Build Resources"
84     description = "Generates the build.properties file."
85     doLast {
86
87         // Must fail if there are uncommitted changes
88         def status  = "git status --short".execute().text.trim()
89         if (!status.isEmpty()) {
90             throw new GradleException("There are uncomitted changes:\n " + status)
91         }
92         Properties info = new Properties()
93
94         def revision = "git rev-parse --short HEAD".execute().text.trim()
95         def userName = ["git", "log", "-1", "--format=%an <%ae>"].execute().text.trim()
96         def date = "git log -1 --format=%ci".execute().text.trim()
97
98         info.setProperty("revision", revision)
99         info.setProperty("date", date)
100         info.setProperty("author", userName)
101         info.setProperty("os.arch", System.getProperty("os.arch"))
102         info.setProperty("os.name", System.getProperty("os.name"))
103         info.setProperty("user.country", System.getProperty("user.country"))
104         info.setProperty("java.version", System.getProperty("java.version"))
105
106         def writer = new File("build.properties").newWriter("utf-8")
107         info.store(writer, "JPF core build info")
108         writer.close()
109     }
110 }
111
112 task copyResources(type: Copy) {
113     group = "JPF Build Resources"
114     description = "Copies .version and build.properties files to the build directory."
115
116     dependsOn generateBuildInfo
117     dependsOn generateVersion
118
119     from "build.properties"
120     into sourceSets.main.java.outputDir.path + "/gov/nasa/jpf"
121
122     from ".version"
123     into sourceSets.main.java.outputDir.path + "/gov/nasa/jpf"
124 }
125
126 task compile {
127     group = "JPF Build"
128     description = "Compiles all JPF core sources."
129
130     // These are automatic generated tasks from the Java Gradle Plugin.
131     // Gradle is able to infer the order of the source sets
132     // due to the compileClasspath attribute
133     dependsOn compileTestJava
134     dependsOn compileExamplesJava
135 }
136
137 task srcDist(type: Zip) {
138     group = "JPF Distribution"
139     description = "Builds the source distribution."
140
141     baseName = project.name
142     version = "git rev-parse --short HEAD".execute().text.trim()
143     classifier = "src"
144     extension = "zip"
145
146     destinationDir = buildDir
147     includeEmptyDirs = false
148
149     from projectDir
150     include "build.gradle"
151     include "settings.gradle"
152     include "gradlew"
153     include "gradlew.bat"
154     include "gradle/**/*"
155     include "src/**/*"
156     include "bin/**/*"
157     include "jpf.properties"
158     include "build.properties"
159     include "LICENSE-2.0.txt"
160     include "README.md"
161 }
162
163 task dist(type: Zip) {
164     group = "JPF Distribution"
165     description = "Builds binary distribution."
166
167     baseName = project.name
168     version = "git rev-parse --short HEAD".execute().text.trim()
169     extension = "zip"
170
171     destinationDir = buildDir
172     includeEmptyDirs = false
173
174     from projectDir
175     include "jpf.properties"
176     include "build.properties"
177     include "bin/**/*"
178     include "lib/**/*"
179     include "${buildDir.name}/**/*.jar"
180 }
181
182 task createJpfClassesJar(type: Jar) {
183     archiveName = "jpf-classes.jar"
184     destinationDir = file("${buildDir}")
185
186     group = "JPF Jars"
187     description = "Creates the ${archiveName} file."
188
189     dependsOn compile
190     dependsOn copyResources
191
192     from sourceSets.classes.java.outputDir
193     from sourceSets.annotations.java.outputDir
194     from(sourceSets.main.java.outputDir) {
195         include "gov/nasa/jpf/JPFShell.class"
196         include "gov/nasa/jpf/vm/Verify.class"
197         include "gov/nasa/jpf/util/TypeRef.class"
198         include "gov/nasa/jpf/util/test/TestJPF.class"
199         include "gov/nasa/jpf/util/test/TestMultiProcessJPF.class"
200         include "gov/nasa/jpf/util/test/TestJPFHelper.class"
201     }
202 }
203
204 task createJpfJar(type: Jar) {
205     archiveName = "jpf.jar"
206     destinationDir = file("${buildDir}")
207
208     group = "JPF Jars"
209     description = "Creates the ${archiveName} file."
210
211     dependsOn compile
212     dependsOn copyResources
213
214     from sourceSets.main.java.outputDir
215     from sourceSets.peers.java.outputDir
216     from sourceSets.annotations.java.outputDir
217     from(sourceSets.classes.java.outputDir) {
218         include "org/junit/*.class"
219     }
220
221     manifest {
222         attributes "Implementation-Title": "Java Pathfinder core system"
223         from manifestCommonAttrbutes
224     }
225 }
226
227 task createAnnotationsJar(type: Jar) {
228     archiveName = "jpf-annotations.jar"
229     destinationDir = file("${buildDir}")
230
231     group = "JPF Jars"
232     description = "Creates the ${archiveName} file."
233
234     dependsOn compile
235     dependsOn copyResources
236
237     from sourceSets.annotations.java.outputDir
238 }
239
240 task createClassloaderSpecificTestsJar(type: Jar) {
241     archiveName = "classloader_specific_tests.jar"
242     destinationDir = file("${buildDir}")
243
244     group = "JPF Jars"
245     description = "Creates the ${archiveName} file."
246
247     dependsOn compile
248     dependsOn copyResources
249
250     from(sourceSets.test.java.outputDir) {
251         include "classloader_specific_tests/*.class"
252     }
253 }
254
255 task createRunJpfJar(type: Jar) {
256     archiveName = "RunJPF.jar"
257     destinationDir = file("${buildDir}")
258
259     description = "Creates the ${archiveName} file."
260     group = "JPF Jars"
261
262     dependsOn compile
263     dependsOn copyResources
264
265     from(sourceSets.main.java.outputDir) {
266         include "gov/nasa/jpf/tool/Run.class"
267         include "gov/nasa/jpf/tool/RunJPF.class"
268         include "gov/nasa/jpf/Config.class"
269         include "gov/nasa/jpf/ConfigChangeListener.class"
270         include "gov/nasa/jpf/Config\$MissingRequiredKeyException.class"
271         include "gov/nasa/jpf/JPFClassLoader.class"
272         include "gov/nasa/jpf/JPFShell.class"
273         include "gov/nasa/jpf/JPFException.class"
274         include "gov/nasa/jpf/JPFConfigException.class"
275         include "gov/nasa/jpf/JPFTargetException.class"
276         include "gov/nasa/jpf/util/JPFSiteUtils.class"
277         include "gov/nasa/jpf/util/FileUtils.class"
278         include "gov/nasa/jpf/util/StringMatcher.class"
279         include "gov/nasa/jpf/util/Pair.class"
280     }
281     manifest {
282         attributes(
283             "Implementation-Title": "Java Pathfinder core launch system",
284             "Main-Class": "gov.nasa.jpf.tool.RunJPF"
285         )
286         from manifestCommonAttrbutes
287     }
288 }
289
290 task createRunTestJar(type: Jar) {
291     archiveName = "RunTest.jar"
292     destinationDir = file("${buildDir}")
293
294     description = "Creates the ${archiveName} file."
295     group = "JPF Jars"
296
297     dependsOn compile
298     dependsOn copyResources
299
300     from(sourceSets.main.java.outputDir) {
301         include "gov/nasa/jpf/tool/Run.class"
302         include "gov/nasa/jpf/tool/RunTest.class"
303         include "gov/nasa/jpf/tool/RunTest\$Failed.class"
304         include "gov/nasa/jpf/Config.class"
305         include "gov/nasa/jpf/ConfigChangeListener.class"
306         include "gov/nasa/jpf/Config\$MissingRequiredKeyException.class"
307         include "gov/nasa/jpf/JPFClassLoader.class"
308         include "gov/nasa/jpf/JPFException.class"
309         include "gov/nasa/jpf/JPFConfigException.class"
310         include "gov/nasa/jpf/util/JPFSiteUtils.class"
311         include "gov/nasa/jpf/util/FileUtils.class"
312         include "gov/nasa/jpf/util/StringMatcher.class"
313         include "gov/nasa/jpf/util/DevNullPrintStream.class"
314     }
315     manifest {
316         attributes(
317             "Implementation-Title": "Java Pathfinder test launch system",
318             "Main-Class": "gov.nasa.jpf.tool.RunTest"
319         )
320         from manifestCommonAttrbutes
321     }
322 }
323
324 task buildJars {
325     group = "JPF Build"
326     description = "Generates all core JPF jar files."
327
328     dependsOn createClassloaderSpecificTestsJar
329     dependsOn createAnnotationsJar
330     dependsOn createJpfClassesJar
331     dependsOn createJpfJar
332     dependsOn createRunJpfJar
333     dependsOn createRunTestJar
334 }
335
336 test {
337     description = "Runs core regression tests."
338
339     dependsOn buildJars
340
341     enableAssertions = true
342     forkEvery = 1
343
344     maxHeapSize = "1024m"
345
346     include "**/*Test.class"
347     exclude "**/SplitInputStreamTest.class"
348     exclude "**/JPF_*.class"
349
350     testLogging {
351         events "passed", "skipped", "failed"
352     }
353
354     afterSuite { testDescriptor, result ->
355         if (!testDescriptor.parent) {
356             println "Test Execution: ${result.resultType}"
357
358             def summaryFields = ["${result.testCount} tests",
359                                  "${result.successfulTestCount} passed",
360                                  "${result.failedTestCount} failed",
361                                  "${result.skippedTestCount} skipped"]
362
363             println "Summary: " + summaryFields.join(", ")
364         }
365     }
366 }
367
368 defaultTasks "buildJars"