Skip to content

Commit ba5debc

Browse files
committed
Configure publishing patch artifacts
1 parent d97f546 commit ba5debc

File tree

10 files changed

+433
-26
lines changed

10 files changed

+433
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.papermc.mache.lib.data.meta
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class MacheDependencies(
7+
val codebook: List<MavenArtifact>,
8+
val paramMappings: List<MavenArtifact>,
9+
val constants: List<MavenArtifact>,
10+
val remapper: List<MavenArtifact>,
11+
val decompiler: List<MavenArtifact>,
12+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.papermc.mache.lib.data.meta
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class MacheMeta(
7+
val dependencies: MacheDependencies,
8+
val repositories: List<MacheRepository>,
9+
val decompilerArgs: List<String>,
10+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.papermc.mache.lib.data.meta
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class MacheRepository(
7+
val url: String,
8+
val name: String,
9+
val groups: List<String>? = null,
10+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.papermc.mache.lib.data.meta
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class MavenArtifact(
7+
val group: String,
8+
val name: String,
9+
val version: String,
10+
val classifier: String? = null,
11+
val extension: String? = null,
12+
)

build-logic/src/main/kotlin/io/papermc/mache/ConfigureVersionProject.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.papermc.mache
22

3-
import MacheExtension
43
import dotGradleDirectory
54
import io.papermc.mache.constants.DOWNLOAD_SERVER_JAR
65
import io.papermc.mache.constants.MC_MANIFEST

build-logic/src/main/kotlin/MacheExtension.kt build-logic/src/main/kotlin/io/papermc/mache/MacheExtension.kt

+32
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
package io.papermc.mache
2+
3+
import org.gradle.api.NamedDomainObjectContainer
14
import org.gradle.api.model.ObjectFactory
25
import org.gradle.api.provider.ListProperty
36
import org.gradle.api.provider.Property
7+
import org.gradle.kotlin.dsl.domainObjectContainer
48
import org.gradle.kotlin.dsl.listProperty
59
import org.gradle.kotlin.dsl.property
610

711
open class MacheExtension(objects: ObjectFactory) {
12+
/**
13+
* The version of Minecraft which will serve as the base.
14+
*/
815
val minecraftVersion: Property<String> = objects.property()
916

17+
/**
18+
* Base arguments passed to the decompiler.
19+
*/
1020
val decompilerArgs: ListProperty<String> = objects.listProperty()
1121

22+
/**
23+
* Maven repositories needed to resolve the configurations necessary to run mache. The configurations are
24+
* `codebook`, `paramMappings`, `constants`, `remapper`, and `decompiler`.
25+
*
26+
* These are defined in this way because we need this information for the metadata file we generate. Repositories
27+
* defined in the normal Gradle style will not be reported in the metadata file.
28+
*/
29+
val repositories: NamedDomainObjectContainer<MacheRepo> = objects.domainObjectContainer(MacheRepo::class)
30+
1231
init {
1332
decompilerArgs.convention(
1433
listOf(
@@ -41,5 +60,18 @@ open class MacheExtension(objects: ObjectFactory) {
4160
"-nls=1",
4261
),
4362
)
63+
64+
repositories.register("PaperMC") {
65+
url.set("https://repo.papermc.io/repository/maven-public/")
66+
includeGroups.add("io.papermc")
67+
}
68+
repositories.register("FabricMC") {
69+
url.set("https://maven.fabricmc.net/")
70+
includeGroups.add("net.fabricmc")
71+
}
72+
repositories.register("DenWav") {
73+
url.set("https://repo.denwav.dev/repository/maven-public/")
74+
includeGroups.add("org.vineflower")
75+
}
4476
}
4577
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.papermc.mache
2+
3+
import org.gradle.api.Named
4+
import org.gradle.api.provider.ListProperty
5+
import org.gradle.api.provider.Property
6+
import org.gradle.api.tasks.Input
7+
8+
abstract class MacheRepo : Named {
9+
/**
10+
* The base Maven repository URL.
11+
*/
12+
@get:Input
13+
abstract val url: Property<String>
14+
15+
/**
16+
* Use this repository only for the given groups and their subgroups.
17+
*/
18+
@get:Input
19+
abstract val includeGroups: ListProperty<String>
20+
21+
@Input
22+
abstract override fun getName(): String
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package io.papermc.mache.tasks
2+
3+
import io.papermc.mache.MacheRepo
4+
import io.papermc.mache.convertToPath
5+
import io.papermc.mache.ensureClean
6+
import io.papermc.mache.lib.data.meta.MacheDependencies
7+
import io.papermc.mache.lib.data.meta.MacheMeta
8+
import io.papermc.mache.lib.data.meta.MacheRepository
9+
import io.papermc.mache.lib.data.meta.MavenArtifact
10+
import io.papermc.mache.lib.json
11+
import javax.inject.Inject
12+
import kotlin.io.path.writeText
13+
import kotlinx.serialization.encodeToString
14+
import org.gradle.api.DefaultTask
15+
import org.gradle.api.NamedDomainObjectContainer
16+
import org.gradle.api.artifacts.Configuration
17+
import org.gradle.api.artifacts.ExternalDependency
18+
import org.gradle.api.file.ProjectLayout
19+
import org.gradle.api.file.RegularFileProperty
20+
import org.gradle.api.provider.ListProperty
21+
import org.gradle.api.provider.Property
22+
import org.gradle.api.tasks.Classpath
23+
import org.gradle.api.tasks.Input
24+
import org.gradle.api.tasks.Nested
25+
import org.gradle.api.tasks.OutputFile
26+
import org.gradle.api.tasks.TaskAction
27+
28+
abstract class GenerateMacheMetadata : DefaultTask() {
29+
30+
@get:Nested
31+
abstract val repos: NamedDomainObjectContainer<MacheRepo>
32+
33+
@get:Classpath
34+
abstract val codebookConfiguration: Property<Configuration>
35+
36+
@get:Classpath
37+
abstract val paramMappingsConfiguration: Property<Configuration>
38+
39+
@get:Classpath
40+
abstract val constantsConfiguration: Property<Configuration>
41+
42+
@get:Classpath
43+
abstract val remapperConfiguration: Property<Configuration>
44+
45+
@get:Classpath
46+
abstract val decompilerConfiguration: Property<Configuration>
47+
48+
@get:Input
49+
abstract val decompilerArgs: ListProperty<String>
50+
51+
@get:OutputFile
52+
abstract val outputFile: RegularFileProperty
53+
54+
@get:Inject
55+
abstract val layout: ProjectLayout
56+
57+
init {
58+
run {
59+
outputFile.convention(layout.buildDirectory.dir(name).map { it.file("$name.json") })
60+
}
61+
}
62+
63+
@TaskAction
64+
fun run() {
65+
val codebook = codebookConfiguration.get().asMavenArtifacts()
66+
val paramMappings = paramMappingsConfiguration.get().asMavenArtifacts()
67+
val constants = constantsConfiguration.get().asMavenArtifacts()
68+
val remapper = remapperConfiguration.get().asMavenArtifacts()
69+
val decompiler = decompilerConfiguration.get().asMavenArtifacts()
70+
71+
val meta = MacheMeta(
72+
dependencies = MacheDependencies(codebook, paramMappings, constants, remapper, decompiler),
73+
repositories = repos.map { r ->
74+
MacheRepository(r.url.get(), r.name, r.includeGroups.get().takeIf { it.isNotEmpty() })
75+
},
76+
decompilerArgs = decompilerArgs.get(),
77+
)
78+
val metaJson = json.encodeToString(meta)
79+
80+
outputFile.convertToPath().ensureClean().writeText(metaJson)
81+
}
82+
83+
private fun Configuration.asMavenArtifacts(): List<MavenArtifact> {
84+
return dependencies.map { dep ->
85+
val group = dep.group ?: throw IllegalStateException("Dependency without group: $dep")
86+
val version = dep.version ?: throw IllegalStateException("Dependency without version: $dep")
87+
val classifier = (dep as? ExternalDependency)?.artifacts?.firstNotNullOfOrNull { it.classifier }
88+
val extension = (dep as? ExternalDependency)?.artifacts?.firstNotNullOfOrNull { it.extension }?.takeIf { it != "jar" }
89+
MavenArtifact(group, dep.name, version, classifier, extension)
90+
}
91+
}
92+
}

build-logic/src/main/kotlin/mache.gradle.kts

+77-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io.papermc.mache.ConfigureVersionProject
2+
import io.papermc.mache.MacheExtension
23
import io.papermc.mache.constants.DECOMP_JAR
34
import io.papermc.mache.constants.DOWNLOAD_SERVER_JAR
45
import io.papermc.mache.constants.PATCHED_JAR
@@ -9,43 +10,20 @@ import io.papermc.mache.tasks.ApplyPatches
910
import io.papermc.mache.tasks.ApplyPatchesFuzzy
1011
import io.papermc.mache.tasks.DecompileJar
1112
import io.papermc.mache.tasks.ExtractServerJar
13+
import io.papermc.mache.tasks.GenerateMacheMetadata
1214
import io.papermc.mache.tasks.RebuildPatches
1315
import io.papermc.mache.tasks.RemapJar
1416
import io.papermc.mache.tasks.SetupSources
1517
import org.gradle.accessors.dm.LibrariesForLibs
1618

1719
plugins {
1820
java
21+
`maven-publish`
1922
id("mache-lib")
2023
}
2124

2225
val mache = extensions.create("mache", MacheExtension::class)
2326

24-
repositories {
25-
maven("https://repo.papermc.io/repository/maven-public/") {
26-
name = "PaperMC"
27-
mavenContent {
28-
includeGroupAndSubgroups("io.papermc")
29-
}
30-
}
31-
maven("https://maven.fabricmc.net/") {
32-
name = "FabricMC"
33-
mavenContent {
34-
includeGroupAndSubgroups("net.fabricmc")
35-
}
36-
}
37-
maven("https://repo.denwav.dev/repository/maven-public/") {
38-
name = "DenWav"
39-
mavenContent {
40-
includeGroupAndSubgroups("org.vineflower")
41-
}
42-
}
43-
maven("https://libraries.minecraft.net/") {
44-
name = "Minecraft"
45-
}
46-
mavenCentral()
47-
}
48-
4927
val libs: LibrariesForLibs by extensions
5028

5129
val codebook by configurations.registering
@@ -151,6 +129,80 @@ tasks.register("rebuildPatches", RebuildPatches::class) {
151129
patchDir.set(layout.projectDirectory.dir("patches"))
152130
}
153131

132+
val generateMacheMetadata by tasks.registering(GenerateMacheMetadata::class) {
133+
repos.addAll(mache.repositories)
134+
135+
codebookConfiguration.set(codebook)
136+
paramMappingsConfiguration.set(paramMappings)
137+
constantsConfiguration.set(constants)
138+
remapperConfiguration.set(remapper)
139+
decompilerConfiguration.set(decompiler)
140+
141+
decompilerArgs.set(mache.decompilerArgs)
142+
}
143+
144+
val buildIdVar: Provider<String> = providers.environmentVariable("BUILD_ID").orElse("local")
145+
val versionProvider: Provider<String> = mache.minecraftVersion.zip(buildIdVar) { mcVersion, buildId ->
146+
"$mcVersion+build.$buildId"
147+
}
148+
149+
val createMacheArtifact by tasks.registering(Zip::class) {
150+
group = "mache"
151+
description = "Create the mache metadata artifact for publishing."
152+
153+
from(generateMacheMetadata) {
154+
rename { "mache.json" }
155+
}
156+
into("patches") {
157+
from(layout.projectDirectory.dir("patches"))
158+
}
159+
160+
archiveBaseName.set("mache")
161+
archiveVersion.set(versionProvider)
162+
archiveExtension.set("zip")
163+
}
164+
165+
val archive = artifacts.archives(createMacheArtifact)
166+
154167
afterEvaluate {
168+
repositories {
169+
for (repository in mache.repositories) {
170+
maven(repository.url) {
171+
name = repository.name
172+
mavenContent {
173+
for (group in repository.includeGroups.get()) {
174+
includeGroupAndSubgroups(group)
175+
}
176+
}
177+
}
178+
}
179+
180+
maven("https://libraries.minecraft.net/") {
181+
name = "Minecraft"
182+
}
183+
mavenCentral()
184+
}
185+
155186
ConfigureVersionProject.configure(project, mache)
156187
}
188+
189+
publishing {
190+
afterEvaluate {
191+
publications {
192+
register<MavenPublication>("mache") {
193+
groupId = "io.papermc"
194+
artifactId = "mache"
195+
version = versionProvider.get()
196+
197+
artifact(archive)
198+
}
199+
}
200+
}
201+
202+
repositories {
203+
maven("https://repo.papermc.io/repository/maven-releases/") {
204+
name = "papermc"
205+
credentials(PasswordCredentials::class)
206+
}
207+
}
208+
}

0 commit comments

Comments
 (0)