Skip to content

Commit 1ef24d2

Browse files
committed
Merge pull request #15328 from rmuir/shave_mustache
Factor mustache -> modules/lang-mustache
2 parents fc9afa2 + e454fad commit 1ef24d2

File tree

45 files changed

+668
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+668
-279
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class PluginBuildPlugin extends BuildPlugin {
6565
// with a full elasticsearch server that includes optional deps
6666
provided "com.spatial4j:spatial4j:${project.versions.spatial4j}"
6767
provided "com.vividsolutions:jts:${project.versions.jts}"
68-
provided "com.github.spullara.mustache.java:compiler:${project.versions.mustache}"
6968
provided "log4j:log4j:${project.versions.log4j}"
7069
provided "log4j:apache-log4j-extras:${project.versions.log4j}"
7170
provided "org.slf4j:slf4j-api:${project.versions.slf4j}"

buildSrc/version.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ lucene = 5.4.0-snapshot-1715952
44
# optional dependencies
55
spatial4j = 0.5
66
jts = 1.13
7-
mustache = 0.9.1
87
jackson = 2.6.2
98
log4j = 1.2.17
109
slf4j = 1.6.2

core/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ dependencies {
7474
compile "com.spatial4j:spatial4j:${versions.spatial4j}", optional
7575
compile "com.vividsolutions:jts:${versions.jts}", optional
7676

77-
// templating
78-
compile "com.github.spullara.mustache.java:compiler:${versions.mustache}", optional
79-
8077
// logging
8178
compile "log4j:log4j:${versions.log4j}", optional
8279
compile "log4j:apache-log4j-extras:${versions.log4j}", optional

core/src/main/java/org/elasticsearch/index/query/TemplateQueryParser.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,15 @@
1818
*/
1919
package org.elasticsearch.index.query;
2020

21-
import org.elasticsearch.ElasticsearchParseException;
22-
import org.elasticsearch.common.HasContextAndHeaders;
2321
import org.elasticsearch.common.Nullable;
2422
import org.elasticsearch.common.ParseFieldMatcher;
25-
import org.elasticsearch.common.bytes.BytesReference;
26-
import org.elasticsearch.common.lease.Releasables;
27-
import org.elasticsearch.common.xcontent.XContent;
28-
import org.elasticsearch.common.xcontent.XContentFactory;
2923
import org.elasticsearch.common.xcontent.XContentParser;
3024
import org.elasticsearch.script.*;
31-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
32-
import org.elasticsearch.search.builder.SearchSourceBuilder;
3325

3426
import java.io.IOException;
3527
import java.util.HashMap;
3628
import java.util.Map;
3729

38-
import static org.elasticsearch.common.Strings.hasLength;
39-
4030
/**
4131
* In the simplest case, parse template string and variables from the request,
4232
* compile the template and execute the template against the given variables.

core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/template/RestRenderSearchTemplateAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.elasticsearch.script.Script.ScriptField;
4242
import org.elasticsearch.script.ScriptService.ScriptType;
4343
import org.elasticsearch.script.Template;
44-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
4544

4645
import java.util.Map;
4746

@@ -89,7 +88,7 @@ protected void handleRequest(RestRequest request, RestChannel channel, Client cl
8988
throw new ElasticsearchParseException("failed to parse request. unknown field [{}] of type [{}]", currentFieldName, token);
9089
}
9190
}
92-
template = new Template(templateId, ScriptType.INDEXED, MustacheScriptEngineService.NAME, null, params);
91+
template = new Template(templateId, ScriptType.INDEXED, Template.DEFAULT_LANG, null, params);
9392
}
9493
renderSearchTemplateRequest = new RenderSearchTemplateRequest();
9594
renderSearchTemplateRequest.template(template);

core/src/main/java/org/elasticsearch/rest/action/template/RestDeleteSearchTemplateAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.elasticsearch.rest.RestController;
2525
import org.elasticsearch.rest.RestRequest;
2626
import org.elasticsearch.rest.action.script.RestDeleteIndexedScriptAction;
27-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
27+
import org.elasticsearch.script.Template;
2828

2929
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
3030

@@ -38,6 +38,6 @@ public RestDeleteSearchTemplateAction(Settings settings, RestController controll
3838

3939
@Override
4040
protected String getScriptLang(RestRequest request) {
41-
return MustacheScriptEngineService.NAME;
41+
return Template.DEFAULT_LANG;
4242
}
4343
}

core/src/main/java/org/elasticsearch/rest/action/template/RestGetSearchTemplateAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.elasticsearch.rest.RestController;
2626
import org.elasticsearch.rest.RestRequest;
2727
import org.elasticsearch.rest.action.script.RestGetIndexedScriptAction;
28-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
28+
import org.elasticsearch.script.Template;
2929

3030
import static org.elasticsearch.rest.RestRequest.Method.GET;
3131

@@ -42,7 +42,7 @@ public RestGetSearchTemplateAction(Settings settings, RestController controller,
4242

4343
@Override
4444
protected String getScriptLang(RestRequest request) {
45-
return MustacheScriptEngineService.NAME;
45+
return Template.DEFAULT_LANG;
4646
}
4747

4848
@Override

core/src/main/java/org/elasticsearch/rest/action/template/RestPutSearchTemplateAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.elasticsearch.common.settings.Settings;
2424
import org.elasticsearch.rest.*;
2525
import org.elasticsearch.rest.action.script.RestPutIndexedScriptAction;
26-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
26+
import org.elasticsearch.script.Template;
2727

2828
import static org.elasticsearch.rest.RestRequest.Method.POST;
2929
import static org.elasticsearch.rest.RestRequest.Method.PUT;
@@ -59,6 +59,6 @@ public void handleRequest(RestRequest request, RestChannel channel, final Client
5959

6060
@Override
6161
protected String getScriptLang(RestRequest request) {
62-
return MustacheScriptEngineService.NAME;
62+
return Template.DEFAULT_LANG;
6363
}
6464
}

core/src/main/java/org/elasticsearch/script/ScriptModule.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import org.elasticsearch.common.inject.AbstractModule;
2323
import org.elasticsearch.common.inject.multibindings.MapBinder;
2424
import org.elasticsearch.common.inject.multibindings.Multibinder;
25-
import org.elasticsearch.common.logging.Loggers;
2625
import org.elasticsearch.common.settings.Settings;
27-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
2826

2927
import java.util.ArrayList;
3028
import java.util.HashMap;
@@ -75,13 +73,6 @@ protected void configure() {
7573

7674
Multibinder<ScriptEngineService> multibinder = Multibinder.newSetBinder(binder(), ScriptEngineService.class);
7775
multibinder.addBinding().to(NativeScriptEngineService.class);
78-
79-
try {
80-
Class.forName("com.github.mustachejava.Mustache");
81-
multibinder.addBinding().to(MustacheScriptEngineService.class).asEagerSingleton();
82-
} catch (Throwable t) {
83-
Loggers.getLogger(ScriptService.class, settings).debug("failed to load mustache", t);
84-
}
8576

8677
for (Class<? extends ScriptEngineService> scriptEngine : scriptEngines) {
8778
multibinder.addBinding().to(scriptEngine).asEagerSingleton();

core/src/main/java/org/elasticsearch/script/Template.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
import org.elasticsearch.common.xcontent.XContentParser;
3030
import org.elasticsearch.common.xcontent.XContentType;
3131
import org.elasticsearch.script.ScriptService.ScriptType;
32-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
3332

3433
import java.io.IOException;
3534
import java.util.Collections;
3635
import java.util.Map;
3736

3837
public class Template extends Script {
38+
39+
/** Default templating language */
40+
public static final String DEFAULT_LANG = "mustache";
3941

4042
private XContentType contentType;
4143

@@ -51,7 +53,7 @@ public Template() {
5153
* The inline template.
5254
*/
5355
public Template(String template) {
54-
super(template, MustacheScriptEngineService.NAME);
56+
super(template, DEFAULT_LANG);
5557
}
5658

5759
/**
@@ -73,7 +75,7 @@ public Template(String template) {
7375
*/
7476
public Template(String template, ScriptType type, @Nullable String lang, @Nullable XContentType xContentType,
7577
@Nullable Map<String, Object> params) {
76-
super(template, type, lang == null ? MustacheScriptEngineService.NAME : lang, params);
78+
super(template, type, lang == null ? DEFAULT_LANG : lang, params);
7779
this.contentType = xContentType;
7880
}
7981

@@ -120,16 +122,16 @@ public static Template readTemplate(StreamInput in) throws IOException {
120122
}
121123

122124
public static Script parse(Map<String, Object> config, boolean removeMatchedEntries, ParseFieldMatcher parseFieldMatcher) {
123-
return new TemplateParser(Collections.emptyMap(), MustacheScriptEngineService.NAME).parse(config, removeMatchedEntries, parseFieldMatcher);
125+
return new TemplateParser(Collections.emptyMap(), DEFAULT_LANG).parse(config, removeMatchedEntries, parseFieldMatcher);
124126
}
125127

126128
public static Template parse(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException {
127-
return new TemplateParser(Collections.emptyMap(), MustacheScriptEngineService.NAME).parse(parser, parseFieldMatcher);
129+
return new TemplateParser(Collections.emptyMap(), DEFAULT_LANG).parse(parser, parseFieldMatcher);
128130
}
129131

130132
@Deprecated
131133
public static Template parse(XContentParser parser, Map<String, ScriptType> additionalTemplateFieldNames, ParseFieldMatcher parseFieldMatcher) throws IOException {
132-
return new TemplateParser(additionalTemplateFieldNames, MustacheScriptEngineService.NAME).parse(parser, parseFieldMatcher);
134+
return new TemplateParser(additionalTemplateFieldNames, DEFAULT_LANG).parse(parser, parseFieldMatcher);
133135
}
134136

135137
@Deprecated
@@ -172,7 +174,7 @@ public TemplateParser(Map<String, ScriptType> additionalTemplateFieldNames, Stri
172174

173175
@Override
174176
protected Template createSimpleScript(XContentParser parser) throws IOException {
175-
return new Template(String.valueOf(parser.objectText()), ScriptType.INLINE, MustacheScriptEngineService.NAME, contentType, null);
177+
return new Template(String.valueOf(parser.objectText()), ScriptType.INLINE, DEFAULT_LANG, contentType, null);
176178
}
177179

178180
@Override

core/src/test/java/org/elasticsearch/index/IndexModuleTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.elasticsearch.script.ScriptContextRegistry;
6060
import org.elasticsearch.script.ScriptEngineService;
6161
import org.elasticsearch.script.ScriptService;
62-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
6362
import org.elasticsearch.test.ESTestCase;
6463
import org.elasticsearch.test.IndexSettingsModule;
6564
import org.elasticsearch.test.engine.MockEngineFactory;
@@ -102,7 +101,6 @@ static NodeServicesProvider newNodeServiceProvider(Settings settings, Environmen
102101
BigArrays bigArrays = new BigArrays(recycler, circuitBreakerService);
103102
IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndicesFieldDataCacheListener(circuitBreakerService), threadPool);
104103
Set<ScriptEngineService> scriptEngines = new HashSet<>();
105-
scriptEngines.add(new MustacheScriptEngineService(settings));
106104
scriptEngines.addAll(Arrays.asList(scriptEngineServices));
107105
ScriptService scriptService = new ScriptService(settings, environment, scriptEngines, new ResourceWatcherService(settings, threadPool), new ScriptContextRegistry(Collections.emptyList()));
108106
IndicesQueriesRegistry indicesQueriesRegistry = new IndicesQueriesRegistry(settings, Collections.emptySet(), new NamedWriteableRegistry());

core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
8585
import org.elasticsearch.script.*;
8686
import org.elasticsearch.script.Script.ScriptParseException;
87-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
8887
import org.elasticsearch.search.internal.SearchContext;
8988
import org.elasticsearch.test.ESTestCase;
9089
import org.elasticsearch.test.IndexSettingsModule;
@@ -205,15 +204,8 @@ protected void configure() {
205204
MockScriptEngine mockScriptEngine = new MockScriptEngine();
206205
Multibinder<ScriptEngineService> multibinder = Multibinder.newSetBinder(binder(), ScriptEngineService.class);
207206
multibinder.addBinding().toInstance(mockScriptEngine);
208-
try {
209-
Class.forName("com.github.mustachejava.Mustache");
210-
} catch(ClassNotFoundException e) {
211-
throw new IllegalStateException("error while loading mustache", e);
212-
}
213-
MustacheScriptEngineService mustacheScriptEngineService = new MustacheScriptEngineService(settings);
214207
Set<ScriptEngineService> engines = new HashSet<>();
215208
engines.add(mockScriptEngine);
216-
engines.add(mustacheScriptEngineService);
217209
List<ScriptContext.Plugin> customContexts = new ArrayList<>();
218210
bind(ScriptContextRegistry.class).toInstance(new ScriptContextRegistry(customContexts));
219211
try {

core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected boolean supportsBoostAndQueryName() {
5151

5252
@Override
5353
protected TemplateQueryBuilder doCreateTestQueryBuilder() {
54-
return new TemplateQueryBuilder(new Template(templateBase.toString()));
54+
return new TemplateQueryBuilder(new Template(templateBase.toString(), ScriptType.INLINE, "mockscript", null, null));
5555
}
5656

5757
@Override

core/src/test/java/org/elasticsearch/script/FileScriptTests.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,16 @@
1919
package org.elasticsearch.script;
2020

2121
import org.elasticsearch.common.ContextAndHeaderHolder;
22-
import org.elasticsearch.common.bytes.BytesArray;
2322
import org.elasticsearch.common.settings.Settings;
2423
import org.elasticsearch.env.Environment;
25-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
2624
import org.elasticsearch.test.ESTestCase;
27-
import org.junit.Test;
2825

2926
import java.nio.file.Files;
3027
import java.nio.file.Path;
3128
import java.util.Collections;
3229
import java.util.HashSet;
3330
import java.util.Set;
3431

35-
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
36-
import static org.hamcrest.Matchers.containsString;
37-
3832
// TODO: these really should just be part of ScriptService tests, there is nothing special about them
3933
public class FileScriptTests extends ESTestCase {
4034

core/src/test/java/org/elasticsearch/script/ScriptModesTests.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.common.Nullable;
2323
import org.elasticsearch.common.settings.Settings;
2424
import org.elasticsearch.script.ScriptService.ScriptType;
25-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
2625
import org.elasticsearch.search.lookup.SearchLookup;
2726
import org.elasticsearch.test.ESTestCase;
2827
import org.junit.After;
@@ -45,7 +44,7 @@
4544
// TODO: this needs to be a base test class, and all scripting engines extend it
4645
public class ScriptModesTests extends ESTestCase {
4746
private static final Set<String> ALL_LANGS = unmodifiableSet(
48-
newHashSet(MustacheScriptEngineService.NAME, "custom", "test"));
47+
newHashSet("custom", "test"));
4948

5049
static final String[] ENABLE_VALUES = new String[]{"on", "true", "yes", "1"};
5150
static final String[] DISABLE_VALUES = new String[]{"off", "false", "no", "0"};
@@ -73,7 +72,6 @@ public void setupScriptEngines() {
7372
scriptContextRegistry = new ScriptContextRegistry(contexts.values());
7473
scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]);
7574
scriptEngines = buildScriptEnginesByLangMap(newHashSet(
76-
new MustacheScriptEngineService(Settings.EMPTY),
7775
//add the native engine just to make sure it gets filtered out
7876
new NativeScriptEngineService(Settings.EMPTY, Collections.<String, NativeScriptFactory>emptyMap()),
7977
new CustomScriptEngineService()));
@@ -93,8 +91,8 @@ public void assertNativeScriptsAreAlwaysAllowed() {
9391
public void assertAllSettingsWereChecked() {
9492
if (assertScriptModesNonNull) {
9593
assertThat(scriptModes, notNullValue());
96-
//3 is the number of engines (native excluded), custom is counted twice though as it's associated with two different names
97-
int numberOfSettings = 3 * ScriptType.values().length * scriptContextRegistry.scriptContexts().size();
94+
//2 is the number of engines (native excluded), custom is counted twice though as it's associated with two different names
95+
int numberOfSettings = 2 * ScriptType.values().length * scriptContextRegistry.scriptContexts().size();
9896
assertThat(scriptModes.scriptModes.size(), equalTo(numberOfSettings));
9997
if (assertAllSettingsWereChecked) {
10098
assertThat(checkedSettings.size(), equalTo(numberOfSettings));
@@ -190,21 +188,6 @@ public void testConflictingScriptTypeAndOpGenericSettings() {
190188
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INLINE}, complementOf);
191189
}
192190

193-
public void testInteractionBetweenGenericAndEngineSpecificSettings() {
194-
Settings.Builder builder = Settings.builder().put("script.inline", randomFrom(DISABLE_VALUES))
195-
.put(specificEngineOpSettings(MustacheScriptEngineService.NAME, ScriptType.INLINE, ScriptContext.Standard.AGGS), randomFrom(ENABLE_VALUES))
196-
.put(specificEngineOpSettings(MustacheScriptEngineService.NAME, ScriptType.INLINE, ScriptContext.Standard.SEARCH), randomFrom(ENABLE_VALUES));
197-
Set<String> mustacheLangSet = singleton(MustacheScriptEngineService.NAME);
198-
Set<String> allButMustacheLangSet = new HashSet<>(ALL_LANGS);
199-
allButMustacheLangSet.remove(MustacheScriptEngineService.NAME);
200-
this.scriptModes = new ScriptModes(scriptEngines, scriptContextRegistry, builder.build());
201-
assertScriptModes(ScriptMode.ON, mustacheLangSet, new ScriptType[]{ScriptType.INLINE}, ScriptContext.Standard.AGGS, ScriptContext.Standard.SEARCH);
202-
assertScriptModes(ScriptMode.OFF, mustacheLangSet, new ScriptType[]{ScriptType.INLINE}, complementOf(ScriptContext.Standard.AGGS, ScriptContext.Standard.SEARCH));
203-
assertScriptModesAllOps(ScriptMode.OFF, allButMustacheLangSet, ScriptType.INLINE);
204-
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED);
205-
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
206-
}
207-
208191
private void assertScriptModesAllOps(ScriptMode expectedScriptMode, Set<String> langs, ScriptType... scriptTypes) {
209192
assertScriptModes(expectedScriptMode, langs, scriptTypes, scriptContexts);
210193
}

core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.elasticsearch.common.settings.Settings;
2626
import org.elasticsearch.env.Environment;
2727
import org.elasticsearch.script.ScriptService.ScriptType;
28-
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
2928
import org.elasticsearch.search.lookup.SearchLookup;
3029
import org.elasticsearch.test.ESTestCase;
3130
import org.elasticsearch.watcher.ResourceWatcherService;
@@ -73,8 +72,7 @@ public void setup() throws IOException {
7372
.put("path.conf", genericConfigFolder)
7473
.build();
7574
resourceWatcherService = new ResourceWatcherService(baseSettings, null);
76-
scriptEngineServices = newHashSet(new TestEngineService(),
77-
new MustacheScriptEngineService(baseSettings));
75+
scriptEngineServices = newHashSet(new TestEngineService());
7876
scriptEnginesByLangMap = ScriptModesTests.buildScriptEnginesByLangMap(scriptEngineServices);
7977
//randomly register custom script contexts
8078
int randomInt = randomIntBetween(0, 3);
@@ -199,10 +197,6 @@ public void testDefaultBehaviourFineGrainedSettings() throws IOException {
199197
createFileScripts("groovy", "mustache", "test");
200198

201199
for (ScriptContext scriptContext : scriptContexts) {
202-
//mustache engine is sandboxed, all scripts are enabled by default
203-
assertCompileAccepted(MustacheScriptEngineService.NAME, "script", ScriptType.INLINE, scriptContext, contextAndHeaders);
204-
assertCompileAccepted(MustacheScriptEngineService.NAME, "script", ScriptType.INDEXED, scriptContext, contextAndHeaders);
205-
assertCompileAccepted(MustacheScriptEngineService.NAME, "file_script", ScriptType.FILE, scriptContext, contextAndHeaders);
206200
//custom engine is sandboxed, all scripts are enabled by default
207201
assertCompileAccepted("test", "script", ScriptType.INLINE, scriptContext, contextAndHeaders);
208202
assertCompileAccepted("test", "script", ScriptType.INDEXED, scriptContext, contextAndHeaders);

core/src/test/resources/org/elasticsearch/validate/config/scripts/file_template_1.mustache

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)