[jsscripting] Add an alternative MIME type/alias (#13851)
The alternative MIME type text/javascript is also used by Nashorn, therefore we add the same extension as for the main MIME type. The alias is introduced to simplify the usage in SCRIPT transformation profiles. * Fix syntax problems in the bndtools file * Add null check to avoid potential NPE In some cases during testing, a NPE occured, this should solve it. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
parent
52b7b7981f
commit
54b2772df4
|
@ -1,9 +1,10 @@
|
||||||
Bundle-SymbolicName: ${project.artifactId}
|
Bundle-SymbolicName: ${project.artifactId}
|
||||||
DynamicImport-Package: *
|
DynamicImport-Package: *
|
||||||
Import-Package: org.openhab.core.automation.module.script,javax.management,javax.script,javax.xml.datatype,javax.xml.stream;version="[1.0,2)",org.osgi.framework;version="[1.8,2)",org.slf4j;version="[1.7,2)"
|
Import-Package: org.openhab.core.automation.module.script,javax.management,javax.script,javax.xml.datatype,javax.xml.stream;version="[1.0,2)",org.osgi.framework;version="[1.8,2)",org.slf4j;version="[1.7,2)"
|
||||||
Require-Capability: osgi.extender;
|
Require-Capability:
|
||||||
|
osgi.extender:=
|
||||||
filter:="(osgi.extender=osgi.serviceloader.processor)",
|
filter:="(osgi.extender=osgi.serviceloader.processor)",
|
||||||
osgi.serviceloader;
|
osgi.serviceloader:=
|
||||||
filter:="(osgi.serviceloader=org.graalvm.polyglot.impl.AbstractPolyglotImpl)";
|
filter:="(osgi.serviceloader=org.graalvm.polyglot.impl.AbstractPolyglotImpl)";
|
||||||
cardinality:=multiple
|
cardinality:=multiple
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,14 @@ import org.osgi.service.component.annotations.Reference;
|
||||||
public final class GraalJSScriptEngineFactory implements ScriptEngineFactory {
|
public final class GraalJSScriptEngineFactory implements ScriptEngineFactory {
|
||||||
private static final String CFG_INJECTION_ENABLED = "injectionEnabled";
|
private static final String CFG_INJECTION_ENABLED = "injectionEnabled";
|
||||||
private static final String INJECTION_CODE = "Object.assign(this, require('openhab'));";
|
private static final String INJECTION_CODE = "Object.assign(this, require('openhab'));";
|
||||||
private final JSDependencyTracker jsDependencyTracker;
|
|
||||||
private boolean injectionEnabled = true;
|
private boolean injectionEnabled = true;
|
||||||
|
|
||||||
public static final String MIME_TYPE = "application/javascript;version=ECMAScript-2021";
|
public static final String MIME_TYPE = "application/javascript;version=ECMAScript-2021";
|
||||||
|
private static final String ALT_MIME_TYPE = "text/javascript;version=ECMAScript-2021";
|
||||||
|
private static final String ALIAS = "graaljs";
|
||||||
|
|
||||||
private final JSScriptServiceUtil jsScriptServiceUtil;
|
private final JSScriptServiceUtil jsScriptServiceUtil;
|
||||||
|
private final JSDependencyTracker jsDependencyTracker;
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public GraalJSScriptEngineFactory(final @Reference JSScriptServiceUtil jsScriptServiceUtil,
|
public GraalJSScriptEngineFactory(final @Reference JSScriptServiceUtil jsScriptServiceUtil,
|
||||||
|
@ -68,7 +71,7 @@ public final class GraalJSScriptEngineFactory implements ScriptEngineFactory {
|
||||||
// scriptTypes.addAll(graalJSEngineFactory.getMimeTypes());
|
// scriptTypes.addAll(graalJSEngineFactory.getMimeTypes());
|
||||||
// scriptTypes.addAll(graalJSEngineFactory.getExtensions());
|
// scriptTypes.addAll(graalJSEngineFactory.getExtensions());
|
||||||
|
|
||||||
return List.of(MIME_TYPE);
|
return List.of(MIME_TYPE, ALT_MIME_TYPE, ALIAS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -179,6 +179,9 @@ public class OpenhabGraalJSScriptEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptContext ctx = delegate.getContext();
|
ScriptContext ctx = delegate.getContext();
|
||||||
|
if (ctx == null) {
|
||||||
|
throw new IllegalStateException("Failed to retrieve script context");
|
||||||
|
}
|
||||||
|
|
||||||
// these are added post-construction, so we need to fetch them late
|
// these are added post-construction, so we need to fetch them late
|
||||||
this.engineIdentifier = (String) ctx.getAttribute(CONTEXT_KEY_ENGINE_IDENTIFIER);
|
this.engineIdentifier = (String) ctx.getAttribute(CONTEXT_KEY_ENGINE_IDENTIFIER);
|
||||||
|
|
Loading…
Reference in New Issue