forked from wpilibsuite/vscode-wpilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versions.gradle
55 lines (41 loc) · 1.68 KB
/
versions.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def versionFiles = [new File('vscode-wpilib/package.json'), new File('wpilib-utility-standalone/package.json')]
def oldVersionFile = new File("$buildDir/existingVersions.json")
task updateVersions(type: Task) {
doLast {
def existingVersions = []
versionFiles.each {
def file = it
def parsedJson = new groovy.json.JsonSlurper().parseText(file.text)
def existingVersion = new Expando();
existingVersion.version = parsedJson.version
existingVersion.file = file.toString()
existingVersions << existingVersion
parsedJson.version = pubVersion
def converted = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(parsedJson))
file.text = converted
}
if (oldVersionFile.exists()) {
return
}
oldVersionFile.parentFile.mkdirs()
oldVersionFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(existingVersions))
}
}
task resetVersions(type: Task) {
doLast {
def oldVersions = new groovy.json.JsonSlurper().parseText(oldVersionFile.text)
versionFiles.each {
def file = it
def parsedJson = new groovy.json.JsonSlurper().parseText(file.text)
for (Object oldv : oldVersions) {
if (file.toString().equals(oldv.file)) {
parsedJson.version = oldv.version
break
}
}
def converted = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(parsedJson))
file.text = converted
}
oldVersionFile.delete()
}
}