Created buildinfo task (#78)
[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 clean {
48     group = "JPF Build"
49 }
50
51 task generateVersion {
52     description = "Generates the .version file with the current revision hash"
53     group = "JPF Build Properties"
54
55     doLast {
56         def revision = "git rev-parse HEAD".execute().text
57         new File(".version").withWriter("utf-8") { writer ->
58             writer.writeLine revision
59         }
60     }
61 }
62
63 task buildInfo {
64     group = "JPF Build Properties"
65     description = "Creates build info properties."
66     doLast {
67
68         // Must fail if there are uncommitted changes
69         def status  = "git status --short".execute().text.trim()
70         if (!status.isEmpty()) {
71             throw new GradleException("There are uncomitted changes:\n " + status)
72         }
73         Properties info = new Properties()
74
75         def revision = "git rev-parse --short HEAD".execute().text.trim()
76         def userName = ["git", "log", "-1", "--format=%an <%ae>"].execute().text.trim()
77         def date = "git log -1 --format=%ci".execute().text.trim()
78
79         info.setProperty("revision", revision)
80         info.setProperty("date", date)
81         info.setProperty("author", userName)
82         info.setProperty("os.arch", System.getProperty("os.arch"))
83         info.setProperty("os.name", System.getProperty("os.name"))
84         info.setProperty("user.country", System.getProperty("user.country"))
85         info.setProperty("java.version", System.getProperty("java.version"))
86
87         def writer = new File("build.properties").newWriter("utf-8")
88         info.store(writer, "JPF core build info")
89         writer.close()
90     }
91 }
92
93 task compile(type: Copy) {
94     group = "JPF Build"
95     description = "Compiles all JPF core sources."
96
97     // These are automatic generated tasks from the Java Gradle Plugin.
98     // Gradle is able to infer the ordering of the source sets
99     // due to the compileClasspath attribute
100     dependsOn compileTestJava, compileExamplesJava, generateVersion
101
102     // Copies build.properties file to the build directory
103     from "build.properties"
104     into sourceSets.main.java.outputDir.path + "/gov/nasa/jpf"
105
106     // Copies .version file to the build directory
107     from ".version"
108     into sourceSets.main.java.outputDir.path + "/gov/nasa/jpf"
109 }
110
111 task jpfClassesJar(type: Jar) {
112     archiveName = "jpf-classes.jar"
113     destinationDir = file("${buildDir}")
114
115     description = "Creates the ${archiveName} file."
116     group = "JPF Jars"
117
118     dependsOn compile
119
120     from sourceSets.classes.java.outputDir
121     from sourceSets.annotations.java.outputDir
122     from(sourceSets.main.java.outputDir) {
123         include "gov/nasa/jpf/JPFShell.class"
124         include "gov/nasa/jpf/vm/Verify.class"
125         include "gov/nasa/jpf/util/TypeRef.class"
126         include "gov/nasa/jpf/util/test/TestJPF.class"
127         include "gov/nasa/jpf/util/test/TestMultiProcessJPF.class"
128         include "gov/nasa/jpf/util/test/TestJPFHelper.class"
129     }
130 }
131
132 task jpfJar(type: Jar) {
133     archiveName = "jpf.jar"
134     destinationDir = file("${buildDir}")
135
136     description = "Creates the ${archiveName} file."
137     group = "JPF Jars"
138
139     dependsOn compile
140
141     from sourceSets.main.java.outputDir
142     from sourceSets.peers.java.outputDir
143     from sourceSets.annotations.java.outputDir
144     from(sourceSets.classes.java.outputDir) {
145         include "org/junit/*.class"
146     }
147
148     manifest {
149         attributes(
150             "Built-By": System.getProperty("user.name"),
151             "Implementation-Vendor": "NASA Ames Research Center",
152             "Implementation-Title": "Java Pathfinder core system",
153             "Implementation-Version": "1234" //FIXME
154         )
155     }
156 }
157
158 task annotationsJar(type: Jar) {
159     archiveName = "jpf-annotations.jar"
160     destinationDir = file("${buildDir}")
161
162     description = "Creates the ${archiveName} file."
163     group = "JPF Jars"
164
165     dependsOn compile
166
167     from sourceSets.annotations.java.outputDir
168 }
169
170 task classloaderSpecificTestsJar(type: Jar) {
171     archiveName = "classloader_specific_tests.jar"
172     destinationDir = file("${buildDir}")
173
174     description = "Creates the ${archiveName} file."
175     group = "JPF Jars"
176
177     dependsOn compile
178
179     from(sourceSets.test.java.outputDir) {
180         include "classloader_specific_tests/*.class"
181     }
182 }
183
184 task runJpfJar(type: Jar) {
185     archiveName = "RunJPF.jar"
186     destinationDir = file("${buildDir}")
187
188     description = "Creates the ${archiveName} file."
189     group = "JPF Jars"
190
191     dependsOn compile
192
193     from(sourceSets.main.java.outputDir) {
194         include "gov/nasa/jpf/tool/Run.class"
195         include "gov/nasa/jpf/tool/RunJPF.class"
196         include "gov/nasa/jpf/Config.class"
197         include "gov/nasa/jpf/ConfigChangeListener.class"
198         include "gov/nasa/jpf/Config\$MissingRequiredKeyException.class"
199         include "gov/nasa/jpf/JPFClassLoader.class"
200         include "gov/nasa/jpf/JPFShell.class"
201         include "gov/nasa/jpf/JPFException.class"
202         include "gov/nasa/jpf/JPFConfigException.class"
203         include "gov/nasa/jpf/JPFTargetException.class"
204         include "gov/nasa/jpf/util/JPFSiteUtils.class"
205         include "gov/nasa/jpf/util/FileUtils.class"
206         include "gov/nasa/jpf/util/StringMatcher.class"
207         include "gov/nasa/jpf/util/Pair.class"
208     }
209     manifest {
210         attributes(
211             "Built-By": System.getProperty("user.name"),
212             "Implementation-Vendor": "NASA Ames Research Center",
213             "Implementation-Title": "Java Pathfinder core launch system",
214             "Implementation-Version": "1234", //FIXME
215             "Main-Class": "gov.nasa.jpf.tool.RunJPF"
216         )
217     }
218 }
219
220 task runTestJar(type: Jar) {
221     archiveName = "RunTest.jar"
222     destinationDir = file("${buildDir}")
223
224     description = "Creates the ${archiveName} file."
225     group = "JPF Jars"
226
227     dependsOn compile
228
229     from(sourceSets.main.java.outputDir) {
230         include "gov/nasa/jpf/tool/Run.class"
231         include "gov/nasa/jpf/tool/RunTest.class"
232         include "gov/nasa/jpf/tool/RunTest\$Failed.class"
233         include "gov/nasa/jpf/Config.class"
234         include "gov/nasa/jpf/ConfigChangeListener.class"
235         include "gov/nasa/jpf/Config\$MissingRequiredKeyException.class"
236         include "gov/nasa/jpf/JPFClassLoader.class"
237         include "gov/nasa/jpf/JPFException.class"
238         include "gov/nasa/jpf/JPFConfigException.class"
239         include "gov/nasa/jpf/util/JPFSiteUtils.class"
240         include "gov/nasa/jpf/util/FileUtils.class"
241         include "gov/nasa/jpf/util/StringMatcher.class"
242         include "gov/nasa/jpf/util/DevNullPrintStream.class"
243     }
244     manifest {
245         attributes(
246             "Built-By": System.getProperty("user.name"),
247             "Implementation-Vendor": "NASA Ames Research Center",
248             "Implementation-Title": "Java Pathfinder test launch system",
249             "Implementation-Version": "1234", // FIXME
250             "Main-Class": "gov.nasa.jpf.tool.RunTest"
251         )
252     }
253 }
254
255 task buildJars {
256     group = "JPF Build"
257     description = "Generates the core JPF jar files."
258
259     dependsOn classloaderSpecificTestsJar, annotationsJar,
260               jpfClassesJar, jpfJar, runJpfJar,
261               runTestJar
262 }
263
264 test {
265     group = "JPF Build"
266     description = "Runs core regression tests."
267
268     dependsOn buildJars
269
270     enableAssertions = true
271     forkEvery = 1
272
273     maxHeapSize = "1024m"
274
275     include "**/*Test.class"
276     exclude "**/SplitInputStreamTest.class"
277     exclude "**/JPF_*.class"
278
279     testLogging {
280         events "passed", "skipped", "failed"
281     }
282
283     afterSuite { testDescriptor, result ->
284         if (!testDescriptor.parent) {
285             println "Test Execution: ${result.resultType}"
286
287             def summaryFields = ["${result.testCount} tests",
288                                  "${result.successfulTestCount} passed",
289                                  "${result.failedTestCount} failed",
290                                  "${result.skippedTestCount} skipped"]
291
292             println "Summary: " + summaryFields.join(", ")
293         }
294     }
295 }
296
297 defaultTasks "buildJars"