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