use of the.bytecode.club.bytecodeviewer.api.Plugin in project bytecode-viewer by Konloch.
the class PluginManager method runPlugin.
/**
* Starts and runs a plugin from file
* @param f the file of the plugin
* @throws Exception
*/
public static void runPlugin(File f) throws Throwable {
String ext = f.getName().substring(f.getName().lastIndexOf('.') + 1);
PluginLaunchStrategy strategy = launchStrategies.get(ext);
if (strategy == null) {
throw new RuntimeException(String.format("No launch strategy for extension %s (%s)", ext, f.getAbsolutePath()));
}
Plugin p = strategy.run(f);
if (p != null) {
runPlugin(p);
}
}
use of the.bytecode.club.bytecodeviewer.api.Plugin in project bytecode-viewer by Konloch.
the class CompiledJavaPluginLaunchStrategy method run.
@Override
public Plugin run(File file) throws Throwable {
Set<LoadedNodeData> set = loadData(file);
LoadedNodeData pdata = null;
for (LoadedNodeData d : set) {
ClassNode cn = d.node;
if (cn.superName.equals(PLUGIN_CLASS_NAME)) {
if (pdata == null) {
pdata = d;
} else {
throw new RuntimeException("Multiple plugin subclasses.");
}
}
}
LoadingClassLoader cl = new LoadingClassLoader(pdata, set);
Plugin p = cl.pluginKlass.newInstance();
LoadedPluginData npdata = new LoadedPluginData(pdata, cl, p);
loaded.add(npdata);
return p;
}
use of the.bytecode.club.bytecodeviewer.api.Plugin in project bytecode-viewer by Konloch.
the class GroovyPluginLaunchStrategy method run.
@Override
public Plugin run(File file) throws Throwable {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("groovy");
if (engine == null)
throw new Exception("Cannot find Groovy script engine! Please contact Konloch.");
Reader reader = new FileReader(file);
engine.eval(reader);
return (Plugin) engine.eval("new " + file.getName().replace(".gy", "").replace(".groovy", "") + "();");
}
use of the.bytecode.club.bytecodeviewer.api.Plugin in project bytecode-viewer by Konloch.
the class PythonPluginLaunchStrategy method run.
@Override
public Plugin run(File file) throws Throwable {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("python");
if (engine == null)
throw new Exception("Cannot find Jython script engine! Please contact Konloch.");
Reader reader = new FileReader(file);
engine.eval(reader);
return (Plugin) engine.eval(file.getName().replace(".py", "").replace(".python", "") + "()");
}
use of the.bytecode.club.bytecodeviewer.api.Plugin in project bytecode-viewer by Konloch.
the class RubyPluginLaunchStrategy method run.
@Override
public Plugin run(File file) throws Throwable {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("jruby");
if (engine == null)
throw new Exception("Cannot find jRuby script engine! Please contact Konloch.");
Reader reader = new FileReader(file);
engine.eval(reader);
return (Plugin) engine.eval(file.getName().replace(".rb", "").replace(".ruby", "") + ".new");
}
Aggregations