Sfoglia il codice sorgente

Remove MVEL as a built-in scripting language

Lee Hinman 11 anni fa
parent
commit
50bb274efa

+ 0 - 12
pom.xml

@@ -208,13 +208,6 @@
             <scope>compile</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.mvel</groupId>
-            <artifactId>mvel2</artifactId>
-            <version>2.2.0.Final</version>
-            <scope>compile</scope>
-        </dependency>
-
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-core</artifactId>
@@ -656,7 +649,6 @@
                         <includes>
                             <include>com.google.guava:guava</include>
                             <include>com.carrotsearch:hppc</include>
-                            <include>org.mvel:mvel2</include>
                             <include>com.fasterxml.jackson.core:jackson-core</include>
                             <include>com.fasterxml.jackson.dataformat:jackson-dataformat-smile</include>
                             <include>com.fasterxml.jackson.dataformat:jackson-dataformat-yaml</include>
@@ -682,10 +674,6 @@
                             <pattern>jsr166e</pattern>
                             <shadedPattern>org.elasticsearch.common.util.concurrent.jsr166e</shadedPattern>
                         </relocation>
-                        <relocation>
-                            <pattern>org.mvel2</pattern>
-                            <shadedPattern>org.elasticsearch.common.mvel2</shadedPattern>
-                        </relocation>
                         <relocation>
                             <pattern>com.fasterxml.jackson</pattern>
                             <shadedPattern>org.elasticsearch.common.jackson</shadedPattern>

+ 0 - 8
src/main/java/org/elasticsearch/script/ScriptModule.java

@@ -29,7 +29,6 @@ import org.elasticsearch.common.logging.Loggers;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.script.groovy.GroovyScriptEngineService;
 import org.elasticsearch.script.mustache.MustacheScriptEngineService;
-import org.elasticsearch.script.mvel.MvelScriptEngineService;
 
 import java.util.List;
 import java.util.Map;
@@ -85,13 +84,6 @@ public class ScriptModule extends AbstractModule {
         } catch (Throwable t) {
             Loggers.getLogger(ScriptService.class, settings).debug("failed to load groovy", t);
         }
