Ignoring build.properties file
[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 srcDist(type: Zip) {
112     group = "JPF Build"
113     description = "Builds the source distribution"
114
115     baseName = project.name
116     version = "git rev-parse --short HEAD".execute().text.trim()
117     classifier = "src"
118     extension = "zip"
119
120     destinationDir = buildDir
121     includeEmptyDirs = false
122
123     from projectDir
124     include "build.gradle"
125     include "settings.gradle"
126     include "gradlew"
127     include "gradlew.bat"
128     include "gradle/**/*"
129     include "nbproject/**/*"
130     include "eclipse/**/*"
131     include "src/**/*"
132     include "bin/**/*"
133     include "jpf.properties"
134     include "build.properties"
135     include "LICENSE-2.0.txt"
136     include "README.md"
137 }
138
139 task dist(type: Zip) {
140     group = "JPF Build"
141     description = "Builds binary distribution"
142
143     baseName = project.name
144     version = "git rev-parse --short HEAD".execute().text.trim()
145     extension = "zip"
146
147     destinationDir = buildDir
148     includeEmptyDirs = false
149
150     from projectDir
151     include "jpf.properties"
152     include "build.properties"
153     include "bin/**/*"
154     include "lib/**/*"
155     include "${buildDir.name}/**/*.jar"
156 }
157
158 task jpfClassesJar(type: Jar) {
159     archiveName = "jpf-classes.jar"
160     destinationDir = file("${buildDir}")
161
162     description = "Creates the ${archiveName} file."
163     group = "JPF Jars"
164
165     dependsOn compile
166
167     from sourceSets.classes.java.outputDir
168     from sourceSets.annotations.java.outputDir
169     from(sourceSets.main.java.outputDir) {
170         include "gov/nasa/jpf/JPFShell.class"
171         include "gov/nasa/jpf/vm/Verify.class"
172         include "gov/nasa/jpf/util/TypeRef.class"
173         include "gov/nasa/jpf/util/test/TestJPF.class"
174         include "gov/nasa/jpf/util/test/TestMultiProcessJPF.class"
175         include "gov/nasa/jpf/util/test/TestJPFHelper.class"
176     }
177 }
178
179 task jpfJar(type: Jar) {
180     archiveName = "jpf.jar"
181     destinationDir = file("${buildDir}")
182
183     description = "Creates the ${archiveName} file."
184     group = "JPF Jars"
185
186     dependsOn compile
187
188     from sourceSets.main.java.outputDir
189     from sourceSets.peers.java.outputDir
190     from sourceSets.annotations.java.outputDir
191     from(sourceSets.classes.java.outputDir) {
192         include "org/junit/*.class"
193     }
194
195     manifest {
196         attributes(
197             "Built-By": System.getProperty("user.name"),
198             "Implementation-Vendor": "NASA Ames Research Center",
199             "Implementation-Title": "Java Pathfinder core system",
200             "Implementation-Version": "1234" //FIXME
201         )
202     }
203 }
204
205 task annotationsJar(type: Jar) {
206     archiveName = "jpf-annotations.jar"
207     destinationDir = file("${buildDir}")
208
209     description = "Creates the ${archiveName} file."
210     group = "JPF Jars"
211
212     dependsOn compile
213
214     from sourceSets.annotations.java.outputDir
215 }
216
217 task classloaderSpecificTestsJar(type: Jar) {
218     archiveName = "classloader_specific_tests.jar"
219     destinationDir = file("${buildDir}")
220
221     description = "Creates the ${archiveName} file."
222     group = "JPF Jars"
223
224     dependsOn compile
225
226     from(sourceSets.test.java.outputDir) {
227         include "classloader_specific_tests/*.class"
228     }
229 }
230
231 task runJpfJar(type: Jar) {
232     archiveName = "RunJPF.jar"
233     destinationDir = file("${buildDir}")
234
235     description = "Creates the ${archiveName} file."
236     group = "JPF Jars"
237
238     dependsOn compile
239
240     from(sourceSets.main.java.outputDir) {
241         include "gov/nasa/jpf/tool/Run.class"
242         include "gov/nasa/jpf/tool/RunJPF.class"
243         include "gov/nasa/jpf/Config.class"
244         include "gov/nasa/jpf/ConfigChangeListener.class"
245         include "gov/nasa/jpf/Config\$MissingRequiredKeyException.class"
246         include "gov/nasa/jpf/JPFClassLoader.class"
247         include "gov/nasa/jpf/JPFShell.class"
248         include "gov/nasa/jpf/JPFException.class"
249         include "gov/nasa/jpf/JPFConfigException.class"
250         include "gov/nasa/jpf/JPFTargetException.class"
251         include "gov/nasa/jpf/util/JPFSiteUtils.class"
252         include "gov/nasa/jpf/util/FileUtils.class"
253         include "gov/nasa/jpf/util/StringMatcher.class"
254         include "gov/nasa/jpf/util/Pair.class"
255     }
256     manifest {
257         attributes(
258             "Built-By": System.getProperty("user.name"),
259             "Implementation-Vendor": "NASA Ames Research Center",
260             "Implementation-Title": "Java Pathfinder core launch system",
261             "Implementation-Version": "1234", //FIXME
262             "Main-Class": "gov.nasa.jpf.tool.RunJPF"
263         )
264     }
265 }
266
267 task runTestJar(type: Jar) {
268     archiveName = "RunTest.jar"
269     destinationDir = file("${buildDir}")
270
271     description = "Creates the ${archiveName} file."
272     group = "JPF Jars"
273
274     dependsOn compile
275
276     from(sourceSets.main.java.outputDir) {
277         include "gov/nasa/jpf/tool/Run.class"
278         include "gov/nasa/jpf/tool/RunTest.class"
279         include "gov/nasa/jpf/tool/RunTest\$Failed.class"
280         include "gov/nasa/jpf/Config.class"
281         include "gov/nasa/jpf/ConfigChangeListener.class"
282         include "gov/nasa/jpf/Config\$MissingRequiredKeyException.class"
283         include "gov/nasa/jpf/JPFClassLoader.class"
284         include "gov/nasa/jpf/JPFException.class"
285         include "gov/nasa/jpf/JPFConfigException.class"
286         include "gov/nasa/jpf/util/JPFSiteUtils.class"
287         include "gov/nasa/jpf/util/FileUtils.class"
288         include "gov/nasa/jpf/util/StringMatcher.class"
289         include "gov/nasa/jpf/util/DevNullPrintStream.class"
290     }
291     manifest {
292         attributes(
293             "Built-By": System.getProperty("user.name"),
294             "Implementation-Vendor": "NASA Ames Research Center",
295             "Implementation-Title": "Java Pathfinder test launch system",
296             "Implementation-Version": "1234", // FIXME
297             "Main-Class": "gov.nasa.jpf.tool.RunTest"
298         )
299     }
300 }
301
302 task buildJars {
303     group = "JPF Build"
304     description = "Generates the core JPF jar files."
305
306     dependsOn buildInfo
307
308     dependsOn classloaderSpecificTestsJar, annotationsJar,
309               jpfClassesJar, jpfJar, runJpfJar,
310               runTestJar
311 }
312
313 test {
314     group = "JPF Build"
315     description = "Runs core regression tests."
316
317     dependsOn buildJars
318
319     enableAssertions = true
320     forkEvery = 1
321
322     maxHeapSize = "1024m"
323
324     include "**/*Test.class"
325     exclude "**/SplitInputStreamTest.class"
326     exclude "**/JPF_*.class"
327
328     testLogging {
329         events "passed", "skipped", "failed"
330     }
331
332     afterSuite { testDescriptor, result ->
333         if (!testDescriptor.parent) {
334             println "Test Execution: ${result.resultType}"
335
336             def summaryFields = ["${result.testCount} tests",
337                                  "${result.successfulTestCount} passed",
338                                  "${result.failedTestCount} failed",
339                                  "${result.skippedTestCount} skipped"]
340
341             println "Summary: " + summaryFields.join(", ")
342         }
343     }
344 }
345
346 defaultTasks "buildJars"