rework dsl, add mod configurations (remapped), add support for other mappings #3
70
src/main/kotlin/dev/frogmc/phytotelma/ModConfigurations.kt
Normal file
70
src/main/kotlin/dev/frogmc/phytotelma/ModConfigurations.kt
Normal file
|
@ -0,0 +1,70 @@
|
|||
package dev.frogmc.phytotelma
|
||||
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
|
||||
object ModConfigurations {
|
||||
val configurations = listOf(
|
||||
ModConfiguration(
|
||||
JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, listOf(
|
||||
JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
), DependencyType.RUNTIME
|
||||
),
|
||||
ModConfiguration(
|
||||
JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, listOf(
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
), DependencyType.RUNTIME
|
||||
),
|
||||
ModConfiguration(
|
||||
JavaPlugin.API_CONFIGURATION_NAME, listOf(
|
||||
JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
), DependencyType.COMPILE
|
||||
),
|
||||
ModConfiguration(
|
||||
JavaPlugin.COMPILE_ONLY_API_CONFIGURATION_NAME, listOf(
|
||||
JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
), DependencyType.COMPILE
|
||||
),
|
||||
ModConfiguration(
|
||||
JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, listOf(
|
||||
JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
)
|
||||
),
|
||||
ModConfiguration(
|
||||
JavaPlugin.TEST_COMPILE_ONLY_CONFIGURATION_NAME, listOf(
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
)
|
||||
),
|
||||
ModConfiguration(
|
||||
JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, listOf(
|
||||
JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
)
|
||||
),
|
||||
ModConfiguration(
|
||||
JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, listOf(
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
data class ModConfiguration(
|
||||
val name: String,
|
||||
val classpathNames: List<String>,
|
||||
val dependencyType: DependencyType = DependencyType.NONE,
|
||||
)
|
||||
|
||||
enum class DependencyType {
|
||||
NONE,
|
||||
RUNTIME,
|
||||
COMPILE
|
||||
}
|
|
@ -2,14 +2,9 @@ package dev.frogmc.phytotelma
|
|||
|
||||
import dev.frogmc.phytotelma.ext.PhytotelmaGradleExtension
|
||||
import dev.frogmc.phytotelma.ext.PhytotelmaGradleExtensionImpl
|
||||
import groovy.util.Node
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.ExcludeRule
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.publish.PublishingExtension
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
|
||||
import org.gradle.configurationcache.extensions.capitalized
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
|
@ -62,40 +57,19 @@ class PhytotelmaPlugin : Plugin<Project> {
|
|||
PhytotelmaGradleExtensionImpl::class.java
|
||||
)
|
||||
|
||||
remappedConfigurationNames.forEach { conf ->
|
||||
project.configurations.create("mod" + conf.key.capitalized()) { c ->
|
||||
ModConfigurations.configurations.forEach { conf ->
|
||||
project.configurations.create("mod" + conf.name.capitalized()) { c ->
|
||||
c.isCanBeResolved = true
|
||||
c.isCanBeConsumed = false
|
||||
|
||||
project.configurations.getByName(conf.key).extendsFrom(c)
|
||||
when (conf.dependencyType) {
|
||||
DependencyType.RUNTIME -> project.configurations.getByName(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME).extendsFrom(c)
|
||||
DependencyType.COMPILE -> project.configurations.getByName(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME).extendsFrom(c)
|
||||
DependencyType.NONE -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.tasks.filterIsInstance<PublishToMavenRepository>()
|
||||
.forEach {
|
||||
it.actions.addFirst {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*project.extensions.findByType(PublishingExtension::class.java)
|
||||
.takeIf { it != null }.let { it!! }
|
||||
.publications.filterIsInstance<MavenPublication>().forEach { p ->
|
||||
p.pom {
|
||||
it.withXml {
|
||||
val project = it.asNode().get("project") as Node
|
||||
val dependencies = project.get("dependencies") as Node
|
||||
dependencies.appendNode("dependency")
|
||||
.setValue(
|
||||
"<groupId>dev.frogmc</groupId>\n" +
|
||||
"<artifactId>thyroxine</artifactId>\n" +
|
||||
"<version>0.0.1-alpha.6</version>\n" +
|
||||
"<scope>runtime</scope>"
|
||||
)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
project.configurations.register(Constants.INCLUDE_CONFIGURATION) {
|
||||
it.isCanBeResolved = true
|
||||
it.isCanBeConsumed = false
|
||||
|
|
|
@ -2,10 +2,7 @@ package dev.frogmc.phytotelma.ext
|
|||
|
||||
import com.electronwill.nightconfig.core.file.FileNotFoundAction
|
||||
import com.electronwill.nightconfig.toml.TomlParser
|
||||
import dev.frogmc.phytotelma.Constants
|
||||
import dev.frogmc.phytotelma.PhytotelmaPlugin
|
||||
import dev.frogmc.phytotelma.ProjectStorage
|
||||
import dev.frogmc.phytotelma.VersionChecker
|
||||
import dev.frogmc.phytotelma.*
|
||||
import dev.frogmc.phytotelma.accesswidener.AccessWidener
|
||||
import dev.frogmc.phytotelma.build.PhytotelmaBuildTask
|
||||
import dev.frogmc.phytotelma.common.Env
|
||||
|
@ -24,7 +21,6 @@ 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.publish.maven.plugins.MavenPublishPlugin
|
||||
import org.gradle.configurationcache.extensions.capitalized
|
||||
import org.jetbrains.java.decompiler.main.Fernflower
|
||||
import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger
|
||||
|
@ -203,15 +199,15 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
|||
}
|
||||
|
||||
private fun remapModDependencies() {
|
||||
PhytotelmaPlugin.remappedConfigurationNames.forEach { conf ->
|
||||
val artifacts = project.configurations.getByName("mod" + conf.key.capitalized())
|
||||
ModConfigurations.configurations.forEach { conf ->
|
||||
val artifacts = project.configurations.getByName("mod" + conf.name.capitalized())
|
||||
.resolvedConfiguration.resolvedArtifacts
|
||||
if (artifacts.isEmpty()) {
|
||||
return
|
||||
}
|
||||
val target = project.configurations.create("mod" + conf.key.capitalized()+"Mapped") { c ->
|
||||
c.isTransitive = false // TODO while this configuration should not be transitive, the original dependency should be!
|
||||
conf.value.forEach {
|
||||
val target = project.configurations.create("mod" + conf.name.capitalized()+"Mapped") { c ->
|
||||
c.isTransitive = false
|
||||
conf.classpathNames.forEach {
|
||||
project.configurations.getByName(it).extendsFrom(c)
|
||||
}
|
||||
}
|
||||
|
@ -226,28 +222,21 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
|||
.resolve("dev/frogmc/phytotelma/remapped_mods")
|
||||
val remappedPaths = mutableListOf<Path>()
|
||||
artifacts.forEach { artifact ->
|
||||
println(artifact.file)
|
||||
val id = artifact.id.componentIdentifier.toString().split(":")
|
||||
val group = artifact.moduleVersion.id.group
|
||||
val name = artifact.moduleVersion.id.name
|
||||
val groupname = (group + "_" + name).replace(".", "_")
|
||||
val version = artifact.moduleVersion.id.version
|
||||
val classifier = artifact.classifier
|
||||
val remappedPath = targetPath.resolve(groupname).resolve(version).resolve(artifact.file.name)
|
||||
/*val remappedPath = targetPath.resolve(group.replace(".", "/"))
|
||||
.resolve(name).resolve(version).resolve(artifact.file.name)*/
|
||||
remappedPath.createParentDirectories()
|
||||
remappedPaths.add(remappedPath)
|
||||
|
||||
val pom = remappedPath.resolveSibling(artifact.file.name.removeSuffix(".jar")+".pom")
|
||||
//val pom = remappedPath.resolveSibling(artifact.file.name.substring(0, artifact.file.name.lastIndexOf("."))+".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" +
|
||||
"\t\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
|
||||
"\t<modelVersion>4.0.0</modelVersion>\n" +
|
||||
//"\t<groupId>$group</groupId>\n" +
|
||||
//"\t<artifactId>$name</artifactId>\n" +
|
||||
"\t<groupId>dev.frogmc.phytotelma.remapped_mods</groupId>\n" +
|
||||
"\t<artifactId>$groupname</artifactId>\n" +
|
||||
"\t<version>$version</version>\n" +
|
||||
|
@ -257,7 +246,6 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
|||
|
||||
Thyroxine.remap(mappings, artifact.file.toPath(), remappedPath, false, false)
|
||||
|
||||
//project.dependencies.add(conf.key, group+":"+name+":"+version+(classifier?:""))
|
||||
project.dependencies.add(target.name, "dev.frogmc.phytotelma.remapped_mods:$groupname:$version"+(classifier?.let { ":$it" }?:""))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue