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