Merge remote-tracking branch 'dakrone/there-can-be-only-one2'

This commit is contained in:
Lee Hinman 2016-05-13 10:27:49 -06:00
commit 864ba8dac1
19 changed files with 62 additions and 96 deletions

View File

@ -54,8 +54,8 @@ public class NativeScriptEngineService extends AbstractComponent implements Scri
}
@Override
public List<String> getExtensions() {
return Collections.emptyList();
public String getExtension() {
return ""; // Native scripts have no extensions
}
@Override

View File

@ -33,7 +33,7 @@ public interface ScriptEngineService extends Closeable {
String getType();
List<String> getExtensions();
String getExtension();
Object compile(String script, Map<String, String> params);

View File

@ -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);

View File

@ -241,8 +241,8 @@ public class ScriptModesTests extends ESTestCase {
}
@Override
public List<String> getExtensions() {
return Collections.unmodifiableList(Arrays.asList("custom", "test"));
public String getExtension() {
return NAME;
}
@Override

View File

@ -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<String> EXTENSIONS = Collections.unmodifiableList(Arrays.asList("test", "tst"));
@Override
public String getType() {
return NAME;
}
@Override
public List<String> getExtensions() {
return EXTENSIONS;
public String getExtension() {
return NAME;
}
@Override
@ -560,8 +558,8 @@ public class ScriptServiceTests extends ESTestCase {
}
@Override
public List<String> getExtensions() {
return EXTENSIONS;
public String getExtension() {
return NAME;
}
@Override

View File

@ -73,16 +73,14 @@ public class ScriptSettingsTests extends ESTestCase {
public static final String NAME = "custom";
public static final List<String> TYPES = Collections.unmodifiableList(Arrays.asList("test"));
@Override
public String getType() {
return NAME;
}
@Override
public List<String> getExtensions() {
return Collections.unmodifiableList(Arrays.asList("test"));
public String getExtension() {
return NAME;
}
@Override

View File

@ -382,8 +382,6 @@ public class AvgIT extends AbstractNumericTestCase {
public static final String NAME = "extract_field";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -394,8 +392,8 @@ public class AvgIT extends AbstractNumericTestCase {
}
@Override
public List<String> 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<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -521,8 +517,8 @@ public class AvgIT extends AbstractNumericTestCase {
}
@Override
public List<String> getExtensions() {
return TYPES;
public String getExtension() {
return NAME;
}
@Override

View File

@ -378,8 +378,6 @@ public class SumIT extends AbstractNumericTestCase {
public static final String NAME = "extract_field";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -390,8 +388,8 @@ public class SumIT extends AbstractNumericTestCase {
}
@Override
public List<String> 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<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -519,8 +515,8 @@ public class SumIT extends AbstractNumericTestCase {
}
@Override
public List<String> getExtensions() {
return TYPES;
public String getExtension() {
return NAME;
}
@Override

View File

@ -236,8 +236,6 @@ public class ValueCountIT extends ESIntegTestCase {
public static final String NAME = "field_value";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -248,8 +246,8 @@ public class ValueCountIT extends ESIntegTestCase {
}
@Override
public List<String> getExtensions() {
return TYPES;
public String getExtension() {
return NAME;
}
@Override

View File

@ -103,8 +103,6 @@ public class UpdateIT extends ESIntegTestCase {
public static final String NAME = "put_values";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -115,8 +113,8 @@ public class UpdateIT extends ESIntegTestCase {
}
@Override
public List<String> 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<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -204,8 +200,8 @@ public class UpdateIT extends ESIntegTestCase {
}
@Override
public List<String> 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<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -286,8 +280,8 @@ public class UpdateIT extends ESIntegTestCase {
}
@Override
public List<String> 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<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@ -368,8 +360,8 @@ public class UpdateIT extends ESIntegTestCase {
}
@Override
public List<String> getExtensions() {
return TYPES;
public String getExtension() {
return NAME;
}
@Override

View File

@ -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.

View File

@ -62,8 +62,6 @@ public class ExpressionScriptEngineService extends AbstractComponent implements
public static final String NAME = "expression";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Inject
public ExpressionScriptEngineService(Settings settings) {
super(settings);
@ -75,8 +73,8 @@ public class ExpressionScriptEngineService extends AbstractComponent implements
}
@Override
public List<String> getExtensions() {
return TYPES;
public String getExtension() {
return NAME;
}
@Override

View File

@ -76,7 +76,6 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri
*/
public static final String NAME = "groovy";
public static final List<String> TYPES = Collections.singletonList(NAME);
/**
* The name of the Groovy compiler setting to use associated with activating <code>invokedynamic</code> support.
*/
@ -166,8 +165,8 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri
}
@Override
public List<String> getExtensions() {
return TYPES;
public String getExtension() {
return NAME;
}
@Override

View File

@ -55,8 +55,6 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme
public static final String NAME = "mustache";
public static final List<String> 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<String> getExtensions() {
return TYPES;
public String getExtension() {
return NAME;
}
@Override

View File

@ -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<String> 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<String> 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<String> getExtensions() {
return EXTENSIONS;
public String getExtension() {
return NAME;
}
/**

View File

@ -70,7 +70,7 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements
public static final String NAME = "javascript";
public static final List<String> 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<String> getExtensions() {
return EXTENSIONS;
public String getExtension() {
return EXTENSION;
}
@Override

View File

@ -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));
}
}

View File

@ -58,7 +58,8 @@ import java.util.Map;
//TODO we can optimize the case for Map<String, Object> 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<String> getExtensions() {
return Collections.unmodifiableList(Arrays.asList("py"));
public String getExtension() {
return EXTENSION;
}
@Override

View File

@ -38,8 +38,6 @@ public class MockScriptEngine implements ScriptEngineService {
public static final String NAME = "mockscript";
public static final List<String> TYPES = Collections.singletonList(NAME);
public static class TestPlugin extends Plugin {
public TestPlugin() {
@ -68,8 +66,8 @@ public class MockScriptEngine implements ScriptEngineService {
}
@Override
public List<String> getExtensions() {
return TYPES;
public String getExtension() {
return NAME;
}
@Override