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
Dan Cunningham 2021-12-12 22:13:04 -08:00 committed by GitHub
parent 3b2d2ad4cc
commit eb3f1e92cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -149,8 +149,7 @@ public class ScriptModuleTypeProvider implements ModuleTypeProvider {
if (!scriptTypes.isEmpty()) {
ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0));
if (scriptEngine != null) {
javax.script.ScriptEngineFactory factory = scriptEngine.getFactory();
parameterOptions.put(getPreferredMimeType(factory), getLanguageName(factory));
parameterOptions.put(getPreferredMimeType(engineFactory), getLanguageName(scriptEngine.getFactory()));
logger.trace("ParameterOptions: {}", parameterOptions);
} else {
logger.trace("setScriptEngineFactory: engine was null");
@ -165,8 +164,7 @@ public class ScriptModuleTypeProvider implements ModuleTypeProvider {
if (!scriptTypes.isEmpty()) {
ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0));
if (scriptEngine != null) {
javax.script.ScriptEngineFactory factory = scriptEngine.getFactory();
parameterOptions.remove(getPreferredMimeType(factory));
parameterOptions.remove(getPreferredMimeType(engineFactory));
logger.trace("ParameterOptions: {}", parameterOptions);
} else {
logger.trace("unsetScriptEngineFactory: engine was null");
@ -176,10 +174,10 @@ public class ScriptModuleTypeProvider implements ModuleTypeProvider {
}
}
private String getPreferredMimeType(javax.script.ScriptEngineFactory factory) {
List<String> mimeTypes = new ArrayList<>(factory.getMimeTypes());
private String getPreferredMimeType(ScriptEngineFactory factory) {
List<String> mimeTypes = new ArrayList<>(factory.getScriptTypes());
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) {