-
Notifications
You must be signed in to change notification settings - Fork 26
/
utilities.gradle
69 lines (65 loc) · 2.22 KB
/
utilities.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Author: UpcraftLP
// Source: https://github.com/OnyxStudios/Gradle-Scripts/
def getProjectProperty(String name) {
return project.findProperty(name) ?: System.getenv(name)
}
def getSystemProperty(String name) {
return System.getenv(name) ?: project.findProperty(name)
}
String getChangelogText() {
def changelogFile = project.file("changelog.md")
String str = ''
if (!changelogFile.exists()) {
println("No changelog file found, creating one at \"" + changelogFile.getAbsolutePath() + "\"")
try {
changelogFile.getParentFile().mkdirs()
changelogFile.createNewFile()
String newText = '------------------------------------------------------\n' +
'Version ' + project.version + '\n' +
'------------------------------------------------------\n' +
'Additions\n' +
'- None\n' +
'\n' +
'Changes\n' +
'- None\n' +
'\n' +
'Bug Fixes\n' +
'- None\n'
String oldText = changelogFile.getText()
changelogFile.setText(newText + oldText)
return str
}
catch (IOException e) {
println("Unable to write changelog file: " + e.getMessage())
e.printStackTrace()
return ''
}
}
String separator = '---'
int lineCount = 0
boolean done = false
changelogFile.eachLine {
if (done || it == null) {
return
}
if (lineCount < 3) {
lineCount++
if (it.startsWith(separator)) {
return ""
}
}
if (!it.startsWith(separator)) {
str += "$it" + (lineCount < 3 ? ':\n\n' : '\n')
return
}
done = true // once we go past the first version block, parse no more
}
str += "\n\n see full changelog [here](${findProperty("changelog_base_url")}/${project.mod_version}/changelog.md \"Changelog\")"
return str
}
// Export methods by turning them into closures
ext {
getProjectProperty = this.&getProjectProperty
getSystemProperty = this.&getSystemProperty
getChangelogText = this.&getChangelogText
}