diff --git a/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java b/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java index 093cde4aa04..51d7c96c1ac 100644 --- a/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java +++ b/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java @@ -54,8 +54,8 @@ public class NativeScriptEngineService extends AbstractComponent implements Scri } @Override - public List getExtensions() { - return Collections.emptyList(); + public String getExtension() { + return ""; // Native scripts have no extensions } @Override diff --git a/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java b/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java index b89871b4dab..f8ae209c0c5 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java @@ -33,7 +33,7 @@ public interface ScriptEngineService extends Closeable { String getType(); - List getExtensions(); + String getExtension(); Object compile(String script, Map params); diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java index 557499d07f7..78579ea9d6c 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java @@ -170,9 +170,7 @@ public class ScriptService extends AbstractComponent implements Closeable { for (ScriptEngineService scriptEngine : scriptEngines) { String language = scriptEngineRegistry.getLanguage(scriptEngine.getClass()); enginesByLangBuilder.put(language, scriptEngine); - for (String ext : scriptEngine.getExtensions()) { - enginesByExtBuilder.put(ext, scriptEngine); - } + enginesByExtBuilder.put(scriptEngine.getExtension(), scriptEngine); } this.scriptEnginesByLang = unmodifiableMap(enginesByLangBuilder); this.scriptEnginesByExt = unmodifiableMap(enginesByExtBuilder); diff --git a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java index 88a32cc5ddb..ed224bb7bbd 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java @@ -241,8 +241,8 @@ public class ScriptModesTests extends ESTestCase { } @Override - public List getExtensions() { - return Collections.unmodifiableList(Arrays.asList("custom", "test")); + public String getExtension() { + return NAME; } @Override diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index 96a406fb4a7..060c45bb9e6 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -145,7 +145,7 @@ public class ScriptServiceTests extends ESTestCase { public void testScriptsWithoutExtensions() throws IOException { buildScriptService(Settings.EMPTY); Path testFileNoExt = scriptsFilePath.resolve("test_no_ext"); - Path testFileWithExt = scriptsFilePath.resolve("test_script.tst"); + Path testFileWithExt = scriptsFilePath.resolve("test_script.test"); Streams.copy("test_file_no_ext".getBytes("UTF-8"), Files.newOutputStream(testFileNoExt)); Streams.copy("test_file".getBytes("UTF-8"), Files.newOutputStream(testFileWithExt)); resourceWatcherService.notifyNow(); @@ -173,7 +173,7 @@ public class ScriptServiceTests extends ESTestCase { Path testHiddenFile = scriptsFilePath.resolve(".hidden_file"); Streams.copy("test_hidden_file".getBytes("UTF-8"), Files.newOutputStream(testHiddenFile)); - Path testFileScript = scriptsFilePath.resolve("file_script.tst"); + Path testFileScript = scriptsFilePath.resolve("file_script.test"); Streams.copy("test_file_script".getBytes("UTF-8"), Files.newOutputStream(testFileScript)); resourceWatcherService.notifyNow(); @@ -510,16 +510,14 @@ public class ScriptServiceTests extends ESTestCase { public static final String NAME = "test"; - public static final List EXTENSIONS = Collections.unmodifiableList(Arrays.asList("test", "tst")); - @Override public String getType() { return NAME; } @Override - public List getExtensions() { - return EXTENSIONS; + public String getExtension() { + return NAME; } @Override @@ -560,8 +558,8 @@ public class ScriptServiceTests extends ESTestCase { } @Override - public List getExtensions() { - return EXTENSIONS; + public String getExtension() { + return NAME; } @Override diff --git a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java index ef432120039..fcb87321063 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java @@ -73,16 +73,14 @@ public class ScriptSettingsTests extends ESTestCase { public static final String NAME = "custom"; - public static final List TYPES = Collections.unmodifiableList(Arrays.asList("test")); - @Override public String getType() { return NAME; } @Override - public List getExtensions() { - return Collections.unmodifiableList(Arrays.asList("test")); + public String getExtension() { + return NAME; } @Override diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java index eeb0129c2a3..ef530c5876a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java @@ -382,8 +382,6 @@ public class AvgIT extends AbstractNumericTestCase { public static final String NAME = "extract_field"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -394,8 +392,8 @@ public class AvgIT extends AbstractNumericTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override @@ -509,8 +507,6 @@ public class AvgIT extends AbstractNumericTestCase { public static final String NAME = "field_value"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -521,8 +517,8 @@ public class AvgIT extends AbstractNumericTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java index 50e0e40d4a0..c39558dc120 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java @@ -378,8 +378,6 @@ public class SumIT extends AbstractNumericTestCase { public static final String NAME = "extract_field"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -390,8 +388,8 @@ public class SumIT extends AbstractNumericTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override @@ -507,8 +505,6 @@ public class SumIT extends AbstractNumericTestCase { public static final String NAME = "field_value"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -519,8 +515,8 @@ public class SumIT extends AbstractNumericTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java index 483f542f584..0cfdc9bd3e6 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java @@ -236,8 +236,6 @@ public class ValueCountIT extends ESIntegTestCase { public static final String NAME = "field_value"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -248,8 +246,8 @@ public class ValueCountIT extends ESIntegTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override diff --git a/core/src/test/java/org/elasticsearch/update/UpdateIT.java b/core/src/test/java/org/elasticsearch/update/UpdateIT.java index 313dc1554e3..562867ebe24 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateIT.java @@ -103,8 +103,6 @@ public class UpdateIT extends ESIntegTestCase { public static final String NAME = "put_values"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -115,8 +113,8 @@ public class UpdateIT extends ESIntegTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override @@ -192,8 +190,6 @@ public class UpdateIT extends ESIntegTestCase { public static final String NAME = "field_inc"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -204,8 +200,8 @@ public class UpdateIT extends ESIntegTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override @@ -274,8 +270,6 @@ public class UpdateIT extends ESIntegTestCase { public static final String NAME = "scripted_upsert"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -286,8 +280,8 @@ public class UpdateIT extends ESIntegTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override @@ -356,8 +350,6 @@ public class UpdateIT extends ESIntegTestCase { public static final String NAME = "extract_ctx"; - public static final List TYPES = Collections.singletonList(NAME); - @Override public void close() throws IOException { } @@ -368,8 +360,8 @@ public class UpdateIT extends ESIntegTestCase { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override diff --git a/docs/reference/migration/migrate_5_0/scripting.asciidoc b/docs/reference/migration/migrate_5_0/scripting.asciidoc index ca545cf432d..1d1a21034c7 100644 --- a/docs/reference/migration/migrate_5_0/scripting.asciidoc +++ b/docs/reference/migration/migrate_5_0/scripting.asciidoc @@ -93,3 +93,14 @@ script engine in particular registered both `"lang": "js"` and `"lang": "javascript"`. Script engines can now only register a single language. All references to `"lang": "js"` should be changed to `"lang": "javascript"` for existing users of the lang-javascript plugin. + +==== Scripting engines now register only a single extension + +Prior to 5.0.0 scripting engines could register multiple extensions. The only +engine doing this was the Javascript engine, which registered "js" and +"javascript". It now only registers the "js" file extension for on-disk scripts. + +==== `.javascript` files are no longer supported (use `.js`) + +The Javascript engine previously registered "js" and "javascript". It now only +registers the "js" file extension for on-disk scripts. diff --git a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngineService.java b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngineService.java index 2979001f82d..21bc8e07ab0 100644 --- a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngineService.java +++ b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngineService.java @@ -62,8 +62,6 @@ public class ExpressionScriptEngineService extends AbstractComponent implements public static final String NAME = "expression"; - public static final List TYPES = Collections.singletonList(NAME); - @Inject public ExpressionScriptEngineService(Settings settings) { super(settings); @@ -75,8 +73,8 @@ public class ExpressionScriptEngineService extends AbstractComponent implements } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override diff --git a/modules/lang-groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java b/modules/lang-groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java index 7c0be71596c..7a1f10adf44 100644 --- a/modules/lang-groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java +++ b/modules/lang-groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java @@ -76,7 +76,6 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri */ public static final String NAME = "groovy"; - public static final List TYPES = Collections.singletonList(NAME); /** * The name of the Groovy compiler setting to use associated with activating invokedynamic support. */ @@ -166,8 +165,8 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngineService.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngineService.java index 094adb95f92..253f5cb3fcc 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngineService.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngineService.java @@ -55,8 +55,6 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme public static final String NAME = "mustache"; - public static final List TYPES = Collections.singletonList(NAME); - static final String CONTENT_TYPE_PARAM = "content_type"; static final String JSON_CONTENT_TYPE = "application/json"; static final String PLAIN_TEXT_CONTENT_TYPE = "text/plain"; @@ -117,8 +115,8 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java index 494e71b8782..cd0c0a14ff0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java @@ -53,21 +53,6 @@ public final class PainlessScriptEngineService extends AbstractComponent impleme */ public static final String NAME = "painless"; - /** - * Standard list of names for the Painless language. (There is only one.) - */ - public static final List TYPES = Collections.singletonList(NAME); - - /** - * Standard extension of the Painless language. - */ - public static final String EXTENSION = "painless"; - - /** - * Standard list of extensions for the Painless language. (There is only one.) - */ - public static final List EXTENSIONS = Collections.singletonList(EXTENSION); - /** * Default compiler settings to be used. */ @@ -112,8 +97,8 @@ public final class PainlessScriptEngineService extends AbstractComponent impleme * @return Always contains only the single extension of the language. */ @Override - public List getExtensions() { - return EXTENSIONS; + public String getExtension() { + return NAME; } /** diff --git a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 88b4fe80ce4..da7583b771a 100644 --- a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -70,7 +70,7 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements public static final String NAME = "javascript"; - public static final List EXTENSIONS = Collections.unmodifiableList(Arrays.asList("js", "javascript")); + public static final String EXTENSION = "js"; private final AtomicLong counter = new AtomicLong(); @@ -166,8 +166,8 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements } @Override - public List getExtensions() { - return EXTENSIONS; + public String getExtension() { + return EXTENSION; } @Override diff --git a/plugins/lang-python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java b/plugins/lang-python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java index a9fca62dc20..ca1d3436c11 100644 --- a/plugins/lang-python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java +++ b/plugins/lang-python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java @@ -40,6 +40,6 @@ public class PythonPlugin extends Plugin { } public void onModule(ScriptModule module) { - module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(PythonScriptEngineService.class, PythonScriptEngineService.TYPE)); + module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(PythonScriptEngineService.class, PythonScriptEngineService.NAME)); } } diff --git a/plugins/lang-python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java b/plugins/lang-python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java index da094808940..d9930284d15 100644 --- a/plugins/lang-python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java +++ b/plugins/lang-python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java @@ -58,7 +58,8 @@ import java.util.Map; //TODO we can optimize the case for Map similar to PyStringMap public class PythonScriptEngineService extends AbstractComponent implements ScriptEngineService { - public static final String TYPE = "python"; + public static final String NAME = "python"; + public static final String EXTENSION = "py"; private final PythonInterpreter interp; @@ -97,12 +98,12 @@ public class PythonScriptEngineService extends AbstractComponent implements Scri @Override public String getType() { - return TYPE; + return NAME; } @Override - public List getExtensions() { - return Collections.unmodifiableList(Arrays.asList("py")); + public String getExtension() { + return EXTENSION; } @Override diff --git a/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java b/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java index 142b33f6431..d0765d6627c 100644 --- a/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java +++ b/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java @@ -38,8 +38,6 @@ public class MockScriptEngine implements ScriptEngineService { public static final String NAME = "mockscript"; - public static final List TYPES = Collections.singletonList(NAME); - public static class TestPlugin extends Plugin { public TestPlugin() { @@ -68,8 +66,8 @@ public class MockScriptEngine implements ScriptEngineService { } @Override - public List getExtensions() { - return TYPES; + public String getExtension() { + return NAME; } @Override