-
-        try {
-            settings.getClassLoader().loadClass("org.mvel2.MVEL");
-            multibinder.addBinding().to(MvelScriptEngineService.class);
-        } catch (Throwable t) {
-            Loggers.getLogger(ScriptService.class, settings).debug("failed to load mvel", t);
-        }
         
         try {
             settings.getClassLoader().loadClass("com.github.mustachejava.Mustache");

+ 0 - 219
src/main/java/org/elasticsearch/script/mvel/MvelScriptEngineService.java

@@ -1,219 +0,0 @@
-/*
- * Licensed to Elasticsearch under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.elasticsearch.script.mvel;
-
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.search.Scorer;
-import org.elasticsearch.common.Nullable;
-import org.elasticsearch.common.component.AbstractComponent;
-import org.elasticsearch.common.inject.Inject;
-import org.elasticsearch.common.math.UnboxedMathUtils;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.script.ExecutableScript;
-import org.elasticsearch.script.ScriptEngineService;
-import org.elasticsearch.script.SearchScript;
-import org.elasticsearch.search.lookup.SearchLookup;
-import org.mvel2.MVEL;
-import org.mvel2.ParserConfiguration;
-import org.mvel2.ParserContext;
-import org.mvel2.compiler.ExecutableStatement;
-import org.mvel2.integration.impl.MapVariableResolverFactory;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- *
- */
-public class MvelScriptEngineService extends AbstractComponent implements ScriptEngineService {
-
-    private final ParserConfiguration parserConfiguration;
-
-    @Inject
-    public MvelScriptEngineService(Settings settings) {
-        super(settings);
-
-        parserConfiguration = new ParserConfiguration();
-        parserConfiguration.addPackageImport("java.util");
-        parserConfiguration.addPackageImport("org.joda.time");
-        parserConfiguration.addImport("time", MVEL.getStaticMethod(System.class, "currentTimeMillis", new Class[0]));
-        // unboxed version of Math, better performance since conversion from boxed to unboxed my mvel is not needed
-        for (Method m : UnboxedMathUtils.class.getMethods()) {
-            if ((m.getModifiers() & Modifier.STATIC) > 0) {
-                parserConfiguration.addImport(m.getName(), m);
-            }
-        }
-    }
-
-    @Override
-    public void close() {
-        // nothing to do here...
-    }
-
-    @Override
-    public String[] types() {
-        return new String[]{"mvel"};
-    }
-
-    @Override
-    public String[] extensions() {
-        return new String[]{"mvel"};
-    }
-
-    @Override
-    public boolean sandboxed() {
-        return false;
-    }
-
-    @Override
-    public Object compile(String script) {
-        return MVEL.compileExpression(script.trim(), new ParserContext(parserConfiguration));
-    }
-
-    @Override
-    public Object execute(Object compiledScript, Map vars) {
-        return MVEL.executeExpression(compiledScript, vars);
-    }
-
-    @Override
-    public ExecutableScript executable(Object compiledScript, Map vars) {
-        return new MvelExecutableScript(compiledScript, vars);
-    }
-
-    @Override
-    public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
-        return new MvelSearchScript(compiledScript, lookup, vars);
-    }
-
-    @Override
-    public Object unwrap(Object value) {
-        return value;
-    }
-
-    public static class MvelExecutableScript implements ExecutableScript {
-
-        private final ExecutableStatement script;
-
-        private final MapVariableResolverFactory resolver;
-
-        public MvelExecutableScript(Object script, Map vars) {
-            this.script = (ExecutableStatement) script;
-            if (vars != null) {
-                this.resolver = new MapVariableResolverFactory(vars);
-            } else {
-                this.resolver = new MapVariableResolverFactory(new HashMap());
-            }
-        }
-
-        @Override
-        public void setNextVar(String name, Object value) {
-            resolver.createVariable(name, value);
-        }
-
-        @Override
-        public Object run() {
-            return script.getValue(null, resolver);
-        }
-
-        @Override
-        public Object unwrap(Object value) {
-            return value;
-        }
-    }
-
-    public static class MvelSearchScript implements SearchScript {
-
-        private final ExecutableStatement script;
-
-        private final SearchLookup lookup;
-
-        private final MapVariableResolverFactory resolver;
-
-        public MvelSearchScript(Object script, SearchLookup lookup, Map<String, Object> vars) {
-            this.script = (ExecutableStatement) script;
-            this.lookup = lookup;
-            if (vars != null) {
-                this.resolver = new MapVariableResolverFactory(vars);
-            } else {
-                this.resolver = new MapVariableResolverFactory(new HashMap());
-            }
-            for (Map.Entry<String, Object> entry : lookup.asMap().entrySet()) {
-                resolver.createVariable(entry.getKey(), entry.getValue());
-            }
-        }
-
-        @Override
-        public void setScorer(Scorer scorer) {
-            lookup.setScorer(scorer);
-        }
-
-        @Override
-        public void setNextReader(AtomicReaderContext context) {
-            lookup.setNextReader(context);
-        }
-
-        @Override
-        public void setNextDocId(int doc) {
-            lookup.setNextDocId(doc);
-        }
-
-        @Override
-        public void setNextScore(float score) {
-            resolver.createVariable("_score", score);
-        }
-
-        @Override
-        public void setNextVar(String name, Object value) {
-            resolver.createVariable(name, value);
-        }
-
-        @Override
-        public void setNextSource(Map<String, Object> source) {
-            lookup.source().setNextSource(source);
-        }
-
-        @Override
-        public Object run() {
-            return script.getValue(null, resolver);
-        }
-
-        @Override
-        public float runAsFloat() {
-            return ((Number) run()).floatValue();
-        }
-
-        @Override
-        public long runAsLong() {
-            return ((Number) run()).longValue();
-        }
-
-        @Override
-        public double runAsDouble() {
-            return ((Number) run()).doubleValue();
-        }
-
-        @Override
-        public Object unwrap(Object value) {
-            return value;
-        }
-    }
-}