|
@@ -1,8 +1,5 @@
|
1
|
1
|
subprojects {
|
2
|
|
- def jgit = new org.mdonoughe.JGitDescribeTask()
|
3
|
|
- jgit.dir = new File(projectDir, '../.git')
|
4
|
|
- jgit.subdir = project.name
|
5
|
|
- project.version = jgit.getDescription() + '-SNAPSHOT'
|
|
2
|
+ apply plugin: GitVersion
|
6
|
3
|
|
7
|
4
|
group = 'com.dmdirc.parser'
|
8
|
5
|
|
|
@@ -167,3 +164,43 @@ buildscript {
|
167
|
164
|
classpath group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '2.3.1.+'
|
168
|
165
|
}
|
169
|
166
|
}
|
|
167
|
+
|
|
168
|
+class GitVersion implements Plugin<Project> {
|
|
169
|
+ void apply(Project project) {
|
|
170
|
+ def jgit = new org.mdonoughe.JGitDescribeTask()
|
|
171
|
+ jgit.dir = getGitDirectory(project)
|
|
172
|
+
|
|
173
|
+ def subdir = getRelativeSubdir(project, jgit.dir)
|
|
174
|
+ if (!subdir.isEmpty()) {
|
|
175
|
+ jgit.subdir = subdir
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ def version = jgit.description
|
|
179
|
+ project.version = getProjectVersion(version)
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ File getGitDirectory(Project project) {
|
|
183
|
+ def target = project.projectDir
|
|
184
|
+ def gitDir = new File(target, '.git')
|
|
185
|
+ while (!gitDir.exists() && target.parentFile != null) {
|
|
186
|
+ target = target.parentFile
|
|
187
|
+ gitDir = new File(target, '.git')
|
|
188
|
+ }
|
|
189
|
+ return gitDir
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ String getRelativeSubdir(Project project, File gitDir) {
|
|
193
|
+ def parent = gitDir.parentFile.absolutePath
|
|
194
|
+ def target = project.projectDir.absolutePath
|
|
195
|
+ return target.substring(parent.length())
|
|
196
|
+ }
|
|
197
|
+
|
|
198
|
+ String getProjectVersion(String gitVersion) {
|
|
199
|
+ if (gitVersion.matches('.*-[0-9]+-[0-9a-f]+$')) {
|
|
200
|
+ return gitVersion + '-SNAPSHOT'
|
|
201
|
+ } else {
|
|
202
|
+ return gitVersion
|
|
203
|
+ }
|
|
204
|
+ }
|
|
205
|
+
|
|
206
|
+}
|