rework dsl, add mod configurations (remapped), add support for other mappings #3

Merged
Ecorous merged 11 commits from owlsys/other-mappings into mistress 2024-07-04 14:39:40 -04:00
Showing only changes of commit 47b6d93b18 - Show all commits

View file

@ -21,6 +21,7 @@ import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.Delete
import org.gradle.configurationcache.extensions.capitalized import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.java.decompiler.main.Fernflower import org.jetbrains.java.decompiler.main.Fernflower
import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger
@ -173,18 +174,14 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
} }
} }
project.tasks.register(Constants.CLEAR_LOCAL_CACHE_TASK) { task -> project.tasks.register(Constants.CLEAR_LOCAL_CACHE_TASK, Delete::class.java) { task ->
task.group = Constants.TASK_GROUP task.group = Constants.TASK_GROUP
task.actions.add { task.delete = setOf(ProjectStorage.get(project).localCacheDir)
clearLocalCache()
}
} }
project.tasks.register(Constants.CLEAR_GLOBAL_CACHE_TASK) { task -> project.tasks.register(Constants.CLEAR_GLOBAL_CACHE_TASK, Delete::class.java) { task ->
task.group = Constants.TASK_GROUP task.group = Constants.TASK_GROUP
task.actions.add { task.delete = setOf(PhytotelmaPlugin.globalCacheDir)
clearGlobalCache()
}
} }
project.afterEvaluate { project.afterEvaluate {
@ -192,16 +189,6 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
} }
} }
@OptIn(ExperimentalPathApi::class)
private fun clearLocalCache() {
ProjectStorage.get(project).localCacheDir?.deleteRecursively()
}
@OptIn(ExperimentalPathApi::class)
private fun clearGlobalCache() {
PhytotelmaPlugin.globalCacheDir.deleteRecursively()
}
private fun remapModDependencies() { private fun remapModDependencies() {
ModConfigurations.configurations.forEach { conf -> ModConfigurations.configurations.forEach { conf ->
val artifacts = project.configurations.getByName("mod" + conf.name.capitalized()) val artifacts = project.configurations.getByName("mod" + conf.name.capitalized())
@ -209,7 +196,7 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
if (artifacts.isEmpty()) { if (artifacts.isEmpty()) {
return return
} }
val target = project.configurations.create("mod" + conf.name.capitalized()+"Mapped") { c -> val target = project.configurations.create("mod" + conf.name.capitalized() + "Mapped") { c ->
c.isTransitive = false c.isTransitive = false
conf.classpathNames.forEach { conf.classpathNames.forEach {
project.configurations.getByName(it).extendsFrom(c) project.configurations.getByName(it).extendsFrom(c)
@ -231,11 +218,12 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
val groupname = (group + "_" + name).replace(".", "_") val groupname = (group + "_" + name).replace(".", "_")
val version = artifact.moduleVersion.id.version val version = artifact.moduleVersion.id.version
val classifier = artifact.classifier val classifier = artifact.classifier
val remappedPath = targetPath.resolve(groupname).resolve(version).resolve(groupname+"-"+version+(classifier?.let { "-$it" }?:"")+".jar") val remappedPath = targetPath.resolve(groupname).resolve(version)
.resolve(groupname + "-" + version + (classifier?.let { "-$it" } ?: "") + ".jar")
remappedPath.createParentDirectories() remappedPath.createParentDirectories()
remappedPaths.add(remappedPath) remappedPaths.add(remappedPath)
val pom = remappedPath.resolveSibling(remappedPath.fileName.toString().removeSuffix(".jar")+".pom") val pom = remappedPath.resolveSibling(remappedPath.fileName.toString().removeSuffix(".jar") + ".pom")
pom.writeText( pom.writeText(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" + "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
@ -250,7 +238,10 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
Thyroxine.remap(mappings, artifact.file.toPath(), remappedPath, false, false) Thyroxine.remap(mappings, artifact.file.toPath(), remappedPath, false, false)
project.dependencies.add(target.name, "dev.frogmc.phytotelma.remapped_mods:$groupname:$version"+(classifier?.let { ":$it" }?:"")) project.dependencies.add(
target.name,
"dev.frogmc.phytotelma.remapped_mods:$groupname:$version" + (classifier?.let { ":$it" } ?: "")
)
} }
} }
} }