-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57452ea
commit baf12dc
Showing
19 changed files
with
432 additions
and
150 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ dependencyResolutionManagement { | |
} | ||
} | ||
} | ||
|
||
rootProject.name = "weave-build-logic" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ subprojects { | |
repositories { | ||
mavenCentral() | ||
maven("https://repo.weavemc.dev/releases") | ||
mavenLocal() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
plugins { | ||
id("config-kotlin") | ||
id("config-publish") | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(8) | ||
} | ||
|
||
dependencies { | ||
implementation(project(":internals")) | ||
runtimeOnly(libs.log4j.slf4j2.impl) | ||
runtimeOnly(libs.log4j.core) | ||
runtimeOnly(libs.terminalconsoleappender) { | ||
exclude(group = "org.apache.logging.log4j") | ||
} | ||
|
||
runtimeOnly(libs.bundles.jline) | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("maven") { | ||
from(components["java"]) | ||
groupId = "net.weavemc" | ||
artifactId = "weave-gradle-launcher" | ||
version = project.version.toString() | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
gradle-plugin/launcher/src/main/kotlin/net/weavemc/gradle/Launcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package net.weavemc.gradle | ||
|
||
import net.weavemc.internals.* | ||
import java.net.URL | ||
import java.net.URLClassLoader | ||
import java.nio.file.Path | ||
import kotlin.io.path.absolutePathString | ||
import kotlin.io.path.createDirectories | ||
import kotlin.io.path.exists | ||
|
||
fun main(args: Array<String>) { | ||
System.setProperty("terminal.ansi", "true") | ||
|
||
val version = args.firstOrNull() ?: error("Specify a version to launch!") | ||
val versionInfo = fetchVersionManifest()?.fetchVersion(version) ?: error("Could not fetch version $version!") | ||
|
||
val gameDir = getMinecraftDir().also { it.createDirectories() } | ||
val gamePath = gameDir.resolve("versions").resolve(version).resolve("$version.jar") | ||
if (!gamePath.exists()) error("Minecraft JAR does not exist?") | ||
|
||
val librariesDir = gameDir.resolve("libraries") | ||
val libraryPaths = mutableListOf<Path>(gamePath) | ||
|
||
// TODO: extract to function? | ||
for (lib in versionInfo.relevantLibraries) for (download in lib.downloads.allDownloads) { | ||
val target = download.path.split('/').fold(librariesDir) { acc, curr -> acc.resolve(curr) } | ||
libraryPaths.add(target) | ||
if (!target.exists()) DownloadUtil.download(URL(download.url), target) | ||
} | ||
|
||
val gameArgs = buildList { | ||
fun addArgument(name: String, value: String) { | ||
val prefix = "--$name" | ||
if (prefix !in this) { | ||
add(prefix) | ||
add(value) | ||
} | ||
} | ||
|
||
addAll(args.drop(1)) | ||
addArgument("accessToken", "0") | ||
addArgument("version", versionInfo.id) | ||
addArgument("assetIndex", versionInfo.assetIndex.id) | ||
addArgument("assetsDir", gameDir.resolve("assets").absolutePathString()) | ||
}.toTypedArray() | ||
|
||
val urls = libraryPaths.mapToArray { it.toUri().toURL() } | ||
DevLauncherClassLoader(urls).loadClass(versionInfo.mainClass) | ||
.getMethod("main", gameArgs::class.java)(null, gameArgs) | ||
} | ||
|
||
class DevLauncherClassLoader(urls: Array<URL>) : URLClassLoader(urls) { | ||
private val disallowedReloading = listOf( | ||
"java.", "javax.", "org.xml.", "org.w3c.", "sun.", "jdk.", "com.sun.management.", | ||
"kotlin.", "kotlinx.", "org.slf4j." | ||
) | ||
|
||
override fun loadClass(name: String, resolve: Boolean): Class<*> { | ||
findLoadedClass(name)?.let { return it } | ||
if (disallowedReloading.any { name.startsWith(it) }) return super.loadClass(name, resolve) | ||
|
||
val clazz = findClass(name) | ||
if (resolve) resolveClass(clazz) | ||
return clazz | ||
} | ||
} | ||
|
||
private inline fun <A, reified B> Collection<A>.mapToArray(block: (A) -> B): Array<B> { | ||
val iterator = iterator() | ||
return Array(size) { block(iterator.next()) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN" packages="com.mojang.util,net.minecrell.terminalconsole.util"> | ||
<Appenders> | ||
<Console name="SysOut" target="SYSTEM_OUT"> | ||
<PatternLayout> | ||
<!-- Apparently if we remove the selector it breaks? --> | ||
<LoggerNamePatternSelector defaultPattern="%style{[%d{HH:mm:ss}]}{blue} %highlight{[%t/%level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=green, TRACE=blue} %style{(%logger{1})}{cyan} %highlight{%msg%n}{FATAL=red, ERROR=red, WARN=normal, INFO=normal, DEBUG=normal, TRACE=normal}" /> | ||
</PatternLayout> | ||
</Console> | ||
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz"> | ||
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg{nolookups}%n" /> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy /> | ||
<OnStartupTriggeringPolicy /> | ||
</Policies> | ||
</RollingRandomAccessFile> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="info"> | ||
<filters> | ||
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL" /> | ||
</filters> | ||
<AppenderRef ref="SysOut"/> | ||
<AppenderRef ref="File"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.