Skip to content

Commit

Permalink
feat: remove graalpython & some adaptations
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jan 6, 2025
1 parent 9e6a5b6 commit 5a6e729
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 186 deletions.
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "org.allaymc.scriptpluginext"
version = "0.3.0"
version = "0.4.0"

java {
toolchain {
Expand All @@ -14,7 +14,7 @@ java {

repositories {
mavenCentral()
maven("https://jitpack.io/")
maven("https://www.jitpack.io/")
maven("https://repo.opencollab.dev/maven-releases/")
maven("https://repo.opencollab.dev/maven-snapshots/")
maven("https://storehouse.okaeri.eu/repository/maven-public/")
Expand All @@ -26,7 +26,6 @@ dependencies {

implementation(libs.polyglot)
implementation(libs.javascript)
implementation(libs.python)
implementation(libs.chromeinspector)

annotationProcessor(rootProject.libs.lombok)
Expand Down
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[versions]
graalvm = "24.1.0"
graalvm = "24.1.1"

[libraries]
# Allay
allay = { group = "org.allaymc.allay", name = "server", version = "master-SNAPSHOT" }
# GraalVM
polyglot = { group = "org.graalvm.polyglot", name = "polyglot", version.ref = "graalvm" }
javascript = { group = "org.graalvm.polyglot", name = "js-community", version.ref = "graalvm" }
python = { group = "org.graalvm.polyglot", name = "python-community", version.ref = "graalvm" }
chromeinspector = { group = "org.graalvm.tools", name = "chromeinspector-tool", version.ref = "graalvm" }
# Lombok
lombok = { group = "org.projectlombok", name = "lombok", version = "1.18.34" }
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.allaymc.scriptpluginext;

import org.allaymc.scriptpluginext.javascript.JsPluginLoader;
import org.allaymc.scriptpluginext.python.PyPluginLoader;
import org.allaymc.scriptpluginext.js.JSPluginLoader;
import org.allaymc.server.extension.Extension;
import org.allaymc.server.plugin.AllayPluginManager;

Expand All @@ -11,7 +10,6 @@
public class ScriptPluginExtension extends Extension {
@Override
public void main(String[] args) {
AllayPluginManager.registerLoaderFactory(new PyPluginLoader.PyPluginLoaderFactory());
AllayPluginManager.registerLoaderFactory(new JsPluginLoader.JsPluginLoaderFactory());
AllayPluginManager.registerLoaderFactory(new JSPluginLoader.JsPluginLoaderFactory());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.allaymc.scriptpluginext.javascript;
package org.allaymc.scriptpluginext.js;

import lombok.SneakyThrows;
import org.allaymc.scriptpluginext.ScriptPluginDescriptor;
Expand All @@ -10,16 +10,16 @@
/**
* @author daoge_cmd
*/
public class JsPlugin extends Plugin {
public class JSPlugin extends Plugin {

protected Context jsContext;
protected Value jsExport;
protected JsPluginProxyLogger proxyLogger;
protected Context context;
protected Value export;
protected JSPluginProxyLogger proxyLogger;

@Override
public void setPluginContainer(PluginContainer pluginContainer) {
super.setPluginContainer(pluginContainer);
proxyLogger = new JsPluginProxyLogger(pluginLogger);
this.proxyLogger = new JSPluginProxyLogger(pluginLogger);
}

@SneakyThrows
Expand All @@ -44,11 +44,11 @@ public void onLoad() {
.option("inspect.Internal", "true")
.option("inspect.SourcePath", pluginContainer.loader().getPluginPath().toFile().getAbsolutePath());
}
jsContext = cbd.build();
context = cbd.build();
initGlobalMembers();
var entranceJsFileName = pluginContainer.descriptor().getEntrance();
var path = pluginContainer.loader().getPluginPath().resolve(entranceJsFileName);
jsExport = jsContext.eval(
export = context.eval(
Source.newBuilder("js", path.toFile())
.name(entranceJsFileName)
.mimeType("application/javascript+module")
Expand All @@ -65,7 +65,7 @@ public void onEnable() {
@Override
public void onDisable() {
tryCallJsFunction("onDisable");
jsContext.close(true);
context.close(true);
}

@Override
Expand All @@ -81,13 +81,13 @@ public void reload() {
}

protected void initGlobalMembers() {
var binding = jsContext.getBindings("js");
var binding = context.getBindings("js");
binding.putMember("plugin", this);
binding.putMember("console", proxyLogger);
}

protected void tryCallJsFunction(String functionName) {
var func = jsExport.getMember(functionName);
var func = export.getMember(functionName);
if (func != null && func.canExecute()) {
func.executeVoid();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.allaymc.scriptpluginext.javascript;
package org.allaymc.scriptpluginext.js;

import lombok.Getter;
import lombok.SneakyThrows;
Expand All @@ -21,14 +21,14 @@
* @author daoge_cmd
*/
@Slf4j
public class JsPluginLoader implements PluginLoader {
public class JSPluginLoader implements PluginLoader {

@Getter
protected Path pluginPath;
protected PluginDescriptor descriptor;

@SneakyThrows
public JsPluginLoader(Path pluginPath) {
public JSPluginLoader(Path pluginPath) {
this.pluginPath = pluginPath;
}

Expand All @@ -51,13 +51,13 @@ public PluginContainer loadPlugin() {
((AllayI18n) I18n.get()).applyI18nLoader(new ScriptPluginI18nLoader(pluginPath));

return PluginContainer.createPluginContainer(
new JsPlugin(),
new JSPlugin(),
descriptor, this,
DefaultPluginSource.getOrCreateDataFolder(descriptor.getName())
);
}

public static class JsPluginLoaderFactory implements PluginLoaderFactory {
public static class JsPluginLoaderFactory implements PluginLoader.Factory {

@Override
public boolean canLoad(Path pluginPath) {
Expand All @@ -66,7 +66,7 @@ public boolean canLoad(Path pluginPath) {

@Override
public PluginLoader create(Path pluginPath) {
return new JsPluginLoader(pluginPath);
return new JSPluginLoader(pluginPath);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.allaymc.scriptpluginext.javascript;
package org.allaymc.scriptpluginext.js;

import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.proxy.ProxyArray;
Expand All @@ -9,15 +9,15 @@
/**
* @author daoge_cmd
*/
public final class JsPluginProxyLogger implements ProxyObject {
public final class JSPluginProxyLogger implements ProxyObject {
private static final Value NULL = Value.asValue(null);

private final ProxyExecutable log;
private final ProxyExecutable warn;
private final ProxyExecutable debug;
private final ProxyExecutable error;

public JsPluginProxyLogger(Logger logger) {
public JSPluginProxyLogger(Logger logger) {
this.log = arguments -> {
logger.info(joinValues(arguments));
return NULL;
Expand Down
85 changes: 0 additions & 85 deletions src/main/java/org/allaymc/scriptpluginext/python/PyPlugin.java

This file was deleted.

This file was deleted.

0 comments on commit 5a6e729

Please sign in to comment.