Editing main.jpf
[jpf-core.git] / gradle / build-resources.gradle
1 task generateVersion {
2     group = "JPF Build Resources"
3     description = "Generates the .version file with the current revision hash"
4     doLast {
5         def revision = "git rev-parse HEAD".execute().text
6         new File(".version").withWriter("utf-8") { writer ->
7             writer.writeLine revision
8         }
9     }
10 }
11
12 task generateBuildInfo {
13     group = "JPF Build Resources"
14     description = "Generates the build.properties file."
15     doLast {
16
17         Properties info = new Properties()
18
19         def status  = "git status --short".execute().text.trim()
20         def revision = "git rev-parse --short HEAD".execute().text.trim()
21         def userName = ["git", "log", "-1", "--format=%an <%ae>"].execute().text.trim()
22         def date = "git log -1 --format=%ci".execute().text.trim()
23
24         info.setProperty("revision", revision)
25         info.setProperty("date", date)
26         info.setProperty("author", userName)
27         info.setProperty("os.arch", System.getProperty("os.arch"))
28         info.setProperty("os.name", System.getProperty("os.name"))
29         info.setProperty("user.country", System.getProperty("user.country"))
30         info.setProperty("java.version", System.getProperty("java.version"))
31
32         def writer = new File("build.properties").newWriter("utf-8")
33         info.store(writer, "JPF core build info")
34         writer.close()
35     }
36 }
37
38 task copyResources(type: Copy) {
39     group = "JPF Build Resources"
40     description = "Copies .version and build.properties files to the build directory."
41
42     dependsOn generateBuildInfo
43     dependsOn generateVersion
44
45     from "build.properties"
46     into sourceSets.main.java.outputDir.path + "/gov/nasa/jpf"
47
48     from ".version"
49     into sourceSets.main.java.outputDir.path + "/gov/nasa/jpf"
50 }