Skip to content

Commit c0afb3d

Browse files
committed
Add ScriptEngineManager::isPreCompilationSupported
Signed-off-by: Florian Hotze <[email protected]>
1 parent b932a4d commit c0afb3d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptEngineFactory.java

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ public interface ScriptEngineFactory {
5858
*/
5959
List<String> getScriptTypes();
6060

61+
/**
62+
* This method returns whether the ScriptEngine supports pre-compilation of scripts.
63+
*
64+
* @return true if pre-compilation is supported, else false
65+
*/
66+
default boolean supportsPreCompilation() {
67+
return false;
68+
}
69+
6170
/**
6271
* This method "scopes" new values into the given ScriptEngine.
6372
*

bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptEngineManager.java

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public interface ScriptEngineManager {
6161
*/
6262
boolean isSupported(String scriptType);
6363

64+
/**
65+
* Checks if the supplied file extension or MimeType supports pre-compilation.
66+
*
67+
* @param scriptType a file extension (script) or MimeType (ScriptAction or ScriptCondition)
68+
* @return true, if pre-compilation supported, else false
69+
*/
70+
boolean isPreCompilationSupported(String scriptType);
71+
6472
/**
6573
* Add a listener that is notified when a ScriptEngineFactory is added or removed
6674
*

bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java

+9
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ public boolean isSupported(String scriptType) {
251251
return findEngineFactory(scriptType) != null;
252252
}
253253

254+
@Override
255+
public boolean isPreCompilationSupported(String scriptType) {
256+
ScriptEngineFactory engineFactory = findEngineFactory(scriptType);
257+
if (engineFactory != null) {
258+
return engineFactory.supportsPreCompilation();
259+
}
260+
return false;
261+
}
262+
254263
private void addAttributeToScriptContext(ScriptEngine engine, String name, Object value) {
255264
ScriptContext scriptContext = engine.getContext();
256265

0 commit comments

Comments
 (0)