--- old/src/java.scripting/share/classes/javax/script/ScriptEngineManager.java 2017-12-11 23:48:36.723835465 +0530 +++ new/src/java.scripting/share/classes/javax/script/ScriptEngineManager.java 2017-12-11 23:48:36.515835456 +0530 @@ -77,11 +77,21 @@ private void init(final ClassLoader loader) { globalScope = new SimpleBindings(); - engineSpis = new HashSet(); + engineSpis = new ArrayList(); nameAssociations = new HashMap(); extensionAssociations = new HashMap(); mimeTypeAssociations = new HashMap(); initEngines(loader); + sortEngines(); + } + + private void sortEngines() { + Collections.sort(engineSpis, new Comparator() { + @Override + public int compare(ScriptEngineFactory lhs, ScriptEngineFactory rhs) { + return lhs.getEngineName().compareTo(rhs.getEngineName()); + } + }); } private ServiceLoader getServiceLoader(final ClassLoader loader) { @@ -400,7 +410,7 @@ } /** Set of script engine factories discovered. */ - private HashSet engineSpis; + private List engineSpis; /** Map of engine name to script engine factory. */ private HashMap nameAssociations; --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/ScriptEngineOrder.sh 2017-12-11 23:48:36.915835474 +0530 @@ -0,0 +1,52 @@ +# +# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# @test +# @bug 8011697 +# @summary test to check consistency in discovering and returning script engine +# by ScriptEngineManager +# +# @run shell ScriptEngineOrder.sh + +set -x +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi + +. ${TESTSRC}/CommonSetup.sh + +echo "Building dummy script engine modules.." +#test to check the consistency in returning engines by ScriptEngineManager +$JAVAC --limit-modules java.base,java.logging,java.scripting,jdk.scripting.dummyNashorn,jdk.scripting.dummyRhino,jdk.scripting.testEngines -d ${TESTCLASSES}/mods --module-source-path ${TESTSRC}/multiEngines $(find ${TESTSRC}/multiEngines -name *.java) + +echo "Running script engine test.." +$JAVA --limit-modules java.base,java.logging,java.scripting,jdk.scripting.dummyNashorn,jdk.scripting.dummyRhino,jdk.scripting.testEngines --module-path ${TESTCLASSES}/mods --module jdk.scripting.testEngines/jdk.test.engines.ScriptEngineTest + +ret=$? +if [ $ret -ne 0 ] +then + exit $ret +fi + --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/multiEngines/jdk.scripting.dummyNashorn/jdk/dummyNashorn/api/scripting/DummyNashornJSEngine.java 2017-12-11 23:48:37.291835490 +0530 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * + * + * This is a dummyNashorn script engine implementation + */ +package jdk.dummyNashorn.api.scripting; +import javax.script.*; +import java.io.*; + +public class DummyNashornJSEngine extends AbstractScriptEngine { + public Object eval(String str, ScriptContext ctx) { + return eval(new StringReader(str), ctx); + } + + public Object eval(Reader reader, ScriptContext ctx) { + System.out.println("eval done!"); + return null; + } + + public ScriptEngineFactory getFactory() { + return new DummyNashornJSEngineFactory(); + } + + public Bindings createBindings() { + return new SimpleBindings(); + } +} --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/multiEngines/jdk.scripting.dummyNashorn/jdk/dummyNashorn/api/scripting/DummyNashornJSEngineFactory.java 2017-12-11 23:48:37.667835507 +0530 @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * + * + * This is script engine factory for dummyNashorn engine. + */ +package jdk.dummyNashorn.api.scripting; +import javax.script.*; +import java.util.*; + +public class DummyNashornJSEngineFactory implements ScriptEngineFactory { + public String getEngineName() { + return "dummyNashorn"; + } + + public String getEngineVersion() { + return "-1.0"; + } + + public List getExtensions() { + return extensions; + } + + public String getLanguageName() { + return "dummyNashorn"; + } + + public String getLanguageVersion() { + return "-1.0"; + } + + public String getMethodCallSyntax(String obj, String m, String... args) { + StringBuffer buf = new StringBuffer(); + buf.append("call " + m + " "); + buf.append(" on " + obj + " with "); + for (int i = 0; i < args.length; i++) { + buf.append(args[i] + ", "); + } + buf.append(";"); + return buf.toString(); + } + + public List getMimeTypes() { + return mimeTypes; + } + + public List getNames() { + return names; + } + + public String getOutputStatement(String str) { + return "output " + str; + } + + public String getParameter(String key) { + if (key.equals(ScriptEngine.ENGINE)) { + return getEngineName(); + } else if (key.equals(ScriptEngine.ENGINE_VERSION)) { + return getEngineVersion(); + } else if (key.equals(ScriptEngine.NAME)) { + return getEngineName(); + } else if (key.equals(ScriptEngine.LANGUAGE)) { + return getLanguageName(); + } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) { + return getLanguageVersion(); + } else { + return null; + } + } + + public String getProgram(String... statements) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < statements.length; i++) { + buf.append(statements[i]); + } + return buf.toString(); + } + + public ScriptEngine getScriptEngine() { + return new DummyNashornJSEngine(); + } + + private static List names; + private static List extensions; + private static List mimeTypes; + static { + names = new ArrayList(1); + names.add("dummyNashorn"); + names.add("js"); + names = Collections.unmodifiableList(names); + extensions = names; + mimeTypes = new ArrayList(0); + mimeTypes = Collections.unmodifiableList(mimeTypes); + } +} --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/multiEngines/jdk.scripting.dummyNashorn/module-info.java 2017-12-11 23:48:38.043835524 +0530 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +module jdk.scripting.dummyNashorn { + requires java.scripting; + exports jdk.dummyNashorn.api.scripting; + provides javax.script.ScriptEngineFactory with + jdk.dummyNashorn.api.scripting.DummyNashornJSEngineFactory; +} + --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/multiEngines/jdk.scripting.dummyRhino/jdk/dummyRhino/api/scripting/DummyRhinoJSEngine.java 2017-12-11 23:48:38.411835540 +0530 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * + * + * This is a dummyRhino script engine implementation + */ +package jdk.dummyRhino.api.scripting; +import javax.script.*; +import java.io.*; + +public class DummyRhinoJSEngine extends AbstractScriptEngine { + public Object eval(String str, ScriptContext ctx) { + return eval(new StringReader(str), ctx); + } + + public Object eval(Reader reader, ScriptContext ctx) { + System.out.println("eval done!"); + return null; + } + + public ScriptEngineFactory getFactory() { + return new DummyRhinoJSEngineFactory(); + } + + public Bindings createBindings() { + return new SimpleBindings(); + } +} --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/multiEngines/jdk.scripting.dummyRhino/jdk/dummyRhino/api/scripting/DummyRhinoJSEngineFactory.java 2017-12-11 23:48:38.783835557 +0530 @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * + * + * This is script engine factory for dummyRhino engine. + */ +package jdk.dummyRhino.api.scripting; +import javax.script.*; +import java.util.*; + +public class DummyRhinoJSEngineFactory implements ScriptEngineFactory { + public String getEngineName() { + return "dummyRhino"; + } + + public String getEngineVersion() { + return "-1.0"; + } + + public List getExtensions() { + return extensions; + } + + public String getLanguageName() { + return "dummyRhino"; + } + + public String getLanguageVersion() { + return "-1.0"; + } + + public String getMethodCallSyntax(String obj, String m, String... args) { + StringBuffer buf = new StringBuffer(); + buf.append("call " + m + " "); + buf.append(" on " + obj + " with "); + for (int i = 0; i < args.length; i++) { + buf.append(args[i] + ", "); + } + buf.append(";"); + return buf.toString(); + } + + public List getMimeTypes() { + return mimeTypes; + } + + public List getNames() { + return names; + } + + public String getOutputStatement(String str) { + return "output " + str; + } + + public String getParameter(String key) { + if (key.equals(ScriptEngine.ENGINE)) { + return getEngineName(); + } else if (key.equals(ScriptEngine.ENGINE_VERSION)) { + return getEngineVersion(); + } else if (key.equals(ScriptEngine.NAME)) { + return getEngineName(); + } else if (key.equals(ScriptEngine.LANGUAGE)) { + return getLanguageName(); + } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) { + return getLanguageVersion(); + } else { + return null; + } + } + + public String getProgram(String... statements) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < statements.length; i++) { + buf.append(statements[i]); + } + return buf.toString(); + } + + public ScriptEngine getScriptEngine() { + return new DummyRhinoJSEngine(); + } + + private static List names; + private static List extensions; + private static List mimeTypes; + static { + names = new ArrayList(1); + names.add("dummyRhino"); + names.add("js"); + names = Collections.unmodifiableList(names); + extensions = names; + mimeTypes = new ArrayList(0); + mimeTypes = Collections.unmodifiableList(mimeTypes); + } +} --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/multiEngines/jdk.scripting.dummyRhino/module-info.java 2017-12-11 23:48:39.151835573 +0530 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +module jdk.scripting.dummyRhino { + requires java.scripting; + exports jdk.dummyRhino.api.scripting; + provides javax.script.ScriptEngineFactory with + jdk.dummyRhino.api.scripting.DummyRhinoJSEngineFactory; +} + --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/multiEngines/jdk.scripting.testEngines/jdk/test/engines/ScriptEngineTest.java 2017-12-11 23:48:39.519835589 +0530 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.test.engines; +import javax.script.*; +public class ScriptEngineTest { + + public static void main(String[] args) throws Exception { + for (int i = 0; i < 100; i++) { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine scriptEngine = manager.getEngineByName("js"); + if(!(scriptEngine.toString().contains("jdk.dummyNashorn.api.scripting.DummyNashornJSEngine"))) + throw new RuntimeException("Script EngineOrder is inconsistent"); + } + } + +} --- /dev/null 2017-12-11 21:50:24.120008033 +0530 +++ new/test/jdk/javax/script/multiEngines/jdk.scripting.testEngines/module-info.java 2017-12-11 23:48:39.895835606 +0530 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +module jdk.scripting.testEngines{ + requires java.scripting; +} +