Use the mime types provided by the ScriptEngineFactory (#2595)
* Use the mime types provided by the ScriptEngineFactory and not the underlying script engines they provide. This allows mutliple versions of script engines to co-exist, like Nashorn and GraalVM . Signed-off-by: Dan Cunningham <dan@digitaldan.com>pull/2612/head
parent
3b2d2ad4cc
commit
eb3f1e92cc
|
@ -149,8 +149,7 @@ public class ScriptModuleTypeProvider implements ModuleTypeProvider {
|
||||||
if (!scriptTypes.isEmpty()) {
|
if (!scriptTypes.isEmpty()) {
|
||||||
ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0));
|
ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0));
|
||||||
if (scriptEngine != null) {
|
if (scriptEngine != null) {
|
||||||
javax.script.ScriptEngineFactory factory = scriptEngine.getFactory();
|
parameterOptions.put(getPreferredMimeType(engineFactory), getLanguageName(scriptEngine.getFactory()));
|
||||||
parameterOptions.put(getPreferredMimeType(factory), getLanguageName(factory));
|
|
||||||
logger.trace("ParameterOptions: {}", parameterOptions);
|
logger.trace("ParameterOptions: {}", parameterOptions);
|
||||||
} else {
|
} else {
|
||||||
logger.trace("setScriptEngineFactory: engine was null");
|
logger.trace("setScriptEngineFactory: engine was null");
|
||||||
|
@ -165,8 +164,7 @@ public class ScriptModuleTypeProvider implements ModuleTypeProvider {
|
||||||
if (!scriptTypes.isEmpty()) {
|
if (!scriptTypes.isEmpty()) {
|
||||||
ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0));
|
ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0));
|
||||||
if (scriptEngine != null) {
|
if (scriptEngine != null) {
|
||||||
javax.script.ScriptEngineFactory factory = scriptEngine.getFactory();
|
parameterOptions.remove(getPreferredMimeType(engineFactory));
|
||||||
parameterOptions.remove(getPreferredMimeType(factory));
|
|
||||||
logger.trace("ParameterOptions: {}", parameterOptions);
|
logger.trace("ParameterOptions: {}", parameterOptions);
|
||||||
} else {
|
} else {
|
||||||
logger.trace("unsetScriptEngineFactory: engine was null");
|
logger.trace("unsetScriptEngineFactory: engine was null");
|
||||||
|
@ -176,10 +174,10 @@ public class ScriptModuleTypeProvider implements ModuleTypeProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPreferredMimeType(javax.script.ScriptEngineFactory factory) {
|
private String getPreferredMimeType(ScriptEngineFactory factory) {
|
||||||
List<String> mimeTypes = new ArrayList<>(factory.getMimeTypes());
|
List<String> mimeTypes = new ArrayList<>(factory.getScriptTypes());
|
||||||
mimeTypes.removeIf(mimeType -> !mimeType.contains("application") || mimeType.contains("x-"));
|
mimeTypes.removeIf(mimeType -> !mimeType.contains("application") || mimeType.contains("x-"));
|
||||||
return mimeTypes.isEmpty() ? factory.getMimeTypes().get(0) : mimeTypes.get(0);
|
return mimeTypes.isEmpty() ? factory.getScriptTypes().get(0) : mimeTypes.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLanguageName(javax.script.ScriptEngineFactory factory) {
|
private String getLanguageName(javax.script.ScriptEngineFactory factory) {
|
||||||
|
|
Loading…
Reference in New Issue