Update deps, move to dev.architectury

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-05-28 18:50:31 +08:00
parent f8d61a5ae2
commit 6e57469e4e
8 changed files with 33 additions and 102 deletions

View File

@@ -0,0 +1,74 @@
package dev.architectury.plugin
import dev.architectury.plugin.utils.GradleSupport
import dev.architectury.transformer.Transform
import dev.architectury.transformer.Transformer
import dev.architectury.transformer.transformers.BuiltinProperties
import dev.architectury.transformer.util.Logger
import org.gradle.api.Project
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.jvm.tasks.Jar
import java.io.File
import java.nio.file.Path
import java.util.*
import kotlin.properties.Delegates
import kotlin.time.ExperimentalTime
open class TransformingTask : Jar() {
@InputFile
val input: RegularFileProperty = GradleSupport.getFileProperty(project)
@Internal
val transformers = mutableListOf<Transformer>()
@Internal
var platform: String? = null
@ExperimentalTime
@TaskAction
fun doTask() {
val input: Path = this.input.asFile.get().toPath()
val output: Path = this.archiveFile.get().asFile.toPath()
val extension = project.extensions.getByType(ArchitectPluginExtension::class.java)
extension.properties(platform ?: throw NullPointerException("No Platform specified")).forEach { (key, value) ->
System.setProperty(key, value)
}
System.setProperty(BuiltinProperties.LOCATION, project.file(".gradle").absolutePath)
Logger.debug("")
Logger.debug("============================")
Logger.debug("Transforming from $input to $output")
Logger.debug("============================")
Logger.debug("")
Transform.runTransformers(input, output, transformers)
}
operator fun invoke(transformer: Transformer) {
transformers.add(transformer)
}
operator fun plusAssign(transformer: Transformer) {
transformers.add(transformer)
}
}
fun Project.projectUniqueIdentifier(): String {
val cache = File(project.file(".gradle"), "architectury-cache")
cache.mkdirs()
val uniqueIdFile = File(cache, "projectID")
var id by Delegates.notNull<String>()
if (uniqueIdFile.exists()) {
id = uniqueIdFile.readText()
} else {
id = UUID.randomUUID().toString().filterNot { it == '-' }
uniqueIdFile.writeText(id)
}
var name = project.name
if (project.rootProject != project) name = project.rootProject.name + "_" + name
return "architectury_inject_${name}_$id".filter { Character.isJavaIdentifierPart(it) }
}
class Epic : RuntimeException()