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