Compare commits
No commits in common. "e7974cd487228498b1284f1bbcdb8ba9ec8fb6f4" and "47393b74c9e7145eaa067a46d7956813405e12e9" have entirely different histories.
e7974cd487
...
47393b74c9
|
@ -4,7 +4,7 @@
|
|||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -9,12 +9,9 @@ version = "1.0.0"
|
|||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//implementation(files("mojmap-patcher-1.0.0-SNAPSHOT.jar"))
|
||||
implementation("org.ecorous.esnesnon:mojmap-patcher:1.0.0-SNAPSHOT")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
@ -32,14 +29,14 @@ tasks.test {
|
|||
useJUnitPlatform()
|
||||
}
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
repositories {
|
||||
mavenLocal {
|
||||
|
||||
url = uri("file://home/ecorous/wawa/test-repo")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
|
||||
}
|
||||
rootProject.name = "nonsense-gradle"
|
||||
|
||||
|
|
|
@ -2,37 +2,22 @@ package org.ecorous.esnesnon.gradle
|
|||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
|
||||
import java.net.URI
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.absolute
|
||||
|
||||
|
||||
|
||||
class NonsenseGradlePlugin : Plugin<Project> {
|
||||
|
||||
val toInject = listOf("com.electronwill.night-config:toml:3.6.0")
|
||||
val toInject = listOf("com.electronwill.night-config:toml:3.6.0", "")
|
||||
|
||||
override fun apply(project: Project) {
|
||||
println("> Applying Nonsense Gradle Plugin")
|
||||
project.repositories.maven {
|
||||
it.name = "Minecraft/Local"
|
||||
it.url = project.gradle.gradleUserHomeDir.resolve("caches/nonsense-gradle/").toURI()
|
||||
}
|
||||
project.repositories.maven {
|
||||
it.name = "Minecraft Libraries"
|
||||
it.url = URI.create("https://libraries.minecraft.net/")
|
||||
}
|
||||
project.repositories.mavenCentral()
|
||||
val buildTask = project.tasks.getByPath("build")
|
||||
buildTask.dependsOn("setupNonsense")
|
||||
project.dependencies.apply {
|
||||
toInject.forEach {
|
||||
add("implementation", it)
|
||||
}
|
||||
add("implementation", "com.electronwill.night-config:toml:3.6.0")
|
||||
// create("com.electronwill.night-config:toml:3.6.0")
|
||||
}
|
||||
|
||||
|
||||
|
||||
project.task("setupNonsense").apply {
|
||||
group = "nonsense"
|
||||
doFirst {
|
||||
|
|
|
@ -2,44 +2,49 @@ package org.ecorous.esnesnon.gradle
|
|||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import java.io.File
|
||||
import org.gradle.api.Project
|
||||
import java.net.URI
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.*
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.writeBytes
|
||||
|
||||
object VersionChecker {
|
||||
private var validVersions = mutableListOf<VersionUrl>()
|
||||
private var versionData: VersionData? = null
|
||||
|
||||
fun downloadClient(version: String, gradleUserHomeDir: File): Path {
|
||||
|
||||
fetchVersionData(version)
|
||||
fun downloadClient(version: String) {
|
||||
val clientData = fetchClientDownload(version)
|
||||
// download client data
|
||||
val downloadDirectory = gradleUserHomeDir.toPath().resolve("caches/nonsense-gradle/net/minecraft/client/$version/")
|
||||
println("Directory: "+downloadDirectory.absolutePathString())
|
||||
val downloadDirectory = Path(".gradle/.nonsense-gradle/net/minecraft/client/$version/")
|
||||
val downloadFile = downloadDirectory.resolve("client-$version.jar")
|
||||
if (downloadFile.exists()) {
|
||||
println("Client already downloaded to $downloadFile. Assuming it's valid. FIXME: Add checksum validation.")
|
||||
return downloadFile
|
||||
return
|
||||
}
|
||||
if (!downloadDirectory.parent.parent.parent.parent.exists() ||
|
||||
!downloadDirectory.parent.parent.parent.exists() ||
|
||||
!downloadDirectory.parent.parent.exists() ||
|
||||
!downloadDirectory.parent.exists() ||
|
||||
!downloadDirectory.exists()
|
||||
) { // .gradle/.nonsense-gradle/
|
||||
println("Creating directory: ${downloadDirectory.parent.parent.parent.parent}")
|
||||
downloadDirectory.parent.parent.parent.parent.createDirectories() // .gradle/.nonsense-gradle/
|
||||
println("Creating directory: ${downloadDirectory.parent.parent.parent}")
|
||||
downloadDirectory.parent.parent.parent.createDirectories() // .gradle/.nonsense-gradle/net/
|
||||
println("Creating directory: ${downloadDirectory.parent.parent}")
|
||||
downloadDirectory.parent.parent.createDirectories() // .gradle/.nonsense-gradle/net/minecraft/
|
||||
println("Creating directory: ${downloadDirectory.parent}")
|
||||
downloadDirectory.parent.createDirectories() // .gradle/.nonsense-gradle/net/minecraft/minecraft/
|
||||
println("Creating directory: $downloadDirectory")
|
||||
downloadDirectory.createDirectories() // .gradle/.nonsense-gradle/net/minecraft/minecraft/$version/
|
||||
}
|
||||
downloadDirectory.createDirectories()
|
||||
val raw = rawDownload(clientData.url)
|
||||
if (!downloadFile.exists()) {
|
||||
downloadFile.createFile()
|
||||
}
|
||||
downloadFile.writeBytes(raw)
|
||||
println("Downloaded client to $downloadFile")
|
||||
return downloadFile
|
||||
}
|
||||
|
||||
fun getDependencies(version: String, action: (String) -> Unit) {
|
||||
fetchVersionData(version).libraries.map { it.name }.forEach {
|
||||
action.invoke(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun validateVersion(version: String): Boolean {
|
||||
|
@ -52,17 +57,10 @@ object VersionChecker {
|
|||
return validVersions.first { it.id == version }.url
|
||||
}
|
||||
|
||||
fun fetchVersionData(version: String): VersionData {
|
||||
if (versionData == null || versionData!!.id != version) {
|
||||
val url = getVersionUrl(version)
|
||||
val response = getUrl(url)
|
||||
versionData = Gson().fromJson(response, VersionData::class.java)
|
||||
}
|
||||
return versionData!!
|
||||
}
|
||||
|
||||
fun fetchClientDownload(version: String): VersionClientData {
|
||||
return fetchVersionData(version).downloads.client
|
||||
val url = getVersionUrl(version)
|
||||
val response = getUrl(url)
|
||||
return Gson().fromJson(response, VersionData::class.java).downloads.client
|
||||
}
|
||||
|
||||
private fun rawDownload(url: String): ByteArray {
|
||||
|
@ -111,11 +109,8 @@ private class Version(val id: String, val type: String, val url: String, val tim
|
|||
|
||||
private class VersionUrl(val id: String, val url: String)
|
||||
|
||||
class VersionData(val downloads: VersionDownloads, val libraries: List<LibraryDownload>, val id: String)
|
||||
private class VersionData(val downloads: VersionDownloads)
|
||||
|
||||
class LibraryDownload(val artifact: LibraryArtifact, val name: String)
|
||||
class LibraryArtifact(val path: String, val sha1: String, val size: Int, val url: String)
|
||||
|
||||
class VersionDownloads(val client: VersionClientData)
|
||||
private class VersionDownloads(val client: VersionClientData)
|
||||
|
||||
class VersionClientData(val sha1: String, val size: Int, val url: String)
|
|
@ -1,9 +1,7 @@
|
|||
package org.ecorous.esnesnon.gradle.ext
|
||||
|
||||
import org.ecorous.esnesnon.gradle.VersionChecker
|
||||
import org.ecorous.esnesnon.mojmap_patcher.MojMapPatcher
|
||||
import org.gradle.api.Project
|
||||
import kotlin.io.path.notExists
|
||||
|
||||
fun Project.minecraft(version: String) {
|
||||
if (VersionChecker.validateVersion(version)) {
|
||||
|
@ -12,17 +10,10 @@ fun Project.minecraft(version: String) {
|
|||
println("Client data: ${clientData.url}")
|
||||
// download client data
|
||||
println("Downloading client...")
|
||||
val clientJar = VersionChecker.downloadClient(version, gradle.gradleUserHomeDir)
|
||||
VersionChecker.downloadClient(version)
|
||||
println("Downloaded client!")
|
||||
val remappedJar = clientJar.resolveSibling("client-$version-remapped.jar")
|
||||
println("Time to setup Minecraft!")
|
||||
if (remappedJar.notExists()) {
|
||||
MojMapPatcher.run(version, clientJar, remappedJar)
|
||||
}
|
||||
VersionChecker.getDependencies(version){
|
||||
dependencies.add("implementation", it)
|
||||
}
|
||||
dependencies.add("implementation", files(remappedJar))
|
||||
dependencies.add("implementation", files(absoluteProjectPath(".gradle/.nonsense-gradle/net/minecraft/client/$version/client-$version.jar")))
|
||||
} else {
|
||||
println("Invalid version! $version")
|
||||
error("Invalid minecraft version provided: $version")
|
||||
|
|
Loading…
Reference in a new issue