Skip to content

Commit 81012dc

Browse files
authored
Add versions to build (#3)
* Add build.gradle versions * Create versions.gradle * Update appveyor.yml
1 parent ec8a0b8 commit 81012dc

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ install:
1919
cache: C:\Users\appveyor\.gradle
2020
build_script:
2121
- ps: >-
22-
./gradlew build --continue --no-daemon
22+
./gradlew build updateVersions --continue --no-daemon
2323
2424
if ($lastexitcode -ne 0) {
2525
throw ("Exec: " + $errorMessage)

build.gradle

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
plugins {
22
id 'java-gradle-plugin'
33
id 'maven-publish'
4+
id "edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin" version "2.0"
45
id "com.gradle.plugin-publish" version "0.9.10"
56
}
67

8+
// Ensure that the WPILibVersioningPlugin is setup by setting the release type, if releaseType wasn't
9+
// already specified on the command line
10+
if (!hasProperty('releaseType')) {
11+
WPILibVersion {
12+
releaseType = 'dev'
13+
}
14+
}
15+
16+
ext.pubVersion = ''
17+
if (project.hasProperty("publishVersion")) {
18+
pubVersion = project.publishVersion
19+
} else {
20+
pubVersion = WPILibVersion.version
21+
}
22+
23+
if (pubVersion == '') {
24+
pubVersion = '0.0.1-unknown'
25+
}
26+
727
group 'edu.wpi.first'
8-
version '0.0.4'
28+
version pubVersion
929

1030
repositories {
1131
maven {
@@ -59,6 +79,8 @@ gradlePlugin {
5979
}
6080
}
6181

82+
apply from: 'versions.gradle'
83+
6284
task wrapper(type: Wrapper) {
6385
gradleVersion = '4.7'
6486
}

versions.gradle

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
def versionFiles = [new File('extension/package.json')]
2+
def oldVersionFile = new File("$buildDir/existingVersions.json")
3+
4+
task updateVersions(type: Task) {
5+
doLast {
6+
def existingVersions = []
7+
8+
versionFiles.each {
9+
def file = it
10+
11+
def parsedJson = new groovy.json.JsonSlurper().parseText(file.text)
12+
13+
def existingVersion = new Expando();
14+
existingVersion.version = parsedJson.version
15+
16+
existingVersion.file = file.toString()
17+
18+
existingVersions << existingVersion
19+
20+
parsedJson.version = pubVersion
21+
22+
def converted = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(parsedJson))
23+
24+
file.text = converted
25+
}
26+
if (oldVersionFile.exists()) {
27+
return
28+
}
29+
30+
oldVersionFile.parentFile.mkdirs()
31+
32+
oldVersionFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(existingVersions))
33+
}
34+
}
35+
36+
task resetVersions(type: Task) {
37+
doLast {
38+
def oldVersions = new groovy.json.JsonSlurper().parseText(oldVersionFile.text)
39+
versionFiles.each {
40+
def file = it
41+
42+
def parsedJson = new groovy.json.JsonSlurper().parseText(file.text)
43+
for (Object oldv : oldVersions) {
44+
if (file.toString().equals(oldv.file)) {
45+
parsedJson.version = oldv.version
46+
break
47+
}
48+
}
49+
def converted = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(parsedJson))
50+
51+
file.text = converted
52+
}
53+
oldVersionFile.delete()
54+
}
55+
}

0 commit comments

Comments
 (0)