-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsettings.gradle
More file actions
230 lines (206 loc) · 6.2 KB
/
settings.gradle
File metadata and controls
230 lines (206 loc) · 6.2 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import groovy.json.JsonSlurper
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven {
name "Fabric"
url "https://maven.fabricmc.net/"
}
maven {
name "Kiku Snapshots"
url "https://maven.kikugie.dev/snapshots"
}
maven {
name "Kiku Releases"
url "https://maven.kikugie.dev/releases"
}
}
}
plugins {
id "dev.kikugie.stonecutter" version "0.4.4"
}
def multiVersions = getMultiVersions()
println "Found MC versions: ${multiVersions}"
def additionalDepends = getAdditionalDepends()
if (additionalDepends.isEmpty()) {
println "There are no any additional depends!"
} else {
println "Found additional depends: ${additionalDepends}"
}
stonecutter {
shared {
versions(multiVersions)
vcsVersion = multiVersions.last()
}
create(rootProject)
multiVersions.each { multiVersion ->
createGradleProperties(multiVersion, additionalDepends)
createAW(multiVersion)
}
}
rootProject.name = properties.get("data.mod_name")
def createAW(String version) {
def awFile = createAWFile(version)
if (awFile == null) {
return
}
def writer = new FileWriter(awFile)
writer.write("accessWidener v2 named\n")
writer.write("# ${version} AW\n")
writer.close()
println "Successfully created AW for ${version}"
}
def createGradleProperties(String version, ArrayList<String> additionalDepends) {
def file = getOrCreateGradlePropertiesFile(version)
if (file == null) {
return
}
def isEmpty = file.text.isBlank() || file.text.isEmpty()
def update = file.text.replace(" ", "").contains("=[UPDATE]")
if (!isEmpty && !update) {
return
}
def gradleProperties = new Properties()
gradleProperties.load(new FileInputStream(file))
if (update) {
def text = new String(file.text).replace(" ", "\u3164").trim()
gradleProperties.forEach { key, value ->
println "${key} = ${value}"
if (value.toString() != "[UPDATE]") {
return
}
def string = key.toString()
def oldLine = "${key}=[UPDATE]"
def updatedLine = null
if (string.startsWith("dep.")) {
updatedLine = "${key}=${getDependVersion(substringSince(string, "."), version)}"
}
if (string.startsWith("build.")) {
def buildProperty = substringSince(string, ".")
if (buildProperty == "yarn") {
updatedLine = "${key}=${getYarnVersion(version)}"
}
if (buildProperty == "fabric_loader") {
updatedLine = "${key}=${getFabricLoaderVersion(version)}"
}
if (buildProperty == "fabric_api") {
updatedLine = "${key}=${getDependVersion("fabric-api", version)}"
}
}
if (updatedLine == null) {
return
}
text = text.replace(oldLine, updatedLine)
}
file.text = text.replace("\u3164", " ")
println "Successfully updated gradle.properties for ${version}"
} else {
def writer = new FileWriter(file)
writer.write("# Versioned Properties\n")
writer.write("# Tip: You can set any dependency value to \"[UPDATE]\"\n")
writer.write("# and reload Gradle to update only it's value.\n")
writer.write("\n")
writer.write("# Fabric Properties, check https://fabricmc.net/develop/\n")
writer.write("build.yarn=${getYarnVersion(version)}\n")
// writer.write("build.fabric_loader=${getFabricLoaderVersion(version)}\n")
writer.write("build.fabric_api=${getDependVersion("fabric-api", version)}")
if (!additionalDepends.isEmpty()) {
writer.write("\n")
writer.write("\n")
writer.write("# Additional Dependencies Properties\n")
additionalDepends.each { depend ->
def dep = depend.toString()
writer.write("# ${dep}, check https://modrinth.com/mod/${dep}/versions?g=${version}&l=fabric\n")
writer.write("dep.${dep}=${getDependVersion(dep, version)}\n")
}
}
writer.close()
println "Successfully created gradle.properties for ${version}"
}
}
static String getYarnVersion(String minecraftVersion) {
def url = new URL("https://meta.fabricmc.net/v2/versions/yarn/${minecraftVersion}?limit=1")
def json = new JsonSlurper().parseText(url.text)
return json[0]["version"].toString()
}
static String getFabricLoaderVersion(String minecraftVersion) {
def url = new URL("https://meta.fabricmc.net/v2/versions/loader/${minecraftVersion}?limit=1")
def json = new JsonSlurper().parseText(url.text)
return json[0]["loader"]["version"].toString()
}
static String getDependVersion(String modId, String minecraftVersion) {
def url = new URL("https://api.modrinth.com/v2/project/${modId}/version")
def json = new JsonSlurper().parseText(url.text)
def result = json.findResult { o ->
if (o["game_versions"].contains(minecraftVersion) && o["loaders"].contains("fabric")) {
return o
}
return null
}
if (result == null) {
return "unknown"
}
return result["version_number"].toString()
}
static def substringSince(String text, String since) {
def i = text.indexOf(since)
if (i == -1) {
return text
}
return text.substring(i + 1)
}
String[] getMultiVersions() {
def versions = []
multi_versions.toString().split(" ").each { s ->
def index = s.indexOf("[")
if (index == -1) {
versions.add(s)
return
}
versions.add(s.substring(0, index))
}
return versions
}
File createAWFile(String version) {
def awsFolder = file("src/main/resources/aws/")
if (!awsFolder.exists() && !awsFolder.mkdirs()) {
println("Failed to get or create AW folder for " + version)
return null
}
def awFile = file("src/main/resources/aws/${version}.accesswidener")
if (awFile.exists()) {
return null
}
if (!awFile.createNewFile()) {
println("Failed to create AW file for " + version)
return null
}
return awFile
}
File getOrCreateGradlePropertiesFile(String version) {
def folderFile = file("/versions/${version}")
if (!folderFile.exists() && !folderFile.mkdirs()) {
println("Failed to get or create folder for " + version)
return null
}
def gradlePropertiesFile = file("/versions/${version}/gradle.properties")
if (!gradlePropertiesFile.exists() && !gradlePropertiesFile.createNewFile()) {
println("Failed to get or create gradle.properties for " + version)
return null
}
return gradlePropertiesFile
}
def getAdditionalDepends() {
def additionalDepends = []
properties.each { k, v ->
def key = k.toString()
if (key.startsWith("dep.")) {
def i = key.indexOf(".") + 1
def modId = key.substring(i)
additionalDepends.add(modId)
}
}
return additionalDepends
}