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