refactor clear cache tasks

This commit is contained in:
moehreag 2024-07-02 20:45:20 +02:00
parent b720533287
commit 47b6d93b18

View file

@ -21,6 +21,7 @@ import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.Delete
import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.java.decompiler.main.Fernflower
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.actions.add {
clearLocalCache()
}
task.delete = setOf(ProjectStorage.get(project).localCacheDir)
}
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.actions.add {
clearGlobalCache()
}
task.delete = setOf(PhytotelmaPlugin.globalCacheDir)
}
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() {
ModConfigurations.configurations.forEach { conf ->
val artifacts = project.configurations.getByName("mod" + conf.name.capitalized())
@ -209,7 +196,7 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
if (artifacts.isEmpty()) {
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
conf.classpathNames.forEach {
project.configurations.getByName(it).extendsFrom(c)
@ -231,11 +218,12 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
val groupname = (group + "_" + name).replace(".", "_")
val version = artifact.moduleVersion.id.version
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()
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(
"<?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" +
@ -250,7 +238,10 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
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" } ?: "")
)
}
}
}