more fixes for run configs + asset downloading
Some checks failed
Publish to snapshot maven / build (push) Failing after 17s

This commit is contained in:
moehreag 2024-05-19 18:29:39 +02:00
parent b111afe9a5
commit efff2e71d3
5 changed files with 70 additions and 13 deletions

View file

@ -1,6 +1,7 @@
package org.ecorous.esnesnon.gradle package org.ecorous.esnesnon.gradle
import net.fabricmc.fernflower.api.IFabricJavadocProvider import net.fabricmc.fernflower.api.IFabricJavadocProvider
import org.ecorous.esnesnon.gradle.run.AssetDownloader
import org.ecorous.esnesnon.gradle.run.RunConfigGenerator import org.ecorous.esnesnon.gradle.run.RunConfigGenerator
import org.ecorous.esnesnon.gradle.vineflower.ParchmentJavadocProvider import org.ecorous.esnesnon.gradle.vineflower.ParchmentJavadocProvider
import org.ecorous.esnesnon.nonsense_remapper.provider.ParchmentProvider import org.ecorous.esnesnon.nonsense_remapper.provider.ParchmentProvider
@ -106,6 +107,12 @@ class NonsenseGradlePlugin : Plugin<Project> {
} }
} }
project.task("downloadAssets").apply {
doFirst {
AssetDownloader.download()
}
}
// TODO mod relocation/renaming: decide on mod file extension // TODO mod relocation/renaming: decide on mod file extension
/*project.tasks.getByName("jar").actions.addLast { /*project.tasks.getByName("jar").actions.addLast {
it.outputs.files.forEach {file -> it.outputs.files.forEach {file ->

View file

@ -73,12 +73,16 @@ object VersionChecker {
return fetchVersionData(version).downloads.client return fetchVersionData(version).downloads.client
} }
fun downloadAssetIndex(version: String, path: Path) { fun downloadAssetIndex(version: String, path: Path): String {
val url = fetchVersionData(version).assetIndex.url val index = fetchVersionData(version).assetIndex
CachingHttpClient.get(URI.create(url)).use { val dest = path.resolve(index.id+".json")
Files.copy(it, path) if (dest.notExists()) {
CachingHttpClient.getUncached(URI.create(index.url)).use {
Files.copy(it, dest)
} }
} }
return index.id
}
private fun rawDownload(url: String): ByteArray { private fun rawDownload(url: String): ByteArray {
return CachingHttpClient.getUncached(URI.create(url)).readAllBytes() return CachingHttpClient.getUncached(URI.create(url)).readAllBytes()

View file

@ -15,9 +15,9 @@ object CachingHttpClient {
fun downloadTo(uri: URI, path: Path) { fun downloadTo(uri: URI, path: Path) {
if (path.notExists()) { if (path.notExists()) {
path.createParentDirectories()
Files.copy(getUncached(uri), path) Files.copy(getUncached(uri), path)
} }
} }
fun get(uri: URI): InputStream { fun get(uri: URI): InputStream {

View file

@ -0,0 +1,44 @@
package org.ecorous.esnesnon.gradle.run
import com.google.gson.Gson
import com.google.gson.JsonObject
import org.ecorous.esnesnon.gradle.NonsenseGradlePlugin
import org.ecorous.esnesnon.gradle.VersionChecker
import org.ecorous.esnesnon.gradle.common.CachingHttpClient
import java.net.URI
import java.nio.charset.StandardCharsets
import java.nio.file.Path
import kotlin.io.path.createDirectories
import kotlin.io.path.reader
object AssetDownloader {
private const val ASSETS_URL = "https://resources.download.minecraft.net"
fun download() {
val version = NonsenseGradlePlugin.minecraftVersion
val path = NonsenseGradlePlugin.nonsenseCacheDir.resolve("assets")
val id = VersionChecker.downloadAssetIndex(version, path.resolve("indexes"))
val index = Gson().fromJson(
path.resolve("indexes").resolve("$id.json").reader(StandardCharsets.UTF_8),
JsonObject::class.java
)
val objectsPath = path.resolve("objects")
objectsPath.createDirectories()
val entries = index.getAsJsonObject("objects").entrySet()
println("Downloading ${entries.size} assets...")
entries.forEach {
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)
get(objectsPath, hash)
}
}
private fun get(localDir: Path, hash: String) {
val shortHash = hash.substring(0, 2)
val path = localDir.resolve("$shortHash/$hash")
CachingHttpClient.downloadTo(URI.create("$ASSETS_URL/$shortHash/$hash"), path)
}
}

View file

@ -8,11 +8,12 @@ import org.ecorous.esnesnon.gradle.run.adapter.IdeaAdapter
import org.gradle.api.Project import org.gradle.api.Project
import java.nio.file.Files import java.nio.file.Files
import kotlin.io.path.absolute import kotlin.io.path.absolute
import kotlin.io.path.createDirectories
import kotlin.io.path.createParentDirectories import kotlin.io.path.createParentDirectories
import kotlin.io.path.notExists import kotlin.io.path.notExists
object RunConfigGenerator { object RunConfigGenerator {
private const val LOG4J_CONFIG_PATH = ".gradle/nonsense/log4j.xml" private const val LOG4J_CONFIG_PATH = ".gradle/nonsense-gradle/log4j.xml"
private const val ASSET_DIR = "assets" private const val ASSET_DIR = "assets"
private val ADAPTERS = arrayOf(EclipseAdapter(), IdeaAdapter()) private val ADAPTERS = arrayOf(EclipseAdapter(), IdeaAdapter())
@ -26,11 +27,11 @@ object RunConfigGenerator {
} }
val assetPath = NonsenseGradlePlugin.nonsenseCacheDir.resolve(ASSET_DIR).absolute() val assetPath = NonsenseGradlePlugin.nonsenseCacheDir.resolve(ASSET_DIR).absolute()
val assetIndexPath = assetPath.resolve("indexes").resolve(NonsenseGradlePlugin.minecraftVersion + ".json") val assetIndexPath = assetPath.resolve("indexes")
if (assetIndexPath.notExists()) { if (assetIndexPath.notExists()) {
assetIndexPath.createParentDirectories() assetIndexPath.createDirectories()
VersionChecker.downloadAssetIndex(NonsenseGradlePlugin.minecraftVersion, assetIndexPath)
} }
val indexId = VersionChecker.downloadAssetIndex(NonsenseGradlePlugin.minecraftVersion, assetIndexPath)
val runConfigPath = project.rootDir.resolve(".idea").resolve("runConfigurations") val runConfigPath = project.rootDir.resolve(".idea").resolve("runConfigurations")
runConfigPath.mkdirs() runConfigPath.mkdirs()
@ -43,16 +44,17 @@ object RunConfigGenerator {
adapter.generate( adapter.generate(
project, project,
"Minecraft ${env.pascalName}", "Minecraft ${env.pascalName}",
"org.ecorous.esnesnon.nonsense.loader.impl.launch.client.Nonsense${env.pascalName}", "org.ecorous.esnesnon.nonsense.loader.impl.launch.${env.id}.Nonsense${env.pascalName}",
arrayOf( arrayOf(
"-Dnonsense.development=true", "-Dnonsense.development=true",
"-Dnonsense.plugin.minecraft.gameJar=${NonsenseGradlePlugin.remappedGameJarPath}", "-Dnonsense.plugin.minecraft.gameJar=${NonsenseGradlePlugin.remappedGameJarPath}",
"-Dlog4j.configurationFile=$assetPath" "-Dlog4j.configurationFile=$log4jPath"
), ),
arrayOf( arrayOf(
"--assetDir", assetPath.toString(), "--assetsDir", assetPath.toString(),
"--version", "Nonsense", "--version", "Nonsense",
"--assetIndex", assetIndexPath.toString() "--assetIndex", indexId,
"--accessToken", "0"
) )
) )
} }