Skip to content

Commit b49c633

Browse files
committed
chore: Use spaces instead of tabs
1 parent 47dbb58 commit b49c633

File tree

7 files changed

+111
-98
lines changed

7 files changed

+111
-98
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*]
4+
indent_size = 4
5+
indent_style = space

src/installer/java/xyz/wagyourtail/patchbase/installer/PatchbaseInstaller.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import java.util.zip.ZipOutputStream;
1717

1818
public class PatchbaseInstaller {
19-
private static final GDiffPatcher PATCHER = new GDiffPatcher();
20-
private static final byte[] EMPTY_DATA = new byte[0];
19+
private static final GDiffPatcher PATCHER = new GDiffPatcher();
20+
private static final byte[] EMPTY_DATA = new byte[0];
2121

22-
/*
22+
/*
2323
* create your installer around this method.
2424
*/
2525
public void patch(Path patchJar, Path baseJar, Path outputJar) throws IOException {
@@ -32,16 +32,16 @@ public void patch(Path patchJar, Path baseJar, Path outputJar) throws IOExceptio
3232
readZipInputStreamFor(baseJar, entry.substring(0, entry.length() - 6), true, originalStream -> {
3333
try {
3434
byte[] original = new ClassWriter(new ClassReader(originalStream), ClassReader.SKIP_DEBUG).toByteArray();
35-
byte[] result = patch(original, Patch.from(is));
35+
byte[] result = patch(original, Patch.from(is));
3636

37-
// if we removed the file, don't write on disk
38-
if ( result != EMPTY_DATA ) {
39-
Path p = fs.getPath(entry.substring(0, entry.length() - 6));
40-
if (p.getParent() != null) {
41-
Files.createDirectories(p.getParent());
42-
}
43-
Files.write(p, result, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
44-
}
37+
// if we removed the file, don't write on disk
38+
if ( result != EMPTY_DATA ) {
39+
Path p = fs.getPath(entry.substring(0, entry.length() - 6));
40+
if (p.getParent() != null) {
41+
Files.createDirectories(p.getParent());
42+
}
43+
Files.write(p, result, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
44+
}
4545
} catch (IOException e) {
4646
throw new RuntimeException(e);
4747
}
@@ -110,24 +110,24 @@ public static FileSystem openZipFileSystem(Path path, Map<String, Object> args)
110110
return FileSystems.newFileSystem(URI.create("jar:" + path.toUri()), args, null);
111111
}
112112

113-
private static byte[] patch( byte[] data, Patch patch ) throws IOException {
114-
if (patch.exists && data.length == 0) {
115-
throw new IOException( "Patch expected " + patch.getName() + " to exist, but received empty data" );
116-
}
117-
if (!patch.exists && data.length > 0) {
118-
throw new IOException( "Patch expected " + patch.getName() + " to not exist, but received " + data.length + " bytes" );
119-
}
113+
private static byte[] patch( byte[] data, Patch patch ) throws IOException {
114+
if (patch.exists && data.length == 0) {
115+
throw new IOException( "Patch expected " + patch.getName() + " to exist, but received empty data" );
116+
}
117+
if (!patch.exists && data.length > 0) {
118+
throw new IOException( "Patch expected " + patch.getName() + " to not exist, but received " + data.length + " bytes" );
119+
}
120120

121-
int checksum = patch.checksum(data);
122-
if (checksum != patch.checksum) {
123-
throw new IOException( "Patch expected " + patch.getName() + " to have the checksum " + Integer.toHexString( patch.checksum ) + " but it was " + Integer.toHexString( checksum ) );
124-
}
121+
int checksum = patch.checksum(data);
122+
if (checksum != patch.checksum) {
123+
throw new IOException( "Patch expected " + patch.getName() + " to have the checksum " + Integer.toHexString( patch.checksum ) + " but it was " + Integer.toHexString( checksum ) );
124+
}
125125

126-
if (patch.data.length == 0) { // File removed
127-
return EMPTY_DATA;
128-
} else {
129-
return PATCHER.patch( data, patch.data );
130-
}
131-
}
126+
if (patch.data.length == 0) { // File removed
127+
return EMPTY_DATA;
128+
} else {
129+
return PATCHER.patch( data, patch.data );
130+
}
131+
}
132132

133133
}

src/main/kotlin/xyz/wagyourtail/patchbase/gradle/PatchBaseMinecraftTransformer.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ fun MinecraftConfig.patchBase(action: PatchBaseMinecraftTransformer.() -> Unit =
1414
customPatcher(PatchBaseMinecraftTransformer(this.project, this as MinecraftProvider), action)
1515
}
1616

17-
class PatchBaseMinecraftTransformer(project: Project, provider: MinecraftProvider) : JarModAgentMinecraftTransformer(project, provider) {
17+
class PatchBaseMinecraftTransformer(project: Project, provider: MinecraftProvider) :
18+
JarModAgentMinecraftTransformer(project, provider) {
1819
val patchBase = project.configurations.maybeCreate("patchBase".withSourceSet(provider.sourceSet))
1920

2021
override fun transform(minecraft: MinecraftJar): MinecraftJar {
2122
val patchDep = patchBase.dependencies.last()
22-
val patchJar = patchBase
23-
.incoming
24-
.artifactView { view -> view.componentFilter { it is ModuleComponentIdentifier && it.group == patchDep.group && it.version == patchDep.version && it.module == patchDep.name } }
25-
.files
26-
.first { it.extension == "jar" || it.extension == "zip" }
23+
val patchJar = patchBase
24+
.incoming
25+
.artifactView { view -> view.componentFilter { it is ModuleComponentIdentifier && it.group == patchDep.group && it.version == patchDep.version && it.module == patchDep.name } }
26+
.files
27+
.first { it.extension == "jar" || it.extension == "zip" }
2728
val outputFolder = minecraft.path
28-
.parent
29-
.resolve(patchDep.name)
30-
.resolve(patchDep.version!!)
29+
.parent
30+
.resolve(patchDep.name)
31+
.resolve(patchDep.version!!)
3132

3233
val patchedMC = MinecraftJar(minecraft, outputFolder, patches = minecraft.patches + "patchbase")
3334

src/main/kotlin/xyz/wagyourtail/patchbase/gradle/PatchExtension.kt

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ import kotlin.io.path.nameWithoutExtension
1919

2020
@Suppress("UnstableApiUsage")
2121
abstract class PatchExtension(val project: Project) {
22-
/**
23-
* The default value for [[CreateSourcePatchTask.diffContextSize]
24-
*/
25-
@set:ApiStatus.Experimental
26-
var diffContextSize: Int by FinalizeOnRead(3)
22+
/**
23+
* The default value for [[CreateSourcePatchTask.diffContextSize]
24+
*/
25+
@set:ApiStatus.Experimental
26+
var diffContextSize: Int by FinalizeOnRead(3)
2727

28-
/**
29-
* The default value for [CreateSourcePatchTask.trimWhitespace]
30-
*/
31-
@set:ApiStatus.Experimental
32-
var trimWhitespace: Boolean by FinalizeOnRead(true)
28+
/**
29+
* The default value for [CreateSourcePatchTask.trimWhitespace]
30+
*/
31+
@set:ApiStatus.Experimental
32+
var trimWhitespace: Boolean by FinalizeOnRead(true)
3333

34-
/**
35-
* The default value for [CreateClassPatchTask.minimizePatch]
36-
*/
37-
@set:ApiStatus.Experimental
38-
var minimizePatch: Boolean by FinalizeOnRead(true)
34+
/**
35+
* The default value for [CreateClassPatchTask.minimizePatch]
36+
*/
37+
@set:ApiStatus.Experimental
38+
var minimizePatch: Boolean by FinalizeOnRead(true)
3939

4040
fun patchBaseCreator(sourceSet: SourceSet, devJar: Boolean = false) {
4141
val mc = project.unimined.minecrafts[sourceSet]!!
@@ -49,15 +49,16 @@ abstract class PatchExtension(val project: Project) {
4949
project.logger.warn("[PatchBase/Creator ${this.project.path} ${sourceSet}] mcPatcher is not a JarModAgentMinecraftTransformer, this may cause issues with dev runs")
5050
}
5151

52-
val mcp = mc as MinecraftProvider // needed for access to `getMcDevFile()`
52+
val mcp = mc as MinecraftProvider // needed for access to `getMcDevFile()`
5353

5454
project.tasks.register("createSourcePatch".withSourceSet(sourceSet), CreateSourcePatchTask::class.java) {
5555
it.group = "patchbase"
5656
it.sourceDir.set(project.file("src/${sourceSet.name}/java"))
5757
it.outputDir.set(project.file("patches/${sourceSet.name}"))
58-
it.trimWhitespace.set( trimWhitespace )
59-
it.diffContextSize.set( diffContextSize )
60-
val sourceFile = mc.minecraftFileDev.resolveSibling(mcp.getMcDevFile().nameWithoutExtension + "-sources.jar")
58+
it.trimWhitespace.set(trimWhitespace)
59+
it.diffContextSize.set(diffContextSize)
60+
val sourceFile =
61+
mc.minecraftFileDev.resolveSibling(mcp.getMcDevFile().nameWithoutExtension + "-sources.jar")
6162
it.sources.set(project.files(sourceFile))
6263
if (!sourceFile.exists()) {
6364
it.dependsOn("genSources")
@@ -68,9 +69,10 @@ abstract class PatchExtension(val project: Project) {
6869
it.group = "patchbase"
6970
it.patchDir.set(project.file("patches/${sourceSet.name}"))
7071
it.outputDir.set(project.file("src/${sourceSet.name}/java"))
71-
it.trimWhitespace.set( trimWhitespace )
72-
it.diffContextSize.set( diffContextSize )
73-
val sourceFile = mc.minecraftFileDev.resolveSibling(mcp.getMcDevFile().nameWithoutExtension + "-sources.jar")
72+
it.trimWhitespace.set(trimWhitespace)
73+
it.diffContextSize.set(diffContextSize)
74+
val sourceFile =
75+
mc.minecraftFileDev.resolveSibling(mcp.getMcDevFile().nameWithoutExtension + "-sources.jar")
7476
it.sources.set(project.files(sourceFile))
7577
if (!sourceFile.exists()) {
7678
it.dependsOn("genSources".withSourceSet(sourceSet))
@@ -79,8 +81,12 @@ abstract class PatchExtension(val project: Project) {
7981

8082
project.tasks.register("createClassPatch".withSourceSet(sourceSet), CreateClassPatchTask::class.java) {
8183
it.group = "patchbase"
82-
it.inputFile.set((project.tasks.findByName("remap" + "jar".withSourceSet(sourceSet).capitalized()) as Jar).outputs.files.singleFile)
83-
it.minimizePatch.set( minimizePatch )
84+
it.inputFile.set(
85+
(project.tasks.findByName(
86+
"remap" + "jar".withSourceSet(sourceSet).capitalized()
87+
) as Jar).outputs.files.singleFile
88+
)
89+
it.minimizePatch.set(minimizePatch)
8490

8591
when (mc.side) {
8692
EnvType.CLIENT -> it.classpath.set(project.files(mc.minecraftData.minecraftClientFile))
@@ -93,20 +99,20 @@ abstract class PatchExtension(val project: Project) {
9399
it.dependsOn("remap" + "jar".withSourceSet(sourceSet).capitalized())
94100
}
95101

96-
if ( devJar ) {
97-
project.tasks.register("createDevClassPatch".withSourceSet(sourceSet), CreateClassPatchTask::class.java) {
98-
it.group = "patchbase"
99-
it.inputFile.set(
100-
(project.tasks.findByName(
101-
"jar".withSourceSet(sourceSet).capitalized()
102-
) as Jar).outputs.files.singleFile
103-
)
102+
if (devJar) {
103+
project.tasks.register("createDevClassPatch".withSourceSet(sourceSet), CreateClassPatchTask::class.java) {
104+
it.group = "patchbase"
105+
it.inputFile.set(
106+
(project.tasks.findByName(
107+
"jar".withSourceSet(sourceSet).capitalized()
108+
) as Jar).outputs.files.singleFile
109+
)
104110

105-
it.classpath.set( project.files( mc.getMcDevFile() ) )
106-
it.archiveClassifier.set("patch-dev")
107-
it.dependsOn("jar".withSourceSet(sourceSet).capitalized())
108-
}
109-
}
111+
it.classpath.set(project.files(mc.getMcDevFile()))
112+
it.archiveClassifier.set("patch-dev")
113+
it.dependsOn("jar".withSourceSet(sourceSet).capitalized())
114+
}
115+
}
110116
}
111117

112118
fun patchBase(minecraftConfig: MinecraftConfig) {

src/main/kotlin/xyz/wagyourtail/patchbase/gradle/tasks/AbstractSourceTask.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import kotlin.io.path.inputStream
1414
import kotlin.io.path.isDirectory
1515

1616
abstract class AbstractSourceTask : ConventionTask() {
17-
/**
18-
* Controls how much context (surrounding lines) are provided in the patch files.
19-
*/
20-
@get:Input
17+
/**
18+
* Controls how much context (surrounding lines) are provided in the patch files.
19+
*/
20+
@get:Input
2121
abstract val diffContextSize: Property<Int>
2222

23-
/**
24-
* Trims leading whitespace in the patch files.
25-
*/
26-
@get:Input
23+
/**
24+
* Trims leading whitespace in the patch files.
25+
*/
26+
@get:Input
2727
abstract val trimWhitespace: Property<Boolean>
2828

29-
@get:Input
29+
@get:Input
3030
abstract val sources: Property<FileCollection>
3131

3232
fun findSource(path: Path, action: (InputStream?) -> Unit) {
@@ -72,12 +72,12 @@ abstract class AbstractSourceTask : ConventionTask() {
7272
}
7373
}
7474
bLines.add("")
75-
if (trimWhitespace.get()) {
76-
aLines = aLines.map(String::trim).toMutableList()
77-
bLines = bLines.map(String::trim).toMutableList()
78-
}
75+
if (trimWhitespace.get()) {
76+
aLines = aLines.map(String::trim).toMutableList()
77+
bLines = bLines.map(String::trim).toMutableList()
78+
}
7979

80-
val patch = DiffUtils.diff(aLines, bLines)
80+
val patch = DiffUtils.diff(aLines, bLines)
8181
patch.deltas.forEach {
8282
it.target.position
8383
it.target.lines = bLines.subList(it.target.position, it.target.position + it.target.size())

src/main/kotlin/xyz/wagyourtail/patchbase/gradle/tasks/ApplySourcePatchTask.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ abstract class ApplySourcePatchTask : AbstractSourceTask() {
3232
} else {
3333
findSource(relative.resolveSibling(relative.nameWithoutExtension)) { original ->
3434
if (original != null) {
35-
targetParent.resolve(relative.nameWithoutExtension).writeText(applyDiff(original.readBytes().decodeToString(), path.readText()))
35+
targetParent.resolve(relative.nameWithoutExtension)
36+
.writeText(applyDiff(original.readBytes().decodeToString(), path.readText()))
3637
} else {
3738
throw IllegalStateException("Cannot apply patch to non-existent file: $relative")
3839
}

src/main/kotlin/xyz/wagyourtail/patchbase/gradle/tasks/CreateClassPatchTask.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ import java.io.InputStream
1616
import kotlin.io.path.*
1717

1818
abstract class CreateClassPatchTask : Jar() {
19-
/**
20-
* Shrinks the created `.class` patches by remapping constant pool indices.
21-
*/
22-
@get:Input
23-
abstract val minimizePatch: Property<Boolean>
19+
/**
20+
* Shrinks the created `.class` patches by remapping constant pool indices.
21+
*/
22+
@get:Input
23+
abstract val minimizePatch: Property<Boolean>
2424

25-
@get:InputFile
25+
@get:InputFile
2626
abstract val inputFile: RegularFileProperty
2727

2828
@get:Input
2929
abstract val classpath: Property<FileCollection>
3030

31-
@OptIn(ExperimentalPathApi::class)
31+
@OptIn(ExperimentalPathApi::class)
3232
@TaskAction
3333
fun run() {
3434
val tempDir = temporaryDir.resolve("diffs").toPath()
@@ -61,7 +61,7 @@ abstract class CreateClassPatchTask : Jar() {
6161
fun makePatch(a: InputStream, b: InputStream, name: String): ByteArray {
6262
val ra = ClassWriter(ClassReader(a), ClassReader.SKIP_DEBUG).toByteArray()
6363
val rb = ClassWriter(ClassReader(b), ClassReader.SKIP_DEBUG).toByteArray()
64-
val x = Patch.from(name, "", ra, rb, minimizePatch.get())
64+
val x = Patch.from(name, "", ra, rb, minimizePatch.get())
6565
return x.toBytes()
6666
}
6767

0 commit comments

Comments
 (0)