diff --git a/.gitignore b/.gitignore index 7e80851..fd472d0 100644 --- a/.gitignore +++ b/.gitignore @@ -37,8 +37,8 @@ ehthumbs_vista.db *.lnk # Gradle -.gradle -/build/ +**/.gradle/ +**/build/ .gradletasknamecache # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..505555b --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,23 @@ +import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion + +plugins { + `kotlin-dsl` + `kotlin-dsl-precompiled-script-plugins` +} + +repositories { + mavenCentral() + gradlePluginPortal() +} + +dependencies { + implementation(libs.gradle.licenser) + implementation(libs.gradle.ktlint) + implementation(libs.gradle.shadow) + implementation(libs.gradle.kotlin.dsl) + implementation(libs.gradle.kotlin.plugin.withVersion(embeddedKotlinVersion)) +} + +fun Provider.withVersion(version: String): Provider { + return map { "${it.module.group}:${it.module.name}:$version" } +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..c653d66 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,9 @@ +enableFeaturePreview("VERSION_CATALOGS") + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/buildSrc/src/main/kotlin/config-kotlin.gradle.kts b/buildSrc/src/main/kotlin/config-kotlin.gradle.kts new file mode 100644 index 0000000..057edda --- /dev/null +++ b/buildSrc/src/main/kotlin/config-kotlin.gradle.kts @@ -0,0 +1,77 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + idea + id("org.gradle.kotlin.kotlin-dsl") + id("org.cadixdev.licenser") + id("org.jlleitschuh.gradle.ktlint") +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + } + withSourcesJar() +} + +repositories { + mavenCentral() + maven("https://oss.sonatype.org/content/repositories/snapshots/") { + mavenContent { + includeModule("org.cadixdev", "mercury") + } + } + maven("https://maven.quiltmc.org/repository/release/") { + mavenContent { + includeGroup("org.quiltmc") + } + } +} + +configurations.all { + if (name == "compileOnly") { + return@all + } + dependencies.remove(project.dependencies.gradleApi()) + dependencies.removeIf { it.group == "org.jetbrains.kotlin" } +} + +dependencies { + compileOnly(gradleApi()) + compileOnly(kotlin("stdlib-jdk8")) +} + +gradlePlugin { + isAutomatedPublishing = false +} + +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + useIR = true + freeCompilerArgs = listOf("-Xopt-in=kotlin.io.path.ExperimentalPathApi") + } +} + +ktlint { + enableExperimentalRules.set(true) + + disabledRules.add("no-wildcard-imports") +} + +tasks.register("format") { + group = "formatting" + description = "Formats source code according to project style" + dependsOn(tasks.licenseFormat, tasks.ktlintFormat) +} + +license { + header.set(resources.text.fromFile(rootProject.file("license/copyright.txt"))) + include("**/*.kt") +} + +idea { + module { + isDownloadSources = true + } +} diff --git a/build.gradle.kts b/buildSrc/src/main/kotlin/config-publish.gradle.kts similarity index 58% rename from build.gradle.kts rename to buildSrc/src/main/kotlin/config-publish.gradle.kts index dd2e63e..2578679 100644 --- a/build.gradle.kts +++ b/buildSrc/src/main/kotlin/config-publish.gradle.kts @@ -1,40 +1,23 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import gradle.kotlin.dsl.accessors._1393fc786dc6e595ab520b2457e34d2e.implementation +import org.gradle.api.artifacts.repositories.PasswordCredentials import org.gradle.api.publish.maven.MavenPom -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.publish.maven.tasks.PublishToMavenLocal +import org.gradle.api.publish.maven.tasks.PublishToMavenRepository +import org.gradle.kotlin.dsl.credentials +import org.gradle.kotlin.dsl.existing +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.getValue +import org.gradle.kotlin.dsl.maven +import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.registering +import org.gradle.kotlin.dsl.withType plugins { - idea - eclipse - `kotlin-dsl` `maven-publish` - id("org.cadixdev.licenser") version "0.6.0" - id("com.github.johnrengelman.shadow") version "7.0.0" - id("org.jlleitschuh.gradle.ktlint") version "10.0.0" -} - -group = "io.papermc.paperweight" -version = "1.0.0-SNAPSHOT" - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } - withSourcesJar() -} - -val sourcesJar by tasks.existing - -tasks.withType { - kotlinOptions { - jvmTarget = "1.8" - useIR = true - freeCompilerArgs = listOf("-Xopt-in=kotlin.io.path.ExperimentalPathApi") - } -} - -gradlePlugin { - // we handle publications ourselves - isAutomatedPublishing = false + id("org.jetbrains.kotlin.jvm") + id("com.github.johnrengelman.shadow") } val shade: Configuration by configurations.creating @@ -42,58 +25,6 @@ configurations.implementation { extendsFrom(shade) } -repositories { - mavenCentral() - maven("https://oss.sonatype.org/content/repositories/snapshots/") { - mavenContent { - includeModule("org.cadixdev", "mercury") - } - } - maven("https://maven.quiltmc.org/repository/release/") { - mavenContent { - includeGroup("org.quiltmc") - } - } -} - -dependencies { - shade(libs.httpclient) - shade(libs.kotson) - - // ASM for inspection - shade(libs.bundles.asm) - - shade(libs.bundles.hypo) - shade(libs.bundles.cadix) - - shade(libs.lorenzTiny) - - shade(libs.jbsdiff) -} - -ktlint { - enableExperimentalRules.set(true) - - disabledRules.add("no-wildcard-imports") -} - -tasks.register("format") { - group = "formatting" - description = "Formats source code according to project style" - dependsOn(tasks.licenseFormat, tasks.ktlintFormat) -} - -license { - header.set(resources.text.fromFile(file("license/copyright.txt"))) - include("**/*.kt") -} - -idea { - module { - isDownloadSources = true - } -} - fun ShadowJar.configureStandard() { configurations = listOf(shade) @@ -101,33 +32,18 @@ fun ShadowJar.configureStandard() { exclude(dependency("org.jetbrains.kotlin:.*:.*")) } - exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA") + exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "OSGI-INF/**", "*.profile", "module-info.class", "ant_tasks/**") mergeServiceFiles() } -tasks.shadowJar { +val sourcesJar by tasks.existing + +val shadowJar by tasks.existing(ShadowJar::class) { configureStandard() val prefix = "paper.libs" - listOf( - "dev.denwav.hypo", - "com.github.salomonbrys.kotson", - "com.google.gson", - "io.sigpipe", - "me.jamiemansfield", - "net.fabricmc", - "org.apache.commons.codec", - "org.apache.commons.compress", - "org.apache.commons.logging", - "org.apache.felix", - "org.apache.http", - "org.cadixdev", - "org.eclipse", - "org.objectweb", - "org.osgi", - "org.tukaani" - ).forEach { pack -> + listOf("com", "dev", "io.sigpipe", "me", "net", "org").forEach { pack -> relocate(pack, "$prefix.$pack") } } @@ -146,7 +62,7 @@ publishing { publications { register("shadow") { pluginConfig(version()) - artifact(tasks.shadowJar) { + artifact(shadowJar) { classifier = null } } @@ -199,8 +115,10 @@ fun MavenPublication.standardConfig(versionName: String) { } fun MavenPublication.pluginConfig(versionName: String) { - groupId = project.group.toString() - artifactId = "io.papermc.paperweight.gradle.plugin" + val baseName = project.group.toString() + "." + project.name.substringAfter('-') + + groupId = baseName + artifactId = "$baseName.gradle.plugin" version = versionName artifact(sourcesJar) diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..a2db51e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +group = io.papermc.paperweight +version = 1.0.0-SNAPSHOT diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d98a536..eacfe90 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,6 +27,13 @@ hypo-mappings = { module = "dev.denwav.hypo:hypo-mappings", version.ref = "hypo" lorenzTiny = "org.quiltmc:lorenz-tiny:3.0.0" jbsdiff = "io.sigpipe:jbsdiff:1.0" +# Gradle +gradle-licenser = "org.cadixdev.licenser:org.cadixdev.licenser.gradle.plugin:0.6.0" +gradle-shadow = "com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:7.0.0" +gradle-ktlint = "org.jlleitschuh.gradle.ktlint:org.jlleitschuh.gradle.ktlint.gradle.plugin:10.0.0" +gradle-kotlin-dsl = "org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:2.1.4" +gradle-kotlin-plugin = { module = "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin" } + [bundles] asm = ["asm-core", "asm-tree"] cadix = ["cadix-lorenz-core", "cadix-lorenz-asm", "cadix-lorenz-proguard", "cadix-atlas", "cadix-at", "cadix-mercury"] diff --git a/license/copyright.txt b/license/copyright.txt index 19e8c35..25e29a0 100644 --- a/license/copyright.txt +++ b/license/copyright.txt @@ -1,6 +1,6 @@ paperweight is a Gradle plugin for the PaperMC project. -Copyright (c) 2020 Kyle Wood (DemonWav) +Copyright (c) 2021 Kyle Wood (DemonWav) Contributors This library is free software; you can redistribute it and/or diff --git a/paperweight-core/build.gradle.kts b/paperweight-core/build.gradle.kts new file mode 100644 index 0000000..baaf54a --- /dev/null +++ b/paperweight-core/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + `config-kotlin` + `config-publish` +} + +dependencies { + shade(projects.paperweightLib) + + implementation(libs.kotson) +} diff --git a/src/main/kotlin/Paperweight.kt b/paperweight-core/src/main/kotlin/PaperweightCore.kt similarity index 89% rename from src/main/kotlin/Paperweight.kt rename to paperweight-core/src/main/kotlin/PaperweightCore.kt index e758ce1..2552c95 100644 --- a/src/main/kotlin/Paperweight.kt +++ b/paperweight-core/src/main/kotlin/PaperweightCore.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,19 +20,21 @@ * USA */ -package io.papermc.paperweight +package io.papermc.paperweight.core -import io.papermc.paperweight.ext.PaperweightExtension -import io.papermc.paperweight.plugin.AllTasks +import io.papermc.paperweight.DownloadService +import io.papermc.paperweight.core.ext.PaperweightCoreExtension +import io.papermc.paperweight.core.taskcontainers.AllTasks +import io.papermc.paperweight.core.tasks.PaperweightCoreUpstreamData import io.papermc.paperweight.tasks.GeneratePaperclipPatch import io.papermc.paperweight.tasks.RemapJar import io.papermc.paperweight.tasks.RemapJarAtlas import io.papermc.paperweight.tasks.patchremap.RemapPatches import io.papermc.paperweight.util.Constants import io.papermc.paperweight.util.cache -import io.papermc.paperweight.util.ext import io.papermc.paperweight.util.initSubmodules import io.papermc.paperweight.util.registering +import java.io.File import kotlin.io.path.* import org.gradle.api.Plugin import org.gradle.api.Project @@ -41,9 +43,9 @@ import org.gradle.api.tasks.TaskProvider import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.* -class Paperweight : Plugin { +class PaperweightCore : Plugin { override fun apply(target: Project) { - target.extensions.create(Constants.EXTENSION, PaperweightExtension::class.java, target.objects, target.layout) + target.extensions.create(Constants.EXTENSION, PaperweightCoreExtension::class) target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {} @@ -65,6 +67,14 @@ class Paperweight : Plugin { val tasks = AllTasks(target) target.createPatchRemapTask(tasks) + target.tasks.register(Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM) { + dependsOn(tasks.patchPaper) + decompiledJar.set(tasks.decompileJar.flatMap { it.outputJar }) + mcLibrariesDir.set(tasks.downloadMcLibraries.flatMap { it.sourcesOutputDir }) + + dataFile.set(target.layout.file(providers.gradleProperty(Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM).map { File(it) })) + } + // Setup the server jar target.afterEvaluate { target.ext.serverProject.forUseAtConfigurationTime().orNull?.setupServerProject(target, tasks)?.let { repackageJar -> @@ -142,7 +152,7 @@ class Paperweight : Plugin { } private fun Project.createPatchRemapTask(allTasks: AllTasks) { - val extension: PaperweightExtension = ext + val extension: PaperweightCoreExtension = ext /* * To ease the waiting time for debugging this task, all of the task dependencies have been removed (notice all diff --git a/src/main/kotlin/ext/CraftBukkitExtension.kt b/paperweight-core/src/main/kotlin/ext/CraftBukkitExtension.kt similarity index 97% rename from src/main/kotlin/ext/CraftBukkitExtension.kt rename to paperweight-core/src/main/kotlin/ext/CraftBukkitExtension.kt index c80c9de..3fda6fb 100644 --- a/src/main/kotlin/ext/CraftBukkitExtension.kt +++ b/paperweight-core/src/main/kotlin/ext/CraftBukkitExtension.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,7 +20,7 @@ * USA */ -package io.papermc.paperweight.ext +package io.papermc.paperweight.core.ext import io.papermc.paperweight.util.path import kotlin.io.path.name diff --git a/src/main/kotlin/ext/PaperExtension.kt b/paperweight-core/src/main/kotlin/ext/PaperExtension.kt similarity index 96% rename from src/main/kotlin/ext/PaperExtension.kt rename to paperweight-core/src/main/kotlin/ext/PaperExtension.kt index b9d8928..acdb3f2 100644 --- a/src/main/kotlin/ext/PaperExtension.kt +++ b/paperweight-core/src/main/kotlin/ext/PaperExtension.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,7 +20,7 @@ * USA */ -package io.papermc.paperweight.ext +package io.papermc.paperweight.core.ext import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.ProjectLayout @@ -28,6 +28,7 @@ import org.gradle.api.file.RegularFileProperty import org.gradle.api.model.ObjectFactory open class PaperExtension(objects: ObjectFactory, layout: ProjectLayout) { + @Suppress("MemberVisibilityCanBePrivate") val baseTargetDir: DirectoryProperty = objects.dirWithDefault(layout, ".") val spigotApiPatchDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "Spigot-API-Patches") diff --git a/src/main/kotlin/ext/PaperweightExtension.kt b/paperweight-core/src/main/kotlin/ext/PaperweightCoreExtension.kt similarity index 89% rename from src/main/kotlin/ext/PaperweightExtension.kt rename to paperweight-core/src/main/kotlin/ext/PaperweightCoreExtension.kt index d68661f..92e72b5 100644 --- a/src/main/kotlin/ext/PaperweightExtension.kt +++ b/paperweight-core/src/main/kotlin/ext/PaperweightCoreExtension.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,7 +20,7 @@ * USA */ -package io.papermc.paperweight.ext +package io.papermc.paperweight.core.ext import org.gradle.api.Action import org.gradle.api.Project @@ -30,7 +30,7 @@ import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property import org.gradle.kotlin.dsl.property -open class PaperweightExtension(objects: ObjectFactory, layout: ProjectLayout) { +open class PaperweightCoreExtension(objects: ObjectFactory, layout: ProjectLayout) { @Suppress("MemberVisibilityCanBePrivate") val workDir: DirectoryProperty = objects.dirWithDefault(layout, "work") @@ -39,6 +39,7 @@ open class PaperweightExtension(objects: ObjectFactory, layout: ProjectLayout) { val versionPackage: Property = objects.property() val serverProject: Property = objects.property() + @Suppress("MemberVisibilityCanBePrivate") val craftBukkit = CraftBukkitExtension(objects, workDir) val spigot = SpigotExtension(objects, workDir) val paper = PaperExtension(objects, layout) diff --git a/src/main/kotlin/ext/SpigotExtension.kt b/paperweight-core/src/main/kotlin/ext/SpigotExtension.kt similarity index 94% rename from src/main/kotlin/ext/SpigotExtension.kt rename to paperweight-core/src/main/kotlin/ext/SpigotExtension.kt index 89ce75c..6b0bcc8 100644 --- a/src/main/kotlin/ext/SpigotExtension.kt +++ b/paperweight-core/src/main/kotlin/ext/SpigotExtension.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,12 +20,13 @@ * USA */ -package io.papermc.paperweight.ext +package io.papermc.paperweight.core.ext import org.gradle.api.file.DirectoryProperty import org.gradle.api.model.ObjectFactory open class SpigotExtension(objects: ObjectFactory, workDir: DirectoryProperty) { + @Suppress("MemberVisibilityCanBePrivate") val spigotDir: DirectoryProperty = objects.dirFrom(workDir, "Spigot") val spigotApiDir: DirectoryProperty = objects.dirFrom(spigotDir, "Spigot-API") diff --git a/src/main/kotlin/ext/extensions.kt b/paperweight-core/src/main/kotlin/ext/extensions.kt similarity index 94% rename from src/main/kotlin/ext/extensions.kt rename to paperweight-core/src/main/kotlin/ext/extensions.kt index 2530f47..fc3cb23 100644 --- a/src/main/kotlin/ext/extensions.kt +++ b/paperweight-core/src/main/kotlin/ext/extensions.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,7 +20,7 @@ * USA */ -package io.papermc.paperweight.ext +package io.papermc.paperweight.core.ext import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.ProjectLayout diff --git a/src/main/kotlin/plugin/AllTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt similarity index 89% rename from src/main/kotlin/plugin/AllTasks.kt rename to paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt index 2034e3d..98de8b1 100644 --- a/src/main/kotlin/plugin/AllTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/AllTasks.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,18 +20,14 @@ * USA */ -package io.papermc.paperweight.plugin +package io.papermc.paperweight.core.taskcontainers -import io.papermc.paperweight.ext.PaperweightExtension -import io.papermc.paperweight.tasks.ApplyGitPatches -import io.papermc.paperweight.tasks.ApplyPaperPatches -import io.papermc.paperweight.tasks.CopyResources -import io.papermc.paperweight.tasks.RebuildPaperPatches -import io.papermc.paperweight.tasks.RunForgeFlower +import io.papermc.paperweight.core.ext +import io.papermc.paperweight.core.ext.PaperweightCoreExtension +import io.papermc.paperweight.tasks.* import io.papermc.paperweight.tasks.patchremap.ApplyAccessTransform import io.papermc.paperweight.util.Constants import io.papermc.paperweight.util.cache -import io.papermc.paperweight.util.ext import io.papermc.paperweight.util.registering import io.papermc.paperweight.util.set import java.nio.file.Path @@ -45,7 +41,7 @@ open class AllTasks( project: Project, tasks: TaskContainer = project.tasks, cache: Path = project.layout.cache, - extension: PaperweightExtension = project.ext, + extension: PaperweightCoreExtension = project.ext, ) : SpigotTasks(project) { val applyMergedAt by tasks.registering { diff --git a/src/main/kotlin/plugin/GeneralTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/GeneralTasks.kt similarity index 85% rename from src/main/kotlin/plugin/GeneralTasks.kt rename to paperweight-core/src/main/kotlin/taskcontainers/GeneralTasks.kt index 7f30fa3..c1faaf6 100644 --- a/src/main/kotlin/plugin/GeneralTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/GeneralTasks.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,18 +20,16 @@ * USA */ -package io.papermc.paperweight.plugin +package io.papermc.paperweight.core.taskcontainers import com.github.salomonbrys.kotson.fromJson import io.papermc.paperweight.DownloadService -import io.papermc.paperweight.ext.PaperweightExtension -import io.papermc.paperweight.tasks.DownloadServerJar -import io.papermc.paperweight.tasks.FilterJar -import io.papermc.paperweight.tasks.InitSubmodules +import io.papermc.paperweight.core.ext +import io.papermc.paperweight.core.ext.PaperweightCoreExtension +import io.papermc.paperweight.tasks.* import io.papermc.paperweight.util.BuildDataInfo import io.papermc.paperweight.util.contents import io.papermc.paperweight.util.download -import io.papermc.paperweight.util.ext import io.papermc.paperweight.util.gson import io.papermc.paperweight.util.registering import org.gradle.api.Project @@ -43,7 +41,7 @@ import org.gradle.kotlin.dsl.* open class GeneralTasks( project: Project, tasks: TaskContainer = project.tasks, - extension: PaperweightExtension = project.ext, + extension: PaperweightCoreExtension = project.ext, downloadService: Provider = project.download, ) : InitialTasks(project) { diff --git a/src/main/kotlin/plugin/InitialTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt similarity index 91% rename from src/main/kotlin/plugin/InitialTasks.kt rename to paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt index c202206..744d31a 100644 --- a/src/main/kotlin/plugin/InitialTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/InitialTasks.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,21 +20,20 @@ * USA */ -package io.papermc.paperweight.plugin +package io.papermc.paperweight.core.taskcontainers import com.github.salomonbrys.kotson.array import com.github.salomonbrys.kotson.get import com.github.salomonbrys.kotson.string import com.google.gson.JsonObject import io.papermc.paperweight.DownloadService -import io.papermc.paperweight.ext.PaperweightExtension -import io.papermc.paperweight.tasks.DownloadTask -import io.papermc.paperweight.tasks.SetupMcLibraries +import io.papermc.paperweight.core.ext +import io.papermc.paperweight.core.ext.PaperweightCoreExtension +import io.papermc.paperweight.tasks.* import io.papermc.paperweight.util.Constants import io.papermc.paperweight.util.MinecraftManifest import io.papermc.paperweight.util.cache import io.papermc.paperweight.util.download -import io.papermc.paperweight.util.ext import io.papermc.paperweight.util.fromJson import io.papermc.paperweight.util.gson import io.papermc.paperweight.util.registering @@ -50,7 +49,7 @@ open class InitialTasks( project: Project, tasks: TaskContainer = project.tasks, cache: Path = project.layout.cache, - extension: PaperweightExtension = project.ext, + extension: PaperweightCoreExtension = project.ext, downloadService: Provider = project.download ) { diff --git a/src/main/kotlin/plugin/SpigotTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt similarity index 88% rename from src/main/kotlin/plugin/SpigotTasks.kt rename to paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt index cc5509b..ae8a10a 100644 --- a/src/main/kotlin/plugin/SpigotTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/SpigotTasks.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,30 +20,15 @@ * USA */ -package io.papermc.paperweight.plugin +package io.papermc.paperweight.core.taskcontainers import io.papermc.paperweight.DownloadService -import io.papermc.paperweight.ext.PaperweightExtension -import io.papermc.paperweight.tasks.AddAdditionalSpigotMappings -import io.papermc.paperweight.tasks.ApplyDiffPatches -import io.papermc.paperweight.tasks.ApplyGitPatches -import io.papermc.paperweight.tasks.ApplyRawDiffPatches -import io.papermc.paperweight.tasks.CleanupMappings -import io.papermc.paperweight.tasks.DownloadSpigotDependencies -import io.papermc.paperweight.tasks.FilterSpigotExcludes -import io.papermc.paperweight.tasks.GenerateSpigotMappings -import io.papermc.paperweight.tasks.InspectVanillaJar -import io.papermc.paperweight.tasks.MergeAccessTransforms -import io.papermc.paperweight.tasks.PatchMappings -import io.papermc.paperweight.tasks.RemapAccessTransform -import io.papermc.paperweight.tasks.RemapSources -import io.papermc.paperweight.tasks.RemapSpigotAt -import io.papermc.paperweight.tasks.SpigotDecompileJar -import io.papermc.paperweight.tasks.SpigotRemapJar +import io.papermc.paperweight.core.ext +import io.papermc.paperweight.core.ext.PaperweightCoreExtension +import io.papermc.paperweight.tasks.* import io.papermc.paperweight.util.Constants import io.papermc.paperweight.util.cache import io.papermc.paperweight.util.download -import io.papermc.paperweight.util.ext import io.papermc.paperweight.util.registering import io.papermc.paperweight.util.set import java.nio.file.Path @@ -58,7 +43,7 @@ open class SpigotTasks( project: Project, tasks: TaskContainer = project.tasks, cache: Path = project.layout.cache, - extension: PaperweightExtension = project.ext, + extension: PaperweightCoreExtension = project.ext, downloadService: Provider = project.download, ) : VanillaTasks(project) { diff --git a/src/main/kotlin/plugin/VanillaTasks.kt b/paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt similarity index 93% rename from src/main/kotlin/plugin/VanillaTasks.kt rename to paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt index d585e85..2b48319 100644 --- a/src/main/kotlin/plugin/VanillaTasks.kt +++ b/paperweight-core/src/main/kotlin/taskcontainers/VanillaTasks.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -20,13 +20,11 @@ * USA */ -package io.papermc.paperweight.plugin +package io.papermc.paperweight.core.taskcontainers import io.papermc.paperweight.DownloadService +import io.papermc.paperweight.tasks.* import io.papermc.paperweight.tasks.DownloadMcLibraries -import io.papermc.paperweight.tasks.FixJar -import io.papermc.paperweight.tasks.GenerateMappings -import io.papermc.paperweight.tasks.RemapJar import io.papermc.paperweight.util.Constants import io.papermc.paperweight.util.cache import io.papermc.paperweight.util.download diff --git a/paperweight-core/src/main/kotlin/tasks/PaperweightCoreUpstreamData.kt b/paperweight-core/src/main/kotlin/tasks/PaperweightCoreUpstreamData.kt new file mode 100644 index 0000000..66f64bf --- /dev/null +++ b/paperweight-core/src/main/kotlin/tasks/PaperweightCoreUpstreamData.kt @@ -0,0 +1,63 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.core.tasks + +import io.papermc.paperweight.util.path +import javax.inject.Inject +import kotlin.io.path.absolutePathString +import kotlin.io.path.bufferedWriter +import kotlin.io.path.createDirectories +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.ProviderFactory +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +abstract class PaperweightCoreUpstreamData : DefaultTask() { + + @get:InputFile + abstract val decompiledJar: RegularFileProperty + + @get:InputDirectory + abstract val mcLibrariesDir: DirectoryProperty + + @get:OutputFile + abstract val dataFile: RegularFileProperty + + @get:Inject + abstract val providers: ProviderFactory + + @TaskAction + fun run() { + val dataFilePath = dataFile.path + + dataFilePath.parent.createDirectories() + dataFilePath.bufferedWriter(Charsets.UTF_8).use { writer -> + writer.appendLine(decompiledJar.path.absolutePathString()) + writer.appendLine(mcLibrariesDir.path.absolutePathString()) + } + } +} diff --git a/paperweight-core/src/main/kotlin/utils.kt b/paperweight-core/src/main/kotlin/utils.kt new file mode 100644 index 0000000..1a2b4ea --- /dev/null +++ b/paperweight-core/src/main/kotlin/utils.kt @@ -0,0 +1,30 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.core + +import io.papermc.paperweight.core.ext.PaperweightCoreExtension +import io.papermc.paperweight.util.Constants +import org.gradle.api.Project + +val Project.ext: PaperweightCoreExtension + get() = extensions.getByName(Constants.EXTENSION) as PaperweightCoreExtension diff --git a/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.core.properties b/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.core.properties new file mode 100644 index 0000000..8efea5a --- /dev/null +++ b/paperweight-core/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.core.properties @@ -0,0 +1 @@ +implementation-class=io.papermc.paperweight.core.PaperweightCore diff --git a/paperweight-lib/build.gradle.kts b/paperweight-lib/build.gradle.kts new file mode 100644 index 0000000..f58708f --- /dev/null +++ b/paperweight-lib/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + `config-kotlin` +} + +dependencies { + implementation(libs.httpclient) + implementation(libs.kotson) + + // ASM for inspection + implementation(libs.bundles.asm) + + implementation(libs.bundles.hypo) + implementation(libs.bundles.cadix) + + implementation(libs.lorenzTiny) + + implementation(libs.jbsdiff) +} diff --git a/src/main/kotlin/DownloadService.kt b/paperweight-lib/src/main/kotlin/DownloadService.kt similarity index 99% rename from src/main/kotlin/DownloadService.kt rename to paperweight-lib/src/main/kotlin/DownloadService.kt index 54e6d1f..7c56b43 100644 --- a/src/main/kotlin/DownloadService.kt +++ b/paperweight-lib/src/main/kotlin/DownloadService.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/PaperweightException.kt b/paperweight-lib/src/main/kotlin/PaperweightException.kt similarity index 95% rename from src/main/kotlin/PaperweightException.kt rename to paperweight-lib/src/main/kotlin/PaperweightException.kt index 1b6226b..d8fc1a9 100644 --- a/src/main/kotlin/PaperweightException.kt +++ b/paperweight-lib/src/main/kotlin/PaperweightException.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/AddAdditionalSpigotMappings.kt b/paperweight-lib/src/main/kotlin/tasks/AddAdditionalSpigotMappings.kt similarity index 98% rename from src/main/kotlin/tasks/AddAdditionalSpigotMappings.kt rename to paperweight-lib/src/main/kotlin/tasks/AddAdditionalSpigotMappings.kt index f0bc175..7e42a97 100644 --- a/src/main/kotlin/tasks/AddAdditionalSpigotMappings.kt +++ b/paperweight-lib/src/main/kotlin/tasks/AddAdditionalSpigotMappings.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/ApplyDiffPatches.kt b/paperweight-lib/src/main/kotlin/tasks/ApplyDiffPatches.kt similarity index 99% rename from src/main/kotlin/tasks/ApplyDiffPatches.kt rename to paperweight-lib/src/main/kotlin/tasks/ApplyDiffPatches.kt index f00c396..5be95f9 100644 --- a/src/main/kotlin/tasks/ApplyDiffPatches.kt +++ b/paperweight-lib/src/main/kotlin/tasks/ApplyDiffPatches.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/ApplyGitPatches.kt b/paperweight-lib/src/main/kotlin/tasks/ApplyGitPatches.kt similarity index 99% rename from src/main/kotlin/tasks/ApplyGitPatches.kt rename to paperweight-lib/src/main/kotlin/tasks/ApplyGitPatches.kt index 2c6db8b..8fe1860 100644 --- a/src/main/kotlin/tasks/ApplyGitPatches.kt +++ b/paperweight-lib/src/main/kotlin/tasks/ApplyGitPatches.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/ApplyPaperPatches.kt b/paperweight-lib/src/main/kotlin/tasks/ApplyPaperPatches.kt similarity index 98% rename from src/main/kotlin/tasks/ApplyPaperPatches.kt rename to paperweight-lib/src/main/kotlin/tasks/ApplyPaperPatches.kt index e5dd963..cac8bfc 100644 --- a/src/main/kotlin/tasks/ApplyPaperPatches.kt +++ b/paperweight-lib/src/main/kotlin/tasks/ApplyPaperPatches.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/ApplyRawDiffPatches.kt b/paperweight-lib/src/main/kotlin/tasks/ApplyRawDiffPatches.kt similarity index 97% rename from src/main/kotlin/tasks/ApplyRawDiffPatches.kt rename to paperweight-lib/src/main/kotlin/tasks/ApplyRawDiffPatches.kt index 1c29908..7f12e79 100644 --- a/src/main/kotlin/tasks/ApplyRawDiffPatches.kt +++ b/paperweight-lib/src/main/kotlin/tasks/ApplyRawDiffPatches.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/BaseTask.kt b/paperweight-lib/src/main/kotlin/tasks/BaseTask.kt similarity index 97% rename from src/main/kotlin/tasks/BaseTask.kt rename to paperweight-lib/src/main/kotlin/tasks/BaseTask.kt index 91ad0d9..0b65606 100644 --- a/src/main/kotlin/tasks/BaseTask.kt +++ b/paperweight-lib/src/main/kotlin/tasks/BaseTask.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/CleanupMappings.kt b/paperweight-lib/src/main/kotlin/tasks/CleanupMappings.kt similarity index 99% rename from src/main/kotlin/tasks/CleanupMappings.kt rename to paperweight-lib/src/main/kotlin/tasks/CleanupMappings.kt index 0feac0c..49d880f 100644 --- a/src/main/kotlin/tasks/CleanupMappings.kt +++ b/paperweight-lib/src/main/kotlin/tasks/CleanupMappings.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/ControllableOutputTask.kt b/paperweight-lib/src/main/kotlin/tasks/ControllableOutputTask.kt similarity index 97% rename from src/main/kotlin/tasks/ControllableOutputTask.kt rename to paperweight-lib/src/main/kotlin/tasks/ControllableOutputTask.kt index d57fbcd..ba3d8d5 100644 --- a/src/main/kotlin/tasks/ControllableOutputTask.kt +++ b/paperweight-lib/src/main/kotlin/tasks/ControllableOutputTask.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/CopyResources.kt b/paperweight-lib/src/main/kotlin/tasks/CopyResources.kt similarity index 97% rename from src/main/kotlin/tasks/CopyResources.kt rename to paperweight-lib/src/main/kotlin/tasks/CopyResources.kt index 637abf3..c7fbc05 100644 --- a/src/main/kotlin/tasks/CopyResources.kt +++ b/paperweight-lib/src/main/kotlin/tasks/CopyResources.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -34,6 +34,7 @@ import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction abstract class CopyResources : BaseTask() { + @get:InputFile abstract val inputJar: RegularFileProperty diff --git a/src/main/kotlin/tasks/DownloadServerJar.kt b/paperweight-lib/src/main/kotlin/tasks/DownloadServerJar.kt similarity index 98% rename from src/main/kotlin/tasks/DownloadServerJar.kt rename to paperweight-lib/src/main/kotlin/tasks/DownloadServerJar.kt index dd449f5..12e5f81 100644 --- a/src/main/kotlin/tasks/DownloadServerJar.kt +++ b/paperweight-lib/src/main/kotlin/tasks/DownloadServerJar.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/FilterJar.kt b/paperweight-lib/src/main/kotlin/tasks/FilterJar.kt similarity index 98% rename from src/main/kotlin/tasks/FilterJar.kt rename to paperweight-lib/src/main/kotlin/tasks/FilterJar.kt index bd1d1ce..df5e579 100644 --- a/src/main/kotlin/tasks/FilterJar.kt +++ b/paperweight-lib/src/main/kotlin/tasks/FilterJar.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/FilterSpigotExcludes.kt b/paperweight-lib/src/main/kotlin/tasks/FilterSpigotExcludes.kt similarity index 97% rename from src/main/kotlin/tasks/FilterSpigotExcludes.kt rename to paperweight-lib/src/main/kotlin/tasks/FilterSpigotExcludes.kt index 9fd5c0b..56209d7 100644 --- a/src/main/kotlin/tasks/FilterSpigotExcludes.kt +++ b/paperweight-lib/src/main/kotlin/tasks/FilterSpigotExcludes.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/FixJar.kt b/paperweight-lib/src/main/kotlin/tasks/FixJar.kt similarity index 99% rename from src/main/kotlin/tasks/FixJar.kt rename to paperweight-lib/src/main/kotlin/tasks/FixJar.kt index 627c8dc..10ceed2 100644 --- a/src/main/kotlin/tasks/FixJar.kt +++ b/paperweight-lib/src/main/kotlin/tasks/FixJar.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/GenerateMappings.kt b/paperweight-lib/src/main/kotlin/tasks/GenerateMappings.kt similarity index 99% rename from src/main/kotlin/tasks/GenerateMappings.kt rename to paperweight-lib/src/main/kotlin/tasks/GenerateMappings.kt index 5f30985..da0cca3 100644 --- a/src/main/kotlin/tasks/GenerateMappings.kt +++ b/paperweight-lib/src/main/kotlin/tasks/GenerateMappings.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/GeneratePaperclipPatch.kt b/paperweight-lib/src/main/kotlin/tasks/GeneratePaperclipPatch.kt similarity index 99% rename from src/main/kotlin/tasks/GeneratePaperclipPatch.kt rename to paperweight-lib/src/main/kotlin/tasks/GeneratePaperclipPatch.kt index e9ab40e..443d4c8 100644 --- a/src/main/kotlin/tasks/GeneratePaperclipPatch.kt +++ b/paperweight-lib/src/main/kotlin/tasks/GeneratePaperclipPatch.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/GenerateSpigotMappings.kt b/paperweight-lib/src/main/kotlin/tasks/GenerateSpigotMappings.kt similarity index 99% rename from src/main/kotlin/tasks/GenerateSpigotMappings.kt rename to paperweight-lib/src/main/kotlin/tasks/GenerateSpigotMappings.kt index 93194f4..89a3825 100644 --- a/src/main/kotlin/tasks/GenerateSpigotMappings.kt +++ b/paperweight-lib/src/main/kotlin/tasks/GenerateSpigotMappings.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/InitSubmodules.kt b/paperweight-lib/src/main/kotlin/tasks/InitSubmodules.kt similarity index 96% rename from src/main/kotlin/tasks/InitSubmodules.kt rename to paperweight-lib/src/main/kotlin/tasks/InitSubmodules.kt index 46e239b..f279727 100644 --- a/src/main/kotlin/tasks/InitSubmodules.kt +++ b/paperweight-lib/src/main/kotlin/tasks/InitSubmodules.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/InspectVanillaJar.kt b/paperweight-lib/src/main/kotlin/tasks/InspectVanillaJar.kt similarity index 99% rename from src/main/kotlin/tasks/InspectVanillaJar.kt rename to paperweight-lib/src/main/kotlin/tasks/InspectVanillaJar.kt index c15b2d0..e73654a 100644 --- a/src/main/kotlin/tasks/InspectVanillaJar.kt +++ b/paperweight-lib/src/main/kotlin/tasks/InspectVanillaJar.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/MergeAccessTransforms.kt b/paperweight-lib/src/main/kotlin/tasks/MergeAccessTransforms.kt similarity index 97% rename from src/main/kotlin/tasks/MergeAccessTransforms.kt rename to paperweight-lib/src/main/kotlin/tasks/MergeAccessTransforms.kt index fb1cf4c..f1f9a32 100644 --- a/src/main/kotlin/tasks/MergeAccessTransforms.kt +++ b/paperweight-lib/src/main/kotlin/tasks/MergeAccessTransforms.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/PatchMappings.kt b/paperweight-lib/src/main/kotlin/tasks/PatchMappings.kt similarity index 98% rename from src/main/kotlin/tasks/PatchMappings.kt rename to paperweight-lib/src/main/kotlin/tasks/PatchMappings.kt index 85fe3c5..bd01326 100644 --- a/src/main/kotlin/tasks/PatchMappings.kt +++ b/paperweight-lib/src/main/kotlin/tasks/PatchMappings.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/RebuildPaperPatches.kt b/paperweight-lib/src/main/kotlin/tasks/RebuildPaperPatches.kt similarity index 99% rename from src/main/kotlin/tasks/RebuildPaperPatches.kt rename to paperweight-lib/src/main/kotlin/tasks/RebuildPaperPatches.kt index cde46e3..042f789 100644 --- a/src/main/kotlin/tasks/RebuildPaperPatches.kt +++ b/paperweight-lib/src/main/kotlin/tasks/RebuildPaperPatches.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/RemapAccessTransform.kt b/paperweight-lib/src/main/kotlin/tasks/RemapAccessTransform.kt similarity index 97% rename from src/main/kotlin/tasks/RemapAccessTransform.kt rename to paperweight-lib/src/main/kotlin/tasks/RemapAccessTransform.kt index 82049a4..f3eb516 100644 --- a/src/main/kotlin/tasks/RemapAccessTransform.kt +++ b/paperweight-lib/src/main/kotlin/tasks/RemapAccessTransform.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/RemapJar.kt b/paperweight-lib/src/main/kotlin/tasks/RemapJar.kt similarity index 98% rename from src/main/kotlin/tasks/RemapJar.kt rename to paperweight-lib/src/main/kotlin/tasks/RemapJar.kt index 6a439d5..e7c9160 100644 --- a/src/main/kotlin/tasks/RemapJar.kt +++ b/paperweight-lib/src/main/kotlin/tasks/RemapJar.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/RemapJarAtlas.kt b/paperweight-lib/src/main/kotlin/tasks/RemapJarAtlas.kt similarity index 98% rename from src/main/kotlin/tasks/RemapJarAtlas.kt rename to paperweight-lib/src/main/kotlin/tasks/RemapJarAtlas.kt index 03bc542..db6f148 100644 --- a/src/main/kotlin/tasks/RemapJarAtlas.kt +++ b/paperweight-lib/src/main/kotlin/tasks/RemapJarAtlas.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/RemapSources.kt b/paperweight-lib/src/main/kotlin/tasks/RemapSources.kt similarity index 99% rename from src/main/kotlin/tasks/RemapSources.kt rename to paperweight-lib/src/main/kotlin/tasks/RemapSources.kt index 8b6b18c..b51aaf2 100644 --- a/src/main/kotlin/tasks/RemapSources.kt +++ b/paperweight-lib/src/main/kotlin/tasks/RemapSources.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/RemapSpigotAt.kt b/paperweight-lib/src/main/kotlin/tasks/RemapSpigotAt.kt similarity index 99% rename from src/main/kotlin/tasks/RemapSpigotAt.kt rename to paperweight-lib/src/main/kotlin/tasks/RemapSpigotAt.kt index f957dd0..7620f02 100644 --- a/src/main/kotlin/tasks/RemapSpigotAt.kt +++ b/paperweight-lib/src/main/kotlin/tasks/RemapSpigotAt.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/RunForgeFlower.kt b/paperweight-lib/src/main/kotlin/tasks/RunForgeFlower.kt similarity index 98% rename from src/main/kotlin/tasks/RunForgeFlower.kt rename to paperweight-lib/src/main/kotlin/tasks/RunForgeFlower.kt index de0105c..044a7d4 100644 --- a/src/main/kotlin/tasks/RunForgeFlower.kt +++ b/paperweight-lib/src/main/kotlin/tasks/RunForgeFlower.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/SetupMcLibraries.kt b/paperweight-lib/src/main/kotlin/tasks/SetupMcLibraries.kt similarity index 97% rename from src/main/kotlin/tasks/SetupMcLibraries.kt rename to paperweight-lib/src/main/kotlin/tasks/SetupMcLibraries.kt index 7f26e5e..08fe17a 100644 --- a/src/main/kotlin/tasks/SetupMcLibraries.kt +++ b/paperweight-lib/src/main/kotlin/tasks/SetupMcLibraries.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/SpigotDecompileJar.kt b/paperweight-lib/src/main/kotlin/tasks/SpigotDecompileJar.kt similarity index 98% rename from src/main/kotlin/tasks/SpigotDecompileJar.kt rename to paperweight-lib/src/main/kotlin/tasks/SpigotDecompileJar.kt index f0c8630..e4e792b 100644 --- a/src/main/kotlin/tasks/SpigotDecompileJar.kt +++ b/paperweight-lib/src/main/kotlin/tasks/SpigotDecompileJar.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/SpigotRemapJar.kt b/paperweight-lib/src/main/kotlin/tasks/SpigotRemapJar.kt similarity index 99% rename from src/main/kotlin/tasks/SpigotRemapJar.kt rename to paperweight-lib/src/main/kotlin/tasks/SpigotRemapJar.kt index 619b7e8..dc34ac3 100644 --- a/src/main/kotlin/tasks/SpigotRemapJar.kt +++ b/paperweight-lib/src/main/kotlin/tasks/SpigotRemapJar.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/ZippedTask.kt b/paperweight-lib/src/main/kotlin/tasks/ZippedTask.kt similarity index 98% rename from src/main/kotlin/tasks/ZippedTask.kt rename to paperweight-lib/src/main/kotlin/tasks/ZippedTask.kt index d007bc3..ce747cd 100644 --- a/src/main/kotlin/tasks/ZippedTask.kt +++ b/paperweight-lib/src/main/kotlin/tasks/ZippedTask.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/download-task.kt b/paperweight-lib/src/main/kotlin/tasks/download-task.kt similarity index 99% rename from src/main/kotlin/tasks/download-task.kt rename to paperweight-lib/src/main/kotlin/tasks/download-task.kt index cfc67c7..2542c84 100644 --- a/src/main/kotlin/tasks/download-task.kt +++ b/paperweight-lib/src/main/kotlin/tasks/download-task.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/patchremap/ApplyAccessTransform.kt b/paperweight-lib/src/main/kotlin/tasks/patchremap/ApplyAccessTransform.kt similarity index 99% rename from src/main/kotlin/tasks/patchremap/ApplyAccessTransform.kt rename to paperweight-lib/src/main/kotlin/tasks/patchremap/ApplyAccessTransform.kt index b62042e..779c591 100644 --- a/src/main/kotlin/tasks/patchremap/ApplyAccessTransform.kt +++ b/paperweight-lib/src/main/kotlin/tasks/patchremap/ApplyAccessTransform.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/patchremap/PatchApplier.kt b/paperweight-lib/src/main/kotlin/tasks/patchremap/PatchApplier.kt similarity index 99% rename from src/main/kotlin/tasks/patchremap/PatchApplier.kt rename to paperweight-lib/src/main/kotlin/tasks/patchremap/PatchApplier.kt index fba6d73..96e26ce 100644 --- a/src/main/kotlin/tasks/patchremap/PatchApplier.kt +++ b/paperweight-lib/src/main/kotlin/tasks/patchremap/PatchApplier.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/patchremap/PatchSourceRemapWorker.kt b/paperweight-lib/src/main/kotlin/tasks/patchremap/PatchSourceRemapWorker.kt similarity index 98% rename from src/main/kotlin/tasks/patchremap/PatchSourceRemapWorker.kt rename to paperweight-lib/src/main/kotlin/tasks/patchremap/PatchSourceRemapWorker.kt index 0030004..6ca308e 100644 --- a/src/main/kotlin/tasks/patchremap/PatchSourceRemapWorker.kt +++ b/paperweight-lib/src/main/kotlin/tasks/patchremap/PatchSourceRemapWorker.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/tasks/patchremap/RemapPatches.kt b/paperweight-lib/src/main/kotlin/tasks/patchremap/RemapPatches.kt similarity index 99% rename from src/main/kotlin/tasks/patchremap/RemapPatches.kt rename to paperweight-lib/src/main/kotlin/tasks/patchremap/RemapPatches.kt index f3e5ad1..5117a64 100644 --- a/src/main/kotlin/tasks/patchremap/RemapPatches.kt +++ b/paperweight-lib/src/main/kotlin/tasks/patchremap/RemapPatches.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/util/BuildDataInfo.kt b/paperweight-lib/src/main/kotlin/util/BuildDataInfo.kt similarity index 96% rename from src/main/kotlin/util/BuildDataInfo.kt rename to paperweight-lib/src/main/kotlin/util/BuildDataInfo.kt index 8e9d26d..b835bd2 100644 --- a/src/main/kotlin/util/BuildDataInfo.kt +++ b/paperweight-lib/src/main/kotlin/util/BuildDataInfo.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/util/Constants.kt b/paperweight-lib/src/main/kotlin/util/Constants.kt similarity index 92% rename from src/main/kotlin/util/Constants.kt rename to paperweight-lib/src/main/kotlin/util/Constants.kt index 16a8b73..bcb05b4 100644 --- a/src/main/kotlin/util/Constants.kt +++ b/paperweight-lib/src/main/kotlin/util/Constants.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -36,9 +36,14 @@ object Constants { const val DECOMPILER_CONFIG = "decompiler" const val PAPERCLIP_CONFIG = "paperclip" + const val PAPERWEIGHT_PREPARE_DOWNSTREAM = "prepareForDownstream" + const val CACHE_PATH = "caches" private const val PAPER_PATH = "paperweight" + const val UPSTREAMS = "$PAPER_PATH/upstreams" + const val UPSTREAM_WORK_DIR_PROPERTY = "paperweightUpstreamWorkDir" + private const val JARS_PATH = "$PAPER_PATH/jars" const val MINECRAFT_JARS_PATH = "$JARS_PATH/minecraft" const val MINECRAFT_SOURCES_PATH = "$JARS_PATH/minecraft-sources" diff --git a/src/main/kotlin/util/MappingFormats.kt b/paperweight-lib/src/main/kotlin/util/MappingFormats.kt similarity index 96% rename from src/main/kotlin/util/MappingFormats.kt rename to paperweight-lib/src/main/kotlin/util/MappingFormats.kt index 51919e1..60003e7 100644 --- a/src/main/kotlin/util/MappingFormats.kt +++ b/paperweight-lib/src/main/kotlin/util/MappingFormats.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/util/MavenArtifact.kt b/paperweight-lib/src/main/kotlin/util/MavenArtifact.kt similarity index 99% rename from src/main/kotlin/util/MavenArtifact.kt rename to paperweight-lib/src/main/kotlin/util/MavenArtifact.kt index a905361..6eed362 100644 --- a/src/main/kotlin/util/MavenArtifact.kt +++ b/paperweight-lib/src/main/kotlin/util/MavenArtifact.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/util/McDev.kt b/paperweight-lib/src/main/kotlin/util/McDev.kt similarity index 92% rename from src/main/kotlin/util/McDev.kt rename to paperweight-lib/src/main/kotlin/util/McDev.kt index af004ca..4289fc3 100644 --- a/src/main/kotlin/util/McDev.kt +++ b/paperweight-lib/src/main/kotlin/util/McDev.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -28,7 +28,7 @@ import kotlin.io.path.* object McDev { - fun importMcDev(patches: Iterable, decompJar: Path, libraryImports: Path, libraryDir: Path, targetDir: Path) { + fun importMcDev(patches: Iterable, decompJar: Path, libraryImports: Path?, libraryDir: Path?, targetDir: Path) { val importMcDev = readMcDevNames(patches).asSequence() .map { targetDir.resolve("net/minecraft/$it.java") } .filter { !it.exists() } @@ -52,12 +52,12 @@ object McDev { } // Import library classes - val libraryLines = libraryImports.readLines() + val libraryLines = libraryImports?.readLines() ?: emptyList() if (libraryLines.isEmpty()) { return } - val libFiles = libraryDir.listDirectoryEntries("*-sources.jar") + val libFiles = libraryDir?.listDirectoryEntries("*-sources.jar") ?: return if (libFiles.isEmpty()) { throw PaperweightException("No library files found") } diff --git a/src/main/kotlin/util/MinecraftManifest.kt b/paperweight-lib/src/main/kotlin/util/MinecraftManifest.kt similarity index 75% rename from src/main/kotlin/util/MinecraftManifest.kt rename to paperweight-lib/src/main/kotlin/util/MinecraftManifest.kt index 7956f2a..78962f1 100644 --- a/src/main/kotlin/util/MinecraftManifest.kt +++ b/paperweight-lib/src/main/kotlin/util/MinecraftManifest.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -23,14 +23,14 @@ package io.papermc.paperweight.util data class MinecraftManifest( - internal val latest: Map, - internal val versions: List + val latest: Map, + val versions: List ) data class ManifestVersion( - internal val id: String, - internal val type: String, - internal val time: String, - internal val releaseTime: String, - internal val url: String + val id: String, + val type: String, + val time: String, + val releaseTime: String, + val url: String ) diff --git a/src/main/kotlin/util/asm.kt b/paperweight-lib/src/main/kotlin/util/asm.kt similarity index 98% rename from src/main/kotlin/util/asm.kt rename to paperweight-lib/src/main/kotlin/util/asm.kt index 93252b2..da820ff 100644 --- a/src/main/kotlin/util/asm.kt +++ b/paperweight-lib/src/main/kotlin/util/asm.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/util/file.kt b/paperweight-lib/src/main/kotlin/util/file.kt similarity index 99% rename from src/main/kotlin/util/file.kt rename to paperweight-lib/src/main/kotlin/util/file.kt index ed5c0f4..f051e0d 100644 --- a/src/main/kotlin/util/file.kt +++ b/paperweight-lib/src/main/kotlin/util/file.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/util/git.kt b/paperweight-lib/src/main/kotlin/util/git.kt similarity index 99% rename from src/main/kotlin/util/git.kt rename to paperweight-lib/src/main/kotlin/util/git.kt index 6bd547d..5cbf79c 100644 --- a/src/main/kotlin/util/git.kt +++ b/paperweight-lib/src/main/kotlin/util/git.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/util/jar-runner.kt b/paperweight-lib/src/main/kotlin/util/jar-runner.kt similarity index 98% rename from src/main/kotlin/util/jar-runner.kt rename to paperweight-lib/src/main/kotlin/util/jar-runner.kt index d61f822..9ba4cd3 100644 --- a/src/main/kotlin/util/jar-runner.kt +++ b/paperweight-lib/src/main/kotlin/util/jar-runner.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/src/main/kotlin/util/utils.kt b/paperweight-lib/src/main/kotlin/util/utils.kt similarity index 89% rename from src/main/kotlin/util/utils.kt rename to paperweight-lib/src/main/kotlin/util/utils.kt index ded6b58..46b0531 100644 --- a/src/main/kotlin/util/utils.kt +++ b/paperweight-lib/src/main/kotlin/util/utils.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or @@ -26,7 +26,6 @@ import com.github.salomonbrys.kotson.fromJson import com.google.gson.Gson import io.papermc.paperweight.DownloadService import io.papermc.paperweight.PaperweightException -import io.papermc.paperweight.ext.PaperweightExtension import io.papermc.paperweight.tasks.BaseTask import io.papermc.paperweight.util.Constants.paperTaskOutput import java.io.File @@ -51,6 +50,7 @@ import org.gradle.api.file.ProjectLayout import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskContainer +import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.* val gson: Gson = Gson() @@ -58,14 +58,28 @@ val gson: Gson = Gson() inline fun Gson.fromJson(file: Any): T = file.convertToPath().bufferedReader().use { fromJson(it) } -val Project.ext: PaperweightExtension - get() = extensions.getByName(Constants.EXTENSION) as PaperweightExtension val ProjectLayout.cache: Path get() = projectDirectory.file(".gradle/${Constants.CACHE_PATH}").path +fun ProjectLayout.cacheDir(path: String) = projectDirectory.dir(".gradle/${Constants.CACHE_PATH}").dir(path) fun ProjectLayout.initSubmodules() { Git(projectDirectory.path)("submodule", "update", "--init").executeOut() } +inline fun TaskContainer.providerFor(name: String): TaskProvider { + return if (names.contains(name)) { + named(name) + } else { + register(name) + } +} +inline fun TaskContainer.configureTask(name: String, noinline configure: T.() -> Unit): TaskProvider { + return if (names.contains(name)) { + named(name, configure) + } else { + register(name, configure) + } +} + @Suppress("UNCHECKED_CAST") val Project.download: Provider get() = gradle.sharedServices.registrations.getByName("download").service as Provider diff --git a/src/main/kotlin/util/zip.kt b/paperweight-lib/src/main/kotlin/util/zip.kt similarity index 98% rename from src/main/kotlin/util/zip.kt rename to paperweight-lib/src/main/kotlin/util/zip.kt index 7f05ec7..dde2ea1 100644 --- a/src/main/kotlin/util/zip.kt +++ b/paperweight-lib/src/main/kotlin/util/zip.kt @@ -1,7 +1,7 @@ /* * paperweight is a Gradle plugin for the PaperMC project. * - * Copyright (c) 2020 Kyle Wood (DemonWav) + * Copyright (c) 2021 Kyle Wood (DemonWav) * Contributors * * This library is free software; you can redistribute it and/or diff --git a/paperweight-patcher/build.gradle.kts b/paperweight-patcher/build.gradle.kts new file mode 100644 index 0000000..3eaac2f --- /dev/null +++ b/paperweight-patcher/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `config-kotlin` + `config-publish` +} + +dependencies { + shade(projects.paperweightLib) + implementation(libs.kotson) +} diff --git a/paperweight-patcher/src/main/kotlin/PaperweightPatcher.kt b/paperweight-patcher/src/main/kotlin/PaperweightPatcher.kt new file mode 100644 index 0000000..f928835 --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/PaperweightPatcher.kt @@ -0,0 +1,152 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher + +import io.papermc.paperweight.DownloadService +import io.papermc.paperweight.patcher.tasks.CheckoutRepo +import io.papermc.paperweight.patcher.tasks.PaperweightPatcherUpstreamData +import io.papermc.paperweight.patcher.tasks.SimpleApplyGitPatches +import io.papermc.paperweight.patcher.upstream.PatchTaskConfig +import io.papermc.paperweight.patcher.upstream.PatcherUpstream +import io.papermc.paperweight.patcher.upstream.RepoPatcherUpstream +import io.papermc.paperweight.util.Constants +import io.papermc.paperweight.util.cache +import io.papermc.paperweight.util.configureTask +import java.io.File +import java.util.concurrent.atomic.AtomicReference +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.Delete +import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.* +import util.readUpstreamData + +class PaperweightPatcher : Plugin { + + override fun apply(target: Project) { + val patcher = target.extensions.create(Constants.EXTENSION, PaperweightPatcherExtension::class) + + target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {} + + target.tasks.register("cleanCache") { + group = "Paper" + description = "Delete the project setup cache and task outputs." + delete(target.layout.cache) + } + + target.configurations.create(Constants.PAPERCLIP_CONFIG) + + val workDirProp = target.providers.gradleProperty(Constants.UPSTREAM_WORK_DIR_PROPERTY).forUseAtConfigurationTime() + val dataFileProp = target.providers.gradleProperty(Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM).forUseAtConfigurationTime() + + val applyPatches by target.tasks.registering + val downstreamData = target.tasks.register(Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM) + + val upstreamDataTaskRef = AtomicReference>(null) + + patcher.upstreams.all { + val taskPair = target.createUpstreamTask(this, patcher, workDirProp, dataFileProp, upstreamDataTaskRef) + + patchTasks.all { + val createdPatchTask = target.createPatchTask(this, taskPair, applyPatches) + downstreamData { + dependsOn(createdPatchTask) + } + } + } + + target.afterEvaluate { + val upstreamDataTask = upstreamDataTaskRef.get() ?: return@afterEvaluate + val upstreamData = upstreamDataTask.map { readUpstreamData(it.dataFile) } + + // Create build tasks which requires upstream data + } + } + + private fun Project.createUpstreamTask( + upstream: PatcherUpstream, + ext: PaperweightPatcherExtension, + workDirProp: Provider, + dataFileProp: Provider, + upstreamDataTaskRef: AtomicReference> + ): Pair, TaskProvider>? { + return (upstream as? RepoPatcherUpstream)?.let { repo -> + val workDirFromProp = layout.dir(workDirProp.map { File(it) }).orElse(ext.upstreamsDir) + val dataFileFromProp = layout.file(dataFileProp.map { File(it) }) + + val cloneTask = tasks.configureTask(repo.cloneTaskName) { + repoName.set(repo.name) + url.set(repo.url) + ref.set(repo.ref) + + workDir.set(workDirFromProp) + } + + val upstreamData = tasks.configureTask(repo.upstreamDataTaskName) { + dependsOn(cloneTask) + projectDir.set(cloneTask.flatMap { it.outputDir }) + workDir.set(workDirFromProp) + if (dataFileFromProp.isPresent) { + dataFile.set(dataFileFromProp) + } else { + dataFile.set(workDirFromProp.map { it.file("upstreamData${repo.name.capitalize()}.txt") }) + } + } + + if (repo.useForUpstreamData.get()) { + upstreamDataTaskRef.set(upstreamData) + } else { + upstreamDataTaskRef.compareAndSet(null, upstreamData) + } + + return@let cloneTask to upstreamData + } + } + + private fun Project.createPatchTask( + config: PatchTaskConfig, + upstreamTaskPair: Pair, TaskProvider>?, + applyPatches: TaskProvider + ): TaskProvider { + val patchTask = tasks.configureTask(config.patchTaskName) { + if (upstreamTaskPair != null) { + val (cloneTask, upstreamDataTask) = upstreamTaskPair + dependsOn(upstreamDataTask) + sourceDir.set(cloneTask.flatMap { it.outputDir.dir(config.sourceDirPath) }) + } else { + sourceDir.set(config.sourceDir) + } + + patchDir.set(config.patchDir) + outputDir.set(config.outputDir) + } + + applyPatches { + dependsOn(patchTask) + } + + return patchTask + } +} diff --git a/paperweight-patcher/src/main/kotlin/PaperweightPatcherExtension.kt b/paperweight-patcher/src/main/kotlin/PaperweightPatcherExtension.kt new file mode 100644 index 0000000..52e212d --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/PaperweightPatcherExtension.kt @@ -0,0 +1,82 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher + +import io.papermc.paperweight.patcher.upstream.DefaultPaperRepoPatcherUpstream +import io.papermc.paperweight.patcher.upstream.DefaultRepoPatcherUpstream +import io.papermc.paperweight.patcher.upstream.PaperRepoPatcherUpstream +import io.papermc.paperweight.patcher.upstream.PatcherUpstream +import io.papermc.paperweight.patcher.upstream.RepoPatcherUpstream +import io.papermc.paperweight.util.Constants +import io.papermc.paperweight.util.cacheDir +import org.gradle.api.Action +import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer +import org.gradle.api.file.Directory +import org.gradle.api.file.ProjectLayout +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.TaskContainer +import org.gradle.kotlin.dsl.* + +@Suppress("unused", "MemberVisibilityCanBePrivate") +open class PaperweightPatcherExtension(private val objects: ObjectFactory, layout: ProjectLayout, tasks: TaskContainer) { + + val upstreams: ExtensiblePolymorphicDomainObjectContainer = objects.polymorphicDomainObjectContainer(PatcherUpstream::class) + + /** + * The directory upstreams should be checked out in. Paperweight will use the directory specified in the + * following order, whichever is set first: + * + * 1. The value of the Gradle property `paperweightUpstreamWorkDir`. + * 2. The value of this [upstreamsDir] property. + * 3. The default location of /.gradle/caches/paperweight/upstreams + * + * This means a project which is several upstreams deep will all use the upstreams directory defined by the root project. + */ + val upstreamsDir: Property = objects.directoryProperty().convention(layout.cacheDir(Constants.UPSTREAMS)) + + init { + upstreams.registerFactory(RepoPatcherUpstream::class.java) { name -> DefaultRepoPatcherUpstream(name, objects, tasks) } + upstreams.registerFactory(PaperRepoPatcherUpstream::class.java) { name -> DefaultPaperRepoPatcherUpstream(name, objects, tasks) } + } + + fun usePaperUpstream(refProvider: Provider, action: Action) { + upstreams { + register("paper") { + url.set(github("PaperMC", "Paper")) + ref.set(refProvider) + + action.execute(this) + } + } + } + + fun useStandardUpstream(name: String, action: Action) { + upstreams { + register(name) { + action.execute(this) + } + } + } +} diff --git a/paperweight-patcher/src/main/kotlin/tasks/CheckoutRepo.kt b/paperweight-patcher/src/main/kotlin/tasks/CheckoutRepo.kt new file mode 100644 index 0000000..fe94b8f --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/tasks/CheckoutRepo.kt @@ -0,0 +1,117 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.tasks + +import io.papermc.paperweight.util.Git +import io.papermc.paperweight.util.deleteRecursively +import io.papermc.paperweight.util.path +import kotlin.io.path.* +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction + +abstract class CheckoutRepo : DefaultTask() { + + @get:Input + abstract val repoName: Property + + @get:Input + abstract val url: Property + + @get:Input + abstract val ref: Property + + @get:Input + abstract val shallowClone: Property + + @get:Input + abstract val initializeSubmodules: Property + + @get:Input + abstract val initializeSubmodulesShallow: Property + + @get:Internal + abstract val workDir: DirectoryProperty + + @get:OutputDirectory + abstract val outputDir: DirectoryProperty + + init { + @Suppress("LeakingThis") + run { + repoName.finalizeValueOnRead() + url.finalizeValueOnRead() + ref.finalizeValueOnRead() + shallowClone.convention(true).finalizeValueOnRead() + initializeSubmodules.convention(false).finalizeValueOnRead() + initializeSubmodulesShallow.convention(false).finalizeValueOnRead() + + outputDir.convention(workDir.dir(repoName)).finalizeValueOnRead() + } + } + + @TaskAction + fun run() { + val dir = outputDir.path + val urlText = url.get().trim() + + if (dir.resolve(".git").notExists()) { + dir.deleteRecursively() + dir.createDirectories() + + Git(dir)("init", "--quiet").executeSilently() + } + + val git = Git(dir) + git("remote", "remove", "origin").runSilently(silenceErr = true) // can fail + git("remote", "add", "origin", urlText).executeSilently(silenceErr = true) + git.fetch() + + git("checkout", "-f", "FETCH_HEAD").executeSilently(silenceErr = true) + git("clean", "-fqd").executeSilently(silenceErr = true) + + if (initializeSubmodules.get()) { + git.updateSubmodules() + } + } + + private fun Git.fetch() { + if (shallowClone.get()) { + this("fetch", "--depth", "1", "origin", ref.get()).executeSilently(silenceErr = true) + } else { + this("fetch", "origin", ref.get()).executeSilently(silenceErr = true) + } + } + + private fun Git.updateSubmodules() { + if (initializeSubmodulesShallow.get()) { + this("submodule", "update", "--init", "--recursive", "--depth", "1").executeSilently(silenceErr = true) + } else { + this("submodule", "update", "--init", "--recursive").executeSilently(silenceErr = true) + } + } +} diff --git a/paperweight-patcher/src/main/kotlin/tasks/PaperweightPatcherUpstreamData.kt b/paperweight-patcher/src/main/kotlin/tasks/PaperweightPatcherUpstreamData.kt new file mode 100644 index 0000000..2eebff5 --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/tasks/PaperweightPatcherUpstreamData.kt @@ -0,0 +1,64 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.tasks + +import io.papermc.paperweight.util.Constants +import io.papermc.paperweight.util.path +import kotlin.io.path.* +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import org.gradle.internal.build.NestedRootBuildRunner + +abstract class PaperweightPatcherUpstreamData : DefaultTask() { + + @get:InputDirectory + abstract val projectDir: DirectoryProperty + + @get:InputDirectory + abstract val workDir: DirectoryProperty + + @get:OutputFile + abstract val dataFile: RegularFileProperty + + init { + outputs.upToDateWhen { false } + } + + @TaskAction + fun run() { + val params = NestedRootBuildRunner.createStartParameterForNewBuild(services) + params.projectDir = projectDir.get().asFile + + params.setTaskNames(listOf(Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM)) + params.projectProperties[Constants.UPSTREAM_WORK_DIR_PROPERTY] = workDir.path.absolutePathString() + params.projectProperties[Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM] = dataFile.path.absolutePathString() + + NestedRootBuildRunner.createNestedRootBuild(null, params, services).run { + it.run() + } + } +} diff --git a/paperweight-patcher/src/main/kotlin/tasks/SimpleApplyGitPatches.kt b/paperweight-patcher/src/main/kotlin/tasks/SimpleApplyGitPatches.kt new file mode 100644 index 0000000..bac4507 --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/tasks/SimpleApplyGitPatches.kt @@ -0,0 +1,101 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.tasks + +import io.papermc.paperweight.tasks.ControllableOutputTask +import io.papermc.paperweight.tasks.applyGitPatches +import io.papermc.paperweight.util.Git +import io.papermc.paperweight.util.McDev +import io.papermc.paperweight.util.deleteRecursively +import io.papermc.paperweight.util.path +import io.papermc.paperweight.util.pathOrNull +import kotlin.io.path.* +import kotlin.io.path.createDirectories +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction + +abstract class SimpleApplyGitPatches : ControllableOutputTask() { + + @get:InputDirectory + abstract val sourceDir: DirectoryProperty + + @get:InputDirectory + abstract val patchDir: DirectoryProperty + + @get:Optional + @get:InputFile + abstract val sourceMcDevJar: RegularFileProperty + + @get:Optional + @get:InputFile + abstract val libraryImports: RegularFileProperty + + @get:Optional + @get:InputDirectory + abstract val mcLibrariesDir: DirectoryProperty + + @get:OutputDirectory + abstract val outputDir: DirectoryProperty + + override fun init() { + printOutput.convention(true) + } + + @TaskAction + fun run() { + val output = outputDir.path + output.deleteRecursively() + output.parent.createDirectories() + + val target = output.name + + if (printOutput.get()) { + println(" Creating $target from patch source...") + } + + Git(output.parent)("clone", sourceDir.path.absolutePathString(), output.absolutePathString()).executeSilently() + val srcDir = output.resolve("src/main/java") + + val git = Git(output) + + git("config", "commit.gpgsign", "false").executeSilently() + + val patches = patchDir.path.listDirectoryEntries("*.patch") + + if (sourceMcDevJar.isPresent) { + McDev.importMcDev(patches, sourceMcDevJar.path, libraryImports.pathOrNull, mcLibrariesDir.pathOrNull, srcDir) + } + + git("add", ".").executeSilently() + git("commit", "--allow-empty", "-m", "--author=Initial Source ").executeSilently() + git("tag", "-d", "base").runSilently(silenceErr = true) + git("tag", "base").executeSilently() + + applyGitPatches(git, target, output, patchDir.path, printOutput.get()) + } +} diff --git a/paperweight-patcher/src/main/kotlin/upstream/DefaultPatchTaskConfig.kt b/paperweight-patcher/src/main/kotlin/upstream/DefaultPatchTaskConfig.kt new file mode 100644 index 0000000..024cf4a --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/upstream/DefaultPatchTaskConfig.kt @@ -0,0 +1,56 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.upstream + +import io.papermc.paperweight.patcher.tasks.SimpleApplyGitPatches +import io.papermc.paperweight.util.providerFor +import javax.inject.Inject +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property +import org.gradle.api.tasks.TaskContainer +import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.* + +open class DefaultPatchTaskConfig @Inject constructor( + private val name: String, + private val parentName: String, + private val tasks: TaskContainer, + objects: ObjectFactory, +) : PatchTaskConfig { + + override val sourceDirPath: Property = objects.property() + override val sourceDir: DirectoryProperty = objects.directoryProperty() + override val patchDir: DirectoryProperty = objects.directoryProperty() + override val outputDir: DirectoryProperty = objects.directoryProperty() + + override val patchTaskName: String + get() = "patch${parentName.capitalize()}${name.capitalize()}" + + override val patchTask: TaskProvider + get() = tasks.providerFor(patchTaskName) + + override fun getName(): String { + return name + } +} diff --git a/paperweight-patcher/src/main/kotlin/upstream/MinimalPatcherConfig.kt b/paperweight-patcher/src/main/kotlin/upstream/MinimalPatcherConfig.kt new file mode 100644 index 0000000..a33f245 --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/upstream/MinimalPatcherConfig.kt @@ -0,0 +1,34 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.upstream + +import org.gradle.api.file.DirectoryProperty + +interface MinimalPatcherConfig { + + val apiPatchDir: DirectoryProperty + val apiOutputDir: DirectoryProperty + + val serverPatchDir: DirectoryProperty + val serverOutputDir: DirectoryProperty +} diff --git a/paperweight-patcher/src/main/kotlin/upstream/PaperRepoPatcherUpstream.kt b/paperweight-patcher/src/main/kotlin/upstream/PaperRepoPatcherUpstream.kt new file mode 100644 index 0000000..42b9960 --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/upstream/PaperRepoPatcherUpstream.kt @@ -0,0 +1,30 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.upstream + +import org.gradle.api.Action + +interface PaperRepoPatcherUpstream : RepoPatcherUpstream { + + fun withPaperPatcher(action: Action) +} diff --git a/paperweight-patcher/src/main/kotlin/upstream/PatchTaskConfig.kt b/paperweight-patcher/src/main/kotlin/upstream/PatchTaskConfig.kt new file mode 100644 index 0000000..3179d3f --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/upstream/PatchTaskConfig.kt @@ -0,0 +1,41 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.upstream + +import io.papermc.paperweight.patcher.tasks.SimpleApplyGitPatches +import org.gradle.api.Named +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.TaskProvider + +interface PatchTaskConfig : Named { + + val sourceDirPath: Property + val sourceDir: DirectoryProperty + + val patchDir: DirectoryProperty + val outputDir: DirectoryProperty + + val patchTaskName: String + val patchTask: TaskProvider +} diff --git a/paperweight-patcher/src/main/kotlin/upstream/PatcherUpstream.kt b/paperweight-patcher/src/main/kotlin/upstream/PatcherUpstream.kt new file mode 100644 index 0000000..839b947 --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/upstream/PatcherUpstream.kt @@ -0,0 +1,31 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.upstream + +import org.gradle.api.Named +import org.gradle.api.NamedDomainObjectContainer + +interface PatcherUpstream : Named { + + val patchTasks: NamedDomainObjectContainer +} diff --git a/paperweight-patcher/src/main/kotlin/upstream/RepoPatcherUpstream.kt b/paperweight-patcher/src/main/kotlin/upstream/RepoPatcherUpstream.kt new file mode 100644 index 0000000..18809ff --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/upstream/RepoPatcherUpstream.kt @@ -0,0 +1,49 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.upstream + +import io.papermc.paperweight.patcher.tasks.CheckoutRepo +import io.papermc.paperweight.patcher.tasks.PaperweightPatcherUpstreamData +import org.gradle.api.Action +import org.gradle.api.provider.Property +import org.gradle.api.tasks.TaskProvider + +interface RepoPatcherUpstream : PatcherUpstream { + + val url: Property + val ref: Property + + val cloneTaskName: String + val upstreamDataTaskName: String + val cloneTask: TaskProvider + val upstreamDataTask: TaskProvider + + val useForUpstreamData: Property + + @JvmDefault + fun github(owner: String, repo: String): String { + return "https://github.com/$owner/$repo.git" + } + + fun withStandardPatcher(action: Action) +} diff --git a/paperweight-patcher/src/main/kotlin/upstream/StandardPatcherConfig.kt b/paperweight-patcher/src/main/kotlin/upstream/StandardPatcherConfig.kt new file mode 100644 index 0000000..819b747 --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/upstream/StandardPatcherConfig.kt @@ -0,0 +1,38 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.upstream + +import org.gradle.api.provider.Property + +interface StandardPatcherConfig : MinimalPatcherConfig { + + val apiSourceDirPath: Property + + val serverSourceDirPath: Property + + @JvmDefault + fun baseName(name: String) { + apiSourceDirPath.set("$name-API") + serverSourceDirPath.set("$name-Server") + } +} diff --git a/paperweight-patcher/src/main/kotlin/upstream/patchers.kt b/paperweight-patcher/src/main/kotlin/upstream/patchers.kt new file mode 100644 index 0000000..717a186 --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/upstream/patchers.kt @@ -0,0 +1,103 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package io.papermc.paperweight.patcher.upstream + +import io.papermc.paperweight.patcher.tasks.CheckoutRepo +import io.papermc.paperweight.patcher.tasks.PaperweightPatcherUpstreamData +import io.papermc.paperweight.util.providerFor +import javax.inject.Inject +import org.gradle.api.Action +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property +import org.gradle.api.tasks.TaskContainer +import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.* + +open class DefaultRepoPatcherUpstream @Inject constructor( + private val name: String, + protected val objects: ObjectFactory, + private val tasks: TaskContainer +) : RepoPatcherUpstream { + + override val url: Property = objects.property() + override val ref: Property = objects.property() + override val sourceUpstreamData: Property = objects.property() + + override val patchTasks: NamedDomainObjectContainer = objects.domainObjectContainer(PatchTaskConfig::class) { name -> + objects.newInstance(name, this.name) + } + + override val cloneTaskName: String + get() = "clone${name.capitalize()}Repo" + override val upstreamDataTaskName: String + get() = "get${name.capitalize()}UpstreamData" + override val cloneTask: TaskProvider + get() = tasks.providerFor(cloneTaskName) + override val upstreamDataTask: TaskProvider + get() = tasks.providerFor(upstreamDataTaskName) + + override fun getName(): String { + return name + } + + override fun withStandardPatcher(action: Action) { + val config = objects.newInstance(StandardPatcherConfig::class) + action.execute(config) + + patchTasks { + register("api") { + sourceDirPath.set(config.apiSourceDirPath) + patchDir.set(config.apiPatchDir) + outputDir.set(config.apiOutputDir) + } + + register("server") { + sourceDirPath.set(config.serverSourceDirPath) + patchDir.set(config.serverPatchDir) + outputDir.set(config.serverOutputDir) + } + } + } +} + +open class DefaultPaperRepoPatcherUpstream @Inject constructor(name: String, objects: ObjectFactory, taskContainer: TaskContainer) : + DefaultRepoPatcherUpstream(name, objects, taskContainer), PaperRepoPatcherUpstream { + + override fun withPaperPatcher(action: Action) { + val minimalConfig = objects.newInstance(MinimalPatcherConfig::class) + action.execute(minimalConfig) + + val paperAction = Action { + baseName("Paper") + + apiPatchDir.set(minimalConfig.apiPatchDir) + apiOutputDir.set(minimalConfig.apiOutputDir) + + serverPatchDir.set(minimalConfig.serverPatchDir) + serverOutputDir.set(minimalConfig.serverOutputDir) + } + + withStandardPatcher(paperAction) + } +} diff --git a/paperweight-patcher/src/main/kotlin/util/ReadUpstreamData.kt b/paperweight-patcher/src/main/kotlin/util/ReadUpstreamData.kt new file mode 100644 index 0000000..4d396bf --- /dev/null +++ b/paperweight-patcher/src/main/kotlin/util/ReadUpstreamData.kt @@ -0,0 +1,56 @@ +/* + * paperweight is a Gradle plugin for the PaperMC project. + * + * Copyright (c) 2021 Kyle Wood (DemonWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package util + +import io.papermc.paperweight.PaperweightException +import io.papermc.paperweight.util.path +import java.nio.file.Path +import java.nio.file.Paths +import kotlin.io.path.notExists +import kotlin.io.path.readLines +import org.gradle.api.file.RegularFileProperty + +data class UpstreamData( + val decompiledJar: Path, + val libSourceDir: Path +) + +fun readUpstreamData(inputFile: RegularFileProperty): UpstreamData { + val lines = inputFile.path.readLines(Charsets.UTF_8) + if (lines.size != 2) { + throw PaperweightException("File has invalid format: ${inputFile.path}") + } + + val decompiledJar = checkFile(lines[0]) + val libSourceDir = checkFile(lines[1]) + + return UpstreamData(decompiledJar, libSourceDir) +} + +private fun checkFile(line: String): Path { + val file = Paths.get(line) + if (file.notExists()) { + throw PaperweightException("File does not exist: $file") + } + return file +} diff --git a/paperweight-patcher/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.patcher.properties b/paperweight-patcher/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.patcher.properties new file mode 100644 index 0000000..488e4f2 --- /dev/null +++ b/paperweight-patcher/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.patcher.properties @@ -0,0 +1 @@ +implementation-class=io.papermc.paperweight.patcher.PaperweightPatcher diff --git a/settings.gradle.kts b/settings.gradle.kts index e69b9dc..fe903fb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,6 @@ rootProject.name = "paperweight" +include("paperweight-core", "paperweight-lib", "paperweight-patcher") + enableFeaturePreview("VERSION_CATALOGS") +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") diff --git a/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.properties b/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.properties deleted file mode 100644 index 6784ee2..0000000 --- a/src/main/resources/META-INF/gradle-plugins/io.papermc.paperweight.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=io.papermc.paperweight.Paperweight