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