Skip to content

Commit 2cdc18a

Browse files
committed
initial windows support, use start-patches endpoint instead of loop
1 parent d3632ec commit 2cdc18a

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/SetupMinecraftSources.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ abstract class SetupMinecraftSources : JavaLauncherTask() {
220220
oldPaperGit.reset().setMode(ResetCommand.ResetType.HARD).setRef(oldPaperCommit.get()).call()
221221
oldPaperGit.close()
222222

223+
val isWindows = System.getProperty("os.name").lowercase().contains("win")
223224
oldPaperLog.outputStream().use { logOut ->
224225
val processBuilder = ProcessBuilder(
225-
"./gradlew",
226+
"./gradlew" + if (isWindows) ".bat" else "",
226227
"applyPatches",
227228
"--console",
228229
"plain",

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/patchroulette/AbstractPatchRouletteTask.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ abstract class AbstractPatchRouletteTask : BaseTask() {
127127
fun setPatches(paths: List<String>) {
128128
val response = httpClient().send(
129129
HttpRequest.newBuilder()
130-
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(SetPatches(paths, minecraftVersion.get()))))
130+
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(SetPatches(paths.normalisePathSeparators(), minecraftVersion.get()))))
131131
.uri(URI.create(endpoint.get() + "/set-patches"))
132132
.auth()
133133
.contentTypeApplicationJson()
@@ -156,13 +156,13 @@ abstract class AbstractPatchRouletteTask : BaseTask() {
156156
logger.lifecycle("Cleared patches for ${minecraftVersion.get()}")
157157
}
158158

159-
data class PatchInfo(val path: String, val minecraftVersion: String)
159+
data class PatchesInfo(val paths: List<String>, val minecraftVersion: String)
160160

161-
fun startPatch(path: String) {
161+
fun startPatches(paths: List<String>): List<String> {
162162
val response = httpClient().send(
163163
HttpRequest.newBuilder()
164-
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(PatchInfo(path, minecraftVersion.get()))))
165-
.uri(URI.create(endpoint.get() + "/start-patch"))
164+
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(PatchesInfo(paths.normalisePathSeparators(), minecraftVersion.get()))))
165+
.uri(URI.create(endpoint.get() + "/start-patches"))
166166
.auth()
167167
.contentTypeApplicationJson()
168168
.build(),
@@ -171,13 +171,17 @@ abstract class AbstractPatchRouletteTask : BaseTask() {
171171
if (response.statusCode() != 200) {
172172
throw PaperweightException("Response status code: ${response.statusCode()}, body: ${response.body()}")
173173
}
174-
logger.lifecycle("Started patch $path")
174+
val startedPatches = gson.fromJson<List<String>>(response.body(), typeToken<List<String>>())
175+
logger.lifecycle("Started patches $startedPatches")
176+
return startedPatches
175177
}
176178

179+
data class PatchInfo(val path: String, val minecraftVersion: String)
180+
177181
fun completePatch(path: String) {
178182
val response = httpClient().send(
179183
HttpRequest.newBuilder()
180-
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(PatchInfo(path, minecraftVersion.get()))))
184+
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(PatchInfo(path.normalisePathSeparators(), minecraftVersion.get()))))
181185
.uri(URI.create(endpoint.get() + "/complete-patch"))
182186
.auth()
183187
.contentTypeApplicationJson()
@@ -193,7 +197,7 @@ abstract class AbstractPatchRouletteTask : BaseTask() {
193197
fun cancelPatch(path: String) {
194198
val response = httpClient().send(
195199
HttpRequest.newBuilder()
196-
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(PatchInfo(path, minecraftVersion.get()))))
200+
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(PatchInfo(path.normalisePathSeparators(), minecraftVersion.get()))))
197201
.uri(URI.create(endpoint.get() + "/cancel-patch"))
198202
.auth()
199203
.contentTypeApplicationJson()
@@ -206,3 +210,6 @@ abstract class AbstractPatchRouletteTask : BaseTask() {
206210
logger.lifecycle("Cancelled patch $path")
207211
}
208212
}
213+
214+
private fun String.normalisePathSeparators(): String = replace("\\", "/")
215+
private fun List<String>.normalisePathSeparators(): List<String> = map { it.replace("\\", "/") }

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/patchroulette/PatchRouletteApply.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,16 @@ abstract class PatchRouletteApply : AbstractPatchRouletteTask() {
123123
continue
124124
}
125125

126-
val startedPatches = mutableListOf<Path>()
127126
try {
128-
patches.forEach {
129-
startPatch(it.pathString)
130-
startedPatches.add(it)
131-
}
127+
val startedPatches = startPatches(patches.map { it.pathString })
132128
this.config.path.writeText(gson.toJson(config.copy(currentPatches = patches)))
129+
applyPatches(git, startedPatches.map { Path(it) })
133130
break
134131
} catch (e: PaperweightException) {
135-
logger.lifecycle("Patch could not be started: ${e.message}, retrying...")
136-
startedPatches.forEach { cancelPatch(it.pathString) }
132+
logger.lifecycle("Patches could not be started: ${e.message}, retrying...")
137133
tries--
138134
}
139135
}
140-
141-
applyPatches(git, patches)
142136
}
143137

144138
private fun applyPatches(git: Git, patches: List<Path>) {

0 commit comments

Comments
 (0)