Skip to content

Commit 6861719

Browse files
committed
feature test
1 parent 2ea397d commit 6861719

File tree

9 files changed

+79
-11
lines changed

9 files changed

+79
-11
lines changed

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/extension/PaperExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ open class PaperExtension(objects: ObjectFactory, layout: ProjectLayout) {
4242
val paperServerDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "paper-server")
4343
val sourcePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/sources")
4444
val resourcePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/resources")
45-
val featurePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/feature")
45+
val featurePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/features")
4646

4747
@Suppress("MemberVisibilityCanBePrivate")
4848
val buildDataDir: DirectoryProperty = objects.dirWithDefault(layout, "build-data")

paperweight-core/src/test/kotlin/io/papermc/paperweight/FunctionalTest.kt

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import java.net.URL
2727
import java.nio.file.Path
2828
import java.nio.file.Paths
2929
import kotlin.io.path.*
30+
import kotlin.io.path.readText
31+
import kotlin.io.path.writeText
3032
import kotlin.test.Test
3133
import kotlin.test.assertEquals
3234
import org.gradle.testkit.runner.TaskOutcome
@@ -36,7 +38,7 @@ import org.junit.jupiter.api.io.TempDir
3638

3739
class FunctionalTest {
3840

39-
val debug = false
41+
val debug = true
4042

4143
@Disabled
4244
@Test
@@ -95,16 +97,18 @@ class FunctionalTest {
9597
)
9698

9799
// add AT to source -> patch and AT file is updated
98-
val sourceFile = tempDir.resolve("test-server/src/vanilla/java/Test.java")
99-
val replacedContent = sourceFile.readText().replace(
100-
"\"2\";",
101-
"\"2\"; // Woo"
102-
).replace("public String getTest2() {", "private final String getTest2() {// Paper-AT: private+f getTest2()Ljava/lang/String;")
103-
sourceFile.writeText(replacedContent)
100+
println("adding at to source")
101+
modifyFile(tempDir.resolve("test-server/src/vanilla/java/Test.java")) {
102+
it.replace(
103+
"\"2\";",
104+
"\"2\"; // Woo"
105+
).replace("public String getTest2() {", "private final String getTest2() {// Paper-AT: private+f getTest2()Ljava/lang/String;")
106+
}
104107

105108
Git(tempDir.resolve("test-server/src/vanilla/java")).let { git ->
106109
git("add", ".").executeSilently()
107-
git("commit", "--amend", "--no-edit").executeSilently()
110+
git("commit", "--fixup", "file").executeSilently()
111+
git("rebase", "--autosquash", "mache/main").executeSilently()
108112
}
109113

110114
println("\nrunning rebuildPatches again\n")
@@ -119,6 +123,25 @@ class FunctionalTest {
119123
tempDir.resolve("fake-patches/sources/Test.java.patch").readText()
120124
)
121125
assertEquals(testResource.resolve("build-data/expected.at").readText(), tempDir.resolve("build-data/fake.at").readText())
126+
127+
// feature patch
128+
println("\nmodifying feature patch\n")
129+
modifyFile(tempDir.resolve("test-server/src/vanilla/java/Test.java")) {
130+
it.replace("wonderful feature", "amazing feature")
131+
}
132+
133+
println("\nrebuilding feature patch\n")
134+
val rebP3 = gradleRunner
135+
.withArguments("rebuildPatches", "--stacktrace", "-Dfake=true")
136+
.withDebug(debug)
137+
.build()
138+
assertEquals(rebP3.task(":rebuildPatches")?.outcome, TaskOutcome.SUCCESS)
139+
assertEquals(
140+
testResource.resolve("fake-patches/expected/0001-Feature.patch").readText(),
141+
tempDir.resolve("fake-patches/features/0001-Feature.patch").readText()
142+
)
143+
144+
// todo lib patches
122145
}
123146

124147
@Test
@@ -176,4 +199,8 @@ class FunctionalTest {
176199
).writeBytes(URL("https://libraries.minecraft.net/com/github/oshi/oshi-core/6.4.5/oshi-core-6.4.5.jar").readBytes())
177200
zip(target.resolve("bundle"), target.resolve("bundle.jar"))
178201
}
202+
203+
fun modifyFile(path: Path, action: (content: String) -> String) {
204+
path.writeText(action.invoke(path.readText()))
205+
}
179206
}

paperweight-core/src/test/resources/functional_test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ paperweight {
3434
paper {
3535
sourcePatchDir.set(file('fake-patches/sources'))
3636
resourcePatchDir.set(file('fake-patches/resources'))
37-
featurePatchDir.set(file('fake-patches/feature'))
37+
featurePatchDir.set(file('fake-patches/features'))
3838

3939
additionalAts.set(file('build-data/fake.at'))
4040

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: MiniDigger | Martin <[email protected]>
3+
Date: Sun, 20 Oct 2024 09:24:36 +0200
4+
Subject: [PATCH] Feature
5+
6+
7+
diff --git a/Test.java b/Test.java
8+
index 8bd0bab8fc2fb2f6a4459ed9f618214ec048afc4..6accbd08d129088975d63c13230eefb73bdc3fcb 100644
9+
--- a/Test.java
10+
+++ b/Test.java
11+
@@ -13,4 +13,8 @@ public class Test {
12+
private final String getTest2() {// Paper-AT: private+f getTest2()Ljava/lang/String;
13+
return this.test + "2"; // Woo
14+
}
15+
+
16+
+ public String feature() {
17+
+ return "wonderful feature";
18+
+ }
19+
}

paperweight-core/src/test/resources/functional_test/fake-patches/expected/Test.java.patch

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
+ return this.test; // WOOOO
99
}
1010

11-
private final String getTest2() {
11+
- private final String getTest2() {
1212
- return this.test + "2";
13+
+ private final String getTest2() {// Paper-AT: private+f getTest2()Ljava/lang/String;
1314
+ return this.test + "2"; // Woo
1415
}
1516
}

paperweight-core/src/test/resources/functional_test/fake-patches/feature/.gitkeep

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: MiniDigger | Martin <[email protected]>
3+
Date: Sun, 20 Oct 2024 09:24:36 +0200
4+
Subject: [PATCH] Feature
5+
6+
7+
diff --git a/Test.java b/Test.java
8+
index 418548ec7dd11e57f0838d1dae048b99a2669ea3..95266c0cad0b100367ca840d286b7a004b93f4ef 100644
9+
--- a/Test.java
10+
+++ b/Test.java
11+
@@ -13,4 +13,8 @@ public class Test {
12+
public String getTest2() {
13+
return this.test + "2";
14+
}
15+
+
16+
+ public String feature() {
17+
+ return "wonderful feature";
18+
+ }
19+
}

paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/softspoon/RebuildFilePatches.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ abstract class RebuildFilePatches : BaseTask() {
174174
.executionContext(InMemoryExecutionContext { it.printStackTrace() })
175175
.build()
176176

177+
// mmmh, maybe add comment to base too?
178+
177179
val parsedInput = RestampInput.parseFrom(configuration)
178180
val results = Restamp.run(parsedInput).allResults
179181

0 commit comments

Comments
 (0)