Compare commits

..

No commits in common. "e7974cd487228498b1284f1bbcdb8ba9ec8fb6f4" and "47393b74c9e7145eaa067a46d7956813405e12e9" have entirely different histories.

6 changed files with 40 additions and 72 deletions

View file

@ -4,7 +4,7 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View file

@ -9,12 +9,9 @@ version = "1.0.0"
repositories { repositories {
mavenCentral() mavenCentral()
mavenLocal()
} }
dependencies { 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") implementation("com.google.code.gson:gson:2.10.1")
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
} }
@ -32,14 +29,14 @@ tasks.test {
useJUnitPlatform() useJUnitPlatform()
} }
kotlin { kotlin {
jvmToolchain(21) jvmToolchain(17)
} }
publishing { publishing {
publications { publications {
repositories { repositories {
mavenLocal { mavenLocal {
url = uri("file://home/ecorous/wawa/test-repo")
} }
} }
} }

View file

@ -1,5 +1,5 @@
plugins { 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" rootProject.name = "nonsense-gradle"

View file

@ -2,36 +2,21 @@ package org.ecorous.esnesnon.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project 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> { 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) { override fun apply(project: Project) {
println("> Applying Nonsense Gradle Plugin") 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") val buildTask = project.tasks.getByPath("build")
buildTask.dependsOn("setupNonsense") buildTask.dependsOn("setupNonsense")
project.dependencies.apply { project.dependencies.apply {
toInject.forEach { add("implementation", "com.electronwill.night-config:toml:3.6.0")
add("implementation", it) // create("com.electronwill.night-config:toml:3.6.0")
} }
}
project.task("setupNonsense").apply { project.task("setupNonsense").apply {
group = "nonsense" group = "nonsense"

View file

@ -2,44 +2,49 @@ package org.ecorous.esnesnon.gradle
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import java.io.File import org.gradle.api.Project
import java.net.URI import java.net.URI
import java.net.http.HttpClient import java.net.http.HttpClient
import java.net.http.HttpRequest import java.net.http.HttpRequest
import java.net.http.HttpResponse import java.net.http.HttpResponse
import java.nio.file.Path import kotlin.io.path.Path
import kotlin.io.path.* import kotlin.io.path.createDirectories
import kotlin.io.path.exists
import kotlin.io.path.writeBytes
object VersionChecker { object VersionChecker {
private var validVersions = mutableListOf<VersionUrl>() private var validVersions = mutableListOf<VersionUrl>()
private var versionData: VersionData? = null
fun downloadClient(version: String, gradleUserHomeDir: File): Path { fun downloadClient(version: String) {
fetchVersionData(version)
val clientData = fetchClientDownload(version) val clientData = fetchClientDownload(version)
// download client data // download client data
val downloadDirectory = gradleUserHomeDir.toPath().resolve("caches/nonsense-gradle/net/minecraft/client/$version/") val downloadDirectory = Path(".gradle/.nonsense-gradle/net/minecraft/client/$version/")
println("Directory: "+downloadDirectory.absolutePathString())
val downloadFile = downloadDirectory.resolve("client-$version.jar") val downloadFile = downloadDirectory.resolve("client-$version.jar")
if (downloadFile.exists()) { if (downloadFile.exists()) {
println("Client already downloaded to $downloadFile. Assuming it's valid. FIXME: Add checksum validation.") 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() downloadDirectory.createDirectories()
val raw = rawDownload(clientData.url) val raw = rawDownload(clientData.url)
if (!downloadFile.exists()) {
downloadFile.createFile()
}
downloadFile.writeBytes(raw) downloadFile.writeBytes(raw)
println("Downloaded client to $downloadFile") 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 { fun validateVersion(version: String): Boolean {
@ -52,17 +57,10 @@ object VersionChecker {
return validVersions.first { it.id == version }.url return validVersions.first { it.id == version }.url
} }
fun fetchVersionData(version: String): VersionData { fun fetchClientDownload(version: String): VersionClientData {
if (versionData == null || versionData!!.id != version) {
val url = getVersionUrl(version) val url = getVersionUrl(version)
val response = getUrl(url) val response = getUrl(url)
versionData = Gson().fromJson(response, VersionData::class.java) return Gson().fromJson(response, VersionData::class.java).downloads.client
}
return versionData!!
}
fun fetchClientDownload(version: String): VersionClientData {
return fetchVersionData(version).downloads.client
} }
private fun rawDownload(url: String): ByteArray { 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) 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) private class VersionDownloads(val client: VersionClientData)
class LibraryArtifact(val path: String, val sha1: String, val size: Int, val url: String)
class VersionDownloads(val client: VersionClientData)
class VersionClientData(val sha1: String, val size: Int, val url: String) class VersionClientData(val sha1: String, val size: Int, val url: String)

View file

@ -1,9 +1,7 @@
package org.ecorous.esnesnon.gradle.ext package org.ecorous.esnesnon.gradle.ext
import org.ecorous.esnesnon.gradle.VersionChecker import org.ecorous.esnesnon.gradle.VersionChecker
import org.ecorous.esnesnon.mojmap_patcher.MojMapPatcher
import org.gradle.api.Project import org.gradle.api.Project
import kotlin.io.path.notExists
fun Project.minecraft(version: String) { fun Project.minecraft(version: String) {
if (VersionChecker.validateVersion(version)) { if (VersionChecker.validateVersion(version)) {
@ -12,17 +10,10 @@ fun Project.minecraft(version: String) {
println("Client data: ${clientData.url}") println("Client data: ${clientData.url}")
// download client data // download client data
println("Downloading client...") println("Downloading client...")
val clientJar = VersionChecker.downloadClient(version, gradle.gradleUserHomeDir) VersionChecker.downloadClient(version)
println("Downloaded client!") println("Downloaded client!")
val remappedJar = clientJar.resolveSibling("client-$version-remapped.jar")
println("Time to setup Minecraft!") println("Time to setup Minecraft!")
if (remappedJar.notExists()) { dependencies.add("implementation", files(absoluteProjectPath(".gradle/.nonsense-gradle/net/minecraft/client/$version/client-$version.jar")))
MojMapPatcher.run(version, clientJar, remappedJar)
}
VersionChecker.getDependencies(version){
dependencies.add("implementation", it)
}
dependencies.add("implementation", files(remappedJar))
} else { } else {
println("Invalid version! $version") println("Invalid version! $version")
error("Invalid minecraft version provided: $version") error("Invalid minecraft version provided: $version")