Rename methods on ScriptEngineService

This commit method renames the ScriptEngineService interface methods
types, extensions, and sandboxed to getTypes, getExtensions, and
isSandboxed, respectively.
This commit is contained in:
Jason Tedor 2016-01-26 16:56:46 -05:00
parent 6894594979
commit 9944573449
18 changed files with 81 additions and 82 deletions

View File

@ -51,17 +51,17 @@ public class NativeScriptEngineService extends AbstractComponent implements Scri
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return Collections.emptyList();
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -31,11 +31,11 @@ import java.util.Map;
*/
public interface ScriptEngineService extends Closeable {
List<String> types();
List<String> getTypes();
List<String> extensions();
List<String> getExtensions();
boolean sandboxed();
boolean isSandboxed();
Object compile(String script, Map<String, String> params);

View File

@ -173,7 +173,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
for (String language : scriptEngineRegistry.getLanguages(scriptEngine.getClass())) {
enginesByLangBuilder.put(language, scriptEngine);
}
for (String ext : scriptEngine.extensions()) {
for (String ext : scriptEngine.getExtensions()) {
enginesByExtBuilder.put(ext, scriptEngine);
}
}
@ -481,7 +481,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
case OFF:
return false;
case SANDBOX:
return scriptEngineService.sandboxed();
return scriptEngineService.isSandboxed();
default:
throw new IllegalArgumentException("script mode [" + mode + "] not supported");
}
@ -540,12 +540,12 @@ public class ScriptService extends AbstractComponent implements Closeable {
try {
//we don't know yet what the script will be used for, but if all of the operations for this lang
// with file scripts are disabled, it makes no sense to even compile it and cache it.
if (isAnyScriptContextEnabled(engineService.types().get(0), engineService, ScriptType.FILE)) {
if (isAnyScriptContextEnabled(engineService.getTypes().get(0), engineService, ScriptType.FILE)) {
logger.info("compiling script file [{}]", file.toAbsolutePath());
try(InputStreamReader reader = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8)) {
String script = Streams.copyToString(reader);
CacheKey cacheKey = new CacheKey(engineService, scriptNameExt.v1(), null, Collections.emptyMap());
staticCache.put(cacheKey, new CompiledScript(ScriptType.FILE, scriptNameExt.v1(), engineService.types().get(0), engineService.compile(script, Collections.emptyMap())));
staticCache.put(cacheKey, new CompiledScript(ScriptType.FILE, scriptNameExt.v1(), engineService.getTypes().get(0), engineService.compile(script, Collections.emptyMap())));
scriptMetrics.onCompilation();
}
} else {
@ -650,7 +650,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
final Map<String, String> params;
private CacheKey(final ScriptEngineService service, final String name, final String code, final Map<String, String> params) {
this.lang = service.types().get(0);
this.lang = service.getTypes().get(0);
this.name = name;
this.code = code;
this.params = params;

View File

@ -230,7 +230,7 @@ public class ScriptModesTests extends ESTestCase {
static Map<String, ScriptEngineService> buildScriptEnginesByLangMap(Set<ScriptEngineService> scriptEngines) {
Map<String, ScriptEngineService> builder = new HashMap<>();
for (ScriptEngineService scriptEngine : scriptEngines) {
for (String type : scriptEngine.types()) {
for (String type : scriptEngine.getTypes()) {
builder.put(type, scriptEngine);
}
}
@ -242,17 +242,17 @@ public class ScriptModesTests extends ESTestCase {
public static final List<String> TYPES = Collections.unmodifiableList(Arrays.asList("custom", "test"));
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return Collections.singletonList(TYPES.get(0));
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -39,7 +39,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.common.settings.Settings.builder;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.equalTo;
@ -238,7 +237,7 @@ public class ScriptServiceTests extends ESTestCase {
do {
ScriptType scriptType = randomFrom(ScriptType.values());
ScriptContext scriptContext = randomFrom(this.scriptContexts);
settingKey = scriptEngineService.types().get(0) + "." + scriptType + "." + scriptContext.getKey();
settingKey = scriptEngineService.getTypes().get(0) + "." + scriptType + "." + scriptContext.getKey();
} while (engineSettings.containsKey(settingKey));
engineSettings.put(settingKey, randomFrom(ScriptMode.values()));
}
@ -276,7 +275,7 @@ public class ScriptServiceTests extends ESTestCase {
String part1 = entry.getKey().substring(0, delimiter);
String part2 = entry.getKey().substring(delimiter + 1);
String lang = randomFrom(scriptEnginesByLangMap.get(part1).types());
String lang = randomFrom(scriptEnginesByLangMap.get(part1).getTypes());
switch (entry.getValue()) {
case ON:
builder.put("script.engine" + "." + lang + "." + part2, "on");
@ -299,7 +298,7 @@ public class ScriptServiceTests extends ESTestCase {
String script = scriptType == ScriptType.FILE ? "file_script" : "script";
for (ScriptContext scriptContext : this.scriptContexts) {
//fallback mechanism: 1) engine specific settings 2) op based settings 3) source based settings
ScriptMode scriptMode = engineSettings.get(scriptEngineService.types().get(0) + "." + scriptType + "." + scriptContext.getKey());
ScriptMode scriptMode = engineSettings.get(scriptEngineService.getTypes().get(0) + "." + scriptType + "." + scriptContext.getKey());
if (scriptMode == null) {
scriptMode = scriptContextSettings.get(scriptContext);
}
@ -310,7 +309,7 @@ public class ScriptServiceTests extends ESTestCase {
scriptMode = DEFAULT_SCRIPT_MODES.get(scriptType);
}
for (String lang : scriptEngineService.types()) {
for (String lang : scriptEngineService.getTypes()) {
switch (scriptMode) {
case ON:
assertCompileAccepted(lang, script, scriptType, scriptContext, contextAndHeaders);
@ -319,7 +318,7 @@ public class ScriptServiceTests extends ESTestCase {
assertCompileRejected(lang, script, scriptType, scriptContext, contextAndHeaders);
break;
case SANDBOX:
if (scriptEngineService.sandboxed()) {
if (scriptEngineService.isSandboxed()) {
assertCompileAccepted(lang, script, scriptType, scriptContext, contextAndHeaders);
} else {
assertCompileRejected(lang, script, scriptType, scriptContext, contextAndHeaders);
@ -341,7 +340,7 @@ public class ScriptServiceTests extends ESTestCase {
unknownContext = randomAsciiOfLength(randomIntBetween(1, 30));
} while(scriptContextRegistry.isSupportedContext(new ScriptContext.Plugin(pluginName, unknownContext)));
for (String type : scriptEngineService.types()) {
for (String type : scriptEngineService.getTypes()) {
try {
scriptService.compile(new Script("test", randomFrom(ScriptType.values()), type, null), new ScriptContext.Plugin(
pluginName, unknownContext), contextAndHeaders, Collections.emptyMap());
@ -458,17 +457,17 @@ public class ScriptServiceTests extends ESTestCase {
public static final List<String> EXTENSIONS = Collections.unmodifiableList(Arrays.asList("test", "tst"));
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return EXTENSIONS;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -101,17 +101,17 @@ public class ScriptSettingsTests extends ESTestCase {
public static final List<String> TYPES = Collections.unmodifiableList(Arrays.asList("test1", "test2", "test3"));
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return Collections.singletonList(TYPES.get(0));
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -1418,17 +1418,17 @@ public class DateHistogramIT extends ESIntegTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -1540,17 +1540,17 @@ public class DateHistogramIT extends ESIntegTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -352,17 +352,17 @@ public class AvgIT extends AbstractNumericTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -484,17 +484,17 @@ public class AvgIT extends AbstractNumericTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -348,17 +348,17 @@ public class SumIT extends AbstractNumericTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -482,17 +482,17 @@ public class SumIT extends AbstractNumericTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -242,17 +242,17 @@ public class ValueCountIT extends ESIntegTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -109,17 +109,17 @@ public class UpdateIT extends ESIntegTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -203,17 +203,17 @@ public class UpdateIT extends ESIntegTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -290,17 +290,17 @@ public class UpdateIT extends ESIntegTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -377,17 +377,17 @@ public class UpdateIT extends ESIntegTestCase {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -84,17 +84,17 @@ public class ExpressionScriptEngineService extends AbstractComponent implements
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -161,17 +161,17 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -112,17 +112,17 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -159,17 +159,17 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return Collections.unmodifiableList(Arrays.asList("js"));
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -101,7 +101,7 @@ public class PlanAScriptEngineService extends AbstractComponent implements Scrip
* @return Always contains only the single name of the language.
*/
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@ -110,7 +110,7 @@ public class PlanAScriptEngineService extends AbstractComponent implements Scrip
* @return Always contains only the single extension of the language.
*/
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@ -119,7 +119,7 @@ public class PlanAScriptEngineService extends AbstractComponent implements Scrip
* @return Always true as the engine should be secure at runtime.
*/
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -96,17 +96,17 @@ public class PythonScriptEngineService extends AbstractComponent implements Scri
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return Collections.unmodifiableList(Arrays.asList("py"));
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -61,17 +61,17 @@ public class MockScriptEngine implements ScriptEngineService {
}
@Override
public List<String> types() {
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> extensions() {
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}