primitive run configuration generation
All checks were successful
Publish to snapshot maven / build (push) Successful in 17s
All checks were successful
Publish to snapshot maven / build (push) Successful in 17s
This commit is contained in:
parent
52af4fefb8
commit
971aaf1103
|
@ -0,0 +1,94 @@
|
||||||
|
package org.ecorous.esnesnon.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.plugins.JavaPluginExtension
|
||||||
|
import org.gradle.api.tasks.SourceSet
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.io.path.absolute
|
||||||
|
import kotlin.io.path.createParentDirectories
|
||||||
|
import kotlin.io.path.notExists
|
||||||
|
|
||||||
|
private const val LOG4J_CONFIG_PATH = ".gradle/nonsense/log4j.xml"
|
||||||
|
private const val ASSET_DIR = "caches/nonsense-gradle/assets"
|
||||||
|
|
||||||
|
object RunConfigGenerator {
|
||||||
|
fun generate(project: Project) {
|
||||||
|
|
||||||
|
val log4jPath = project.rootDir.resolve(LOG4J_CONFIG_PATH).toPath().absolute()
|
||||||
|
if (log4jPath.notExists()) {
|
||||||
|
log4jPath.createParentDirectories()
|
||||||
|
RunConfigGenerator::class.java.getResourceAsStream("/log4j.xml").let {
|
||||||
|
it.use { s ->
|
||||||
|
Files.copy(s!!, log4jPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val runConfigPath = project.rootDir.resolve(".idea").resolve("runConfigurations")
|
||||||
|
runConfigPath.mkdirs()
|
||||||
|
val envs = listOf("client", "server")
|
||||||
|
for (s in envs) {
|
||||||
|
val name = "Minecraft_${capitalize(s)}.xml"
|
||||||
|
//if (!runConfigPath.resolve(name).exists()) {
|
||||||
|
val config = RunConfig(s, project)
|
||||||
|
runConfigPath.resolve(name).writeText(config.getXml())
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun capitalize(s: String): String {
|
||||||
|
if (s.isEmpty()) {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return s.substring(0, 1).uppercase(Locale.ROOT) + s.substring(1).replace("([^A-Z])([A-Z])".toRegex(), "$1 $2")
|
||||||
|
}
|
||||||
|
|
||||||
|
class RunConfig(private val env: String, private val project: Project) {
|
||||||
|
|
||||||
|
private fun getAssetIndex(): String {
|
||||||
|
val index = project.gradle.gradleUserHomeDir.toPath().resolve(ASSET_DIR).resolve("indexes").resolve(NonsenseGradlePlugin.minecraftVersion+".json").absolute()
|
||||||
|
if (index.notExists()) {
|
||||||
|
index.createParentDirectories()
|
||||||
|
VersionChecker.downloadAssetIndex(NonsenseGradlePlugin.minecraftVersion, index)
|
||||||
|
}
|
||||||
|
return index.fileName.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getXml(): String {
|
||||||
|
var modulePath = project.name
|
||||||
|
var parent = project.parent
|
||||||
|
while (parent != null) {
|
||||||
|
modulePath = parent.name + "." + modulePath
|
||||||
|
parent = project.parent!!
|
||||||
|
}
|
||||||
|
val moduleName =
|
||||||
|
"$modulePath." + project.extensions.getByType(JavaPluginExtension::class.java).sourceSets.getByName(
|
||||||
|
SourceSet.MAIN_SOURCE_SET_NAME
|
||||||
|
).name
|
||||||
|
val args =
|
||||||
|
"--assetDir ${project.gradle.gradleUserHomeDir.resolve(ASSET_DIR).toPath().absolute()} --version Nonsense --assetIndex ${getAssetIndex()}"
|
||||||
|
val parameters = "-Dnonsense.development=true -Dlog4j.configurationFile=${project.rootDir.resolve(
|
||||||
|
LOG4J_CONFIG_PATH).toPath().absolute()} -Dlog4j2.formatMsgNoLookups=true"
|
||||||
|
val xml = """
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" factoryName="Application" name="Minecraft ${capitalize(env)}" type="Application">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="org.ecorous.esnesnon.nonsense.loader.impl.launch.client.Nonsense${capitalize(env)}"/>
|
||||||
|
<module name="$moduleName"/>
|
||||||
|
<option name="PROGRAM_PARAMETERS" value="$args"/>
|
||||||
|
<option name="VM_PARAMETERS" value="$parameters"/>
|
||||||
|
<option name="WORKING_DIRECTORY" value="${project.rootDir}/run/"/>
|
||||||
|
<method v="2">
|
||||||
|
<option enabled="true" name="Make"/>
|
||||||
|
</method>
|
||||||
|
<envs>
|
||||||
|
|
||||||
|
</envs>
|
||||||
|
<shortenClasspath name="ARGS_FILE"/>
|
||||||
|
<classpathModifications/></configuration>
|
||||||
|
</component>
|
||||||
|
""".trimIndent()
|
||||||
|
return xml
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ 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.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
|
|
||||||
|
@ -75,6 +76,13 @@ object VersionChecker {
|
||||||
return fetchVersionData(version).downloads.client
|
return fetchVersionData(version).downloads.client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun downloadAssetIndex(version: String, path: Path) {
|
||||||
|
val url = fetchVersionData(version).assetIndex.url
|
||||||
|
URI.create(url).toURL().openStream().use {
|
||||||
|
Files.copy(it, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun rawDownload(url: String): ByteArray {
|
private fun rawDownload(url: String): ByteArray {
|
||||||
val client = HttpClient.newHttpClient()
|
val client = HttpClient.newHttpClient()
|
||||||
val request = HttpRequest.newBuilder()
|
val request = HttpRequest.newBuilder()
|
||||||
|
@ -121,11 +129,12 @@ 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)
|
class VersionData(val downloads: VersionDownloads, val libraries: List<LibraryDownload>, val id: String, val assetIndex: AssetIndex)
|
||||||
|
|
||||||
class LibraryDownload(val artifact: LibraryArtifact, val name: String)
|
class LibraryDownload(val artifact: LibraryArtifact, val name: String)
|
||||||
class LibraryArtifact(val path: String, val sha1: String, val size: Int, val url: String)
|
class LibraryArtifact(val path: String, val sha1: String, val size: Int, val url: String)
|
||||||
|
|
||||||
|
class AssetIndex(val id: String, val sha1: String, val size: Int, val totalSize: Int, val url: String)
|
||||||
class VersionDownloads(val client: VersionClientData)
|
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)
|
|
@ -1,6 +1,7 @@
|
||||||
package org.ecorous.esnesnon.gradle.ext
|
package org.ecorous.esnesnon.gradle.ext
|
||||||
|
|
||||||
import org.ecorous.esnesnon.gradle.NonsenseGradlePlugin
|
import org.ecorous.esnesnon.gradle.NonsenseGradlePlugin
|
||||||
|
import org.ecorous.esnesnon.gradle.RunConfigGenerator
|
||||||
import org.ecorous.esnesnon.gradle.VersionChecker
|
import org.ecorous.esnesnon.gradle.VersionChecker
|
||||||
import org.ecorous.esnesnon.nonsense_remapper.NonsenseRemapper
|
import org.ecorous.esnesnon.nonsense_remapper.NonsenseRemapper
|
||||||
import org.ecorous.esnesnon.nonsense_remapper.api.Mapper
|
import org.ecorous.esnesnon.nonsense_remapper.api.Mapper
|
||||||
|
@ -40,7 +41,8 @@ fun Project.minecraft(
|
||||||
dependencies.add("implementation", it)
|
dependencies.add("implementation", it)
|
||||||
}
|
}
|
||||||
dependencies.add("implementation", "net.minecraft:client:$version:remapped")
|
dependencies.add("implementation", "net.minecraft:client:$version:remapped")
|
||||||
//dependencies.add("implementation", files(remappedJar))
|
|
||||||
|
RunConfigGenerator.generate(this)
|
||||||
} else {
|
} else {
|
||||||
println("Invalid version! $version")
|
println("Invalid version! $version")
|
||||||
error("Invalid minecraft version provided: $version")
|
error("Invalid minecraft version provided: $version")
|
||||||
|
|
68
src/main/resources/log4j.xml
Normal file
68
src/main/resources/log4j.xml
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN" packages="com.mojang.util,net.minecrell.terminalconsole.util">
|
||||||
|
<Appenders>
|
||||||
|
|
||||||
|
<!-- System out -->
|
||||||
|
<Console name="SysOut" target="SYSTEM_OUT">
|
||||||
|
<!-- Filter out the authentication errors when starting in development -->
|
||||||
|
<Filters>
|
||||||
|
<RegexFilter regex="^Failed to verify authentication$" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||||
|
<RegexFilter regex="^Failed to fetch user properties$" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||||
|
<RegexFilter regex="^Couldn't connect to realms$" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||||
|
</Filters>
|
||||||
|
<PatternLayout>
|
||||||
|
<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}" disableAnsi="${sys:fabric.log.disableAnsi:-true}">
|
||||||
|
<!-- Dont show the logger name for minecraft classes-->
|
||||||
|
<PatternMatch key="net.minecraft.,com.mojang." pattern="%style{[%d{HH:mm:ss}]}{blue} %highlight{[%t/%level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=green, TRACE=blue} %style{(Minecraft)}{cyan} %highlight{%msg{nolookups}%n}{FATAL=red, ERROR=red, WARN=normal, INFO=normal, DEBUG=normal, TRACE=normal}"/>
|
||||||
|
</LoggerNamePatternSelector>
|
||||||
|
</PatternLayout>
|
||||||
|
</Console>
|
||||||
|
|
||||||
|
<!-- Vanilla server gui -->
|
||||||
|
<Queue name="ServerGuiConsole" ignoreExceptions="true">
|
||||||
|
<PatternLayout>
|
||||||
|
<LoggerNamePatternSelector defaultPattern="[%d{HH:mm:ss} %level] (%logger{1}) %msg{nolookups}%n">
|
||||||
|
<!-- Dont show the logger name for minecraft classes-->
|
||||||
|
<PatternMatch key="net.minecraft.,com.mojang." pattern="[%d{HH:mm:ss} %level] %msg{nolookups}%n"/>
|
||||||
|
</LoggerNamePatternSelector>
|
||||||
|
</PatternLayout>
|
||||||
|
</Queue>
|
||||||
|
|
||||||
|
<!-- latest.log same as vanilla -->
|
||||||
|
<RollingRandomAccessFile name="LatestFile" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
|
||||||
|
<PatternLayout>
|
||||||
|
<LoggerNamePatternSelector defaultPattern="[%d{HH:mm:ss}] [%t/%level] (%logger{1}) %msg{nolookups}%n">
|
||||||
|
<!-- Dont show the logger name for minecraft classes-->
|
||||||
|
<PatternMatch key="net.minecraft.,com.mojang." pattern="[%d{HH:mm:ss}] [%t/%level] (Minecraft) %msg{nolookups}%n"/>
|
||||||
|
</LoggerNamePatternSelector>
|
||||||
|
</PatternLayout>
|
||||||
|
<Policies>
|
||||||
|
<TimeBasedTriggeringPolicy />
|
||||||
|
<OnStartupTriggeringPolicy />
|
||||||
|
</Policies>
|
||||||
|
</RollingRandomAccessFile>
|
||||||
|
|
||||||
|
<!-- Debug log file -->
|
||||||
|
<RollingRandomAccessFile name="DebugFile" fileName="logs/debug.log" filePattern="logs/debug-%i.log.gz">
|
||||||
|
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level] (%logger) %msg{nolookups}%n" />
|
||||||
|
|
||||||
|
<!-- Keep 5 files max -->
|
||||||
|
<DefaultRolloverStrategy max="5" fileIndex="min"/>
|
||||||
|
|
||||||
|
<Policies>
|
||||||
|
<SizeBasedTriggeringPolicy size="200MB"/>
|
||||||
|
<OnStartupTriggeringPolicy />
|
||||||
|
</Policies>
|
||||||
|
|
||||||
|
</RollingRandomAccessFile>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Logger level="${sys:nonsense.log.level:-info}" name="net.minecraft"/>
|
||||||
|
<Root level="all">
|
||||||
|
<AppenderRef ref="DebugFile" level="${sys:nonsense.log.debug.level:-debug}"/>
|
||||||
|
<AppenderRef ref="SysOut" level="${sys:nonsense.log.level:-info}"/>
|
||||||
|
<AppenderRef ref="LatestFile" level="${sys:nonsense.log.level:-info}"/>
|
||||||
|
<AppenderRef ref="ServerGuiConsole" level="${sys:nonsense.log.level:-info}"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
Loading…
Reference in a new issue