summaryrefslogtreecommitdiff
path: root/plugin/src/main/kotlin/moe/nea/archenemy
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/src/main/kotlin/moe/nea/archenemy')
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt26
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt22
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadAssets.kt74
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadVersionMetadata.kt64
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/util/ext.kt7
5 files changed, 188 insertions, 5 deletions
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
index e1a8bfe..d27f948 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
@@ -47,7 +47,7 @@ abstract class ArchenemyMojangExtension(val project: Project) {
fun officialMappings(version: String, side: MCSide): MappingDependency {
_registerMinecraftProvider
val dependency by lazy {
- project.dependencies.create(
+ realize(
sharedExtension.minecraftProvider.getMappingsDependencyCoordinate(
MinecraftProvider.MinecraftCoordinate(
version,
@@ -56,7 +56,14 @@ abstract class ArchenemyMojangExtension(val project: Project) {
)
)
}
- return OfficialMappingDependency(side, version, project.providers.provider { dependency })
+ return OfficialMappingDependency(side, version, project.providers.provider { dependency }).also { it.get() }
+ }
+
+ fun libraries(version: String): List<String> {
+ return sharedExtension.getDownloadVersionMetadataTask(version)
+ .getVersionMetadataNow().libraries
+ .map { it.name }
+ .filter { !it.contains("twitch-platform") && !it.contains("twitch-external-platform") }
}
fun intermediaryMappings(version: String): MappingDependency {
@@ -70,7 +77,7 @@ abstract class ArchenemyMojangExtension(val project: Project) {
base as ModuleDependency
overlay as ModuleDependency
_registerMinecraftProvider
- return project.dependencies.create(
+ return realize(
mergedRepositoryProvider.getCoordinate(
MergedRepositoryProvider.Coordinate(base, overlay)
)
@@ -85,7 +92,7 @@ abstract class ArchenemyMojangExtension(val project: Project) {
): Dependency {
dependency as ModuleDependency
_registerMinecraftProvider
- return project.dependencies.create(
+ return realize(
mappedRepositoryProvider.getDependencyCoordiante(
MappedRepositoryProvider.MappedCoordinates(
dependency, mappings, sourceNamespace, destinationNamespace
@@ -96,7 +103,7 @@ abstract class ArchenemyMojangExtension(val project: Project) {
fun minecraft(version: String, side: MCSide): Dependency {
_registerMinecraftProvider
- return project.dependencies.create(
+ return realize(
sharedExtension.minecraftProvider.getDependencyCoordinate(
MinecraftProvider.MinecraftCoordinate(
version,
@@ -106,6 +113,15 @@ abstract class ArchenemyMojangExtension(val project: Project) {
)
}
+ fun realize(dependency: String): Dependency {
+ return realize(project.dependencies.create(dependency))
+ }
+
+ fun realize(dependency: Dependency): Dependency {
+ project.configurations.detachedConfiguration(dependency).resolve()
+ return dependency
+ }
+
fun getLocalCacheDirectory(): File {
return sharedExtension.getLocalCacheDirectory().resolve("projectspecific")
.resolve(if (project == project.rootProject) "__root" else project.path.replace(":", "_"))
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt
index 950446d..1e5239b 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt
@@ -16,5 +16,27 @@ abstract class ArchenemySharedExtension(val rootProject: Project) {
return rootProject.tasks.getByName("downloadMinecraftVersionManifest") as DownloadMinecraftVersionManifest
}
+ fun getDownloadVersionMetadataTask(version: String): DownloadVersionMetadata {
+ val taskName = "downloadMinecraftVersionMetadata$version"
+ val task = rootProject.tasks.findByName(taskName)
+ if (task != null) {
+ return task as DownloadVersionMetadata
+ }
+ return rootProject.tasks.create(taskName, DownloadVersionMetadata::class.java, version)
+ }
+
+ fun getDownloadAssetsTask(version: String): DownloadAssets {
+ val taskName = "downloadMinecraftAssets$version"
+ val task = rootProject.tasks.findByName(taskName)
+ if (task != null) {
+ return task as DownloadAssets
+ }
+ return rootProject.tasks.create(taskName, DownloadAssets::class.java, version)
+ }
+
+ fun getGlobalCacheDirectory(): File {
+ return rootProject.gradle.gradleUserHomeDir.resolve("caches/archenemy")
+ }
+
val minecraftProvider = MinecraftProvider(this)
} \ No newline at end of file
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadAssets.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadAssets.kt
new file mode 100644
index 0000000..335ac30
--- /dev/null
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadAssets.kt
@@ -0,0 +1,74 @@
+package moe.nea.archenemy.mojang
+
+import kotlinx.serialization.Serializable
+import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.decodeFromStream
+import moe.nea.archenemy.util.DownloadUtils
+import moe.nea.archenemy.util.sharedExtension
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.Internal
+import org.gradle.api.tasks.TaskAction
+import java.net.URL
+import javax.inject.Inject
+
+abstract class DownloadAssets @Inject constructor(
+ @get:Input
+ val version: String
+) : DefaultTask() {
+
+
+ init {
+ dependsOn(project.sharedExtension.getDownloadVersionMetadataTask(version))
+ }
+
+ @Serializable
+ data class AssetIndexList(
+ val objects: Map<String, AssetIndexFile>
+ )
+
+ @Serializable
+ data class AssetIndexFile(
+ val hash: String,
+ val size: Long,
+ )
+
+ @Internal
+ fun getAssetDir() =
+ project.sharedExtension
+ .getGlobalCacheDirectory()
+ .resolve("assets")
+
+ @Internal
+ fun getAssetIndex() =
+ project.sharedExtension
+ .getDownloadVersionMetadataTask(version)
+ .getVersionMetadataNow()
+ .assetIndex
+
+ @TaskAction
+ fun execute() {
+ val manifest =
+ project.sharedExtension
+ .getDownloadVersionMetadataTask(version)
+ .getVersionMetadata()
+ val indexFile = getAssetDir()
+ .resolve("indexes")
+ .resolve(manifest.assetIndex.id + ".json")
+ DownloadUtils.downloadFile(URL(manifest.assetIndex.url), manifest.assetIndex.sha1, indexFile)
+ val assetIndexList: AssetIndexList = indexFile.inputStream().use(Json::decodeFromStream)
+ for ((path, entry) in assetIndexList.objects) {
+ downloadAsset(entry)
+ }
+ }
+
+ private fun downloadAsset(entry: AssetIndexFile) {
+ val prefix = entry.hash.substring(0, 2)
+ val file = getAssetDir().resolve("objects").resolve(prefix).resolve(entry.hash)
+ DownloadUtils.downloadFile(
+ URL("https://resources.download.minecraft.net/$prefix/${entry.hash}"),
+ entry.hash,
+ file
+ )
+ }
+} \ No newline at end of file
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadVersionMetadata.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadVersionMetadata.kt
new file mode 100644
index 0000000..6c900c3
--- /dev/null
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadVersionMetadata.kt
@@ -0,0 +1,64 @@
+package moe.nea.archenemy.mojang
+
+import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.decodeFromStream
+import moe.nea.archenemy.util.DownloadUtils
+import org.gradle.api.DefaultTask
+import org.gradle.api.file.RegularFileProperty
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.Internal
+import org.gradle.api.tasks.OutputFile
+import org.gradle.api.tasks.TaskAction
+import java.net.URL
+import javax.inject.Inject
+
+abstract class DownloadVersionMetadata @Inject constructor(
+ @get:Input
+ val version: String,
+) : DefaultTask() {
+ @get:OutputFile
+ abstract val file: RegularFileProperty
+
+
+ init {
+ file.convention(project.layout.buildDirectory.file("version-metadata/$version")).finalizeValue()
+ dependsOn(
+ project.extensions.getByType(ArchenemySharedExtension::class.java)
+ .getDownloadMinecraftVersionManifestTask()
+ )
+ }
+
+ companion object {
+ private val json = Json { ignoreUnknownKeys = true }
+ }
+
+ @TaskAction
+ fun downloadVersion() {
+ val manifest =
+ project.extensions.getByType(ArchenemySharedExtension::class.java).getDownloadMinecraftVersionManifestTask()
+ .getManifestNow()
+ val versionManifestUrl = manifest.versions.find { it.id == version }!!.url
+ val parts = versionManifestUrl.split("/")
+ val hash = if (parts.size == 7 && parts[5].length == 40) {
+ parts[5]
+ } else {
+ error("uhhh hash not found")
+ }
+ DownloadUtils.downloadFile(
+ URL(versionManifestUrl),
+ hash,
+ file.get().asFile
+ )
+ }
+
+ @Internal
+ fun getVersionMetadata(): MojangVersionMetadata {
+ return file.get().asFile.inputStream().use(json::decodeFromStream)
+ }
+
+ @Internal
+ fun getVersionMetadataNow(): MojangVersionMetadata {
+ project.objects.fileCollection().from(file).files
+ return getVersionMetadata()
+ }
+} \ No newline at end of file
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/util/ext.kt b/plugin/src/main/kotlin/moe/nea/archenemy/util/ext.kt
new file mode 100644
index 0000000..ca0f93f
--- /dev/null
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/util/ext.kt
@@ -0,0 +1,7 @@
+package moe.nea.archenemy.util
+
+import moe.nea.archenemy.mojang.ArchenemySharedExtension
+import org.gradle.api.Project
+
+val Project.sharedExtension
+ get() = project.extensions.getByType(ArchenemySharedExtension::class.java) \ No newline at end of file