Skip to content

Commit fcefe1b

Browse files
committed
feat(core/patcher): Remove no longer needed relocation logic from GenerateDevBundle
1 parent 6f65b54 commit fcefe1b

File tree

2 files changed

+3
-73
lines changed

2 files changed

+3
-73
lines changed

paperweight-lib/src/main/kotlin/io/papermc/paperweight/taskcontainers/DevBundleTasks.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class DevBundleTasks(
107107
serverProject.set(serverProj)
108108
runtimeConfiguration.set(project.configurations.named(SERVER_RUNTIME_CLASSPATH))
109109

110-
relocations.set(gson.toJson(listOf<Relocation>()))
111110
decompiledJar.pathProvider(decompileJar)
112111
atFile.pathProvider(accessTransformFile)
113112

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

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ import java.nio.file.Path
3333
import java.util.Locale
3434
import java.util.concurrent.TimeUnit
3535
import java.util.regex.Pattern
36-
import java.util.stream.Collectors
3736
import javax.inject.Inject
3837
import kotlin.io.path.*
39-
import org.apache.tools.ant.types.selectors.SelectorUtils
4038
import org.gradle.api.DefaultTask
4139
import org.gradle.api.Project
4240
import org.gradle.api.artifacts.Configuration
@@ -99,9 +97,6 @@ abstract class GenerateDevBundle : DefaultTask() {
9997
@get:Classpath
10098
abstract val runtimeConfiguration: Property<Configuration>
10199

102-
@get:Input
103-
abstract val relocations: Property<String>
104-
105100
@get:Input
106101
abstract val paramMappingsUrl: Property<String>
107102

@@ -178,8 +173,6 @@ abstract class GenerateDevBundle : DefaultTask() {
178173
workingDir.createDirectories()
179174
sourceDir.path.copyRecursivelyTo(workingDir)
180175

181-
relocate(relocations(), workingDir)
182-
183176
Files.walk(workingDir).use { stream ->
184177
decompiledJar.path.openZip().use { decompJar ->
185178
val decompRoot = decompJar.rootDirectories.single()
@@ -212,60 +205,6 @@ abstract class GenerateDevBundle : DefaultTask() {
212205
workingDir.deleteRecursive()
213206
}
214207

215-
private fun relocate(relocations: List<Relocation>, workingDir: Path) {
216-
val wrappedRelocations = relocations.map { RelocationWrapper(it) }
217-
218-
Files.walk(workingDir).use { stream ->
219-
stream.filter { it.isRegularFile() && it.name.endsWith(".java") }
220-
.forEach { path -> replaceRelocationsInFile(path, wrappedRelocations) }
221-
}
222-
223-
relocateFiles(wrappedRelocations, workingDir)
224-
}
225-
226-
private fun replaceRelocationsInFile(path: Path, relocations: List<RelocationWrapper>) {
227-
var content = path.readText(Charsets.UTF_8)
228-
229-
// Use hashes as intermediary to avoid double relocating
230-
231-
for (relocation in relocations) {
232-
content = content.replace(relocation.fromDot, '.' + relocation.hashCode().toString())
233-
.replace(relocation.fromSlash, '/' + relocation.hashCode().toString())
234-
}
235-
236-
for (relocation in relocations) {
237-
content = content.replace('.' + relocation.hashCode().toString(), relocation.toDot)
238-
.replace('/' + relocation.hashCode().toString(), relocation.toSlash)
239-
}
240-
241-
path.writeText(content, Charsets.UTF_8)
242-
}
243-
244-
private fun relocateFiles(relocations: List<RelocationWrapper>, workingDir: Path) {
245-
Files.walk(workingDir).use { stream -> stream.collect(Collectors.toList()) }
246-
.asSequence().filter { it.isRegularFile() && it.name.endsWith(".java") }
247-
.forEach { path ->
248-
val potential = path.relativeTo(workingDir).invariantSeparatorsPathString
249-
for (relocation in relocations) {
250-
if (potential.startsWith(relocation.fromSlash)) {
251-
if (excluded(relocation.relocation, potential)) {
252-
break
253-
}
254-
val dest = workingDir.resolve(potential.replace(relocation.fromSlash, relocation.toSlash))
255-
dest.parent.createDirectories()
256-
path.moveTo(dest)
257-
break
258-
}
259-
}
260-
}
261-
}
262-
263-
private fun excluded(relocation: Relocation, potential: String): Boolean = relocation.excludes.map {
264-
it.replace('.', '/')
265-
}.any { exclude ->
266-
SelectorUtils.matchPath(exclude, potential, true)
267-
}
268-
269208
private fun diffFiles(fileName: String, original: Path, patched: Path): String {
270209
val dir = createTempDirectory("diff")
271210
try {
@@ -318,7 +257,7 @@ abstract class GenerateDevBundle : DefaultTask() {
318257
}
319258

320259
private fun asString(out: ByteArrayOutputStream) = String(out.toByteArray(), Charset.defaultCharset())
321-
.replace(System.getProperty("line.separator"), "\n")
260+
.replace(System.lineSeparator(), "\n")
322261

323262
@Suppress("SameParameterValue")
324263
private fun createBundleConfig(dataTargetDir: String, patchTargetDir: String): DevBundleConfig {
@@ -334,8 +273,6 @@ abstract class GenerateDevBundle : DefaultTask() {
334273
)
335274
}
336275

337-
private fun relocations(): List<Relocation> = gson.fromJson(relocations.get())
338-
339276
private fun createBuildDataConfig(targetDir: String): BuildData {
340277
return BuildData(
341278
paramMappings = MavenDep(paramMappingsUrl.get(), listOf(paramMappingsCoordinates.get())),
@@ -346,7 +283,7 @@ abstract class GenerateDevBundle : DefaultTask() {
346283
compileDependencies = determineLibraries(vanillaServerLibraries.get()).sorted(),
347284
runtimeDependencies = collectRuntimeDependencies().map { it.coordinates }.sorted(),
348285
libraryRepositories = libraryRepositories.get(),
349-
relocations = relocations(),
286+
relocations = emptyList(), // Nothing is relocated in the dev bundle as of 1.20.5
350287
minecraftRemapArgs = TinyRemapper.minecraftRemapArgs,
351288
pluginRemapArgs = TinyRemapper.pluginRemapArgs,
352289
)
@@ -379,13 +316,7 @@ abstract class GenerateDevBundle : DefaultTask() {
379316
}
380317
}
381318

382-
val result = new.map { it.toString() }.toMutableSet()
383-
384-
// Remove relocated libraries
385-
val libs = relocations().mapNotNull { it.owningLibraryCoordinates }
386-
result.removeIf { coords -> libs.any { coords.startsWith(it) } }
387-
388-
return result
319+
return new.map { it.toString() }.toSet()
389320
}
390321

391322
private val ResolvedArtifactResult.coordinates: String

0 commit comments

Comments
 (0)