public class ScriptCompiler extends Object
ScriptFactory
s. Intended for use as a separate thread - run(String, String)
will
block while waiting for new tasks to compile.
Works with all installed system ScriptEngine
s. By default compatible with js via Nashorn/Rhino.ScriptEngineManager
Modifier and Type | Class and Description |
---|---|
class |
ScriptCompiler.CompileTaskBuilder |
Constructor and Description |
---|
ScriptCompiler(ClassLoader overrideClassLoader) |
Modifier and Type | Method and Description |
---|---|
boolean |
canCompile(File file) |
ScriptCompiler.CompileTaskBuilder |
compile(File file)
Create a builder to compile the given files.
|
ScriptCompiler.CompileTaskBuilder |
compile(String src,
String identifier,
String extension)
Create a builder to compile the given source code.
|
void |
interrupt()
Cancel all running compile tasks.
|
void |
registerGlobalContextProvider(ContextProvider provider)
Registers a global
ContextProvider , which will be invoked on all scripts created by this ScriptCompiler. |
void |
run(String code,
String extension) |
void |
run(String code,
String extension,
Map<String,Object> vars)
Run the given source code.
|
public ScriptCompiler(ClassLoader overrideClassLoader)
public boolean canCompile(File file)
public ScriptCompiler.CompileTaskBuilder compile(File file)
file
- The file to compileScriptCompiler.CompileTaskBuilder
public ScriptCompiler.CompileTaskBuilder compile(String src, String identifier, String extension)
src
- The source code to compileidentifier
- A unique identifier of the source codeextension
- The source code externsionScriptCompiler.CompileTaskBuilder
public void interrupt()
public void registerGlobalContextProvider(ContextProvider provider)
ContextProvider
, which will be invoked on all scripts created by this ScriptCompiler.provider
- The global providerpublic void run(String code, String extension) throws ScriptException
ScriptException
run(String, String, Map)
public void run(String code, String extension, Map<String,Object> vars) throws ScriptException
code
- the source code to compile/runextension
- the code extension e.g. jsvars
- variables to pass to the scriptScriptException
Copyright © 2021. All rights reserved.