mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-08-16 16:26:12 +00:00
fix resolving dependencies in scripts
This commit is contained in:
parent
12c2c71739
commit
8ddc8abdb9
@ -136,6 +136,8 @@ slimJar {
|
|||||||
relocate("org.apache.maven", "$lib.maven")
|
relocate("org.apache.maven", "$lib.maven")
|
||||||
relocate("org.codehaus.plexus", "$lib.plexus")
|
relocate("org.codehaus.plexus", "$lib.plexus")
|
||||||
relocate("org.eclipse.sisu", "$lib.sisu")
|
relocate("org.eclipse.sisu", "$lib.sisu")
|
||||||
|
relocate("org.eclipse.aether", "$lib.aether")
|
||||||
|
relocate("com.google.inject", "$lib.guice")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
@ -47,7 +47,6 @@ import com.volmit.iris.util.io.IO;
|
|||||||
import com.volmit.iris.util.json.JSONArray;
|
import com.volmit.iris.util.json.JSONArray;
|
||||||
import com.volmit.iris.util.json.JSONObject;
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
import com.volmit.iris.util.mantle.MantleChunk;
|
import com.volmit.iris.util.mantle.MantleChunk;
|
||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.math.Position2;
|
import com.volmit.iris.util.math.Position2;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
@ -218,9 +217,7 @@ public class CommandStudio implements DecreeExecutor {
|
|||||||
int sections = mantle.getWorldHeight() >> 4;
|
int sections = mantle.getWorldHeight() >> 4;
|
||||||
chunkMap.forEach((pos, chunk) -> {
|
chunkMap.forEach((pos, chunk) -> {
|
||||||
var c = mantle.getChunk(pos.getX(), pos.getZ());
|
var c = mantle.getChunk(pos.getX(), pos.getZ());
|
||||||
for (MantleFlag flag : MantleFlag.values()) {
|
c.copyFlags(chunk);
|
||||||
c.flag(flag, chunk.isFlagged(flag));
|
|
||||||
}
|
|
||||||
c.clear();
|
c.clear();
|
||||||
for (int y = 0; y < sections; y++) {
|
for (int y = 0; y < sections; y++) {
|
||||||
var slice = chunk.get(y);
|
var slice = chunk.get(y);
|
||||||
|
@ -144,6 +144,14 @@ public class MantleChunk {
|
|||||||
ref.release();
|
ref.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void copyFlags(MantleChunk chunk) {
|
||||||
|
use();
|
||||||
|
for (int i = 0; i < flags.length(); i++) {
|
||||||
|
flags.set(i, chunk.flags.get(i));
|
||||||
|
}
|
||||||
|
release();
|
||||||
|
}
|
||||||
|
|
||||||
public void flag(MantleFlag flag, boolean f) {
|
public void flag(MantleFlag flag, boolean f) {
|
||||||
if (closed.get()) throw new IllegalStateException("Chunk is closed!");
|
if (closed.get()) throw new IllegalStateException("Chunk is closed!");
|
||||||
flags.set(flag.ordinal(), f);
|
flags.set(flag.ordinal(), f);
|
||||||
|
@ -26,6 +26,7 @@ object SimpleScriptDefinition : ScriptCompilationConfiguration({
|
|||||||
)
|
)
|
||||||
|
|
||||||
jvm {
|
jvm {
|
||||||
|
dependenciesFromClassContext(KotlinScript::class, wholeClasspath = true)
|
||||||
dependenciesFromClassContext(SimpleScript::class, wholeClasspath = true)
|
dependenciesFromClassContext(SimpleScript::class, wholeClasspath = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ import com.volmit.iris.core.scripting.ExecutionEnvironment
|
|||||||
import com.volmit.iris.core.scripting.kotlin.base.DataScript
|
import com.volmit.iris.core.scripting.kotlin.base.DataScript
|
||||||
import com.volmit.iris.core.scripting.kotlin.base.NoiseScript
|
import com.volmit.iris.core.scripting.kotlin.base.NoiseScript
|
||||||
import com.volmit.iris.core.scripting.kotlin.runner.Script
|
import com.volmit.iris.core.scripting.kotlin.runner.Script
|
||||||
|
import com.volmit.iris.core.scripting.kotlin.runner.valueOrThrow
|
||||||
import com.volmit.iris.util.math.RNG
|
import com.volmit.iris.util.math.RNG
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.script.experimental.api.valueOrThrow
|
|
||||||
|
|
||||||
open class IrisPackExecutionEnvironment(
|
open class IrisPackExecutionEnvironment(
|
||||||
private val data: IrisData
|
private val data: IrisData
|
||||||
@ -19,7 +19,7 @@ open class IrisPackExecutionEnvironment(
|
|||||||
val loaded = data.scriptLoader.load(script)
|
val loaded = data.scriptLoader.load(script)
|
||||||
return compileCache.get(script)
|
return compileCache.get(script)
|
||||||
.computeIfAbsent(type) { _ -> runner.compileText(type, loaded.source, script) }
|
.computeIfAbsent(type) { _ -> runner.compileText(type, loaded.source, script) }
|
||||||
.valueOrThrow()
|
.valueOrThrow("Failed to compile script $script")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun execute(script: String) =
|
override fun execute(script: String) =
|
||||||
|
@ -8,13 +8,14 @@ import com.volmit.iris.core.scripting.kotlin.runner.Script
|
|||||||
import com.volmit.iris.core.scripting.kotlin.runner.ScriptRunner
|
import com.volmit.iris.core.scripting.kotlin.runner.ScriptRunner
|
||||||
import com.volmit.iris.core.scripting.kotlin.runner.classpath
|
import com.volmit.iris.core.scripting.kotlin.runner.classpath
|
||||||
import com.volmit.iris.core.scripting.kotlin.runner.valueOrNull
|
import com.volmit.iris.core.scripting.kotlin.runner.valueOrNull
|
||||||
|
import com.volmit.iris.core.scripting.kotlin.runner.valueOrThrow
|
||||||
import com.volmit.iris.util.collection.KMap
|
import com.volmit.iris.util.collection.KMap
|
||||||
import com.volmit.iris.util.data.KCache
|
import com.volmit.iris.util.data.KCache
|
||||||
import com.volmit.iris.util.format.C
|
import com.volmit.iris.util.format.C
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.script.experimental.annotations.KotlinScript
|
||||||
import kotlin.script.experimental.api.ResultWithDiagnostics
|
import kotlin.script.experimental.api.ResultWithDiagnostics
|
||||||
import kotlin.script.experimental.api.valueOrThrow
|
|
||||||
import kotlin.text.split
|
import kotlin.text.split
|
||||||
|
|
||||||
open class IrisSimpleExecutionEnvironment : ExecutionEnvironment.Simple {
|
open class IrisSimpleExecutionEnvironment : ExecutionEnvironment.Simple {
|
||||||
@ -55,7 +56,7 @@ open class IrisSimpleExecutionEnvironment : ExecutionEnvironment.Simple {
|
|||||||
protected open fun compile(script: String, type: KClass<*>) =
|
protected open fun compile(script: String, type: KClass<*>) =
|
||||||
compileCache.get(script)
|
compileCache.get(script)
|
||||||
.computeIfAbsent(type) { _ -> runner.compileText(type, script) }
|
.computeIfAbsent(type) { _ -> runner.compileText(type, script) }
|
||||||
.valueOrThrow()
|
.valueOrThrow("Failed to compile script")
|
||||||
|
|
||||||
private fun evaluate0(name: String, type: KClass<*>, properties: Map<String, Any?>? = null): Any? {
|
private fun evaluate0(name: String, type: KClass<*>, properties: Map<String, Any?>? = null): Any? {
|
||||||
val current = Thread.currentThread()
|
val current = Thread.currentThread()
|
||||||
@ -64,7 +65,7 @@ open class IrisSimpleExecutionEnvironment : ExecutionEnvironment.Simple {
|
|||||||
try {
|
try {
|
||||||
return compile(name, type)
|
return compile(name, type)
|
||||||
.evaluate(properties)
|
.evaluate(properties)
|
||||||
.valueOrThrow()
|
.valueOrThrow("Failed to evaluate script")
|
||||||
.valueOrNull()
|
.valueOrNull()
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
@ -76,7 +77,8 @@ open class IrisSimpleExecutionEnvironment : ExecutionEnvironment.Simple {
|
|||||||
|
|
||||||
override fun configureProject(projectDir: File) {
|
override fun configureProject(projectDir: File) {
|
||||||
projectDir.mkdirs()
|
projectDir.mkdirs()
|
||||||
val libs = javaClass.classLoader.classpath
|
val libs = listOf(javaClass.classLoader.classpath, KotlinScript::class.java.classLoader.classpath)
|
||||||
|
.flatMap { it }
|
||||||
.sortedBy { it.absolutePath }
|
.sortedBy { it.absolutePath }
|
||||||
.toMutableList()
|
.toMutableList()
|
||||||
|
|
||||||
@ -111,7 +113,7 @@ open class IrisSimpleExecutionEnvironment : ExecutionEnvironment.Simple {
|
|||||||
val classpath = files()
|
val classpath = files()
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version("2.1.20")
|
kotlin("jvm") version("2.2.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -2,6 +2,7 @@ package com.volmit.iris.core.scripting.kotlin.runner
|
|||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.lang.RuntimeException
|
||||||
import kotlin.script.experimental.api.*
|
import kotlin.script.experimental.api.*
|
||||||
import kotlin.script.experimental.dependencies.CompoundDependenciesResolver
|
import kotlin.script.experimental.dependencies.CompoundDependenciesResolver
|
||||||
import kotlin.script.experimental.dependencies.FileSystemDependenciesResolver
|
import kotlin.script.experimental.dependencies.FileSystemDependenciesResolver
|
||||||
@ -51,4 +52,8 @@ private fun format(file: File, projectDir: String, home: String): String {
|
|||||||
path.startsWith(home) -> $$"$USER_HOME$/$${path.substring(home.length + 1)}"
|
path.startsWith(home) -> $$"$USER_HOME$/$${path.substring(home.length + 1)}"
|
||||||
else -> path
|
else -> path
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <R> ResultWithDiagnostics<R>.valueOrThrow(message: CharSequence): R = valueOr {
|
||||||
|
throw RuntimeException(it.reports.joinToString("\n", "$message\n") { r -> r.render(withStackTrace = true) })
|
||||||
}
|
}
|
@ -5,7 +5,7 @@
|
|||||||
[versions]
|
[versions]
|
||||||
# Plugins
|
# Plugins
|
||||||
shadow = "9.0.0-rc1" # https://plugins.gradle.org/plugin/com.gradleup.shadow
|
shadow = "9.0.0-rc1" # https://plugins.gradle.org/plugin/com.gradleup.shadow
|
||||||
slimjar = "2.1.2" # https://plugins.gradle.org/plugin/de.crazydev22.slimjar
|
slimjar = "2.1.4" # https://plugins.gradle.org/plugin/de.crazydev22.slimjar
|
||||||
download = "5.6.0" # https://plugins.gradle.org/plugin/de.undercouch.download
|
download = "5.6.0" # https://plugins.gradle.org/plugin/de.undercouch.download
|
||||||
runPaper = "2.3.1" # https://plugins.gradle.org/plugin/xyz.jpenilla.run-paper
|
runPaper = "2.3.1" # https://plugins.gradle.org/plugin/xyz.jpenilla.run-paper
|
||||||
sentryPlugin = "5.8.0" # https://github.com/getsentry/sentry-android-gradle-plugin
|
sentryPlugin = "5.8.0" # https://github.com/getsentry/sentry-android-gradle-plugin
|
||||||
|
Loading…
x
Reference in New Issue
Block a user