Compare commits
No commits in common. "3c1ddb496e22f9b94627aa566d1735d3928fafbf" and "b720533287c712910ed16265ba1017504d4af48a" have entirely different histories.
3c1ddb496e
...
b720533287
|
@ -63,12 +63,8 @@ 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 -> {}
|
||||
}
|
||||
}
|
||||
|
@ -92,5 +88,31 @@ 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,5 +1,3 @@
|
|||
@file:Suppress("unused")
|
||||
|
||||
package dev.frogmc.phytotelma
|
||||
|
||||
import com.google.gson.Gson
|
||||
|
@ -7,11 +5,9 @@ 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.createDirectories
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.writeBytes
|
||||
import kotlin.io.path.writeText
|
||||
import kotlin.io.path.*
|
||||
|
||||
object VersionChecker {
|
||||
private var validVersions = mutableListOf<VersionUrl>()
|
||||
|
@ -81,6 +77,17 @@ 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,13 +21,11 @@ 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
|
||||
|
@ -100,7 +98,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, true)
|
||||
AssetDownloader.download(it.project)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,14 +173,18 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
project.tasks.register(Constants.CLEAR_LOCAL_CACHE_TASK, Delete::class.java) { task ->
|
||||
project.tasks.register(Constants.CLEAR_LOCAL_CACHE_TASK) { task ->
|
||||
task.group = Constants.TASK_GROUP
|
||||
task.delete = setOf(ProjectStorage.get(project).localCacheDir)
|
||||
task.actions.add {
|
||||
clearLocalCache()
|
||||
}
|
||||
}
|
||||
|
||||
project.tasks.register(Constants.CLEAR_GLOBAL_CACHE_TASK, Delete::class.java) { task ->
|
||||
project.tasks.register(Constants.CLEAR_GLOBAL_CACHE_TASK) { task ->
|
||||
task.group = Constants.TASK_GROUP
|
||||
task.delete = setOf(PhytotelmaPlugin.globalCacheDir)
|
||||
task.actions.add {
|
||||
clearGlobalCache()
|
||||
}
|
||||
}
|
||||
|
||||
project.afterEvaluate {
|
||||
|
@ -190,17 +192,24 @@ 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)
|
||||
|
@ -222,12 +231,11 @@ 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" +
|
||||
|
@ -242,17 +250,15 @@ 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)
|
||||
|
||||
|
@ -275,6 +281,7 @@ 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
|
||||
|
@ -296,8 +303,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,59 +9,43 @@ 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, manualInvocation: Boolean = false) {
|
||||
fun download(project: Project) {
|
||||
val version = ProjectStorage.get(project).minecraftVersion!!
|
||||
val path = PhytotelmaPlugin.globalCacheDir.resolve("assets")
|
||||
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 id = VersionChecker.downloadAssetIndex(version, path.resolve("indexes"))
|
||||
|
||||
val index = Gson().fromJson(
|
||||
path.resolve("indexes").resolve("${assetIndex.id}.json").reader(StandardCharsets.UTF_8),
|
||||
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()
|
||||
val totalSize = entries.size
|
||||
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)
|
||||
if (overwrite) {
|
||||
print("\rDownloading $totalSize assets... ($i/$totalSize): $hash" + " ".repeat(30))
|
||||
print("\rDownloading $totalSize assets... ($i/$totalSize): $hash"+" ".repeat(30))
|
||||
System.out.flush()
|
||||
get(objectsPath, hash)
|
||||
}
|
||||
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, overwrite: Boolean) {
|
||||
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, overwrite)
|
||||
CachingHttpClient.downloadTo(URI.create("$ASSETS_URL/$shortHash/$hash"), path, true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ object RunConfigGenerator {
|
|||
assetIndexPath.createDirectories()
|
||||
}
|
||||
val projectData = ProjectStorage.get(project)
|
||||
val indexId = VersionChecker.fetchVersionData(projectData.minecraftVersion!!).assetIndex.id
|
||||
val indexId = VersionChecker.downloadAssetIndex(projectData.minecraftVersion!!, assetIndexPath)
|
||||
|
||||
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.fetchVersionData(ProjectStorage.get(project).minecraftVersion!!).assetIndex.id
|
||||
val indexId = VersionChecker.downloadAssetIndex(ProjectStorage.get(project).minecraftVersion!!, assetIndexPath)
|
||||
val log4jPath = project.rootDir.resolve(".gradle/phytotelma/log4j.xml").toPath().absolute()
|
||||
if (log4jPath.notExists()) {
|
||||
log4jPath.createParentDirectories()
|
||||
|
|
Loading…
Reference in a new issue