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