mirror of
https://github.com/architectury/architectury-plugin.git
synced 2026-03-27 19:57:00 -05:00
Fix architectury/architectury-loom#72 (#25)
This commit is contained in:
@@ -30,6 +30,8 @@ class LoomInterface010(private val project: Project) : LoomInterface {
|
||||
extension.setGenerateSrgTiny(value)
|
||||
}
|
||||
|
||||
override val generateTransformerPropertiesInTask = false
|
||||
|
||||
override fun settingsPostEdit(action: (config: LoomInterface.LoomRunConfig) -> Unit) {
|
||||
extension.settingsPostEdit.add(Consumer { c -> action(LoomRunConfigImpl(c)) })
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class LoomInterface010Legacy(private val project: Project) : LoomInterface {
|
||||
extension.setGenerateSrgTiny(value)
|
||||
}
|
||||
|
||||
override val generateTransformerPropertiesInTask = false
|
||||
|
||||
override fun settingsPostEdit(action: (config: LoomInterface.LoomRunConfig) -> Unit) {
|
||||
extension.settingsPostEdit.add(Consumer { c -> action(LoomRunConfigImpl(c)) })
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ class LoomInterface011(private val project: Project) : LoomInterface {
|
||||
extension.setGenerateSrgTiny(value)
|
||||
}
|
||||
|
||||
override val generateTransformerPropertiesInTask = true
|
||||
|
||||
override fun settingsPostEdit(action: (config: LoomInterface.LoomRunConfig) -> Unit) {
|
||||
extension.settingsPostEdit.add(Consumer { c -> action(LoomRunConfigImpl(c)) })
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ class LoomInterface06(private val project: Project) : LoomInterface {
|
||||
extension.generateSrgTiny = value
|
||||
}
|
||||
|
||||
override val generateTransformerPropertiesInTask = false
|
||||
|
||||
override fun settingsPostEdit(action: (config: LoomInterface.LoomRunConfig) -> Unit) {
|
||||
extension.settingsPostEdit.add(Consumer { c -> action(LoomRunConfigImpl(c)) })
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class LoomInterface09(private val project: Project) : LoomInterface {
|
||||
extension.setGenerateSrgTiny(value)
|
||||
}
|
||||
|
||||
override val generateTransformerPropertiesInTask = false
|
||||
|
||||
override fun settingsPostEdit(action: (config: LoomInterface.LoomRunConfig) -> Unit) {
|
||||
extension.settingsPostEdit.add(Consumer { c -> action(LoomRunConfigImpl(c)) })
|
||||
}
|
||||
|
||||
@@ -91,29 +91,21 @@ open class ArchitectPluginExtension(val project: Project) {
|
||||
|
||||
init {
|
||||
project.afterEvaluate {
|
||||
if (transforms.isNotEmpty()) {
|
||||
StringWriter().also { strWriter ->
|
||||
TransformersWriter(strWriter).use { writer ->
|
||||
for (transform in transforms.values) {
|
||||
project.configurations.getByName(transform.configName).forEach { file ->
|
||||
transform.transformers.map { it.apply(file.toPath()) }
|
||||
.forEach { pair ->
|
||||
writer.write(file.toPath(), pair.clazz, pair.properties)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (loom.generateTransformerPropertiesInTask) {
|
||||
// Only apply if this project has the configureLaunch task.
|
||||
// This is needed because arch plugin can also apply to the root project
|
||||
// where the task doesn't exist and our task isn't needed either.
|
||||
if ("configureLaunch" in project.tasks.names) {
|
||||
val task = project.tasks.register(
|
||||
"prepareArchitecturyTransformer",
|
||||
PrepareArchitecturyTransformer::class.java
|
||||
)
|
||||
project.tasks.named("configureLaunch") {
|
||||
it.dependsOn(task)
|
||||
}
|
||||
|
||||
runtimeTransformerFile.writeText(strWriter.toString())
|
||||
}
|
||||
|
||||
val properties = Properties()
|
||||
properties(transforms.keys.first()).forEach { (key, value) ->
|
||||
properties.setProperty(key, value)
|
||||
}
|
||||
propertiesTransformerFile.writer().use {
|
||||
properties.store(it, "Architectury Runtime Transformer Properties")
|
||||
}
|
||||
} else {
|
||||
prepareTransformer()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,6 +123,34 @@ open class ArchitectPluginExtension(val project: Project) {
|
||||
)
|
||||
}
|
||||
|
||||
fun prepareTransformer() {
|
||||
if (transforms.isNotEmpty()) {
|
||||
StringWriter().also { strWriter ->
|
||||
TransformersWriter(strWriter).use { writer ->
|
||||
for (transform in transforms.values) {
|
||||
project.configurations.getByName(transform.configName).forEach { file ->
|
||||
transform.transformers.map { it.apply(file.toPath()) }
|
||||
.forEach { pair ->
|
||||
writer.write(file.toPath(), pair.clazz, pair.properties)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runtimeTransformerFile.writeText(strWriter.toString())
|
||||
}
|
||||
|
||||
|
||||
val properties = Properties()
|
||||
properties(transforms.keys.first()).forEach { (key, value) ->
|
||||
properties.setProperty(key, value)
|
||||
}
|
||||
propertiesTransformerFile.writer().use {
|
||||
properties.store(it, "Architectury Runtime Transformer Properties")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCompileClasspath(): Iterable<File> {
|
||||
return project.configurations.findByName("architecturyTransformerClasspath")
|
||||
?: project.configurations.getByName("compileClasspath")
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.architectury.plugin
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
open class PrepareArchitecturyTransformer : DefaultTask() {
|
||||
@TaskAction
|
||||
fun run() {
|
||||
project.extensions.getByType(ArchitectPluginExtension::class.java).prepareTransformer()
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,16 @@ interface LoomInterface {
|
||||
val refmapName: String
|
||||
var generateSrgTiny: Boolean
|
||||
|
||||
/**
|
||||
* Loom 0.11+ has to generate the runtime transformer properties file
|
||||
* in a separate hook that is guaranteed to run after mod dep processing.
|
||||
* (Which is a task hooked to `configureLaunch`.)
|
||||
* This is just unfortunate `afterEvaluate` ordering, sadly.
|
||||
*
|
||||
* See [architectury-loom#72](https://github.com/architectury/architectury-loom/issues/72)
|
||||
*/
|
||||
val generateTransformerPropertiesInTask: Boolean
|
||||
|
||||
fun settingsPostEdit(action: (config: LoomRunConfig) -> Unit)
|
||||
fun setIdeConfigGenerated()
|
||||
fun setRemapJarInput(task: Jar, archiveFile: Provider<RegularFile>)
|
||||
|
||||
Reference in New Issue
Block a user