Search in sources :

Example 1 with Plugin

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);
    }
}
Also used : Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 2 with Plugin

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;
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 3 with Plugin

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", "") + "();");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 4 with Plugin

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", "") + "()");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 5 with Plugin

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");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Aggregations

Plugin (the.bytecode.club.bytecodeviewer.api.Plugin)5 FileReader (java.io.FileReader)3 Reader (java.io.Reader)3 ScriptEngine (javax.script.ScriptEngine)3 ScriptEngineManager (javax.script.ScriptEngineManager)3 ClassNode (org.objectweb.asm.tree.ClassNode)1