Compare commits
2 commits
b720533287
...
3c1ddb496e
Author | SHA1 | Date | |
---|---|---|---|
moehreag | 3c1ddb496e | ||
moehreag | 47b6d93b18 |
|
@ -63,8 +63,12 @@ class PhytotelmaPlugin : Plugin<Project> {
|
|||
c.isCanBeConsumed = false
|
||||
|
||||
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.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 -> {}
|
||||
}
|
||||
}
|
||||
|
@ -88,31 +92,5 @@ class PhytotelmaPlugin : Plugin<Project> {
|
|||
|
||||
companion object {
|
||||
lateinit var globalCacheDir: Path
|
||||
val remappedConfigurationNames = mapOf(
|
||||
JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME to listOf(
|
||||
JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
),
|
||||
JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME to listOf(
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
),
|
||||
JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME to listOf(
|
||||
JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
),
|
||||
JavaPlugin.TEST_COMPILE_ONLY_CONFIGURATION_NAME to listOf(
|
||||
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
|
||||
),
|
||||
JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME to listOf(
|
||||
JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
),
|
||||
JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME to listOf(
|
||||
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
@file:Suppress("unused")
|
||||
|
||||
package dev.frogmc.phytotelma
|
||||
|
||||
import com.google.gson.Gson
|
||||
|
@ -5,9 +7,11 @@ import com.google.gson.GsonBuilder
|
|||
import dev.frogmc.phytotelma.common.CachingHttpClient
|
||||
import org.gradle.api.Project
|
||||
import java.net.URI
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.*
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.writeBytes
|
||||
import kotlin.io.path.writeText
|
||||
|
||||
object VersionChecker {
|
||||
private var validVersions = mutableListOf<VersionUrl>()
|
||||
|
@ -77,17 +81,6 @@ object VersionChecker {
|
|||
return fetchVersionData(version).downloads.client
|
||||
}
|
||||
|
||||
fun downloadAssetIndex(version: String, path: Path): String {
|
||||
val index = fetchVersionData(version).assetIndex
|
||||
val dest = path.resolve(index.id + ".json")
|
||||
if (dest.notExists()) {
|
||||
CachingHttpClient.getUncached(URI.create(index.url)).use {
|
||||
Files.copy(it, dest)
|
||||
}
|
||||
}
|
||||
return index.id
|
||||
}
|
||||
|
||||
private fun rawDownload(url: String): ByteArray {
|
||||
return CachingHttpClient.getUncached(URI.create(url)).readAllBytes()
|
||||
}
|
||||
|
|
|
@ -177,14 +177,14 @@ abstract class MinecraftConfiguration @Inject constructor(
|
|||
var back = MappingBundle()
|
||||
var name = "layer["
|
||||
|
||||
val layers = conf.layers.mapIndexed {index, provider ->
|
||||
val layers = conf.layers.mapIndexed { index, provider ->
|
||||
val bundle = provider.get().flatten(true)
|
||||
if (index == 0) {
|
||||
name+=mappingsName
|
||||
name += mappingsName
|
||||
back.insert(bundle)
|
||||
return@mapIndexed bundle
|
||||
}
|
||||
name+=", $mappingsName"
|
||||
name += ", $mappingsName"
|
||||
|
||||
back = back.flatten(false)
|
||||
val prevDst = back.data[0].dstNamespace
|
||||
|
|
|
@ -21,11 +21,13 @@ 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
|
||||
import org.jetbrains.java.decompiler.main.decompiler.SingleFileSaver
|
||||
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
|
||||
import java.io.OutputStream
|
||||
import java.io.PrintStream
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
|
@ -98,7 +100,7 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
|||
project.tasks.register(Constants.DOWNLOAD_ASSETS_TASK) { task ->
|
||||
task.group = Constants.TASK_GROUP
|
||||
task.doFirst {
|
||||
AssetDownloader.download(it.project)
|
||||
AssetDownloader.download(it.project, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,18 +175,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,24 +190,17 @@ 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() {
|
||||
val out = System.out
|
||||
// Mute the output from thyroxine as there may be a lot of remapping operations here
|
||||
System.setOut(PrintStream(OutputStream.nullOutputStream()))
|
||||
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.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 +222,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,15 +242,17 @@ 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" } ?: "")
|
||||
)
|
||||
}
|
||||
}
|
||||
System.setOut(out)
|
||||
}
|
||||
|
||||
override fun minecraft(action: Action<MinecraftConfiguration>) {
|
||||
println("Setting up Tasks...")
|
||||
setupTasks()
|
||||
println("Setting up Minecraft...")
|
||||
val mcConf = objects.newInstance(MinecraftConfiguration::class.java)
|
||||
action.execute(mcConf)
|
||||
|
||||
|
@ -281,7 +275,6 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
|||
projectData.localCacheDir!!.resolve("net/minecraft/client/$version/client-$version-remapped.jar")
|
||||
remappedJar.createParentDirectories()
|
||||
projectData.remappedGameJarPath = remappedJar
|
||||
println("Time to setup Minecraft!")
|
||||
val applyAW = AccessWidener.needsUpdate(project)
|
||||
if (remappedJar.notExists() || applyAW || mcConf.mappingsName != projectData.mappingsName) {
|
||||
projectData.mappingsName = mcConf.mappingsName
|
||||
|
@ -303,8 +296,8 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
|||
VersionChecker.savePomFile(version, remappedJar.parent)
|
||||
project.dependencies.add(Constants.MINECRAFT_CONFIGURATION, "net.minecraft:client:$version:remapped")
|
||||
|
||||
println("Generating run configurations...")
|
||||
RunConfigGenerator.generate(project)
|
||||
AssetDownloader.download(project)
|
||||
|
||||
if (applyAW) {
|
||||
project.afterEvaluate {
|
||||
|
|
|
@ -35,7 +35,7 @@ fun MappingBundle.filterClasses(filter: (String) -> Boolean): MappingBundle {
|
|||
newData.parameters.putAll(parameters.filter { newData.classes.containsKey(it.key.owner) })
|
||||
}
|
||||
|
||||
val bundle = MappingBundle(data.subList(0, data.size-1).plus(newData), mutableListOf())
|
||||
val bundle = MappingBundle(data.subList(0, data.size - 1).plus(newData), mutableListOf())
|
||||
|
||||
if (oldDocs != null) {
|
||||
val newDocs = DocumentationData(newData.dstNamespace)
|
||||
|
|
|
@ -110,8 +110,8 @@ object Nester {
|
|||
val matcher = pattern.matcher(version)
|
||||
matcher.find()
|
||||
val semver = matcher.group(1) +
|
||||
(if (matcher.group(2) != null) "-"+matcher.group(2) else "") +
|
||||
(if (matcher.group(3) != null) "+"+matcher.group(3) else "")
|
||||
(if (matcher.group(2) != null) "-" + matcher.group(2) else "") +
|
||||
(if (matcher.group(3) != null) "+" + matcher.group(3) else "")
|
||||
it.getPath("frog.mod.toml").writeText(
|
||||
"""
|
||||
[frog]
|
||||
|
|
|
@ -9,43 +9,59 @@ import dev.frogmc.phytotelma.common.CachingHttpClient
|
|||
import org.gradle.api.Project
|
||||
import java.net.URI
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.notExists
|
||||
import kotlin.io.path.reader
|
||||
|
||||
object AssetDownloader {
|
||||
private const val ASSETS_URL = "https://resources.download.minecraft.net"
|
||||
|
||||
fun download(project: Project) {
|
||||
fun download(project: Project, manualInvocation: Boolean = false) {
|
||||
val version = ProjectStorage.get(project).minecraftVersion!!
|
||||
val path = PhytotelmaPlugin.globalCacheDir.resolve("assets")
|
||||
val id = VersionChecker.downloadAssetIndex(version, path.resolve("indexes"))
|
||||
val assetIndex = VersionChecker.fetchVersionData(version).assetIndex
|
||||
val dest = path.resolve("indexes").resolve(assetIndex.id + ".json")
|
||||
var overwrite = manualInvocation
|
||||
if (dest.notExists()) {
|
||||
CachingHttpClient.getUncached(URI.create(assetIndex.url)).use {
|
||||
Files.copy(it, dest)
|
||||
}
|
||||
overwrite = true
|
||||
}
|
||||
|
||||
val index = Gson().fromJson(
|
||||
path.resolve("indexes").resolve("$id.json").reader(StandardCharsets.UTF_8),
|
||||
path.resolve("indexes").resolve("${assetIndex.id}.json").reader(StandardCharsets.UTF_8),
|
||||
JsonObject::class.java
|
||||
)
|
||||
val objectsPath = path.resolve("objects")
|
||||
objectsPath.createDirectories()
|
||||
val entries = index.getAsJsonObject("objects").entrySet()
|
||||
val totalSize = entries.size
|
||||
print("Downloading $totalSize assets... ()")
|
||||
System.out.flush()
|
||||
if (overwrite) {
|
||||
print("Downloading $totalSize assets... ()")
|
||||
System.out.flush()
|
||||
}
|
||||
entries.forEachIndexed { i, it ->
|
||||
val hash = it.value.asJsonObject.get("hash").asString
|
||||
/*val size = it.value.asJsonObject.get("size").asInt
|
||||
val name = it.key*/
|
||||
// TODO asset downloading for versions <=1.7 (legacy)
|
||||
print("\rDownloading $totalSize assets... ($i/$totalSize): $hash"+" ".repeat(30))
|
||||
System.out.flush()
|
||||
get(objectsPath, hash)
|
||||
if (overwrite) {
|
||||
print("\rDownloading $totalSize assets... ($i/$totalSize): $hash" + " ".repeat(30))
|
||||
System.out.flush()
|
||||
}
|
||||
get(objectsPath, hash, overwrite)
|
||||
}
|
||||
if (overwrite) {
|
||||
println("\rDownloading $totalSize assets... Done!" + " ".repeat(50))
|
||||
}
|
||||
println("\rDownloading $totalSize assets... Done!"+" ".repeat(50))
|
||||
}
|
||||
|
||||
private fun get(localDir: Path, hash: String) {
|
||||
private fun get(localDir: Path, hash: String, overwrite: Boolean) {
|
||||
val shortHash = hash.substring(0, 2)
|
||||
val path = localDir.resolve("$shortHash/$hash")
|
||||
CachingHttpClient.downloadTo(URI.create("$ASSETS_URL/$shortHash/$hash"), path, true)
|
||||
CachingHttpClient.downloadTo(URI.create("$ASSETS_URL/$shortHash/$hash"), path, overwrite)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ object RunConfigGenerator {
|
|||
assetIndexPath.createDirectories()
|
||||
}
|
||||
val projectData = ProjectStorage.get(project)
|
||||
val indexId = VersionChecker.downloadAssetIndex(projectData.minecraftVersion!!, assetIndexPath)
|
||||
val indexId = VersionChecker.fetchVersionData(projectData.minecraftVersion!!).assetIndex.id
|
||||
|
||||
val projectName = if (project.rootDir == project.projectDir) "" else " (${project.name})"
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ abstract class RunGameTask @Inject constructor(env: Env) : JavaExec() {
|
|||
if (assetIndexPath.notExists()) {
|
||||
assetIndexPath.createDirectories()
|
||||
}
|
||||
val indexId = VersionChecker.downloadAssetIndex(ProjectStorage.get(project).minecraftVersion!!, assetIndexPath)
|
||||
val indexId = VersionChecker.fetchVersionData(ProjectStorage.get(project).minecraftVersion!!).assetIndex.id
|
||||
val log4jPath = project.rootDir.resolve(".gradle/phytotelma/log4j.xml").toPath().absolute()
|
||||
if (log4jPath.notExists()) {
|
||||
log4jPath.createParentDirectories()
|
||||
|
|
Loading…
Reference in a new issue