Initial work on supporting forks

This commit is contained in:
Kyle Wood 2021-06-09 15:45:23 -05:00 committed by Kyle Wood
parent 6b22ccdf03
commit a384d7eef4
No known key found for this signature in database
GPG key ID: 86AF5613ACA30CC5
92 changed files with 1377 additions and 244 deletions

4
.gitignore vendored
View file

@ -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)

23
buildSrc/build.gradle.kts Normal file
View file

@ -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<MinimalExternalModuleDependency>.withVersion(version: String): Provider<String> {
return map { "${it.module.group}:${it.module.name}:$version" }
}

View file

@ -0,0 +1,9 @@
enableFeaturePreview("VERSION_CATALOGS")
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

View file

@ -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<KotlinCompile> {
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
}
}

View file

@ -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<KotlinCompile> {
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<MavenPublication>("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)

2
gradle.properties Normal file
View file

@ -0,0 +1,2 @@
group = io.papermc.paperweight
version = 1.0.0-SNAPSHOT

View file

@ -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"]

View file

@ -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

View file

@ -0,0 +1,10 @@
plugins {
`config-kotlin`
`config-publish`
}
dependencies {
shade(projects.paperweightLib)
implementation(libs.kotson)
}

View file

@ -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<Project> {
class PaperweightCore : Plugin<Project> {
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<Project> {
val tasks = AllTasks(target)
target.createPatchRemapTask(tasks)
target.tasks.register<PaperweightCoreUpstreamData>(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<Project> {
}
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

View file

@ -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

View file

@ -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")

View file

@ -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<String> = objects.property()
val serverProject: Property<Project> = objects.property()
@Suppress("MemberVisibilityCanBePrivate")
val craftBukkit = CraftBukkitExtension(objects, workDir)
val spigot = SpigotExtension(objects, workDir)
val paper = PaperExtension(objects, layout)

View file

@ -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")

View file

@ -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

View file

@ -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<ApplyAccessTransform> {

View file

@ -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<DownloadService> = project.download,
) : InitialTasks(project) {

View file

@ -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<DownloadService> = project.download
) {

View file

@ -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<DownloadService> = project.download,
) : VanillaTasks(project) {

View file

@ -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

View file

@ -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())
}
}
}

View file

@ -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

View file

@ -0,0 +1 @@
implementation-class=io.papermc.paperweight.core.PaperweightCore

View file

@ -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)
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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<Path>, decompJar: Path, libraryImports: Path, libraryDir: Path, targetDir: Path) {
fun importMcDev(patches: Iterable<Path>, 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")
}

View file

@ -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<String, *>,
internal val versions: List<ManifestVersion>
val latest: Map<String, *>,
val versions: List<ManifestVersion>
)
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
)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 <reified T> 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 <reified T : Task> TaskContainer.providerFor(name: String): TaskProvider<T> {
return if (names.contains(name)) {
named<T>(name)
} else {
register<T>(name)
}
}
inline fun <reified T : Task> TaskContainer.configureTask(name: String, noinline configure: T.() -> Unit): TaskProvider<T> {
return if (names.contains(name)) {
named(name, configure)
} else {
register(name, configure)
}
}
@Suppress("UNCHECKED_CAST")
val Project.download: Provider<DownloadService>
get() = gradle.sharedServices.registrations.getByName("download").service as Provider<DownloadService>

View file

@ -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

View file

@ -0,0 +1,9 @@
plugins {
`config-kotlin`
`config-publish`
}
dependencies {
shade(projects.paperweightLib)
implementation(libs.kotson)
}

View file

@ -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<Project> {
override fun apply(target: Project) {
val patcher = target.extensions.create(Constants.EXTENSION, PaperweightPatcherExtension::class)
target.gradle.sharedServices.registerIfAbsent("download", DownloadService::class) {}
target.tasks.register<Delete>("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<TaskProvider<PaperweightPatcherUpstreamData>>(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<String>,
dataFileProp: Provider<String>,
upstreamDataTaskRef: AtomicReference<TaskProvider<PaperweightPatcherUpstreamData>>
): Pair<TaskProvider<CheckoutRepo>, TaskProvider<PaperweightPatcherUpstreamData>>? {
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<CheckoutRepo>(repo.cloneTaskName) {
repoName.set(repo.name)
url.set(repo.url)
ref.set(repo.ref)
workDir.set(workDirFromProp)
}
val upstreamData = tasks.configureTask<PaperweightPatcherUpstreamData>(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<CheckoutRepo>, TaskProvider<PaperweightPatcherUpstreamData>>?,
applyPatches: TaskProvider<Task>
): TaskProvider<SimpleApplyGitPatches> {
val patchTask = tasks.configureTask<SimpleApplyGitPatches>(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
}
}

View file

@ -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<PatcherUpstream> = 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 <project_root>/.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<Directory> = 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<String>, action: Action<PaperRepoPatcherUpstream>) {
upstreams {
register<PaperRepoPatcherUpstream>("paper") {
url.set(github("PaperMC", "Paper"))
ref.set(refProvider)
action.execute(this)
}
}
}
fun useStandardUpstream(name: String, action: Action<RepoPatcherUpstream>) {
upstreams {
register<RepoPatcherUpstream>(name) {
action.execute(this)
}
}
}
}

View file

@ -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<String>
@get:Input
abstract val url: Property<String>
@get:Input
abstract val ref: Property<String>
@get:Input
abstract val shallowClone: Property<Boolean>
@get:Input
abstract val initializeSubmodules: Property<Boolean>
@get:Input
abstract val initializeSubmodulesShallow: Property<Boolean>
@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)
}
}
}

View file

@ -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()
}
}
}

View file

@ -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 <auto@mated.null>").executeSilently()
git("tag", "-d", "base").runSilently(silenceErr = true)
git("tag", "base").executeSilently()
applyGitPatches(git, target, output, patchDir.path, printOutput.get())
}
}

View file

@ -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<String> = 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<SimpleApplyGitPatches>
get() = tasks.providerFor(patchTaskName)
override fun getName(): String {
return name
}
}

View file

@ -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
}

View file

@ -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<MinimalPatcherConfig>)
}

View file

@ -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<String>
val sourceDir: DirectoryProperty
val patchDir: DirectoryProperty
val outputDir: DirectoryProperty
val patchTaskName: String
val patchTask: TaskProvider<SimpleApplyGitPatches>
}

View file

@ -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<PatchTaskConfig>
}

View file

@ -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<String>
val ref: Property<String>
val cloneTaskName: String
val upstreamDataTaskName: String
val cloneTask: TaskProvider<CheckoutRepo>
val upstreamDataTask: TaskProvider<PaperweightPatcherUpstreamData>
val useForUpstreamData: Property<Boolean>
@JvmDefault
fun github(owner: String, repo: String): String {
return "https://github.com/$owner/$repo.git"
}
fun withStandardPatcher(action: Action<StandardPatcherConfig>)
}

View file

@ -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<String>
val serverSourceDirPath: Property<String>
@JvmDefault
fun baseName(name: String) {
apiSourceDirPath.set("$name-API")
serverSourceDirPath.set("$name-Server")
}
}

View file

@ -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<String> = objects.property()
override val ref: Property<String> = objects.property()
override val sourceUpstreamData: Property<Boolean> = objects.property()
override val patchTasks: NamedDomainObjectContainer<PatchTaskConfig> = objects.domainObjectContainer(PatchTaskConfig::class) { name ->
objects.newInstance<DefaultPatchTaskConfig>(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<CheckoutRepo>
get() = tasks.providerFor(cloneTaskName)
override val upstreamDataTask: TaskProvider<PaperweightPatcherUpstreamData>
get() = tasks.providerFor(upstreamDataTaskName)
override fun getName(): String {
return name
}
override fun withStandardPatcher(action: Action<StandardPatcherConfig>) {
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<MinimalPatcherConfig>) {
val minimalConfig = objects.newInstance(MinimalPatcherConfig::class)
action.execute(minimalConfig)
val paperAction = Action<StandardPatcherConfig> {
baseName("Paper")
apiPatchDir.set(minimalConfig.apiPatchDir)
apiOutputDir.set(minimalConfig.apiOutputDir)
serverPatchDir.set(minimalConfig.serverPatchDir)
serverOutputDir.set(minimalConfig.serverOutputDir)
}
withStandardPatcher(paperAction)
}
}

View file

@ -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
}

View file

@ -0,0 +1 @@
implementation-class=io.papermc.paperweight.patcher.PaperweightPatcher

View file

@ -1,3 +1,6 @@
rootProject.name = "paperweight"
include("paperweight-core", "paperweight-lib", "paperweight-patcher")
enableFeaturePreview("VERSION_CATALOGS")
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

View file

@ -1 +0,0 @@
implementation-class=io.papermc.paperweight.Paperweight