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