mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-24 17:09:48 +00:00
Mustache: don't extend AbstractComponent (#23419)
Don't extend `AbstractComponent` in `MustacheScriptEngine` because it doesn't buy anything.
This commit is contained in:
parent
e71d9c1960
commit
2dcdaa1c9d
@ -45,7 +45,7 @@ public class MustachePlugin extends Plugin implements ScriptPlugin, ActionPlugin
|
||||
|
||||
@Override
|
||||
public ScriptEngineService getScriptEngineService(Settings settings) {
|
||||
return new MustacheScriptEngineService(settings);
|
||||
return new MustacheScriptEngineService();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,15 +20,16 @@ package org.elasticsearch.script.mustache;
|
||||
|
||||
import com.github.mustachejava.Mustache;
|
||||
import com.github.mustachejava.MustacheFactory;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||
import org.apache.logging.log4j.util.Supplier;
|
||||
import org.elasticsearch.SpecialPermission;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.io.FastStringReader;
|
||||
import org.elasticsearch.common.io.UTF8StreamWriter;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.GeneralScriptException;
|
||||
@ -52,7 +53,8 @@ import java.util.Map;
|
||||
* process: First compile the string representing the template, the resulting
|
||||
* {@link Mustache} object can then be re-used for subsequent executions.
|
||||
*/
|
||||
public final class MustacheScriptEngineService extends AbstractComponent implements ScriptEngineService {
|
||||
public final class MustacheScriptEngineService implements ScriptEngineService {
|
||||
private static final Logger logger = ESLoggerFactory.getLogger(MustacheScriptEngineService.class);
|
||||
|
||||
public static final String NAME = "mustache";
|
||||
|
||||
@ -71,13 +73,6 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme
|
||||
return writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param settings automatically wired by Guice.
|
||||
* */
|
||||
public MustacheScriptEngineService(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a template string to (in this case) a Mustache object than can
|
||||
* later be re-used for execution to fill in missing parameter values.
|
||||
|
@ -62,7 +62,7 @@ public class CustomMustacheFactoryTests extends ESTestCase {
|
||||
}
|
||||
|
||||
public void testJsonEscapeEncoder() {
|
||||
final ScriptEngineService engine = new MustacheScriptEngineService(Settings.EMPTY);
|
||||
final ScriptEngineService engine = new MustacheScriptEngineService();
|
||||
final Map<String, String> params = randomBoolean() ? singletonMap(Script.CONTENT_TYPE_OPTION, JSON_MIME_TYPE) : emptyMap();
|
||||
|
||||
Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
|
||||
@ -74,7 +74,7 @@ public class CustomMustacheFactoryTests extends ESTestCase {
|
||||
}
|
||||
|
||||
public void testDefaultEncoder() {
|
||||
final ScriptEngineService engine = new MustacheScriptEngineService(Settings.EMPTY);
|
||||
final ScriptEngineService engine = new MustacheScriptEngineService();
|
||||
final Map<String, String> params = singletonMap(Script.CONTENT_TYPE_OPTION, PLAIN_TEXT_MIME_TYPE);
|
||||
|
||||
Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
|
||||
@ -86,7 +86,7 @@ public class CustomMustacheFactoryTests extends ESTestCase {
|
||||
}
|
||||
|
||||
public void testUrlEncoder() {
|
||||
final ScriptEngineService engine = new MustacheScriptEngineService(Settings.EMPTY);
|
||||
final ScriptEngineService engine = new MustacheScriptEngineService();
|
||||
final Map<String, String> params = singletonMap(Script.CONTENT_TYPE_OPTION, X_WWW_FORM_URLENCODED_MIME_TYPE);
|
||||
|
||||
Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
|
||||
|
@ -19,8 +19,8 @@
|
||||
package org.elasticsearch.script.mustache;
|
||||
|
||||
import com.github.mustachejava.MustacheFactory;
|
||||
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
@ -47,7 +47,7 @@ public class MustacheScriptEngineTests extends ESTestCase {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
qe = new MustacheScriptEngineService(Settings.Builder.EMPTY_SETTINGS);
|
||||
qe = new MustacheScriptEngineService();
|
||||
factory = new CustomMustacheFactory();
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ package org.elasticsearch.script.mustache;
|
||||
|
||||
import com.github.mustachejava.Mustache;
|
||||
import com.github.mustachejava.MustacheException;
|
||||
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
@ -55,7 +55,7 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
public class MustacheTests extends ESTestCase {
|
||||
|
||||
private ScriptEngineService engine = new MustacheScriptEngineService(Settings.EMPTY);
|
||||
private ScriptEngineService engine = new MustacheScriptEngineService();
|
||||
|
||||
public void testBasics() {
|
||||
String template = "GET _search {\"query\": " + "{\"boosting\": {"
|
||||
|
@ -28,7 +28,6 @@ import org.elasticsearch.script.ScriptSettings;
|
||||
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
import org.mockito.internal.util.collections.Sets;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -43,7 +42,7 @@ public abstract class AbstractScriptTestCase extends ESTestCase {
|
||||
.put("path.home", createTempDir())
|
||||
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false)
|
||||
.build();
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(new MustacheScriptEngineService(settings)));
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(new MustacheScriptEngineService()));
|
||||
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
|
||||
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user