-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathproject.gradle
98 lines (88 loc) · 3.28 KB
/
project.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
ext.publishDir = "$rootDir" + File.separator + "publish"
def getShortCommitVersion() {
try {
def commitHashProc = "git rev-parse --short HEAD".execute()
commitHashProc.waitFor()
if (commitHashProc.exitValue() == 0) {
def commitHash = commitHashProc.text.trim()
return commitHash.substring(0, 7)
} else {
println commitHashProc.err.text
throw new Exception("git exited with non-zero return value")
}
} catch (Exception e) {
println "Failed to run git: " + e.getMessage()
}
return "0000000"
}
def getCommitVersion() {
try {
def commitHashProc = "git rev-parse HEAD".execute()
commitHashProc.waitFor()
if (commitHashProc.exitValue() == 0) {
def commitHash = commitHashProc.text.trim()
return commitHash
} else {
println commitHashProc.err.text
throw new Exception("git exited with non-zero return value")
}
} catch (Exception e) {
println "Failed to run git: " + e.getMessage()
}
return "0000000000000000000000000000000000000000"
}
def getBranch() {
String sha = getShortCommitVersion()
try {
def commitHashProc = "git name-rev --name-only --exclude=tags/* $sha".execute()
commitHashProc.waitFor()
if (commitHashProc.exitValue() == 0) {
def commitHash = commitHashProc.text.trim()
return commitHash
} else {
println commitHashProc.err.text
throw new Exception("git exited with non-zero return value")
}
} catch (Exception e) {
println "Failed to run git: " + e.getMessage()
}
return "??????"
}
def updateClientCommitProperties() {
String s = File.separator;
String filePath = "$rootDir${s}core${s}src${s}main${s}resources${s}assets${s}minecraft${s}client${s}properties${s}app.properties"
try {
File propertiesFile = new File(filePath)
if (propertiesFile.createNewFile()) {
System.out.println("File created: " + propertiesFile.getName())
} else {
System.out.println("Rewriting " + filePath + "...")
propertiesFile.delete()
propertiesFile.createNewFile()
}
FileWriter writer = new FileWriter(filePath)
writer.write(
"git.commit.id.abbrev=${getShortCommitVersion()}\n" +
"git.commit.id=${getCommitVersion()}\n" +
"git.branch=${getBranch()}")
writer.close()
System.out.println("Successfully wrote to properties file.")
System.out.println("Commit: ${getCommitVersion()}")
System.out.println("Commit abbreviation: ${getShortCommitVersion()}")
System.out.println("Commit branch: ${getBranch()}")
} catch (IOException e) {
System.out.println("An error occurred.")
e.printStackTrace()
}
}
updateClientCommitProperties()
ext {
getBranch = this.&getBranch
getShortCommitVersion = this.&getShortCommitVersion
projModID = "cheatbreaker"
projGroup = "com.cheatbreaker"
projMixinTweaker = "org.spongepowered.asm.launch.MixinTweaker"
projMixinConfigs = "mixins.cheatbreaker.json"
projMixinRefmap = "mixins.cheatbreaker.refmap.json"
projDepsLocation = "com.cheatbreaker.lib"
}