Skip to content

Commit 6d26a4b

Browse files
committed
Fix DownloadService and specify patch files are always LF
1 parent ee63835 commit 6d26a4b

File tree

7 files changed

+19
-10
lines changed

7 files changed

+19
-10
lines changed

.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.patch]
2+
end_of_line = lf

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ gradlew text eol=lf
55
*.bat text eol=crlf
66

77
*.jar binary
8+
9+
*.patch text eol=lf

build-logic/src/main/kotlin/MacheExtension.kt

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ open class MacheExtension(objects: ObjectFactory) {
3737
"-dcc=true",
3838
// Skip Extra Files: Skip copying non-class files from the input folder or file to the output
3939
"-sef=true",
40+
// New Line Seperator: Character that seperates lines in the decompiled output.
41+
"-nls=1",
4042
),
4143
)
4244
}

build-logic/src/main/kotlin/io/papermc/mache/DownloadService.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import java.net.http.HttpResponse.BodyHandlers
1111
import java.nio.channels.Channels
1212
import java.nio.channels.FileChannel
1313
import java.nio.file.Path
14+
import java.nio.file.StandardOpenOption.CREATE
15+
import java.nio.file.StandardOpenOption.TRUNCATE_EXISTING
16+
import java.nio.file.StandardOpenOption.WRITE
1417
import java.nio.file.attribute.FileTime
1518
import java.time.Duration
1619
import java.time.Instant
@@ -24,7 +27,6 @@ import kotlin.io.path.deleteIfExists
2427
import kotlin.io.path.exists
2528
import kotlin.io.path.getLastModifiedTime
2629
import kotlin.io.path.name
27-
import kotlin.io.path.outputStream
2830
import kotlin.io.path.readText
2931
import kotlin.io.path.setLastModifiedTime
3032
import kotlin.io.path.writeText
@@ -128,7 +130,7 @@ abstract class DownloadService : BuildService<BuildServiceParameters.None> {
128130

129131
downloadCallback()
130132

131-
FileChannel.open(target).use { output ->
133+
FileChannel.open(target, CREATE, TRUNCATE_EXISTING, WRITE).use { output ->
132134
Channels.newChannel(response.body()).use { input ->
133135
output.transferFrom(input, 0, Long.MAX_VALUE)
134136
}

build-logic/src/main/kotlin/io/papermc/mache/tasks/ApplyPatches.kt

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ abstract class ApplyPatches : DefaultTask() {
6666
.patchesPath(patchDir.convertToPath(), null)
6767
.basePath(inputFile.convertToPath(), ArchiveFormat.ZIP)
6868
.outputPath(outputJar.convertToPath(), ArchiveFormat.ZIP)
69+
.lineEnding("\n")
6970
.mode(PatchMode.EXACT)
7071
.level(Level.FINE)
7172
.verbose(true)

build-logic/src/main/kotlin/io/papermc/mache/tasks/RebuildPatches.kt

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ abstract class RebuildPatches : DefaultTask() {
6464
.aPath(decompJar.convertToPath(), ArchiveFormat.ZIP)
6565
.bPath(copied.convertToPath(), ArchiveFormat.ZIP)
6666
.outputPath(patchDir.convertToPath(), null)
67+
.lineEnding("\n")
6768
.logTo(ps)
6869
.level(Level.FINE)
6970
.verbose(true)

build-logic/src/main/kotlin/io/papermc/mache/tasks/SetupSources.kt

+7-8
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,21 @@ abstract class SetupSources : DefaultTask() {
134134
}
135135

136136
private fun endingNewlines(path: Path) {
137-
val seps = System.lineSeparator()
138-
val sepLength = seps.length
137+
val sep: Byte = '\n'.code.toByte()
138+
val bytes = ByteBuffer.allocate(1)
139139

140-
val expectedBytes = ByteBuffer.wrap(ByteArray(sepLength) { i -> seps[i].code.toByte() })
141-
val bytes = ByteBuffer.allocate(sepLength)
140+
val sepBuffer = ByteBuffer.wrap(byteArrayOf(sep))
142141

143142
for (file in path.walk().filter { it.name.endsWith(".java") }) {
144143
// try to check and fix each file without reading / writing the whole file
145144
FileChannel.open(file, READ, WRITE).use { f ->
146-
f.position(f.size() - sepLength)
145+
f.position(f.size() - 1)
147146
f.read(bytes)
148147
bytes.position(0)
149-
if (bytes != expectedBytes) {
148+
if (bytes[0] != sep) {
150149
f.position(f.size())
151-
f.write(expectedBytes)
152-
expectedBytes.position(0)
150+
f.write(sepBuffer)
151+
sepBuffer.position(0)
153152
}
154153
}
155154
}

0 commit comments

Comments
 (0)