Mercurial > public > gradleplugins
comparison src/main/groovy/org/ssdt_ohio/gradle/plugins/VersionClassPlugin.groovy @ 27:68b1ec64996b
Merge
author | Christopher Springer <springer@nwoca.org> |
---|---|
date | Wed, 21 Dec 2016 13:16:05 +0000 |
parents | 278d28eea819 |
children | bf31e9ad44cf |
comparison
equal
deleted
inserted
replaced
24:cfbdbeba877f | 27:68b1ec64996b |
---|---|
10 def void apply(Project project) { | 10 def void apply(Project project) { |
11 project.getPlugins().apply(GroovyPlugin.class) | 11 project.getPlugins().apply(GroovyPlugin.class) |
12 def genSrc = 'generated-src/version' | 12 def genSrc = 'generated-src/version' |
13 def generatedSrcDir = new File(project.buildDir, genSrc) | 13 def generatedSrcDir = new File(project.buildDir, genSrc) |
14 | 14 |
15 def makeVersionClassTask = project.task('makeVersionClass') << { | 15 def makeVersionClassTask = project.task('makeVersionClass') { |
16 doLast { | |
17 def now = new Date().format('yyyy-MM-dd hh:mm:ss') | |
16 | 18 |
17 def now = new Date().format('yyyy-MM-dd hh:mm:ss') | 19 def buildNumber = -1 |
20 if (project.rootProject?.file('build-number.txt').exists()) { | |
21 def props = new Properties() | |
22 project.rootProject?.file('build-number.txt').withInputStream {stream -> | |
23 props.load(stream) | |
24 } | |
25 buildNumber = props['build.number'] | |
26 } | |
18 | 27 |
19 def buildNumber = -1 | 28 def targetPackage = getTargetClass(project) |
20 if (project.rootProject?.file('build-number.txt').exists()) { | |
21 def props = new Properties() | |
22 project.rootProject?.file('build-number.txt').withInputStream {stream -> | |
23 props.load(stream) | |
24 } | |
25 buildNumber = props['build.number'] | |
26 } | |
27 | 29 |
28 def targetPackage = getTargetClass(project) | 30 if (!targetPackage) { |
31 return | |
32 } | |
29 | 33 |
30 if (!targetPackage) { | 34 def outFile = new File(generatedSrcDir, "groovy/" + targetPackage.replaceAll('\\.', "/") + "/ProjectVersion.groovy") |
31 return | |
32 } | |
33 | 35 |
34 def outFile = new File(generatedSrcDir, "groovy/" + targetPackage.replaceAll('\\.', "/") + "/ProjectVersion.groovy") | 36 outFile.getParentFile().mkdirs() |
37 logger.info("creating $targetPackage in $outFile") | |
38 def f = new FileWriter(outFile) | |
39 f.write(""" | |
40 package $targetPackage | |
41 /** | |
42 * Generated by gradle build. $now ($buildNumber) | |
43 * @version ${project.version} | |
44 */ | |
45 public class ProjectVersion { | |
35 | 46 |
36 outFile.getParentFile().mkdirs() | 47 final String name = "${project.name}" |
37 logger.info("creating $targetPackage in $outFile") | 48 final String group = "${project.group}" |
38 def f = new FileWriter(outFile) | 49 final String version = "${project.version}" |
39 f.write(""" | 50 final String buildDate = "$now" |
40 package $targetPackage | 51 final int buildNumber = $buildNumber |
41 /** | |
42 * Generated by gradle build. $now ($buildNumber) | |
43 * @version ${project.version} | |
44 */ | |
45 public class ProjectVersion { | |
46 | 52 |
47 final String name = "${project.name}" | 53 String getFullVersion() { |
48 final String group = "${project.group}" | 54 "\$version \$buildDate (#\$buildNumber)" |
49 final String version = "${project.version}" | 55 } |
50 final String buildDate = "$now" | |
51 final int buildNumber = $buildNumber | |
52 | 56 |
53 String getFullVersion() { | 57 String getId() { |
54 "\$version \$buildDate (#\$buildNumber)" | 58 "\$group:\$name:\$version" |
55 } | 59 } |
56 | 60 |
57 String getId() { | 61 String toString() { |
58 "\$group:\$name:\$version" | 62 "\$id \$buildDate (#\$buildNumber)" |
59 } | 63 } |
60 | 64 } |
61 String toString() { | 65 """) |
62 "\$id \$buildDate (#\$buildNumber)" | 66 f.close() |
63 } | 67 } |
64 } | |
65 """) | |
66 f.close() | |
67 } | 68 } |
68 | 69 |
69 project.sourceSets { | 70 project.sourceSets { |
70 main { | 71 main { |
71 groovy { | 72 groovy { |