Skip to content

Commit

Permalink
adjust bundler version artifact id configuration, use openZipSafe for…
Browse files Browse the repository at this point in the history
… reading zips in bundler/paperclip tasks
  • Loading branch information
jpenilla committed Dec 21, 2024
1 parent f6e2593 commit c1c16b7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.file.RegularFile
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.*

Expand All @@ -41,6 +42,7 @@ class BundlerJarTasks(
project: Project,
private val bundlerJarName: Provider<String>,
private val mainClassString: Provider<String>,
private val providers: ProviderFactory = project.providers,
) {
val createBundlerJar: TaskProvider<CreateBundlerJar>
val createPaperclipJar: TaskProvider<CreatePaperclipJar>
Expand Down Expand Up @@ -156,6 +158,7 @@ class BundlerJarTasks(
registerVersionArtifact(
bundlerJarName.get(),
bundlerVersionJson,
providers,
serverJar
)
}
Expand All @@ -175,9 +178,10 @@ class BundlerJarTasks(
fun NamedDomainObjectContainer<CreateBundlerJar.VersionArtifact>.registerVersionArtifact(
name: String,
versionJson: Provider<RegularFile>,
providers: ProviderFactory,
serverJar: Provider<RegularFile>
) = register(name) {
id.set(versionJson.map { gson.fromJson<JsonObject>(it)["id"].asString })
id.set(providers.fileContents(versionJson).asText.map { gson.fromJson<JsonObject>(it)["id"].asString })
file.set(serverJar)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import org.gradle.api.file.RegularFile
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.*

@Suppress("MemberVisibilityCanBePrivate")
class DevBundleTasks(
project: Project,
tasks: TaskContainer = project.tasks,
private val providers: ProviderFactory = project.providers,
) {
val serverBundlerForDevBundle by tasks.registering<CreateBundlerJar> {
paperclip.from(project.configurations.named(PAPERCLIP_CONFIG))
Expand Down Expand Up @@ -75,6 +77,7 @@ class DevBundleTasks(
registerVersionArtifact(
bundlerJarName,
versionJsonFile,
providers,
project.tasks.named<IncludeMappings>("includeMappings").flatMap { it.outputJar }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract class CreateBundlerJar : ZippedTask() {
}

override fun run(rootDir: Path) {
paperclip.singleFile.toPath().openZip().use { zip ->
paperclip.singleFile.toPath().openZipSafe().use { zip ->
zip.getPath("/").copyRecursivelyTo(rootDir)
}

Expand Down Expand Up @@ -127,7 +127,7 @@ abstract class CreateBundlerJar : ZippedTask() {
rootDir.resolve("META-INF/main-class").writeText(mainClass.get())

// copy version.json file
vanillaBundlerJar.path.openZip().use { fs ->
vanillaBundlerJar.path.openZipSafe().use { fs ->
fs.getPath("/").resolve(FileEntry.VERSION_JSON).copyTo(rootDir.resolve("version.json"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ abstract class CreatePaperclipJar : JavaLauncherZippedTask() {
override fun run(rootDir: Path) {
// Vanilla's URL uses a SHA1 hash of the vanilla server jar
val patchEntries: List<PatchEntry>
bundlerJar.path.openZip().use { newBundlerFs ->
originalBundlerJar.path.openZip().use { originalBundlerFs ->
bundlerJar.path.openZipSafe().use { newBundlerFs ->
originalBundlerJar.path.openZipSafe().use { originalBundlerFs ->
val originalBundlerRoot = originalBundlerFs.getPath("/")
val newBundlerRoot = newBundlerFs.getPath("/")

Expand Down

0 comments on commit c1c16b7

Please sign in to comment.