From eaecc8269392ea0bbe1ee444e9e35724f2712bb0 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 9 Aug 2021 13:29:15 -0700 Subject: [PATCH 1/5] Move painless base whitelist into painless jar The base whitelist is shared by all script contexts. However, the text files exist within painless itself, not the limited spi jar which is meant for extension. This commit moves the base definition into painless and reworks context loading in painless to add the base whitelist so that all contexts get it, regardless of whether they have added an explicit whitelist. --- .../elasticsearch/painless/spi/Whitelist.java | 22 -------- .../painless/PainlessPlugin.java | 43 +++++++++++---- .../lookup/PainlessLookupBuilder.java | 49 ++++++++--------- .../painless/{spi => }/java.lang.txt | 0 .../painless/{spi => }/java.math.txt | 0 .../painless/{spi => }/java.text.txt | 0 .../painless/{spi => }/java.time.chrono.txt | 0 .../painless/{spi => }/java.time.format.txt | 0 .../painless/{spi => }/java.time.temporal.txt | 0 .../painless/{spi => }/java.time.txt | 0 .../painless/{spi => }/java.time.zone.txt | 0 .../painless/{spi => }/java.util.function.txt | 0 .../painless/{spi => }/java.util.regex.txt | 0 .../painless/{spi => }/java.util.stream.txt | 0 .../painless/{spi => }/java.util.txt | 0 .../org.elasticsearch.aggs.movfn.txt | 0 .../{spi => }/org.elasticsearch.ingest.txt | 0 .../{spi => }/org.elasticsearch.json.txt | 0 .../{spi => }/org.elasticsearch.net.txt | 0 .../{spi => }/org.elasticsearch.score.txt | 0 ...org.elasticsearch.script.boolean_field.txt | 0 .../org.elasticsearch.script.date_field.txt | 0 .../org.elasticsearch.script.double_field.txt | 0 ...org.elasticsearch.script.fields.filter.txt | 0 ...elasticsearch.script.fields.numbersort.txt | 0 .../org.elasticsearch.script.fields.score.txt | 0 ...elasticsearch.script.fields.stringsort.txt | 0 .../org.elasticsearch.script.fields.txt | 0 ...g.elasticsearch.script.geo_point_field.txt | 0 .../org.elasticsearch.script.ip_field.txt | 0 ...org.elasticsearch.script.keyword_field.txt | 0 .../org.elasticsearch.script.long_field.txt | 0 .../painless/{spi => }/org.elasticsearch.txt | 0 .../painless/AugmentationTests.java | 2 +- .../painless/BaseClassTests.java | 54 +++++++++---------- .../painless/BasicStatementTests.java | 2 +- .../elasticsearch/painless/BindingsTests.java | 2 +- .../elasticsearch/painless/DebugTests.java | 3 +- .../org/elasticsearch/painless/Debugger.java | 4 +- .../painless/DefBootstrapTests.java | 3 +- .../org/elasticsearch/painless/EmitTests.java | 2 +- .../elasticsearch/painless/FactoryTests.java | 16 +++--- .../painless/NeedsScoreTests.java | 2 +- .../painless/ScriptTestCase.java | 2 +- .../ScriptedMetricAggContextsTests.java | 8 +-- .../painless/SimilarityScriptTests.java | 4 +- .../org/elasticsearch/painless/ThisTests.java | 2 +- 47 files changed, 107 insertions(+), 113 deletions(-) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.lang.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.math.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.text.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.time.chrono.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.time.format.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.time.temporal.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.time.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.time.zone.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.util.function.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.util.regex.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.util.stream.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/java.util.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.aggs.movfn.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.ingest.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.json.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.net.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.score.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.boolean_field.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.date_field.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.double_field.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.fields.filter.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.fields.numbersort.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.fields.score.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.fields.stringsort.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.fields.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.geo_point_field.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.ip_field.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.keyword_field.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.script.long_field.txt (100%) rename modules/lang-painless/src/main/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.txt (100%) diff --git a/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/Whitelist.java b/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/Whitelist.java index 06a56d2a3f641..72c0904a65d19 100644 --- a/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/Whitelist.java +++ b/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/Whitelist.java @@ -26,28 +26,6 @@ */ public final class Whitelist { - private static final String[] BASE_WHITELIST_FILES = new String[] { - "org.elasticsearch.txt", - "org.elasticsearch.net.txt", - "org.elasticsearch.script.fields.txt", - "java.lang.txt", - "java.math.txt", - "java.text.txt", - "java.time.txt", - "java.time.chrono.txt", - "java.time.format.txt", - "java.time.temporal.txt", - "java.time.zone.txt", - "java.util.txt", - "java.util.function.txt", - "java.util.regex.txt", - "java.util.stream.txt" - }; - - public static final List BASE_WHITELISTS = - Collections.singletonList(WhitelistLoader.loadFromResourceFiles( - Whitelist.class, WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS, BASE_WHITELIST_FILES)); - /** The {@link ClassLoader} used to look up the whitelisted Java classes, constructors, methods, and fields. */ public final ClassLoader classLoader; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java index a0000c1fbe43d..e1a100813d854 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java @@ -30,6 +30,7 @@ import org.elasticsearch.painless.spi.PainlessExtension; import org.elasticsearch.painless.spi.Whitelist; import org.elasticsearch.painless.spi.WhitelistLoader; +import org.elasticsearch.painless.spi.annotation.WhitelistAnnotationParser; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.ExtensiblePlugin; import org.elasticsearch.plugins.Plugin; @@ -65,6 +66,26 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, ExtensiblePlugin, ActionPlugin { private static final Map, List> whitelists; + private static final String[] BASE_WHITELIST_FILES = new String[] { + "org.elasticsearch.txt", + "org.elasticsearch.net.txt", + "org.elasticsearch.script.fields.txt", + "java.lang.txt", + "java.math.txt", + "java.text.txt", + "java.time.txt", + "java.time.chrono.txt", + "java.time.format.txt", + "java.time.temporal.txt", + "java.time.zone.txt", + "java.util.txt", + "java.util.function.txt", + "java.util.regex.txt", + "java.util.stream.txt" + }; + public static final List BASE_WHITELISTS = + Collections.singletonList(WhitelistLoader.loadFromResourceFiles( + Whitelist.class, WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS, BASE_WHITELIST_FILES)); /* * Contexts from Core that need custom whitelists can add them to the map below. @@ -75,13 +96,13 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens Map, List> map = new HashMap<>(); // Moving Function Pipeline Agg - List movFn = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List movFn = new ArrayList<>(); Whitelist movFnWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.aggs.movfn.txt"); movFn.add(movFnWhitelist); map.put(MovingFunctionScript.CONTEXT, movFn); // Functions used for scoring docs - List scoreFn = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List scoreFn = new ArrayList<>(); Whitelist scoreFnWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.score.txt"); Whitelist scoreFieldWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script.fields.score.txt"); scoreFn.add(scoreFnWhitelist); @@ -89,7 +110,7 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens map.put(ScoreScript.CONTEXT, scoreFn); // Functions available to ingest pipelines - List ingest = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List ingest = new ArrayList<>(); Whitelist ingestWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.ingest.txt"); ingest.add(ingestWhitelist); map.put(IngestScript.CONTEXT, ingest); @@ -100,23 +121,23 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens map.put(scriptContext, getRuntimeFieldWhitelist(scriptContext.name)); } - List numSort = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List numSort = new ArrayList<>(); Whitelist numSortField = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script.fields.numbersort.txt"); numSort.add(numSortField); map.put(NumberSortScript.CONTEXT, numSort); - List strSort = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List strSort = new ArrayList<>(); Whitelist strSortField = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script.fields.stringsort.txt"); strSort.add(strSortField); map.put(StringSortScript.CONTEXT, strSort); - List filter = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List filter = new ArrayList<>(); Whitelist filterWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script.fields.filter.txt"); filter.add(filterWhitelist); map.put(FilterScript.CONTEXT, filter); // Execute context gets everything - List test = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List test = new ArrayList<>(); test.add(movFnWhitelist); test.add(scoreFnWhitelist); test.add(ingestWhitelist); @@ -127,7 +148,7 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens } private static List getRuntimeFieldWhitelist(String contextName) { - List scriptField = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List scriptField = new ArrayList<>(); Whitelist whitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script." + contextName + ".txt"); scriptField.add(whitelist); @@ -143,7 +164,9 @@ public ScriptEngine getScriptEngine(Settings settings, Collection contextWhitelists = whitelists.get(context); if (contextWhitelists == null) { - contextWhitelists = new ArrayList<>(Whitelist.BASE_WHITELISTS); + contextWhitelists = new ArrayList<>(BASE_WHITELISTS); + } else { + contextWhitelists.addAll(BASE_WHITELISTS); } contextsWithWhitelists.put(context, contextWhitelists); } @@ -174,7 +197,7 @@ public void loadExtensions(ExtensionLoader loader) { .flatMap(extension -> extension.getContextWhitelists().entrySet().stream()) .forEach(entry -> { List existing = whitelists.computeIfAbsent(entry.getKey(), - c -> new ArrayList<>(Whitelist.BASE_WHITELISTS)); + c -> new ArrayList<>(BASE_WHITELISTS)); existing.addAll(entry.getValue()); }); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java index cd5214366553f..98e7255a6ab72 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Supplier; import java.util.regex.Pattern; import static org.elasticsearch.painless.WriterConstants.DEF_TO_B_BYTE_IMPLICIT; @@ -213,6 +214,21 @@ private boolean isValidType(Class type) { return type == def.class || classesToPainlessClassBuilders.containsKey(type); } + private Class loadClass(ClassLoader classLoader, String javaClassName, Supplier errorMessage) { + try { + return Class.forName(javaClassName, true, classLoader); + } catch (ClassNotFoundException cnfe) { + try { + // Painless provides some api classes that are available only through the painless implementation. + return Class.forName(javaClassName); + } catch (ClassNotFoundException cnfe2) { + IllegalArgumentException iae = new IllegalArgumentException(errorMessage.get(), cnfe2); + cnfe2.addSuppressed(cnfe); + throw iae; + } + } + } + public void addPainlessClass(ClassLoader classLoader, String javaClassName, boolean importClassName) { Objects.requireNonNull(classLoader); Objects.requireNonNull(javaClassName); @@ -229,11 +245,7 @@ public void addPainlessClass(ClassLoader classLoader, String javaClassName, bool else if ("float".equals(javaClassName)) clazz = float.class; else if ("double".equals(javaClassName)) clazz = double.class; else { - try { - clazz = Class.forName(javaClassName, true, classLoader); - } catch (ClassNotFoundException cnfe) { - throw new IllegalArgumentException("class [" + javaClassName + "] not found", cnfe); - } + clazz = loadClass(classLoader, javaClassName, () -> "class [" + javaClassName + "] not found"); } addPainlessClass(clazz, importClassName); @@ -425,12 +437,9 @@ public void addPainlessMethod(ClassLoader classLoader, String targetCanonicalCla Class augmentedClass = null; if (augmentedCanonicalClassName != null) { - try { - augmentedClass = Class.forName(augmentedCanonicalClassName, true, classLoader); - } catch (ClassNotFoundException cnfe) { - throw new IllegalArgumentException("augmented class [" + augmentedCanonicalClassName + "] not found for method " + - "[[" + targetCanonicalClassName + "], [" + methodName + "], " + canonicalTypeNameParameters + "]", cnfe); - } + augmentedClass = loadClass(classLoader, augmentedCanonicalClassName, + () -> "augmented class [" + augmentedCanonicalClassName + "] not found for method " + + "[[" + targetCanonicalClassName + "], [" + methodName + "], " + canonicalTypeNameParameters + "]"); } List> typeParameters = new ArrayList<>(canonicalTypeNameParameters.size()); @@ -735,14 +744,7 @@ public void addImportedPainlessMethod(ClassLoader classLoader, String targetJava Objects.requireNonNull(returnCanonicalTypeName); Objects.requireNonNull(canonicalTypeNameParameters); - Class targetClass; - - try { - targetClass = Class.forName(targetJavaClassName, true, classLoader); - } catch (ClassNotFoundException cnfe) { - throw new IllegalArgumentException("class [" + targetJavaClassName + "] not found", cnfe); - } - + Class targetClass = loadClass(classLoader, targetJavaClassName, () -> "class [" + targetJavaClassName + "] not found"); String targetCanonicalClassName = typeToCanonicalTypeName(targetClass); if (targetClass == null) { @@ -888,14 +890,7 @@ public void addPainlessClassBinding(ClassLoader classLoader, String targetJavaCl Objects.requireNonNull(returnCanonicalTypeName); Objects.requireNonNull(canonicalTypeNameParameters); - Class targetClass; - - try { - targetClass = Class.forName(targetJavaClassName, true, classLoader); - } catch (ClassNotFoundException cnfe) { - throw new IllegalArgumentException("class [" + targetJavaClassName + "] not found", cnfe); - } - + Class targetClass = loadClass(classLoader, targetJavaClassName, () -> "class [" + targetJavaClassName + "] not found"); String targetCanonicalClassName = typeToCanonicalTypeName(targetClass); List> typeParameters = new ArrayList<>(canonicalTypeNameParameters.size()); diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.lang.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.lang.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.lang.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.lang.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.math.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.math.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.math.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.math.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.text.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.text.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.text.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.text.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.chrono.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.chrono.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.chrono.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.chrono.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.format.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.format.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.format.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.format.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.temporal.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.temporal.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.temporal.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.temporal.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.zone.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.zone.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.time.zone.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.zone.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.function.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.util.function.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.function.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.util.function.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.regex.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.util.regex.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.regex.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.util.regex.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.stream.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.util.stream.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.stream.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.util.stream.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.util.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.util.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.aggs.movfn.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.aggs.movfn.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.aggs.movfn.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.aggs.movfn.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.ingest.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.ingest.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.ingest.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.ingest.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.json.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.json.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.json.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.json.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.net.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.net.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.net.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.net.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.score.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.score.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.score.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.score.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.boolean_field.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.boolean_field.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.boolean_field.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.boolean_field.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.date_field.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.date_field.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.date_field.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.date_field.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.double_field.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.double_field.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.double_field.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.double_field.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.filter.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.filter.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.filter.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.filter.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.numbersort.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.numbersort.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.numbersort.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.numbersort.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.score.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.score.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.score.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.score.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.stringsort.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.stringsort.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.stringsort.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.stringsort.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.geo_point_field.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.geo_point_field.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.geo_point_field.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.geo_point_field.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.ip_field.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.ip_field.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.ip_field.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.ip_field.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.keyword_field.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.keyword_field.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.keyword_field.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.keyword_field.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.long_field.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.long_field.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.long_field.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.long_field.txt diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.txt similarity index 100% rename from modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt rename to modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.txt diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java index 3131730c5325c..4bbfddb146773 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java @@ -25,7 +25,7 @@ public class AugmentationTests extends ScriptTestCase { @Override protected Map, List> scriptContexts() { Map, List> contexts = super.scriptContexts(); - List digestWhitelist = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List digestWhitelist = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); digestWhitelist.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.ingest.txt")); contexts.put(DigestTestScript.CONTEXT, digestWhitelist); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BaseClassTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BaseClassTests.java index 7a8551fcd8b9f..6813b40d61007 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BaseClassTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BaseClassTests.java @@ -28,27 +28,27 @@ public class BaseClassTests extends ScriptTestCase { protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); - contexts.put(Gets.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(NoArgs.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(OneArg.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ArrayArg.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(PrimitiveArrayArg.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(DefArrayArg.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ManyArgs.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(VarArgs.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(DefaultMethods.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ReturnsVoid.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ReturnsPrimitiveBoolean.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ReturnsPrimitiveInt.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ReturnsPrimitiveFloat.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ReturnsPrimitiveDouble.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(NoArgsConstant.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(WrongArgsConstant.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(WrongLengthOfArgConstant.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(UnknownArgType.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(UnknownReturnType.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(UnknownArgTypeInArray.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(TwoExecuteMethods.CONTEXT, Whitelist.BASE_WHITELISTS); + contexts.put(Gets.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(NoArgs.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(OneArg.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ArrayArg.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(PrimitiveArrayArg.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(DefArrayArg.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ManyArgs.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(VarArgs.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(DefaultMethods.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ReturnsVoid.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ReturnsPrimitiveBoolean.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ReturnsPrimitiveInt.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ReturnsPrimitiveFloat.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ReturnsPrimitiveDouble.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(NoArgsConstant.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(WrongArgsConstant.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(WrongLengthOfArgConstant.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(UnknownArgType.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(UnknownReturnType.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(UnknownArgTypeInArray.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(TwoExecuteMethods.CONTEXT, PainlessPlugin.BASE_WHITELISTS); return contexts; } @@ -120,7 +120,7 @@ public void testNoArgs() throws Exception { scriptEngine.compile("testNoArgs3", "_score", NoArgs.CONTEXT, emptyMap())); assertEquals("cannot resolve symbol [_score]", e.getMessage()); - String debug = Debugger.toString(NoArgs.class, "int i = 0", new CompilerSettings(), Whitelist.BASE_WHITELISTS); + String debug = Debugger.toString(NoArgs.class, "int i = 0", new CompilerSettings(), PainlessPlugin.BASE_WHITELISTS); assertThat(debug, containsString("ACONST_NULL")); assertThat(debug, containsString("ARETURN")); } @@ -306,7 +306,7 @@ public void testReturnsVoid() throws Exception { scriptEngine.compile("testReturnsVoid1", "map.remove('a')", ReturnsVoid.CONTEXT, emptyMap()).newInstance().execute(map); assertEquals(emptyMap(), map); - String debug = Debugger.toString(ReturnsVoid.class, "int i = 0", new CompilerSettings(), Whitelist.BASE_WHITELISTS); + String debug = Debugger.toString(ReturnsVoid.class, "int i = 0", new CompilerSettings(), PainlessPlugin.BASE_WHITELISTS); // The important thing is that this contains the opcode for returning void assertThat(debug, containsString(" RETURN")); // We shouldn't contain any weird "default to null" logic @@ -347,7 +347,7 @@ public void testReturnsPrimitiveBoolean() throws Exception { scriptEngine.compile("testReturnsPrimitiveBoolean6", "true || false", ReturnsPrimitiveBoolean.CONTEXT, emptyMap()) .newInstance().execute()); - String debug = Debugger.toString(ReturnsPrimitiveBoolean.class, "false", new CompilerSettings(), Whitelist.BASE_WHITELISTS); + String debug = Debugger.toString(ReturnsPrimitiveBoolean.class, "false", new CompilerSettings(), PainlessPlugin.BASE_WHITELISTS); assertThat(debug, containsString("ICONST_0")); // The important thing here is that we have the bytecode for returning an integer instead of an object. booleans are integers. assertThat(debug, containsString("IRETURN")); @@ -415,7 +415,7 @@ public void testReturnsPrimitiveInt() throws Exception { assertEquals(2, scriptEngine.compile("testReturnsPrimitiveInt7", "1 + 1", ReturnsPrimitiveInt.CONTEXT, emptyMap()).newInstance().execute()); - String debug = Debugger.toString(ReturnsPrimitiveInt.class, "1", new CompilerSettings(), Whitelist.BASE_WHITELISTS); + String debug = Debugger.toString(ReturnsPrimitiveInt.class, "1", new CompilerSettings(), PainlessPlugin.BASE_WHITELISTS); assertThat(debug, containsString("ICONST_1")); // The important thing here is that we have the bytecode for returning an integer instead of an object assertThat(debug, containsString("IRETURN")); @@ -482,7 +482,7 @@ public void testReturnsPrimitiveFloat() throws Exception { "testReturnsPrimitiveFloat7", "def d = Double.valueOf(1.1); d", ReturnsPrimitiveFloat.CONTEXT, emptyMap()) .newInstance().execute()); - String debug = Debugger.toString(ReturnsPrimitiveFloat.class, "1f", new CompilerSettings(), Whitelist.BASE_WHITELISTS); + String debug = Debugger.toString(ReturnsPrimitiveFloat.class, "1f", new CompilerSettings(), PainlessPlugin.BASE_WHITELISTS); assertThat(debug, containsString("FCONST_1")); // The important thing here is that we have the bytecode for returning a float instead of an object assertThat(debug, containsString("FRETURN")); @@ -545,7 +545,7 @@ public void testReturnsPrimitiveDouble() throws Exception { scriptEngine.compile("testReturnsPrimitiveDouble12", "1.1 + 6.7", ReturnsPrimitiveDouble.CONTEXT, emptyMap()) .newInstance().execute(), 0); - String debug = Debugger.toString(ReturnsPrimitiveDouble.class, "1", new CompilerSettings(), Whitelist.BASE_WHITELISTS); + String debug = Debugger.toString(ReturnsPrimitiveDouble.class, "1", new CompilerSettings(), PainlessPlugin.BASE_WHITELISTS); // The important thing here is that we have the bytecode for returning a double instead of an object assertThat(debug, containsString("DRETURN")); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicStatementTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicStatementTests.java index da9c674e9bfe6..c971163034523 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicStatementTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicStatementTests.java @@ -24,7 +24,7 @@ public class BasicStatementTests extends ScriptTestCase { protected Map, List> scriptContexts() { Map, List> contexts = super.scriptContexts(); - contexts.put(OneArg.CONTEXT, Whitelist.BASE_WHITELISTS); + contexts.put(OneArg.CONTEXT, PainlessPlugin.BASE_WHITELISTS); return contexts; } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BindingsTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BindingsTests.java index b525035886332..0740b3d371e4a 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BindingsTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BindingsTests.java @@ -108,7 +108,7 @@ public interface Factory { @Override protected Map, List> scriptContexts() { Map, List> contexts = super.scriptContexts(); - List whitelists = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List whitelists = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.test")); InstanceBindingTestClass instanceBindingTestClass = new InstanceBindingTestClass(1); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DebugTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DebugTests.java index 7b699d61ea7b3..509b1a11dc359 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DebugTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DebugTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.painless.lookup.PainlessLookup; import org.elasticsearch.painless.lookup.PainlessLookupBuilder; -import org.elasticsearch.painless.spi.Whitelist; import org.elasticsearch.script.ScriptException; import java.io.IOException; @@ -26,7 +25,7 @@ import static org.hamcrest.Matchers.not; public class DebugTests extends ScriptTestCase { - private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromWhitelists(Whitelist.BASE_WHITELISTS); + private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromWhitelists(PainlessPlugin.BASE_WHITELISTS); public void testExplain() { // Debug.explain can explain an object diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/Debugger.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/Debugger.java index 63c174ba1303a..16775df059cc9 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/Debugger.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/Debugger.java @@ -26,7 +26,7 @@ final class Debugger { /** compiles source to bytecode, and returns debugging output */ static String toString(final String source) { - return toString(PainlessTestScript.class, source, new CompilerSettings(), Whitelist.BASE_WHITELISTS); + return toString(PainlessTestScript.class, source, new CompilerSettings(), PainlessPlugin.BASE_WHITELISTS); } /** compiles to bytecode, and returns debugging output */ @@ -69,7 +69,7 @@ private static String tree(Class iface, String source, CompilerSettings setti static void phases(final String source, UserTreeVisitor semanticPhaseVisitor, UserTreeVisitor irPhaseVisitor, IRTreeVisitor asmPhaseVisitor) { - tree(PainlessTestScript.class, source, new CompilerSettings(), Whitelist.BASE_WHITELISTS, semanticPhaseVisitor, irPhaseVisitor, + tree(PainlessTestScript.class, source, new CompilerSettings(), PainlessPlugin.BASE_WHITELISTS, semanticPhaseVisitor, irPhaseVisitor, asmPhaseVisitor); } } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java index 6cc70e0743065..bbb9f380d1b0c 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.painless.lookup.PainlessLookup; import org.elasticsearch.painless.lookup.PainlessLookupBuilder; -import org.elasticsearch.painless.spi.Whitelist; import org.elasticsearch.painless.symbol.FunctionTable; import org.elasticsearch.test.ESTestCase; @@ -23,7 +22,7 @@ import java.util.HashMap; public class DefBootstrapTests extends ESTestCase { - private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromWhitelists(Whitelist.BASE_WHITELISTS); + private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromWhitelists(PainlessPlugin.BASE_WHITELISTS); /** calls toString() on integers, twice */ public void testOneType() throws Throwable { diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/EmitTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/EmitTests.java index 037c73015dc20..6e12fbf5d3c3c 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/EmitTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/EmitTests.java @@ -21,7 +21,7 @@ public class EmitTests extends ScriptTestCase { @Override protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); - List whitelists = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List whitelists = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.test")); contexts.put(TestFieldScript.CONTEXT, whitelists); return contexts; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/FactoryTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FactoryTests.java index dffe7261653a1..40ab60ffd1045 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/FactoryTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FactoryTests.java @@ -23,14 +23,14 @@ public class FactoryTests extends ScriptTestCase { @Override protected Map, List> scriptContexts() { Map, List> contexts = super.scriptContexts(); - contexts.put(StatefulFactoryTestScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(FactoryTestScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(DeterministicFactoryTestScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(EmptyTestScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(TemplateScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(VoidReturnTestScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(FactoryTestConverterScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(FactoryTestConverterScriptBadDef.CONTEXT, Whitelist.BASE_WHITELISTS); + contexts.put(StatefulFactoryTestScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(FactoryTestScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(DeterministicFactoryTestScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(EmptyTestScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(TemplateScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(VoidReturnTestScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(FactoryTestConverterScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(FactoryTestConverterScriptBadDef.CONTEXT, PainlessPlugin.BASE_WHITELISTS); return contexts; } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java index 697e46be6c97d..33a66c7564df4 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java @@ -33,7 +33,7 @@ public void testNeedsScores() { IndexService index = createIndex("test", Settings.EMPTY, "type", "d", "type=double"); Map, List> contexts = new HashMap<>(); - contexts.put(NumberSortScript.CONTEXT, Whitelist.BASE_WHITELISTS); + contexts.put(NumberSortScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); PainlessScriptEngine service = new PainlessScriptEngine(Settings.EMPTY, contexts); SearchExecutionContext searchExecutionContext = index.newSearchExecutionContext(0, 0, null, () -> 0, null, emptyMap()); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java index f31a2ec7df839..c1a92c01b97af 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java @@ -52,7 +52,7 @@ protected Settings scriptEngineSettings() { */ protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); - List whitelists = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List whitelists = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.test")); contexts.put(PainlessTestScript.CONTEXT, whitelists); return contexts; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptedMetricAggContextsTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptedMetricAggContextsTests.java index ce200fae716cd..27f7884123147 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptedMetricAggContextsTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptedMetricAggContextsTests.java @@ -32,10 +32,10 @@ public class ScriptedMetricAggContextsTests extends ScriptTestCase { @Override protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); - contexts.put(ScriptedMetricAggContexts.InitScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ScriptedMetricAggContexts.MapScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ScriptedMetricAggContexts.CombineScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(ScriptedMetricAggContexts.ReduceScript.CONTEXT, Whitelist.BASE_WHITELISTS); + contexts.put(ScriptedMetricAggContexts.InitScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ScriptedMetricAggContexts.MapScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ScriptedMetricAggContexts.CombineScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(ScriptedMetricAggContexts.ReduceScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); return contexts; } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/SimilarityScriptTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/SimilarityScriptTests.java index 896d76628f6a6..c8b6fc9232d99 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/SimilarityScriptTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/SimilarityScriptTests.java @@ -42,8 +42,8 @@ public class SimilarityScriptTests extends ScriptTestCase { @Override protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); - contexts.put(SimilarityScript.CONTEXT, Whitelist.BASE_WHITELISTS); - contexts.put(SimilarityWeightScript.CONTEXT, Whitelist.BASE_WHITELISTS); + contexts.put(SimilarityScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); + contexts.put(SimilarityWeightScript.CONTEXT, PainlessPlugin.BASE_WHITELISTS); return contexts; } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ThisTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ThisTests.java index 1116c17c83190..f464b85947554 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ThisTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ThisTests.java @@ -77,7 +77,7 @@ public interface Factory { @Override protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); - List whitelists = new ArrayList<>(Whitelist.BASE_WHITELISTS); + List whitelists = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.this")); contexts.put(ThisScript.CONTEXT, whitelists); return contexts; From 546b4922115db867f48824323916cb58059d0c19 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 9 Aug 2021 15:41:30 -0700 Subject: [PATCH 2/5] checkstyle --- .../src/main/java/org/elasticsearch/painless/spi/Whitelist.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/Whitelist.java b/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/Whitelist.java index 72c0904a65d19..8752bd41aefb2 100644 --- a/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/Whitelist.java +++ b/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/Whitelist.java @@ -8,8 +8,6 @@ package org.elasticsearch.painless.spi; -import org.elasticsearch.painless.spi.annotation.WhitelistAnnotationParser; - import java.util.Collections; import java.util.List; import java.util.Objects; From 7a6d6225db1b1020770d522c09d58b965c7a7d33 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 9 Aug 2021 15:57:25 -0700 Subject: [PATCH 3/5] fixing some tests --- .../painless/PainlessPlugin.java | 20 +++++++++---------- .../painless/AugmentationTests.java | 2 +- .../painless/ScriptTestCase.java | 2 +- .../org.elasticsearch.painless.annotation | 0 ....elasticsearch.painless.annotation.unknown | 0 ...h.painless.annotation.unknown_with_options | 0 .../{spi => }/org.elasticsearch.painless.test | 0 .../{spi => }/org.elasticsearch.painless.this | 0 8 files changed, 12 insertions(+), 12 deletions(-) rename modules/lang-painless/src/test/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.painless.annotation (100%) rename modules/lang-painless/src/test/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.painless.annotation.unknown (100%) rename modules/lang-painless/src/test/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.painless.annotation.unknown_with_options (100%) rename modules/lang-painless/src/test/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.painless.test (100%) rename modules/lang-painless/src/test/resources/org/elasticsearch/painless/{spi => }/org.elasticsearch.painless.this (100%) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java index e1a100813d854..ee33ced4967e7 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java @@ -85,7 +85,7 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens }; public static final List BASE_WHITELISTS = Collections.singletonList(WhitelistLoader.loadFromResourceFiles( - Whitelist.class, WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS, BASE_WHITELIST_FILES)); + PainlessPlugin.class, WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS, BASE_WHITELIST_FILES)); /* * Contexts from Core that need custom whitelists can add them to the map below. @@ -97,21 +97,21 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens // Moving Function Pipeline Agg List movFn = new ArrayList<>(); - Whitelist movFnWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.aggs.movfn.txt"); + Whitelist movFnWhitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.aggs.movfn.txt"); movFn.add(movFnWhitelist); map.put(MovingFunctionScript.CONTEXT, movFn); // Functions used for scoring docs List scoreFn = new ArrayList<>(); - Whitelist scoreFnWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.score.txt"); - Whitelist scoreFieldWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script.fields.score.txt"); + Whitelist scoreFnWhitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.score.txt"); + Whitelist scoreFieldWhitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.score.txt"); scoreFn.add(scoreFnWhitelist); scoreFn.add(scoreFieldWhitelist); map.put(ScoreScript.CONTEXT, scoreFn); // Functions available to ingest pipelines List ingest = new ArrayList<>(); - Whitelist ingestWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.ingest.txt"); + Whitelist ingestWhitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.ingest.txt"); ingest.add(ingestWhitelist); map.put(IngestScript.CONTEXT, ingest); @@ -122,17 +122,17 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens } List numSort = new ArrayList<>(); - Whitelist numSortField = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script.fields.numbersort.txt"); + Whitelist numSortField = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.numbersort.txt"); numSort.add(numSortField); map.put(NumberSortScript.CONTEXT, numSort); List strSort = new ArrayList<>(); - Whitelist strSortField = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script.fields.stringsort.txt"); + Whitelist strSortField = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.stringsort.txt"); strSort.add(strSortField); map.put(StringSortScript.CONTEXT, strSort); List filter = new ArrayList<>(); - Whitelist filterWhitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.script.fields.filter.txt"); + Whitelist filterWhitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.filter.txt"); filter.add(filterWhitelist); map.put(FilterScript.CONTEXT, filter); @@ -141,7 +141,7 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens test.add(movFnWhitelist); test.add(scoreFnWhitelist); test.add(ingestWhitelist); - test.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.json.txt")); + test.add(WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.json.txt")); map.put(PainlessExecuteAction.PainlessTestScript.CONTEXT, test); whitelists = map; @@ -149,7 +149,7 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens private static List getRuntimeFieldWhitelist(String contextName) { List scriptField = new ArrayList<>(); - Whitelist whitelist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, + Whitelist whitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script." + contextName + ".txt"); scriptField.add(whitelist); return scriptField; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java index 4bbfddb146773..d550c78f107f7 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java @@ -26,7 +26,7 @@ public class AugmentationTests extends ScriptTestCase { protected Map, List> scriptContexts() { Map, List> contexts = super.scriptContexts(); List digestWhitelist = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); - digestWhitelist.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.ingest.txt")); + digestWhitelist.add(WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.ingest.txt")); contexts.put(DigestTestScript.CONTEXT, digestWhitelist); return contexts; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java index c1a92c01b97af..4b36706388751 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java @@ -53,7 +53,7 @@ protected Settings scriptEngineSettings() { protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); List whitelists = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); - whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.test")); + whitelists.add(WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.painless.test")); contexts.put(PainlessTestScript.CONTEXT, whitelists); return contexts; } diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation similarity index 100% rename from modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation rename to modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown similarity index 100% rename from modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown rename to modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown_with_options b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown_with_options similarity index 100% rename from modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown_with_options rename to modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown_with_options diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.test b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.test similarity index 100% rename from modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.test rename to modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.test diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.this b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.this similarity index 100% rename from modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.this rename to modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.this From b736a1d10c706c4ea74af585ac73c59dd911c68b Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 9 Aug 2021 16:15:50 -0700 Subject: [PATCH 4/5] Move whitelist tests into spi --- modules/lang-painless/spi/build.gradle | 4 +--- .../org/elasticsearch/painless/spi}/AnnotationTestObject.java | 2 +- .../java/org/elasticsearch/painless/WhitelistLoaderTests.java | 4 +++- .../painless/spi}/org.elasticsearch.painless.annotation | 4 ++-- .../spi}/org.elasticsearch.painless.annotation.unknown | 2 +- ...org.elasticsearch.painless.annotation.unknown_with_options | 2 +- .../test/java/org/elasticsearch/painless/BindingsTests.java | 2 +- .../src/test/java/org/elasticsearch/painless/EmitTests.java | 2 +- .../src/test/java/org/elasticsearch/painless/ThisTests.java | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) rename modules/lang-painless/{src/test/java/org/elasticsearch/painless => spi/src/main/java/org/elasticsearch/painless/spi}/AnnotationTestObject.java (98%) rename modules/lang-painless/{ => spi}/src/test/java/org/elasticsearch/painless/WhitelistLoaderTests.java (96%) rename modules/lang-painless/{src/test/resources/org/elasticsearch/painless => spi/src/test/resources/org/elasticsearch/painless/spi}/org.elasticsearch.painless.annotation (80%) rename modules/lang-painless/{src/test/resources/org/elasticsearch/painless => spi/src/test/resources/org/elasticsearch/painless/spi}/org.elasticsearch.painless.annotation.unknown (74%) rename modules/lang-painless/{src/test/resources/org/elasticsearch/painless => spi/src/test/resources/org/elasticsearch/painless/spi}/org.elasticsearch.painless.annotation.unknown_with_options (69%) diff --git a/modules/lang-painless/spi/build.gradle b/modules/lang-painless/spi/build.gradle index b4f8c542325eb..e3b503084010e 100644 --- a/modules/lang-painless/spi/build.gradle +++ b/modules/lang-painless/spi/build.gradle @@ -14,7 +14,5 @@ archivesBaseName = 'elasticsearch-scripting-painless-spi' dependencies { api project(":server") + testImplementation project(":test:framework") } - -// no tests...yet? -tasks.named("test").configure { enabled = false } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AnnotationTestObject.java b/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/AnnotationTestObject.java similarity index 98% rename from modules/lang-painless/src/test/java/org/elasticsearch/painless/AnnotationTestObject.java rename to modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/AnnotationTestObject.java index 4ee91eaa4a311..5d2247ddd4c1d 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AnnotationTestObject.java +++ b/modules/lang-painless/spi/src/main/java/org/elasticsearch/painless/spi/AnnotationTestObject.java @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -package org.elasticsearch.painless; +package org.elasticsearch.painless.spi; import org.elasticsearch.painless.spi.annotation.WhitelistAnnotationParser; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/WhitelistLoaderTests.java b/modules/lang-painless/spi/src/test/java/org/elasticsearch/painless/WhitelistLoaderTests.java similarity index 96% rename from modules/lang-painless/src/test/java/org/elasticsearch/painless/WhitelistLoaderTests.java rename to modules/lang-painless/spi/src/test/java/org/elasticsearch/painless/WhitelistLoaderTests.java index 2d4111cd1121e..3c4c30dc851e7 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/WhitelistLoaderTests.java +++ b/modules/lang-painless/spi/src/test/java/org/elasticsearch/painless/WhitelistLoaderTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.painless; +import org.elasticsearch.painless.spi.AnnotationTestObject; import org.elasticsearch.painless.spi.Whitelist; import org.elasticsearch.painless.spi.WhitelistClass; import org.elasticsearch.painless.spi.WhitelistLoader; @@ -15,11 +16,12 @@ import org.elasticsearch.painless.spi.annotation.DeprecatedAnnotation; import org.elasticsearch.painless.spi.annotation.NoImportAnnotation; import org.elasticsearch.painless.spi.annotation.WhitelistAnnotationParser; +import org.elasticsearch.test.ESTestCase; import java.util.HashMap; import java.util.Map; -public class WhitelistLoaderTests extends ScriptTestCase { +public class WhitelistLoaderTests extends ESTestCase { public void testUnknownAnnotations() { Map parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS); diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation b/modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation similarity index 80% rename from modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation rename to modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation index 04e22b6dded96..703de27546354 100644 --- a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation +++ b/modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation @@ -1,7 +1,7 @@ # whitelist for annotation tests -class org.elasticsearch.painless.AnnotationTestObject @no_import { +class org.elasticsearch.painless.spi.AnnotationTestObject @no_import { void deprecatedMethod() @deprecated[message="use another method"] void annotatedTestMethod() @test_annotation[one="one",two="two",three="three"] void annotatedMultipleMethod() @test_annotation[one="one",two="two",three="three"] @deprecated[message="test"] -} \ No newline at end of file +} diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown b/modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown similarity index 74% rename from modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown rename to modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown index c67f535705b7a..0cdbad36a3043 100644 --- a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown +++ b/modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown @@ -1,6 +1,6 @@ # whitelist for annotation tests with unknown annotation -class org.elasticsearch.painless.AnnotationTestObject @no_import { +class org.elasticsearch.painless.spi.AnnotationTestObject @no_import { void unknownAnnotationMethod() @unknownAnnotation void unknownAnnotationMethod() @unknownAnootationWithMessage[message="use another method"] } diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown_with_options b/modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown_with_options similarity index 69% rename from modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown_with_options rename to modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown_with_options index 071b7f57fad2d..d9d5d54b24c40 100644 --- a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.annotation.unknown_with_options +++ b/modules/lang-painless/spi/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.annotation.unknown_with_options @@ -1,5 +1,5 @@ # whitelist for annotation tests with unknown annotation containing options -class org.elasticsearch.painless.AnnotationTestObject @no_import { +class org.elasticsearch.painless.spi.AnnotationTestObject @no_import { void unknownAnnotationMethod() @unknownAnootationWithMessage[arg="arg value"] } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BindingsTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BindingsTests.java index 0740b3d371e4a..005e084cd8c9f 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BindingsTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BindingsTests.java @@ -109,7 +109,7 @@ public interface Factory { protected Map, List> scriptContexts() { Map, List> contexts = super.scriptContexts(); List whitelists = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); - whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.test")); + whitelists.add(WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.painless.test")); InstanceBindingTestClass instanceBindingTestClass = new InstanceBindingTestClass(1); WhitelistInstanceBinding getter = new WhitelistInstanceBinding("test", instanceBindingTestClass, diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/EmitTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/EmitTests.java index 6e12fbf5d3c3c..06f75d17ddca9 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/EmitTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/EmitTests.java @@ -22,7 +22,7 @@ public class EmitTests extends ScriptTestCase { protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); List whitelists = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); - whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.test")); + whitelists.add(WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.painless.test")); contexts.put(TestFieldScript.CONTEXT, whitelists); return contexts; } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ThisTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ThisTests.java index f464b85947554..a92cb308e6af6 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ThisTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ThisTests.java @@ -78,7 +78,7 @@ public interface Factory { protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); List whitelists = new ArrayList<>(PainlessPlugin.BASE_WHITELISTS); - whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.this")); + whitelists.add(WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.painless.this")); contexts.put(ThisScript.CONTEXT, whitelists); return contexts; } From fcce13369a4cd9070f75902f033d986506f8a523 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 9 Aug 2021 16:30:08 -0700 Subject: [PATCH 5/5] checkstyle --- .../org/elasticsearch/painless/PainlessPlugin.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java index ee33ced4967e7..a17e692eda7ce 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java @@ -104,7 +104,8 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens // Functions used for scoring docs List scoreFn = new ArrayList<>(); Whitelist scoreFnWhitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.score.txt"); - Whitelist scoreFieldWhitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.score.txt"); + Whitelist scoreFieldWhitelist = + WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.score.txt"); scoreFn.add(scoreFnWhitelist); scoreFn.add(scoreFieldWhitelist); map.put(ScoreScript.CONTEXT, scoreFn); @@ -122,17 +123,20 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens } List numSort = new ArrayList<>(); - Whitelist numSortField = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.numbersort.txt"); + Whitelist numSortField = + WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.numbersort.txt"); numSort.add(numSortField); map.put(NumberSortScript.CONTEXT, numSort); List strSort = new ArrayList<>(); - Whitelist strSortField = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.stringsort.txt"); + Whitelist strSortField = + WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.stringsort.txt"); strSort.add(strSortField); map.put(StringSortScript.CONTEXT, strSort); List filter = new ArrayList<>(); - Whitelist filterWhitelist = WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.filter.txt"); + Whitelist filterWhitelist = + WhitelistLoader.loadFromResourceFiles(PainlessPlugin.class, "org.elasticsearch.script.fields.filter.txt"); filter.add(filterWhitelist); map.put(FilterScript.CONTEXT, filter);