From 5efc712d5c774a8d0bfdb4a00ace1e8cc94c18df Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 5 Dec 2011 17:23:33 +0200 Subject: [PATCH 01/78] first commit --- .gitignore | 7 + README.md | 15 + pom.xml | 122 +++++++ src/main/assemblies/plugin.xml | 26 ++ .../plugin/javascript/JavaScriptPlugin.java | 48 +++ .../JavaScriptScriptEngineService.java | 298 +++++++++++++++ .../script/javascript/support/NativeList.java | 207 +++++++++++ .../script/javascript/support/NativeMap.java | 223 ++++++++++++ .../support/ScriptValueConverter.java | 183 ++++++++++ .../support/ScriptableLinkedHashMap.java | 188 ++++++++++ .../javascript/support/ScriptableMap.java | 32 ++ .../support/ScriptableWrappedMap.java | 342 ++++++++++++++++++ src/main/resources/es-plugin.properties | 1 + .../JavaScriptScriptEngineTests.java | 174 +++++++++ .../JavaScriptScriptMultiThreadedTest.java | 174 +++++++++ .../JavaScriptScriptSearchTests.java | 267 ++++++++++++++ .../script/javascript/SimpleBench.java | 71 ++++ src/test/resources/log4j.properties | 5 + 18 files changed, 2383 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/assemblies/plugin.xml create mode 100644 src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java create mode 100644 src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java create mode 100644 src/main/java/org/elasticsearch/script/javascript/support/NativeList.java create mode 100644 src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java create mode 100644 src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java create mode 100644 src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java create mode 100644 src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java create mode 100644 src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java create mode 100644 src/main/resources/es-plugin.properties create mode 100644 src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java create mode 100644 src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java create mode 100644 src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java create mode 100644 src/test/java/org/elasticsearch/script/javascript/SimpleBench.java create mode 100644 src/test/resources/log4j.properties diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..06a1e6fedb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/data +/work +/logs +/.idea +/target +.DS_Store +*.iml diff --git a/README.md b/README.md new file mode 100644 index 00000000000..f56c629bfae --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +JavaScript lang Plugin for ElasticSearch +================================== + +The JavaScript language plugin allows to have `javascript` as the language of scripts to execute. + +In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.0.0`. + + --------------------------------------- + | AWS Cloud Plugin | ElasticSearch | + --------------------------------------- + | master | 0.18 -> master | + --------------------------------------- + | 1.0.0 | 0.18 -> master | + --------------------------------------- + diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000000..87365b528d6 --- /dev/null +++ b/pom.xml @@ -0,0 +1,122 @@ + + + elasticsearch-lang-javascript + 4.0.0 + org.elasticsearch + elasticsearch-lang-javascript + 1.0.0 + jar + JavaScript lang plugin for ElasticSearch + 2009 + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git + scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git + http://github.com/elasticsearch/elasticsearch-lang-javascript + + + + org.sonatype.oss + oss-parent + 7 + + + + 0.18.5 + + + + + + + + org.elasticsearch + elasticsearch + ${elasticsearch.version} + compile + + + + org.mozilla + rhino + 1.7R3 + compile + + + + + + org.testng + testng + 6.3.1 + test + + + + org.hamcrest + hamcrest-core + 1.3.RC2 + test + + + + org.hamcrest + hamcrest-library + 1.3.RC2 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.11 + + + **/*Tests.java + + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + + jar + + + + + + maven-assembly-plugin + + + ${basedir}/src/main/assemblies/plugin.xml + + + + + + \ No newline at end of file diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml new file mode 100644 index 00000000000..2a637316fa0 --- /dev/null +++ b/src/main/assemblies/plugin.xml @@ -0,0 +1,26 @@ + + + + + zip + + false + + + / + true + true + + org.elasticsearch:elasticsearch + + + + / + true + true + + org.mozilla:rhino + + + + \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java b/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java new file mode 100644 index 00000000000..670194d2c4a --- /dev/null +++ b/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java @@ -0,0 +1,48 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.plugin.javascript; + +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.script.ScriptModule; +import org.elasticsearch.script.javascript.JavaScriptScriptEngineService; + +/** + * + */ +public class JavaScriptPlugin extends AbstractPlugin { + + @Override + public String name() { + return "lang-javascript"; + } + + @Override + public String description() { + return "JavaScript plugin allowing to add javascript scripting support"; + } + + @Override + public void processModule(Module module) { + if (module instanceof ScriptModule) { + ((ScriptModule) module).addScriptEngine(JavaScriptScriptEngineService.class); + } + } +} diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java new file mode 100644 index 00000000000..d1d35d453bb --- /dev/null +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -0,0 +1,298 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript; + +import org.apache.lucene.index.IndexReader; +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.settings.Settings; +import org.elasticsearch.script.ExecutableScript; +import org.elasticsearch.script.ScriptEngineService; +import org.elasticsearch.script.SearchScript; +import org.elasticsearch.script.javascript.support.NativeList; +import org.elasticsearch.script.javascript.support.NativeMap; +import org.elasticsearch.script.javascript.support.ScriptValueConverter; +import org.elasticsearch.search.lookup.SearchLookup; +import org.mozilla.javascript.*; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +/** + * + */ +public class JavaScriptScriptEngineService extends AbstractComponent implements ScriptEngineService { + + private final AtomicLong counter = new AtomicLong(); + + private static WrapFactory wrapFactory = new CustomWrapFactory(); + + private final int optimizationLevel; + + private Scriptable globalScope; + + @Inject + public JavaScriptScriptEngineService(Settings settings) { + super(settings); + + this.optimizationLevel = componentSettings.getAsInt("optimization_level", 1); + + Context ctx = Context.enter(); + try { + ctx.setWrapFactory(wrapFactory); + globalScope = ctx.initStandardObjects(null, true); + } finally { + Context.exit(); + } + } + + @Override + public void close() { + + } + + @Override + public String[] types() { + return new String[]{"js", "javascript"}; + } + + @Override + public String[] extensions() { + return new String[]{"js"}; + } + + @Override + public Object compile(String script) { + Context ctx = Context.enter(); + try { + ctx.setWrapFactory(wrapFactory); + ctx.setOptimizationLevel(optimizationLevel); + return ctx.compileString(script, generateScriptName(), 1, null); + } finally { + Context.exit(); + } + } + + @Override + public ExecutableScript executable(Object compiledScript, Map vars) { + Context ctx = Context.enter(); + try { + ctx.setWrapFactory(wrapFactory); + + Scriptable scope = ctx.newObject(globalScope); + scope.setPrototype(globalScope); + scope.setParentScope(null); + for (Map.Entry entry : vars.entrySet()) { + ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); + } + + return new JavaScriptExecutableScript((Script) compiledScript, scope); + } finally { + Context.exit(); + } + } + + @Override + public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map vars) { + Context ctx = Context.enter(); + try { + ctx.setWrapFactory(wrapFactory); + + Scriptable scope = ctx.newObject(globalScope); + scope.setPrototype(globalScope); + scope.setParentScope(null); + + for (Map.Entry entry : lookup.asMap().entrySet()) { + ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); + } + + if (vars != null) { + for (Map.Entry entry : vars.entrySet()) { + ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); + } + } + + return new JavaScriptSearchScript((Script) compiledScript, scope, lookup); + } finally { + Context.exit(); + } + } + + @Override + public Object execute(Object compiledScript, Map vars) { + Context ctx = Context.enter(); + ctx.setWrapFactory(wrapFactory); + try { + Script script = (Script) compiledScript; + Scriptable scope = ctx.newObject(globalScope); + scope.setPrototype(globalScope); + scope.setParentScope(null); + + for (Map.Entry entry : vars.entrySet()) { + ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); + } + Object ret = script.exec(ctx, scope); + return ScriptValueConverter.unwrapValue(ret); + } finally { + Context.exit(); + } + } + + @Override + public Object unwrap(Object value) { + return ScriptValueConverter.unwrapValue(value); + } + + private String generateScriptName() { + return "Script" + counter.incrementAndGet() + ".js"; + } + + public static class JavaScriptExecutableScript implements ExecutableScript { + + private final Script script; + + private final Scriptable scope; + + public JavaScriptExecutableScript(Script script, Scriptable scope) { + this.script = script; + this.scope = scope; + } + + @Override + public Object run() { + Context ctx = Context.enter(); + try { + ctx.setWrapFactory(wrapFactory); + return ScriptValueConverter.unwrapValue(script.exec(ctx, scope)); + } finally { + Context.exit(); + } + } + + @Override + public void setNextVar(String name, Object value) { + ScriptableObject.putProperty(scope, name, value); + } + + @Override + public Object unwrap(Object value) { + return ScriptValueConverter.unwrapValue(value); + } + } + + public static class JavaScriptSearchScript implements SearchScript { + + private final Script script; + + private final Scriptable scope; + + private final SearchLookup lookup; + + public JavaScriptSearchScript(Script script, Scriptable scope, SearchLookup lookup) { + this.script = script; + this.scope = scope; + this.lookup = lookup; + } + + @Override + public void setScorer(Scorer scorer) { + lookup.setScorer(scorer); + } + + @Override + public void setNextReader(IndexReader reader) { + lookup.setNextReader(reader); + } + + @Override + public void setNextDocId(int doc) { + lookup.setNextDocId(doc); + } + + @Override + public void setNextScore(float score) { + ScriptableObject.putProperty(scope, "_score", score); + } + + @Override + public void setNextVar(String name, Object value) { + ScriptableObject.putProperty(scope, name, value); + } + + @Override + public void setNextSource(Map source) { + lookup.source().setNextSource(source); + } + + @Override + public Object run() { + Context ctx = Context.enter(); + try { + ctx.setWrapFactory(wrapFactory); + return ScriptValueConverter.unwrapValue(script.exec(ctx, scope)); + } finally { + Context.exit(); + } + } + + @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 ScriptValueConverter.unwrapValue(value); + } + } + + /** + * Wrap Factory for Rhino Script Engine + */ + public static class CustomWrapFactory extends WrapFactory { + + public CustomWrapFactory() { + setJavaPrimitiveWrap(false); // RingoJS does that..., claims its annoying... + } + + public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) { + if (javaObject instanceof Map) { + return new NativeMap(scope, (Map) javaObject); + } + if (javaObject instanceof List) { + return new NativeList(scope, (List) javaObject); + } + return super.wrapAsJavaObject(cx, scope, javaObject, staticType); + } + } +} diff --git a/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java b/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java new file mode 100644 index 00000000000..c2345dc2bfc --- /dev/null +++ b/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java @@ -0,0 +1,207 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript.support; + +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Undefined; +import org.mozilla.javascript.Wrapper; + +import java.util.List; + +/** + * + */ +public class NativeList implements Scriptable, Wrapper { + private static final long serialVersionUID = 3664761893203964569L; + + private List list; + private Scriptable parentScope; + private Scriptable prototype; + + + public static NativeList wrap(Scriptable scope, List list) { + return new NativeList(scope, list); + } + + public NativeList(Scriptable scope, List list) { + this.parentScope = scope; + this.list = list; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Wrapper#unwrap() + */ + + public Object unwrap() { + return list; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getClassName() + */ + + public String getClassName() { + return "NativeList"; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) + */ + + public Object get(String name, Scriptable start) { + if ("length".equals(name)) { + return list.size(); + } else { + return Undefined.instance; + } + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) + */ + + public Object get(int index, Scriptable start) { + if (index < 0 || index >= list.size()) { + return Undefined.instance; + } + return list.get(index); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) + */ + + public boolean has(String name, Scriptable start) { + if ("length".equals(name)) { + return true; + } + return false; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) + */ + + public boolean has(int index, Scriptable start) { + return index >= 0 && index < list.size(); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) + */ + + @SuppressWarnings("unchecked") + public void put(String name, Scriptable start, Object value) { + // do nothing here... + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) + */ + + public void put(int index, Scriptable start, Object value) { + if (index == list.size()) { + list.add(value); + } else { + list.set(index, value); + } + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) + */ + + public void delete(String name) { + // nothing here + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#delete(int) + */ + + public void delete(int index) { + list.remove(index); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getPrototype() + */ + + public Scriptable getPrototype() { + return this.prototype; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) + */ + + public void setPrototype(Scriptable prototype) { + this.prototype = prototype; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getParentScope() + */ + + public Scriptable getParentScope() { + return this.parentScope; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) + */ + + public void setParentScope(Scriptable parent) { + this.parentScope = parent; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getIds() + */ + + public Object[] getIds() { + int size = list.size(); + Object[] ids = new Object[size]; + for (int i = 0; i < size; ++i) { + ids[i] = i; + } + return ids; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) + */ + + public Object getDefaultValue(Class hint) { + return null; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) + */ + + public boolean hasInstance(Scriptable value) { + if (!(value instanceof Wrapper)) + return false; + Object instance = ((Wrapper) value).unwrap(); + return List.class.isInstance(instance); + } + +} diff --git a/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java b/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java new file mode 100644 index 00000000000..f36ce23a8b3 --- /dev/null +++ b/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java @@ -0,0 +1,223 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript.support; + +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Wrapper; + +import java.util.Iterator; +import java.util.Map; + +/** + * Wrapper for exposing maps in Rhino scripts. + * + * + */ +public class NativeMap implements Scriptable, Wrapper { + private static final long serialVersionUID = 3664761893203964569L; + + private Map map; + private Scriptable parentScope; + private Scriptable prototype; + + + /** + * Construct + * + * @param scope + * @param map + * @return native map + */ + public static NativeMap wrap(Scriptable scope, Map map) { + return new NativeMap(scope, map); + } + + /** + * Construct + * + * @param scope + * @param map + */ + public NativeMap(Scriptable scope, Map map) { + this.parentScope = scope; + this.map = map; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Wrapper#unwrap() + */ + + public Object unwrap() { + return map; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getClassName() + */ + + public String getClassName() { + return "NativeMap"; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) + */ + + public Object get(String name, Scriptable start) { + // get the property from the underlying QName map + if ("length".equals(name)) { + return map.size(); + } else { + return map.get(name); + } + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) + */ + + public Object get(int index, Scriptable start) { + Object value = null; + int i = 0; + Iterator itrValues = map.values().iterator(); + while (i++ <= index && itrValues.hasNext()) { + value = itrValues.next(); + } + return value; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) + */ + + public boolean has(String name, Scriptable start) { + // locate the property in the underlying map + return map.containsKey(name); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) + */ + + public boolean has(int index, Scriptable start) { + return (index >= 0 && map.values().size() > index); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) + */ + + @SuppressWarnings("unchecked") + public void put(String name, Scriptable start, Object value) { + map.put(name, value); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) + */ + + public void put(int index, Scriptable start, Object value) { + // TODO: implement? + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) + */ + + public void delete(String name) { + map.remove(name); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#delete(int) + */ + + public void delete(int index) { + int i = 0; + Iterator itrKeys = map.keySet().iterator(); + while (i <= index && itrKeys.hasNext()) { + Object key = itrKeys.next(); + if (i == index) { + map.remove(key); + break; + } + } + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getPrototype() + */ + + public Scriptable getPrototype() { + return this.prototype; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) + */ + + public void setPrototype(Scriptable prototype) { + this.prototype = prototype; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getParentScope() + */ + + public Scriptable getParentScope() { + return this.parentScope; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) + */ + + public void setParentScope(Scriptable parent) { + this.parentScope = parent; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getIds() + */ + + public Object[] getIds() { + return map.keySet().toArray(); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) + */ + + public Object getDefaultValue(Class hint) { + return null; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) + */ + + public boolean hasInstance(Scriptable value) { + if (!(value instanceof Wrapper)) + return false; + Object instance = ((Wrapper) value).unwrap(); + return Map.class.isInstance(instance); + } + +} diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java new file mode 100644 index 00000000000..e7bedb40487 --- /dev/null +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java @@ -0,0 +1,183 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript.support; + +import org.mozilla.javascript.*; + +import java.util.*; + +/** + * Value Converter to marshal objects between Java and Javascript. + * + * + */ +public final class ScriptValueConverter { + private static final String TYPE_DATE = "Date"; + + + /** + * Private constructor - methods are static + */ + private ScriptValueConverter() { + } + + /** + * Convert an object from a script wrapper value to a serializable value valid outside + * of the Rhino script processor context. + *

+ * This includes converting JavaScript Array objects to Lists of valid objects. + * + * @param value Value to convert from script wrapper object to external object value. + * @return unwrapped and converted value. + */ + public static Object unwrapValue(Object value) { + if (value == null) { + return null; + } else if (value instanceof Wrapper) { + // unwrap a Java object from a JavaScript wrapper + // recursively call this method to convert the unwrapped value + value = unwrapValue(((Wrapper) value).unwrap()); + } else if (value instanceof IdScriptableObject) { + // check for special case Native object wrappers + String className = ((IdScriptableObject) value).getClassName(); + // check for special case of the String object + if ("String".equals(className)) { + value = Context.jsToJava(value, String.class); + } + // check for special case of a Date object + else if ("Date".equals(className)) { + value = Context.jsToJava(value, Date.class); + } else { + // a scriptable object will probably indicate a multi-value property set + // set using a JavaScript associative Array object + Scriptable values = (Scriptable) value; + Object[] propIds = values.getIds(); + + // is it a JavaScript associative Array object using Integer indexes? + if (values instanceof NativeArray && isArray(propIds)) { + // convert JavaScript array of values to a List of Serializable objects + List propValues = new ArrayList(propIds.length); + for (int i = 0; i < propIds.length; i++) { + // work on each key in turn + Integer propId = (Integer) propIds[i]; + + // we are only interested in keys that indicate a list of values + if (propId instanceof Integer) { + // get the value out for the specified key + Object val = values.get(propId, values); + // recursively call this method to convert the value + propValues.add(unwrapValue(val)); + } + } + + value = propValues; + } else { + // any other JavaScript object that supports properties - convert to a Map of objects + Map propValues = new HashMap(propIds.length); + for (int i = 0; i < propIds.length; i++) { + // work on each key in turn + Object propId = propIds[i]; + + // we are only interested in keys that indicate a list of values + if (propId instanceof String) { + // get the value out for the specified key + Object val = values.get((String) propId, values); + // recursively call this method to convert the value + propValues.put((String) propId, unwrapValue(val)); + } + } + value = propValues; + } + } + } else if (value instanceof Object[]) { + // convert back a list Object Java values + Object[] array = (Object[]) value; + ArrayList list = new ArrayList(array.length); + for (int i = 0; i < array.length; i++) { + list.add(unwrapValue(array[i])); + } + value = list; + } else if (value instanceof Map) { + // ensure each value in the Map is unwrapped (which may have been an unwrapped NativeMap!) + Map map = (Map) value; + Map copyMap = new HashMap(map.size()); + for (Object key : map.keySet()) { + copyMap.put(key, unwrapValue(map.get(key))); + } + value = copyMap; + } + return value; + } + + /** + * Convert an object from any repository serialized value to a valid script object. + * This includes converting Collection multi-value properties into JavaScript Array objects. + * + * @param scope Scripting scope + * @param value Property value + * @return Value safe for scripting usage + */ + public static Object wrapValue(Scriptable scope, Object value) { + // perform conversions from Java objects to JavaScript scriptable instances + if (value == null) { + return null; + } else if (value instanceof Date) { + // convert Date to JavaScript native Date object + // call the "Date" constructor on the root scope object - passing in the millisecond + // value from the Java date - this will construct a JavaScript Date with the same value + Date date = (Date) value; + value = ScriptRuntime.newObject( + Context.getCurrentContext(), scope, TYPE_DATE, new Object[]{date.getTime()}); + } else if (value instanceof Collection) { + // recursively convert each value in the collection + Collection collection = (Collection) value; + Object[] array = new Object[collection.size()]; + int index = 0; + for (Object obj : collection) { + array[index++] = wrapValue(scope, obj); + } + // convert array to a native JavaScript Array + value = Context.getCurrentContext().newArray(scope, array); + } else if (value instanceof Map) { + value = new NativeMap(scope, (Map) value); + } + + // simple numbers, strings and booleans are wrapped automatically by Rhino + + return value; + } + + /** + * Look at the id's of a native array and try to determine whether it's actually an Array or a Hashmap + * + * @param ids id's of the native array + * @return boolean true if it's an array, false otherwise (ie it's a map) + */ + private static boolean isArray(final Object[] ids) { + boolean result = true; + for (int i = 0; i < ids.length; i++) { + if (ids[i] instanceof Integer == false) { + result = false; + break; + } + } + return result; + } +} diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java new file mode 100644 index 00000000000..88d34d7251e --- /dev/null +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java @@ -0,0 +1,188 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript.support; + +import org.mozilla.javascript.Scriptable; + +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Implementation of a Scriptable Map. This is the best choice for maps that want to represent + * JavaScript associative arrays - allowing access via key and integer index. It maintains and + * respects insertion order of the elements and allows either string or integer keys. + * + * + */ +public class ScriptableLinkedHashMap extends LinkedHashMap implements ScriptableMap { + private static final long serialVersionUID = 3774167893214964123L; + + private Scriptable parentScope; + private Scriptable prototype; + + + public ScriptableLinkedHashMap() { + } + + public ScriptableLinkedHashMap(int initialCapacity) { + super(initialCapacity); + } + + public ScriptableLinkedHashMap(Map source) { + super(source); + } + + /** + * @see org.mozilla.javascript.Scriptable#getClassName() + */ + public String getClassName() { + return "ScriptableMap"; + } + + /** + * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) + */ + public Object get(String name, Scriptable start) { + // get the property from the underlying QName map + if ("length".equals(name)) { + return this.size(); + } else { + return get(name); + } + } + + /** + * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) + */ + public Object get(int index, Scriptable start) { + Object value = null; + int i = 0; + Iterator itrValues = this.values().iterator(); + while (i++ <= index && itrValues.hasNext()) { + value = itrValues.next(); + } + return value; + } + + /** + * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) + */ + public boolean has(String name, Scriptable start) { + // locate the property in the underlying map + return containsKey(name); + } + + /** + * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) + */ + public boolean has(int index, Scriptable start) { + return (index >= 0 && this.values().size() > index); + } + + /** + * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) + */ + @SuppressWarnings("unchecked") + public void put(String name, Scriptable start, Object value) { + // add the property to the underlying QName map + put((K) name, (V) value); + } + + /** + * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) + */ + public void put(int index, Scriptable start, Object value) { + // TODO: implement? + } + + /** + * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) + */ + public void delete(String name) { + // remove the property from the underlying QName map + remove(name); + } + + /** + * @see org.mozilla.javascript.Scriptable#delete(int) + */ + public void delete(int index) { + int i = 0; + Iterator itrKeys = this.keySet().iterator(); + while (i <= index && itrKeys.hasNext()) { + Object key = itrKeys.next(); + if (i == index) { + remove(key); + break; + } + } + } + + /** + * @see org.mozilla.javascript.Scriptable#getPrototype() + */ + public Scriptable getPrototype() { + return this.prototype; + } + + /** + * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) + */ + public void setPrototype(Scriptable prototype) { + this.prototype = prototype; + } + + /** + * @see org.mozilla.javascript.Scriptable#getParentScope() + */ + public Scriptable getParentScope() { + return this.parentScope; + } + + /** + * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) + */ + public void setParentScope(Scriptable parent) { + this.parentScope = parent; + } + + /** + * @see org.mozilla.javascript.Scriptable#getIds() + */ + public Object[] getIds() { + return keySet().toArray(); + } + + /** + * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) + */ + public Object getDefaultValue(Class hint) { + return null; + } + + /** + * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) + */ + public boolean hasInstance(Scriptable instance) { + return instance instanceof ScriptableLinkedHashMap; + } +} + diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java new file mode 100644 index 00000000000..a7319c26027 --- /dev/null +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java @@ -0,0 +1,32 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript.support; + +import org.mozilla.javascript.Scriptable; + +import java.util.Map; + +/** + * Contract to be implemented by classes providing Map like collections to JavaScript. + * + * + */ +public interface ScriptableMap extends Scriptable, Map { +} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java new file mode 100644 index 00000000000..e78a92464df --- /dev/null +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java @@ -0,0 +1,342 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript.support; + +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Wrapper; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * Implementation of a Scriptable Map. This is the best choice where you want values to be + * persisted directly to an underlying map supplied on construction. The class automatically + * wraps/unwraps JS objects as they enter/leave the underlying map via the Scriptable interface + * methods - objects are untouched if accessed via the usual Map interface methods. + *

+ *

Access should be by string key only - not integer index - unless you are sure the wrapped + * map will maintain insertion order of the elements. + * + * + */ +public class ScriptableWrappedMap implements ScriptableMap, Wrapper { + private Map map; + private Scriptable parentScope; + private Scriptable prototype; + + + /** + * Construction + * + * @param scope + * @param map + * @return scriptable wrapped map + */ + public static ScriptableWrappedMap wrap(Scriptable scope, Map map) { + return new ScriptableWrappedMap(scope, map); + } + + /** + * Construct + * + * @param map + */ + public ScriptableWrappedMap(Map map) { + this.map = map; + } + + /** + * Construct + * + * @param scope + * @param map + */ + public ScriptableWrappedMap(Scriptable scope, Map map) { + this.parentScope = scope; + this.map = map; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Wrapper#unwrap() + */ + + public Object unwrap() { + return map; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getClassName() + */ + + public String getClassName() { + return "ScriptableWrappedMap"; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) + */ + + public Object get(String name, Scriptable start) { + // get the property from the underlying QName map + if ("length".equals(name)) { + return map.size(); + } else { + return ScriptValueConverter.wrapValue(this.parentScope != null ? this.parentScope : start, map.get(name)); + } + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) + */ + + public Object get(int index, Scriptable start) { + Object value = null; + int i = 0; + Iterator itrValues = map.values().iterator(); + while (i++ <= index && itrValues.hasNext()) { + value = itrValues.next(); + } + return ScriptValueConverter.wrapValue(this.parentScope != null ? this.parentScope : start, value); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) + */ + + public boolean has(String name, Scriptable start) { + // locate the property in the underlying map + return map.containsKey(name); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) + */ + + public boolean has(int index, Scriptable start) { + return (index >= 0 && map.values().size() > index); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) + */ + + @SuppressWarnings("unchecked") + public void put(String name, Scriptable start, Object value) { + map.put(name, ScriptValueConverter.unwrapValue(value)); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) + */ + + public void put(int index, Scriptable start, Object value) { + // TODO: implement? + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) + */ + + public void delete(String name) { + map.remove(name); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#delete(int) + */ + + public void delete(int index) { + int i = 0; + Iterator itrKeys = map.keySet().iterator(); + while (i <= index && itrKeys.hasNext()) { + Object key = itrKeys.next(); + if (i == index) { + map.remove(key); + break; + } + } + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getPrototype() + */ + + public Scriptable getPrototype() { + return this.prototype; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) + */ + + public void setPrototype(Scriptable prototype) { + this.prototype = prototype; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getParentScope() + */ + + public Scriptable getParentScope() { + return this.parentScope; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) + */ + + public void setParentScope(Scriptable parent) { + this.parentScope = parent; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getIds() + */ + + public Object[] getIds() { + return map.keySet().toArray(); + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) + */ + + public Object getDefaultValue(Class hint) { + return null; + } + + /* (non-Javadoc) + * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) + */ + + public boolean hasInstance(Scriptable value) { + if (!(value instanceof Wrapper)) + return false; + Object instance = ((Wrapper) value).unwrap(); + return Map.class.isInstance(instance); + } + + /* (non-Javadoc) + * @see java.util.Map#clear() + */ + + public void clear() { + this.map.clear(); + } + + /* (non-Javadoc) + * @see java.util.Map#containsKey(java.lang.Object) + */ + + public boolean containsKey(Object key) { + return this.map.containsKey(key); + } + + /* (non-Javadoc) + * @see java.util.Map#containsValue(java.lang.Object) + */ + + public boolean containsValue(Object value) { + return this.map.containsValue(value); + } + + /* (non-Javadoc) + * @see java.util.Map#entrySet() + */ + + public Set entrySet() { + return this.map.entrySet(); + } + + /* (non-Javadoc) + * @see java.util.Map#get(java.lang.Object) + */ + + public Object get(Object key) { + return this.map.get(key); + } + + /* (non-Javadoc) + * @see java.util.Map#isEmpty() + */ + + public boolean isEmpty() { + return (this.map.size() == 0); + } + + /* (non-Javadoc) + * @see java.util.Map#keySet() + */ + + public Set keySet() { + return this.map.keySet(); + } + + /* (non-Javadoc) + * @see java.util.Map#put(java.lang.Object, java.lang.Object) + */ + + public Object put(Object key, Object value) { + return this.map.put(key, value); + } + + /* (non-Javadoc) + * @see java.util.Map#putAll(java.util.Map) + */ + + public void putAll(Map t) { + this.map.putAll(t); + } + + /* (non-Javadoc) + * @see java.util.Map#remove(java.lang.Object) + */ + + public Object remove(Object key) { + return this.map.remove(key); + } + + /* (non-Javadoc) + * @see java.util.Map#size() + */ + + public int size() { + return this.map.size(); + } + + /* (non-Javadoc) + * @see java.util.Map#values() + */ + + public Collection values() { + return this.map.values(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + + @Override + public String toString() { + return (this.map != null ? this.map.toString() : super.toString()); + } +} diff --git a/src/main/resources/es-plugin.properties b/src/main/resources/es-plugin.properties new file mode 100644 index 00000000000..e88bdca70c8 --- /dev/null +++ b/src/main/resources/es-plugin.properties @@ -0,0 +1 @@ +plugin=org.elasticsearch.plugin.javascript.JavaScriptPlugin diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java new file mode 100644 index 00000000000..fe59d4aac57 --- /dev/null +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java @@ -0,0 +1,174 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript; + +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.MapBuilder; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.script.ExecutableScript; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; + +/** + * + */ +public class JavaScriptScriptEngineTests { + + private JavaScriptScriptEngineService se; + + @BeforeClass + public void setup() { + se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + } + + @AfterClass + public void close() { + se.close(); + } + + @Test + public void testSimpleEquation() { + Map vars = new HashMap(); + Object o = se.execute(se.compile("1 + 2"), vars); + assertThat(((Number) o).intValue(), equalTo(3)); + } + + @Test + public void testMapAccess() { + Map vars = new HashMap(); + + Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); + Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).put("l", Lists.newArrayList("2", "1")).map(); + vars.put("obj1", obj1); + Object o = se.execute(se.compile("obj1"), vars); + assertThat(o, instanceOf(Map.class)); + obj1 = (Map) o; + assertThat((String) obj1.get("prop1"), equalTo("value1")); + assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); + + o = se.execute(se.compile("obj1.l[0]"), vars); + assertThat(((String) o), equalTo("2")); + } + + @Test + public void testJavaScriptObjectToMap() { + Map vars = new HashMap(); + Object o = se.execute(se.compile("var obj1 = {}; obj1.prop1 = 'value1'; obj1.obj2 = {}; obj1.obj2.prop2 = 'value2'; obj1"), vars); + Map obj1 = (Map) o; + assertThat((String) obj1.get("prop1"), equalTo("value1")); + assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); + } + + @Test + public void testJavaScriptObjectMapInter() { + Map vars = new HashMap(); + Map ctx = new HashMap(); + Map obj1 = new HashMap(); + obj1.put("prop1", "value1"); + ctx.put("obj1", obj1); + vars.put("ctx", ctx); + + se.execute(se.compile("ctx.obj2 = {}; ctx.obj2.prop2 = 'value2'; ctx.obj1.prop1 = 'uvalue1'"), vars); + ctx = (Map) se.unwrap(vars.get("ctx")); + assertThat(ctx.containsKey("obj1"), equalTo(true)); + assertThat((String) ((Map) ctx.get("obj1")).get("prop1"), equalTo("uvalue1")); + assertThat(ctx.containsKey("obj2"), equalTo(true)); + assertThat((String) ((Map) ctx.get("obj2")).get("prop2"), equalTo("value2")); + } + + @Test + public void testJavaScriptInnerArrayCreation() { + Map ctx = new HashMap(); + Map doc = new HashMap(); + ctx.put("doc", doc); + + Object complied = se.compile("ctx.doc.field1 = ['value1', 'value2']"); + ExecutableScript script = se.executable(complied, new HashMap()); + script.setNextVar("ctx", ctx); + script.run(); + + Map unwrap = (Map) script.unwrap(ctx); + + assertThat(((Map) unwrap.get("doc")).get("field1"), instanceOf(List.class)); + } + + @Test + public void testAccessListInScript() { + Map vars = new HashMap(); + Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); + Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).map(); + vars.put("l", Lists.newArrayList("1", "2", "3", obj1)); + + Object o = se.execute(se.compile("l.length"), vars); + assertThat(((Number) o).intValue(), equalTo(4)); + + o = se.execute(se.compile("l[0]"), vars); + assertThat(((String) o), equalTo("1")); + + o = se.execute(se.compile("l[3]"), vars); + obj1 = (Map) o; + assertThat((String) obj1.get("prop1"), equalTo("value1")); + assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); + + o = se.execute(se.compile("l[3].prop1"), vars); + assertThat(((String) o), equalTo("value1")); + } + + @Test + public void testChangingVarsCrossExecution1() { + Map vars = new HashMap(); + Map ctx = new HashMap(); + vars.put("ctx", ctx); + Object compiledScript = se.compile("ctx.value"); + + ExecutableScript script = se.executable(compiledScript, vars); + ctx.put("value", 1); + Object o = script.run(); + assertThat(((Number) o).intValue(), equalTo(1)); + + ctx.put("value", 2); + o = script.run(); + assertThat(((Number) o).intValue(), equalTo(2)); + } + + @Test + public void testChangingVarsCrossExecution2() { + Map vars = new HashMap(); + Object compiledScript = se.compile("value"); + + ExecutableScript script = se.executable(compiledScript, vars); + script.setNextVar("value", 1); + Object o = script.run(); + assertThat(((Number) o).intValue(), equalTo(1)); + + script.setNextVar("value", 2); + o = script.run(); + assertThat(((Number) o).intValue(), equalTo(2)); + } +} diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java new file mode 100644 index 00000000000..9cbdc2cc782 --- /dev/null +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java @@ -0,0 +1,174 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript; + +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom; +import org.elasticsearch.script.ExecutableScript; +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +/** + * + */ +@Test +public class JavaScriptScriptMultiThreadedTest { + + protected final ESLogger logger = Loggers.getLogger(getClass()); + + @Test + public void testExecutableNoRuntimeParams() throws Exception { + final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + final Object compiled = se.compile("x + y"); + final AtomicBoolean failed = new AtomicBoolean(); + + Thread[] threads = new Thread[50]; + final CountDownLatch latch = new CountDownLatch(threads.length); + final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread(new Runnable() { + @Override + public void run() { + try { + barrier.await(); + long x = ThreadLocalRandom.current().nextInt(); + long y = ThreadLocalRandom.current().nextInt(); + long addition = x + y; + Map vars = new HashMap(); + vars.put("x", x); + vars.put("y", y); + ExecutableScript script = se.executable(compiled, vars); + for (int i = 0; i < 100000; i++) { + long result = ((Number) script.run()).longValue(); + assertThat(result, equalTo(addition)); + } + } catch (Throwable t) { + failed.set(true); + logger.error("failed", t); + } finally { + latch.countDown(); + } + } + }); + } + for (int i = 0; i < threads.length; i++) { + threads[i].start(); + } + barrier.await(); + latch.await(); + assertThat(failed.get(), equalTo(false)); + } + + + @Test + public void testExecutableWithRuntimeParams() throws Exception { + final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + final Object compiled = se.compile("x + y"); + final AtomicBoolean failed = new AtomicBoolean(); + + Thread[] threads = new Thread[50]; + final CountDownLatch latch = new CountDownLatch(threads.length); + final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread(new Runnable() { + @Override + public void run() { + try { + barrier.await(); + long x = ThreadLocalRandom.current().nextInt(); + Map vars = new HashMap(); + vars.put("x", x); + ExecutableScript script = se.executable(compiled, vars); + for (int i = 0; i < 100000; i++) { + long y = ThreadLocalRandom.current().nextInt(); + long addition = x + y; + script.setNextVar("y", y); + long result = ((Number) script.run()).longValue(); + assertThat(result, equalTo(addition)); + } + } catch (Throwable t) { + failed.set(true); + logger.error("failed", t); + } finally { + latch.countDown(); + } + } + }); + } + for (int i = 0; i < threads.length; i++) { + threads[i].start(); + } + barrier.await(); + latch.await(); + assertThat(failed.get(), equalTo(false)); + } + + @Test + public void testExecute() throws Exception { + final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + final Object compiled = se.compile("x + y"); + final AtomicBoolean failed = new AtomicBoolean(); + + Thread[] threads = new Thread[50]; + final CountDownLatch latch = new CountDownLatch(threads.length); + final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread(new Runnable() { + @Override + public void run() { + try { + barrier.await(); + Map runtimeVars = new HashMap(); + for (int i = 0; i < 100000; i++) { + long x = ThreadLocalRandom.current().nextInt(); + long y = ThreadLocalRandom.current().nextInt(); + long addition = x + y; + runtimeVars.put("x", x); + runtimeVars.put("y", y); + long result = ((Number) se.execute(compiled, runtimeVars)).longValue(); + assertThat(result, equalTo(addition)); + } + } catch (Throwable t) { + failed.set(true); + logger.error("failed", t); + } finally { + latch.countDown(); + } + } + }); + } + for (int i = 0; i < threads.length; i++) { + threads[i].start(); + } + barrier.await(); + latch.await(); + assertThat(failed.get(), equalTo(false)); + } +} diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java new file mode 100644 index 00000000000..110fe81709a --- /dev/null +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -0,0 +1,267 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript; + +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.network.NetworkUtils; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.node.Node; +import org.elasticsearch.node.NodeBuilder; +import org.elasticsearch.search.sort.SortOrder; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.Map; + +import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.index.query.FilterBuilders.scriptFilter; +import static org.elasticsearch.index.query.QueryBuilders.*; +import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +/** + * + */ +@Test +public class JavaScriptScriptSearchTests { + + protected final ESLogger logger = Loggers.getLogger(getClass()); + + private Node node; + + private Client client; + + @BeforeMethod + public void createNodes() throws Exception { + node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder() + .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()) + .put("gateway.type", "none") + .put("number_of_shards", 1)).node(); + client = node.client(); + } + + @AfterMethod + public void closeNodes() { + client.close(); + node.close(); + } + + @Test + public void testJavaScriptFilter() throws Exception { + client.admin().indices().prepareCreate("test").execute().actionGet(); + client.prepareIndex("test", "type1", "1") + .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()) + .execute().actionGet(); + client.admin().indices().prepareFlush().execute().actionGet(); + client.prepareIndex("test", "type1", "2") + .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject()) + .execute().actionGet(); + client.admin().indices().prepareFlush().execute().actionGet(); + client.prepareIndex("test", "type1", "3") + .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject()) + .execute().actionGet(); + client.admin().indices().refresh(refreshRequest()).actionGet(); + + logger.info("running doc['num1'].value > 1"); + SearchResponse response = client.prepareSearch() + .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > 1").lang("js"))) + .addSort("num1", SortOrder.ASC) + .addScriptField("sNum1", "js", "doc['num1'].value", null) + .execute().actionGet(); + + assertThat(response.hits().totalHits(), equalTo(2l)); + assertThat(response.hits().getAt(0).id(), equalTo("2")); + assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); + assertThat(response.hits().getAt(1).id(), equalTo("3")); + assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); + + logger.info("running doc['num1'].value > param1"); + response = client.prepareSearch() + .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", 2))) + .addSort("num1", SortOrder.ASC) + .addScriptField("sNum1", "js", "doc['num1'].value", null) + .execute().actionGet(); + + assertThat(response.hits().totalHits(), equalTo(1l)); + assertThat(response.hits().getAt(0).id(), equalTo("3")); + assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); + + logger.info("running doc['num1'].value > param1"); + response = client.prepareSearch() + .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", -1))) + .addSort("num1", SortOrder.ASC) + .addScriptField("sNum1", "js", "doc['num1'].value", null) + .execute().actionGet(); + + assertThat(response.hits().totalHits(), equalTo(3l)); + assertThat(response.hits().getAt(0).id(), equalTo("1")); + assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); + assertThat(response.hits().getAt(1).id(), equalTo("2")); + assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); + assertThat(response.hits().getAt(2).id(), equalTo("3")); + assertThat((Double) response.hits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); + } + + @Test + public void testScriptFieldUsingSource() throws Exception { + client.admin().indices().prepareCreate("test").execute().actionGet(); + client.prepareIndex("test", "type1", "1") + .setSource(jsonBuilder().startObject() + .startObject("obj1").field("test", "something").endObject() + .startObject("obj2").startArray("arr2").value("arr_value1").value("arr_value2").endArray().endObject() + .endObject()) + .execute().actionGet(); + client.admin().indices().refresh(refreshRequest()).actionGet(); + + SearchResponse response = client.prepareSearch() + .setQuery(matchAllQuery()) + .addField("_source.obj1") // we also automatically detect _source in fields + .addScriptField("s_obj1", "js", "_source.obj1", null) + .addScriptField("s_obj1_test", "js", "_source.obj1.test", null) + .addScriptField("s_obj2", "js", "_source.obj2", null) + .addScriptField("s_obj2_arr2", "js", "_source.obj2.arr2", null) + .execute().actionGet(); + + Map sObj1 = (Map) response.hits().getAt(0).field("_source.obj1").value(); + assertThat(sObj1.get("test").toString(), equalTo("something")); + assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); + + sObj1 = (Map) response.hits().getAt(0).field("s_obj1").value(); + assertThat(sObj1.get("test").toString(), equalTo("something")); + assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); + + Map sObj2 = (Map) response.hits().getAt(0).field("s_obj2").value(); + List sObj2Arr2 = (List) sObj2.get("arr2"); + assertThat(sObj2Arr2.size(), equalTo(2)); + assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); + assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); + + sObj2Arr2 = (List) response.hits().getAt(0).field("s_obj2_arr2").value(); + assertThat(sObj2Arr2.size(), equalTo(2)); + assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); + assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); + } + + @Test + public void testCustomScriptBoost() throws Exception { + // execute a search before we create an index + try { + client.prepareSearch().setQuery(termQuery("test", "value")).execute().actionGet(); + assert false : "should fail"; + } catch (Exception e) { + // ignore, no indices + } + + try { + client.prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet(); + assert false : "should fail"; + } catch (Exception e) { + // ignore, no indices + } + + client.admin().indices().create(createIndexRequest("test")).actionGet(); + client.index(indexRequest("test").type("type1").id("1") + .source(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject())).actionGet(); + client.index(indexRequest("test").type("type1").id("2") + .source(jsonBuilder().startObject().field("test", "value check").field("num1", 2.0f).endObject())).actionGet(); + client.admin().indices().refresh(refreshRequest()).actionGet(); + + logger.info("--- QUERY_THEN_FETCH"); + + logger.info("running doc['num1'].value"); + SearchResponse response = client.search(searchRequest() + .searchType(SearchType.QUERY_THEN_FETCH) + .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("js"))) + ).actionGet(); + + assertThat(response.hits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); + assertThat(response.hits().getAt(0).id(), equalTo("2")); + assertThat(response.hits().getAt(1).id(), equalTo("1")); + + logger.info("running -doc['num1'].value"); + response = client.search(searchRequest() + .searchType(SearchType.QUERY_THEN_FETCH) + .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("js"))) + ).actionGet(); + + assertThat(response.hits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); + assertThat(response.hits().getAt(0).id(), equalTo("1")); + assertThat(response.hits().getAt(1).id(), equalTo("2")); + + + logger.info("running pow(doc['num1'].value, 2)"); + response = client.search(searchRequest() + .searchType(SearchType.QUERY_THEN_FETCH) + .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("js"))) + ).actionGet(); + + assertThat(response.hits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); + assertThat(response.hits().getAt(0).id(), equalTo("2")); + assertThat(response.hits().getAt(1).id(), equalTo("1")); + + logger.info("running max(doc['num1'].value, 1)"); + response = client.search(searchRequest() + .searchType(SearchType.QUERY_THEN_FETCH) + .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1)").lang("js"))) + ).actionGet(); + + assertThat(response.hits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); + assertThat(response.hits().getAt(0).id(), equalTo("2")); + assertThat(response.hits().getAt(1).id(), equalTo("1")); + + logger.info("running doc['num1'].value * _score"); + response = client.search(searchRequest() + .searchType(SearchType.QUERY_THEN_FETCH) + .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("js"))) + ).actionGet(); + + assertThat(response.hits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); + assertThat(response.hits().getAt(0).id(), equalTo("2")); + assertThat(response.hits().getAt(1).id(), equalTo("1")); + + logger.info("running param1 * param2 * _score"); + response = client.search(searchRequest() + .searchType(SearchType.QUERY_THEN_FETCH) + .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js"))) + ).actionGet(); + + assertThat(response.hits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); + } +} diff --git a/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java b/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java new file mode 100644 index 00000000000..fdaa6554613 --- /dev/null +++ b/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java @@ -0,0 +1,71 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.javascript; + +import org.elasticsearch.common.StopWatch; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.script.ExecutableScript; + +import java.util.HashMap; +import java.util.Map; + +/** + * + */ +public class SimpleBench { + + public static void main(String[] args) { + JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + Object compiled = se.compile("x + y"); + + Map vars = new HashMap(); + // warm up + for (int i = 0; i < 1000; i++) { + vars.put("x", i); + vars.put("y", i + 1); + se.execute(compiled, vars); + } + + final long ITER = 100000; + + StopWatch stopWatch = new StopWatch().start(); + for (long i = 0; i < ITER; i++) { + se.execute(compiled, vars); + } + System.out.println("Execute Took: " + stopWatch.stop().lastTaskTime()); + + stopWatch = new StopWatch().start(); + ExecutableScript executableScript = se.executable(compiled, vars); + for (long i = 0; i < ITER; i++) { + executableScript.run(); + } + System.out.println("Executable Took: " + stopWatch.stop().lastTaskTime()); + + stopWatch = new StopWatch().start(); + executableScript = se.executable(compiled, vars); + for (long i = 0; i < ITER; i++) { + for (Map.Entry entry : vars.entrySet()) { + executableScript.setNextVar(entry.getKey(), entry.getValue()); + } + executableScript.run(); + } + System.out.println("Executable (vars) Took: " + stopWatch.stop().lastTaskTime()); + } +} diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties new file mode 100644 index 00000000000..497c97f9959 --- /dev/null +++ b/src/test/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.rootLogger=INFO, out + +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.conversionPattern=[%d{ISO8601}][%-5p][%-25c] %m%n From 93c36c64ca6ad78eb5a771345876a73fcc1cb8dd Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 5 Dec 2011 17:35:54 +0200 Subject: [PATCH 02/78] move to 1.1.0 snap --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 87365b528d6..92733e83077 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.0.0 + 1.1.0-SNAPSHOT jar JavaScript lang plugin for ElasticSearch 2009 From 887363014d4912f519770e414da1874a7c7bb4da Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 5 Dec 2011 18:00:27 +0200 Subject: [PATCH 03/78] add log4j and fix README --- README.md | 14 +++++++------- pom.xml | 7 +++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f56c629bfae..cd916229531 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ The JavaScript language plugin allows to have `javascript` as the language of sc In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.0.0`. - --------------------------------------- - | AWS Cloud Plugin | ElasticSearch | - --------------------------------------- - | master | 0.18 -> master | - --------------------------------------- - | 1.0.0 | 0.18 -> master | - --------------------------------------- + ---------------------------------------- + | JavaScript Plugin | ElasticSearch | + ---------------------------------------- + | master | 0.18 -> master | + ---------------------------------------- + | 1.0.0 | 0.18 -> master | + ---------------------------------------- diff --git a/pom.xml b/pom.xml index 92733e83077..cd858f753ee 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,13 @@ + + log4j + log4j + 1.2.16 + runtime + + org.testng testng From c849f6e9a2cb65bb05bc3c0d9ed1672e35ad6378 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 13 Dec 2011 15:05:46 +0200 Subject: [PATCH 04/78] fix pom --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index cd858f753ee..5f8cdff17c9 100644 --- a/pom.xml +++ b/pom.xml @@ -119,10 +119,19 @@ maven-assembly-plugin + ${project.build.directory}/releases/ ${basedir}/src/main/assemblies/plugin.xml + + + package + + single + + + From 085f278bd4d47db5cf6ec370138c63ddab8eb5c8 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 31 Jan 2012 13:11:20 +0200 Subject: [PATCH 05/78] move to elasticsearch 0.19.0 snap and use some of its features --- README.md | 2 +- pom.xml | 2 +- .../elasticsearch/plugin/javascript/JavaScriptPlugin.java | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cd916229531..b511d14aee4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ In order to install the plugin, simply run: `bin/plugin -install elasticsearch/e ---------------------------------------- | JavaScript Plugin | ElasticSearch | ---------------------------------------- - | master | 0.18 -> master | + | master | master (0.19) | ---------------------------------------- | 1.0.0 | 0.18 -> master | ---------------------------------------- diff --git a/pom.xml b/pom.xml index 5f8cdff17c9..706d0231919 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ - 0.18.5 + 0.19.0-SNAPSHOT diff --git a/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java b/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java index 670194d2c4a..e2645251164 100644 --- a/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java +++ b/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java @@ -19,7 +19,6 @@ package org.elasticsearch.plugin.javascript; -import org.elasticsearch.common.inject.Module; import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.javascript.JavaScriptScriptEngineService; @@ -39,10 +38,7 @@ public class JavaScriptPlugin extends AbstractPlugin { return "JavaScript plugin allowing to add javascript scripting support"; } - @Override - public void processModule(Module module) { - if (module instanceof ScriptModule) { - ((ScriptModule) module).addScriptEngine(JavaScriptScriptEngineService.class); - } + public void onModule(ScriptModule module) { + module.addScriptEngine(JavaScriptScriptEngineService.class); } } From f76e4726965ac36836fbdf8416c2b546d9bb484b Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 7 Feb 2012 16:40:55 +0200 Subject: [PATCH 06/78] release 1.1.0 supporting elasticsearch 0.19 --- README.md | 8 +++++--- pom.xml | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b511d14aee4..56d2a074501 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,15 @@ JavaScript lang Plugin for ElasticSearch The JavaScript language plugin allows to have `javascript` as the language of scripts to execute. -In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.0.0`. +In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.1.0`. ---------------------------------------- | JavaScript Plugin | ElasticSearch | ---------------------------------------- - | master | master (0.19) | + | master | 0.19 -> master | ---------------------------------------- - | 1.0.0 | 0.18 -> master | + | 1.0.0 | 0.19 -> master | + ---------------------------------------- + | 1.0.0 | 0.18 | ---------------------------------------- diff --git a/pom.xml b/pom.xml index 706d0231919..3886df98492 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.1.0-SNAPSHOT + 1.1.0 jar JavaScript lang plugin for ElasticSearch 2009 @@ -30,7 +30,7 @@ - 0.19.0-SNAPSHOT + 0.19.0.RC1 From e1f4708223bb7a66c150bce0276540d63d4ecbe6 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 7 Feb 2012 16:41:14 +0200 Subject: [PATCH 07/78] move to 1.2.0 snap --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3886df98492..a586f8fa657 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.1.0 + 1.2.0-SNAPSHOT jar JavaScript lang plugin for ElasticSearch 2009 From 3e752af6b420f2bfcf03118320efc96f37af81e9 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sun, 26 Feb 2012 10:19:19 +0200 Subject: [PATCH 08/78] latest elastcisearch --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a586f8fa657..ad7b7e5c775 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ - 0.19.0.RC1 + 0.19.0.RC3 From dc642eaa123b1926d55c839521fdc311e8867270 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sun, 26 Feb 2012 10:20:19 +0200 Subject: [PATCH 09/78] latest assembly --- pom.xml | 2 ++ src/main/assemblies/plugin.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ad7b7e5c775..14e97312bc7 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,9 @@ maven-assembly-plugin + 2.2.2 + false ${project.build.directory}/releases/ ${basedir}/src/main/assemblies/plugin.xml diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index 2a637316fa0..cc9a1cb3189 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -1,6 +1,6 @@ - + plugin zip From 7cc4216ac9f226b2190b6dce08965681c3a4ae19 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sun, 26 Feb 2012 23:08:15 +0100 Subject: [PATCH 10/78] Update maven assembly plugin to latest version : 2.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 14e97312bc7..bb860e32bc4 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ maven-assembly-plugin - 2.2.2 + 2.3 false ${project.build.directory}/releases/ From 3a9070d6db91ef02f34aa603e0b37cd23c898181 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sun, 26 Feb 2012 23:08:24 +0100 Subject: [PATCH 11/78] Ignore eclipse files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 06a1e6fedb6..81c7f9eeacf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ /target .DS_Store *.iml +/.project +/.classpath +/.settings From b9b9631e213760f278488899e3f984c0c8ff0038 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sun, 10 Jun 2012 22:11:21 +0200 Subject: [PATCH 12/78] add license and repo --- LICENSE.txt | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 18 +++++ pom.xml | 6 +- 3 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/README.md b/README.md index 56d2a074501..85d870dda4a 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,21 @@ In order to install the plugin, simply run: `bin/plugin -install elasticsearch/e | 1.0.0 | 0.18 | ---------------------------------------- +License +------- + + This software is licensed under the Apache 2 license, quoted below. + + Copyright 2009-2012 Shay Banon and ElasticSearch + + Licensed 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. diff --git a/pom.xml b/pom.xml index bb860e32bc4..c5f44117999 100644 --- a/pom.xml +++ b/pom.xml @@ -30,10 +30,14 @@ - 0.19.0.RC3 + 0.19.0 + + sonatype + http://oss.sonatype.org/content/repositories/releases/ + From fc789a20a4d4ab0f75734cd638f3117726c21274 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sat, 23 Jun 2012 21:48:22 +0200 Subject: [PATCH 13/78] upgrade to rhino 1.7R4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c5f44117999..992b4e38ce4 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ org.mozilla rhino - 1.7R3 + 1.7R4 compile From 94a4a3e49af50e8bd0106927ae3adb92272e4f9b Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sat, 23 Jun 2012 21:51:48 +0200 Subject: [PATCH 14/78] release 1.2.0 --- README.md | 6 ++++-- pom.xml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 85d870dda4a..9239e39a02f 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,16 @@ JavaScript lang Plugin for ElasticSearch The JavaScript language plugin allows to have `javascript` as the language of scripts to execute. -In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.1.0`. +In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.2.0`. ---------------------------------------- | JavaScript Plugin | ElasticSearch | ---------------------------------------- | master | 0.19 -> master | ---------------------------------------- - | 1.0.0 | 0.19 -> master | + | 1.2.0 | 0.19 -> master | + ---------------------------------------- + | 1.1.0 | 0.19 -> master | ---------------------------------------- | 1.0.0 | 0.18 | ---------------------------------------- diff --git a/pom.xml b/pom.xml index 992b4e38ce4..1e2f8c285de 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.2.0-SNAPSHOT + 1.2.0 jar JavaScript lang plugin for ElasticSearch 2009 From b2c29d4443875007f8ef85372ed86ba33fa9cee6 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sat, 23 Jun 2012 21:52:04 +0200 Subject: [PATCH 15/78] move to 1.3.0 snap --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1e2f8c285de..4150a1cc10e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.2.0 + 1.3.0-SNAPSHOT jar JavaScript lang plugin for ElasticSearch 2009 From eeb4bdbb3464a250adac39966d287ac91b1c4411 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sun, 24 Feb 2013 22:32:11 +0100 Subject: [PATCH 16/78] Move to Elasticsearch 0.21.0.Beta1 Due to refactoring in 0.21.x we have to update this plugin Closes #3. --- README.md | 4 +- pom.xml | 4 +- .../JavaScriptScriptEngineService.java | 6 +- .../JavaScriptScriptSearchTests.java | 98 +++++++++---------- 4 files changed, 56 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 9239e39a02f..cd0ac0a960b 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ In order to install the plugin, simply run: `bin/plugin -install elasticsearch/e ---------------------------------------- | JavaScript Plugin | ElasticSearch | ---------------------------------------- - | master | 0.19 -> master | + | master | 0.21 -> master | ---------------------------------------- - | 1.2.0 | 0.19 -> master | + | 1.2.0 | 0.19 -> 0.20 | ---------------------------------------- | 1.1.0 | 0.19 -> master | ---------------------------------------- diff --git a/pom.xml b/pom.xml index 4150a1cc10e..8213f90164d 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ - 0.19.0 + 0.21.0.Beta1-SNAPSHOT @@ -141,4 +141,4 @@ - \ No newline at end of file + diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index d1d35d453bb..419a588d703 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -19,7 +19,7 @@ package org.elasticsearch.script.javascript; -import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; @@ -220,8 +220,8 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements } @Override - public void setNextReader(IndexReader reader) { - lookup.setNextReader(reader); + public void setNextReader(AtomicReaderContext context) { + lookup.setNextReader(context); } @Override diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 110fe81709a..78d939627c2 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -94,11 +94,11 @@ public class JavaScriptScriptSearchTests { .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(1).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); + assertThat(response.getHits().totalHits(), equalTo(2l)); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); + assertThat(response.getHits().getAt(1).id(), equalTo("3")); + assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); logger.info("running doc['num1'].value > param1"); response = client.prepareSearch() @@ -107,9 +107,9 @@ public class JavaScriptScriptSearchTests { .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); - assertThat(response.hits().totalHits(), equalTo(1l)); - assertThat(response.hits().getAt(0).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); + assertThat(response.getHits().totalHits(), equalTo(1l)); + assertThat(response.getHits().getAt(0).id(), equalTo("3")); + assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); logger.info("running doc['num1'].value > param1"); response = client.prepareSearch() @@ -118,13 +118,13 @@ public class JavaScriptScriptSearchTests { .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); - assertThat(response.hits().totalHits(), equalTo(3l)); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); - assertThat(response.hits().getAt(1).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(2).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); + assertThat(response.getHits().totalHits(), equalTo(3l)); + assertThat(response.getHits().getAt(0).id(), equalTo("1")); + assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); + assertThat(response.getHits().getAt(1).id(), equalTo("2")); + assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); + assertThat(response.getHits().getAt(2).id(), equalTo("3")); + assertThat((Double) response.getHits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); } @Test @@ -147,21 +147,21 @@ public class JavaScriptScriptSearchTests { .addScriptField("s_obj2_arr2", "js", "_source.obj2.arr2", null) .execute().actionGet(); - Map sObj1 = (Map) response.hits().getAt(0).field("_source.obj1").value(); + Map sObj1 = (Map) response.getHits().getAt(0).field("_source.obj1").value(); assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); + assertThat(response.getHits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - sObj1 = (Map) response.hits().getAt(0).field("s_obj1").value(); + sObj1 = (Map) response.getHits().getAt(0).field("s_obj1").value(); assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); + assertThat(response.getHits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - Map sObj2 = (Map) response.hits().getAt(0).field("s_obj2").value(); + Map sObj2 = (Map) response.getHits().getAt(0).field("s_obj2").value(); List sObj2Arr2 = (List) sObj2.get("arr2"); assertThat(sObj2Arr2.size(), equalTo(2)); assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - sObj2Arr2 = (List) response.hits().getAt(0).field("s_obj2_arr2").value(); + sObj2Arr2 = (List) response.getHits().getAt(0).field("s_obj2_arr2").value(); assertThat(sObj2Arr2.size(), equalTo(2)); assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); @@ -199,11 +199,11 @@ public class JavaScriptScriptSearchTests { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat(response.getHits().getAt(1).id(), equalTo("1")); logger.info("running -doc['num1'].value"); response = client.search(searchRequest() @@ -211,11 +211,11 @@ public class JavaScriptScriptSearchTests { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat(response.hits().getAt(1).id(), equalTo("2")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("1")); + assertThat(response.getHits().getAt(1).id(), equalTo("2")); logger.info("running pow(doc['num1'].value, 2)"); @@ -224,11 +224,11 @@ public class JavaScriptScriptSearchTests { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat(response.getHits().getAt(1).id(), equalTo("1")); logger.info("running max(doc['num1'].value, 1)"); response = client.search(searchRequest() @@ -236,11 +236,11 @@ public class JavaScriptScriptSearchTests { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1)").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat(response.getHits().getAt(1).id(), equalTo("1")); logger.info("running doc['num1'].value * _score"); response = client.search(searchRequest() @@ -248,11 +248,11 @@ public class JavaScriptScriptSearchTests { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat(response.getHits().getAt(1).id(), equalTo("1")); logger.info("running param1 * param2 * _score"); response = client.search(searchRequest() @@ -260,8 +260,8 @@ public class JavaScriptScriptSearchTests { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); } } From 67bb04b0f8abe15c0f6d257e216b92234794a5f1 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 26 Feb 2013 16:13:55 +0100 Subject: [PATCH 17/78] release 1.3 --- README.md | 6 ++++-- pom.xml | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cd0ac0a960b..72fabd76d22 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,14 @@ JavaScript lang Plugin for ElasticSearch The JavaScript language plugin allows to have `javascript` as the language of scripts to execute. -In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.2.0`. +In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.3.0`. ---------------------------------------- | JavaScript Plugin | ElasticSearch | ---------------------------------------- - | master | 0.21 -> master | + | master | 0.90 -> master | + ---------------------------------------- + | 1.3.0 | 0.90 -> master | ---------------------------------------- | 1.2.0 | 0.19 -> 0.20 | ---------------------------------------- diff --git a/pom.xml b/pom.xml index 8213f90164d..860b8b35378 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.3.0-SNAPSHOT + 1.3.0 jar JavaScript lang plugin for ElasticSearch 2009 @@ -19,7 +19,8 @@ scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git - scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git + scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git + http://github.com/elasticsearch/elasticsearch-lang-javascript @@ -30,7 +31,7 @@ - 0.21.0.Beta1-SNAPSHOT + 0.90.0.Beta1 From f3d0d30dc505457e97e4ea40ac1f36bdc26fa358 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 26 Feb 2013 16:14:10 +0100 Subject: [PATCH 18/78] move to 1.4 snap --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 860b8b35378..b6cbf5aa0c6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.3.0 + 1.4.0-SNAPSHOT jar JavaScript lang plugin for ElasticSearch 2009 From 8036c4fb81b63d68e67ef35ff836ba2081f7ea41 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 5 Jun 2013 15:18:51 +0200 Subject: [PATCH 19/78] Move to Elasticsearch 0.90.1 And update licence Closes #5. --- README.md | 4 ++-- pom.xml | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 72fabd76d22..087878b7483 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ In order to install the plugin, simply run: `bin/plugin -install elasticsearch/e ---------------------------------------- | 1.2.0 | 0.19 -> 0.20 | ---------------------------------------- - | 1.1.0 | 0.19 -> master | + | 1.1.0 | 0.19 | ---------------------------------------- | 1.0.0 | 0.18 | ---------------------------------------- @@ -24,7 +24,7 @@ License This software is licensed under the Apache 2 license, quoted below. - Copyright 2009-2012 Shay Banon and ElasticSearch + Copyright 2009-2013 Shay Banon and ElasticSearch Licensed 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 diff --git a/pom.xml b/pom.xml index b6cbf5aa0c6..7219290dae4 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ - 0.90.0.Beta1 + 0.90.1 @@ -46,14 +46,12 @@ org.elasticsearch elasticsearch ${elasticsearch.version} - compile org.mozilla rhino 1.7R4 - compile From aa68294c85b7e0b7e53bbc9206f4c616849ae3c0 Mon Sep 17 00:00:00 2001 From: ejain Date: Sat, 8 Dec 2012 16:48:40 -0800 Subject: [PATCH 20/78] Make log4j an optional dependency ...as it is in the main elasticsearch pom.xml. This is useful for people who want to use slf4j/logback instead of log4j. Closes #2. --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 7219290dae4..ef783ad11d8 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,7 @@ log4j 1.2.16 runtime + true From bb41d2fc7f4cf92b0f0dcad5082cc2a878520ac4 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 5 Jun 2013 16:53:10 +0200 Subject: [PATCH 21/78] prepare release elasticsearch-lang-javascript-1.4.0 --- README.md | 30 ++++++++++++++++-------------- pom.xml | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 087878b7483..e90f9cb8781 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,23 @@ JavaScript lang Plugin for ElasticSearch The JavaScript language plugin allows to have `javascript` as the language of scripts to execute. -In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.3.0`. +In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.4.0`. - ---------------------------------------- - | JavaScript Plugin | ElasticSearch | - ---------------------------------------- - | master | 0.90 -> master | - ---------------------------------------- - | 1.3.0 | 0.90 -> master | - ---------------------------------------- - | 1.2.0 | 0.19 -> 0.20 | - ---------------------------------------- - | 1.1.0 | 0.19 | - ---------------------------------------- - | 1.0.0 | 0.18 | - ---------------------------------------- + ----------------------------------------------- + | JavaScript Plugin | ElasticSearch | + ----------------------------------------------- + | 1.5.0-SNAPSHOT (master) | 0.90 -> master | + ----------------------------------------------- + | 1.4.0 | 0.90 -> master | + ----------------------------------------------- + | 1.3.0 | 0.90 | + ----------------------------------------------- + | 1.2.0 | 0.19 -> 0.20 | + ----------------------------------------------- + | 1.1.0 | 0.19 | + ----------------------------------------------- + | 1.0.0 | 0.18 | + ----------------------------------------------- License ------- diff --git a/pom.xml b/pom.xml index ef783ad11d8..077a1b1cc83 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.4.0-SNAPSHOT + 1.4.0 jar JavaScript lang plugin for ElasticSearch 2009 From 3cf3502d73c023809459a3109df26986a2f10d36 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 5 Jun 2013 16:55:13 +0200 Subject: [PATCH 22/78] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 077a1b1cc83..ed2635e7cfa 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.4.0 + 1.5.0-SNAPSHOT jar JavaScript lang plugin for ElasticSearch 2009 From 6503f7983ac7ebdd02d3e3daf02360c199f60bf9 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 21 Aug 2013 11:49:10 +0200 Subject: [PATCH 23/78] Create CONTRIBUTING.md --- CONTRIBUTING.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000000..923342ad6ad --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,98 @@ +Contributing to elasticsearch +============================= + +Elasticsearch is an open source project and we love to receive contributions from our community — you! There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be incorporated into Elasticsearch itself. + +Bug reports +----------- + +If you think you have found a bug in Elasticsearch, first make sure that you are testing against the [latest version of Elasticsearch](http://www.elasticsearch.org/download/) - your issue may already have been fixed. If not, search our [issues list](https://github.com/elasticsearch/elasticsearch/issues) on GitHub in case a similar issue has already been opened. + +It is very helpful if you can prepare a reproduction of the bug. In other words, provide a small test case which we can run to confirm your bug. It makes it easier to find the problem and to fix it. Test cases should be provided as `curl` commands which we can copy and paste into a terminal to run it locally, for example: + +```sh +# delete the index +curl -XDELETE localhost:9200/test + +# insert a document +curl -XPUT localhost:9200/test/test/1 -d '{ + "title": "test document" +}' + +# this should return XXXX but instead returns YYY +curl .... +``` + +Provide as much information as you can. You may think that the problem lies with your query, when actually it depends on how your data is indexed. The easier it is for us to recreate your problem, the faster it is likely to be fixed. + +Feature requests +---------------- + +If you find yourself wishing for a feature that doesn't exist in Elasticsearch, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Elasticsearch has today have been added because our users saw the need. +Open an issue on our [issues list](https://github.com/elasticsearch/elasticsearch/issues) on GitHub which describes the feature you would like to see, why you need it, and how it should work. + +Contributing code and documentation changes +------------------------------------------- + +If you have a bugfix or new feature that you would like to contribute to Elasticsearch, please find or open an issue about it first. Talk about what you would like to do. It may be that somebody is already working on it, or that there are particular issues that you should know about before implementing the change. + +We enjoy working with contributors to get their code accepted. There are many approaches to fixing a problem and it is important to find the best approach before writing too much code. + +The process for contributing to any of the [Elasticsearch repositories](https://github.com/elasticsearch/) is similar. Details for individual projects can be found below. + +### Fork and clone the repository + +You will need to fork the main Elasticsearch code or documentation repository and clone it to your local machine. See +[github help page](https://help.github.com/articles/fork-a-repo) for help. + +Further instructions for specific projects are given below. + +### Submitting your changes + +Once your changes and tests are ready to submit for review: + +1. Test your changes +Run the test suite to make sure that nothing is broken. + +2. Sign the Contributor License Agreement +Please make sure you have signed our [Contributor License Agreement](http://www.elasticsearch.org/contributor-agreement/). We are not asking you to assign copyright to us, but to give us the right to distribute your code without restriction. We ask this of all contributors in order to assure our users of the origin and continuing existence of the code. You only need to sign the CLA once. + +3. Rebase your changes +Update your local repository with the most recent code from the main Elasticsearch repository, and rebase your branch on top of the latest master branch. We prefer your changes to be squashed into a single commit. + +4. Submit a pull request +Push your local changes to your forked copy of the repository and [submit a pull request](https://help.github.com/articles/using-pull-requests). In the pull request, describe what your changes do and mention the number of the issue where discussion has taken place, eg "Closes #123". + +Then sit back and wait. There will probably be discussion about the pull request and, if any changes are needed, we would love to work with you to get your pull request merged into Elasticsearch. + + +Contributing to the Elasticsearch plugin +---------------------------------------- + +**Repository:** [https://github.com/elasticsearch/elasticsearch-lang-javascript](https://github.com/elasticsearch/elasticsearch-lang-javascript) + +Make sure you have [Maven](http://maven.apache.org) installed, as Elasticsearch uses it as its build system. Integration with IntelliJ and Eclipse should work out of the box. Eclipse users can automatically configure their IDE by running `mvn eclipse:eclipse` and then importing the project into their workspace: `File > Import > Existing project into workspace`. + +Please follow these formatting guidelines: + +* Java indent is 4 spaces +* Line width is 140 characters +* The rest is left to Java coding standards +* Disable “auto-format on save” to prevent unnecessary format changes. This makes reviews much harder as it generates unnecessary formatting changes. If your IDE supports formatting only modified chunks that is fine to do. + +To create a distribution from the source, simply run: + +```sh +cd elasticsearch-lang-javascript/ +mvn clean package -DskipTests +``` + +You will find the newly built packages under: `./target/releases/`. + +Before submitting your changes, run the test suite to make sure that nothing is broken, with: + +```sh +mvn clean test +``` + +Source: [Contributing to elasticsearch](http://www.elasticsearch.org/contributing-to-elasticsearch/) From 40f89f70f65d651991c2b98b290ccd289c839048 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 15 Jan 2014 12:28:20 +0100 Subject: [PATCH 24/78] update headers --- README.md | 27 +++++++------------ .../plugin/javascript/JavaScriptPlugin.java | 14 +++++----- .../JavaScriptScriptEngineService.java | 14 +++++----- .../script/javascript/support/NativeList.java | 14 +++++----- .../script/javascript/support/NativeMap.java | 14 +++++----- .../support/ScriptValueConverter.java | 14 +++++----- .../support/ScriptableLinkedHashMap.java | 14 +++++----- .../javascript/support/ScriptableMap.java | 16 +++++------ .../support/ScriptableWrappedMap.java | 14 +++++----- .../JavaScriptScriptEngineTests.java | 14 +++++----- .../JavaScriptScriptMultiThreadedTest.java | 14 +++++----- .../JavaScriptScriptSearchTests.java | 14 +++++----- .../script/javascript/SimpleBench.java | 14 +++++----- 13 files changed, 95 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index e90f9cb8781..92cff3e541c 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,25 @@ -JavaScript lang Plugin for ElasticSearch +JavaScript lang Plugin for Elasticsearch ================================== The JavaScript language plugin allows to have `javascript` as the language of scripts to execute. In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.4.0`. - ----------------------------------------------- - | JavaScript Plugin | ElasticSearch | - ----------------------------------------------- - | 1.5.0-SNAPSHOT (master) | 0.90 -> master | - ----------------------------------------------- - | 1.4.0 | 0.90 -> master | - ----------------------------------------------- - | 1.3.0 | 0.90 | - ----------------------------------------------- - | 1.2.0 | 0.19 -> 0.20 | - ----------------------------------------------- - | 1.1.0 | 0.19 | - ----------------------------------------------- - | 1.0.0 | 0.18 | - ----------------------------------------------- +| JavaScript Lang Plugin | elasticsearch | rhino | Release date | +|-----------------------------|---------------------|----------|:------------:| +| 1.5.0-SNAPSHOT (master) | 0.90 | 1.7R4 | | +| 1.4.0 | 0.90 | 1.7R4 | 2013-06-05 | +| 1.3.0 | 0.90 | 1.7R4 | 2013-02-26 | +| 1.2.0 | 0.19 -> 0.20 | 1.7R4 | 2012-06-23 | +| 1.1.0 | 0.19 | 1.7R3 | 2012-02-07 | +| 1.0.0 | 0.18 | 1.7R3 | 2011-12-05 | License ------- This software is licensed under the Apache 2 license, quoted below. - Copyright 2009-2013 Shay Banon and ElasticSearch + Copyright 2009-2014 Elasticsearch Licensed 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 diff --git a/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java b/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java index e2645251164..0b4ffd7fae5 100644 --- a/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java +++ b/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 419a588d703..eacc8f5f7cb 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java b/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java index c2345dc2bfc..bd1124fa4ba 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java b/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java index f36ce23a8b3..efdbac86a04 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java index e7bedb40487..726d25d616f 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java index 88d34d7251e..680b20a0256 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java index a7319c26027..ed910c5afca 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * @@ -29,4 +29,4 @@ import java.util.Map; * */ public interface ScriptableMap extends Scriptable, Map { -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java index e78a92464df..a7c2f4f5428 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java index fe59d4aac57..bd78b0ded4e 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java index 9cbdc2cc782..14d635dd859 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 78d939627c2..18091f98841 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * diff --git a/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java b/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java index fdaa6554613..49f8e401074 100644 --- a/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java +++ b/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java @@ -1,11 +1,11 @@ /* - * Licensed to ElasticSearch and Shay Banon 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 + * 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 * From a36827cbc0bded3d59d937565ae91be6f825db1f Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 15 Jan 2014 12:46:37 +0100 Subject: [PATCH 25/78] Move tests to elasticsearch test framework Closes #10. --- pom.xml | 112 +++++++++++- .../JavaScriptScriptEngineTests.java | 14 +- .../JavaScriptScriptMultiThreadedTest.java | 11 +- .../JavaScriptScriptSearchTests.java | 173 +++++++----------- 4 files changed, 181 insertions(+), 129 deletions(-) diff --git a/pom.xml b/pom.xml index ed2635e7cfa..f99c33a40ec 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,13 @@ - 0.90.1 + 0.90.10 + 4.6.0 + 1 + true + onerror + + INFO @@ -42,6 +48,13 @@ + + org.apache.lucene + lucene-test-framework + ${lucene.version} + test + + org.elasticsearch elasticsearch @@ -65,9 +78,10 @@ - org.testng - testng - 6.3.1 + org.elasticsearch + elasticsearch + ${elasticsearch.version} + test-jar test @@ -98,13 +112,95 @@ + com.carrotsearch.randomizedtesting + junit4-maven-plugin + 2.0.12 + + + tests + test + + junit4 + + + 20 + pipe,warn + true + + + + + + + + + ${tests.jvms} + + + + + + + **/*Tests.class + **/*Test.class + + + **/Abstract*.class + **/*StressTest.class + + + -Xmx512m + -XX:MaxDirectMemorySize=512m + -Des.logger.prefix= + + ${tests.shuffle} + ${tests.verbose} + ${tests.seed} + ${tests.failfast} + + + ${tests.iters} + ${tests.maxfailures} + ${tests.failfast} + ${tests.class} + ${tests.method} + ${tests.nightly} + ${tests.badapples} + ${tests.weekly} + ${tests.slow} + ${tests.awaitsfix} + ${tests.slow} + ${tests.timeoutSuite} + ${tests.showSuccess} + ${tests.integration} + ${tests.cluster_seed} + ${tests.client.ratio} + ${env.ES_TEST_LOCAL} + ${es.node.mode} + ${es.logger.level} + true + + + + + + + org.apache.maven.plugins maven-surefire-plugin - 2.11 + 2.15 - - **/*Tests.java - + true diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java index bd78b0ded4e..e343de9159b 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java @@ -23,31 +23,31 @@ import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.script.ExecutableScript; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.elasticsearch.test.ElasticsearchTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; /** * */ -public class JavaScriptScriptEngineTests { +public class JavaScriptScriptEngineTests extends ElasticsearchTestCase { private JavaScriptScriptEngineService se; - @BeforeClass + @Before public void setup() { se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); } - @AfterClass + @After public void close() { se.close(); } diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java index 14d635dd859..26eab2091ce 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java @@ -19,12 +19,11 @@ package org.elasticsearch.script.javascript; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom; import org.elasticsearch.script.ExecutableScript; -import org.testng.annotations.Test; +import org.elasticsearch.test.ElasticsearchTestCase; +import org.junit.Test; import java.util.HashMap; import java.util.Map; @@ -32,16 +31,12 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.atomic.AtomicBoolean; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** * */ -@Test -public class JavaScriptScriptMultiThreadedTest { - - protected final ESLogger logger = Loggers.getLogger(getClass()); +public class JavaScriptScriptMultiThreadedTest extends ElasticsearchTestCase { @Test public void testExecutableNoRuntimeParams() throws Exception { diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 18091f98841..68e6a5c7af4 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -21,74 +21,39 @@ package org.elasticsearch.script.javascript; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.search.sort.SortOrder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.junit.Test; +import java.util.Arrays; import java.util.List; import java.util.Map; -import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.client.Requests.searchRequest; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.FilterBuilders.scriptFilter; import static org.elasticsearch.index.query.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** * */ -@Test -public class JavaScriptScriptSearchTests { - - protected final ESLogger logger = Loggers.getLogger(getClass()); - - private Node node; - - private Client client; - - @BeforeMethod - public void createNodes() throws Exception { - node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder() - .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()) - .put("gateway.type", "none") - .put("number_of_shards", 1)).node(); - client = node.client(); - } - - @AfterMethod - public void closeNodes() { - client.close(); - node.close(); - } +public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { @Test public void testJavaScriptFilter() throws Exception { - client.admin().indices().prepareCreate("test").execute().actionGet(); - client.prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()) - .execute().actionGet(); - client.admin().indices().prepareFlush().execute().actionGet(); - client.prepareIndex("test", "type1", "2") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject()) - .execute().actionGet(); - client.admin().indices().prepareFlush().execute().actionGet(); - client.prepareIndex("test", "type1", "3") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject()) - .execute().actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); + wipeIndices("test"); + createIndex("test"); + index("test", "type1", "1", jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()); + flush(); + index("test", "type1", "2", jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject()); + flush(); + index("test", "type1", "3", jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject()); + refresh(); - logger.info("running doc['num1'].value > 1"); - SearchResponse response = client.prepareSearch() + logger.info(" --> running doc['num1'].value > 1"); + SearchResponse response = client().prepareSearch() .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > 1").lang("js"))) .addSort("num1", SortOrder.ASC) .addScriptField("sNum1", "js", "doc['num1'].value", null) @@ -100,8 +65,8 @@ public class JavaScriptScriptSearchTests { assertThat(response.getHits().getAt(1).id(), equalTo("3")); assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); - logger.info("running doc['num1'].value > param1"); - response = client.prepareSearch() + logger.info(" --> running doc['num1'].value > param1"); + response = client().prepareSearch() .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", 2))) .addSort("num1", SortOrder.ASC) .addScriptField("sNum1", "js", "doc['num1'].value", null) @@ -111,8 +76,8 @@ public class JavaScriptScriptSearchTests { assertThat(response.getHits().getAt(0).id(), equalTo("3")); assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); - logger.info("running doc['num1'].value > param1"); - response = client.prepareSearch() + logger.info(" --> running doc['num1'].value > param1"); + response = client().prepareSearch() .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", -1))) .addSort("num1", SortOrder.ASC) .addScriptField("sNum1", "js", "doc['num1'].value", null) @@ -129,16 +94,16 @@ public class JavaScriptScriptSearchTests { @Test public void testScriptFieldUsingSource() throws Exception { - client.admin().indices().prepareCreate("test").execute().actionGet(); - client.prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject() + wipeIndices("test"); + createIndex("test"); + index("test", "type1", "1", + jsonBuilder().startObject() .startObject("obj1").field("test", "something").endObject() .startObject("obj2").startArray("arr2").value("arr_value1").value("arr_value2").endArray().endObject() - .endObject()) - .execute().actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); + .endObject()); + refresh(); - SearchResponse response = client.prepareSearch() + SearchResponse response = client().prepareSearch() .setQuery(matchAllQuery()) .addField("_source.obj1") // we also automatically detect _source in fields .addScriptField("s_obj1", "js", "_source.obj1", null) @@ -169,99 +134,95 @@ public class JavaScriptScriptSearchTests { @Test public void testCustomScriptBoost() throws Exception { - // execute a search before we create an index - try { - client.prepareSearch().setQuery(termQuery("test", "value")).execute().actionGet(); - assert false : "should fail"; - } catch (Exception e) { - // ignore, no indices - } - - try { - client.prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet(); - assert false : "should fail"; - } catch (Exception e) { - // ignore, no indices - } - - client.admin().indices().create(createIndexRequest("test")).actionGet(); - client.index(indexRequest("test").type("type1").id("1") - .source(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject())).actionGet(); - client.index(indexRequest("test").type("type1").id("2") - .source(jsonBuilder().startObject().field("test", "value check").field("num1", 2.0f).endObject())).actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); + wipeIndices("test"); + createIndex("test"); + index("test", "type1", "1", jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()); + index("test", "type1", "2", jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject()); + refresh(); logger.info("--- QUERY_THEN_FETCH"); - logger.info("running doc['num1'].value"); - SearchResponse response = client.search(searchRequest() + logger.info(" --> running doc['num1'].value"); + SearchResponse response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("js"))) ).actionGet(); + assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); + assertThat(response.getHits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); assertThat(response.getHits().getAt(0).id(), equalTo("2")); assertThat(response.getHits().getAt(1).id(), equalTo("1")); - logger.info("running -doc['num1'].value"); - response = client.search(searchRequest() + logger.info(" --> running -doc['num1'].value"); + response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("js"))) ).actionGet(); + assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); + assertThat(response.getHits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); assertThat(response.getHits().getAt(0).id(), equalTo("1")); assertThat(response.getHits().getAt(1).id(), equalTo("2")); - logger.info("running pow(doc['num1'].value, 2)"); - response = client.search(searchRequest() + logger.info(" --> running pow(doc['num1'].value, 2)"); + response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("js"))) ).actionGet(); + assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); + assertThat(response.getHits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); assertThat(response.getHits().getAt(0).id(), equalTo("2")); assertThat(response.getHits().getAt(1).id(), equalTo("1")); - logger.info("running max(doc['num1'].value, 1)"); - response = client.search(searchRequest() + logger.info(" --> running max(doc['num1'].value, 1)"); + response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1)").lang("js"))) ).actionGet(); + assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); + assertThat(response.getHits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); assertThat(response.getHits().getAt(0).id(), equalTo("2")); assertThat(response.getHits().getAt(1).id(), equalTo("1")); - logger.info("running doc['num1'].value * _score"); - response = client.search(searchRequest() + logger.info(" --> running doc['num1'].value * _score"); + response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("js"))) ).actionGet(); + assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); + assertThat(response.getHits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); assertThat(response.getHits().getAt(0).id(), equalTo("2")); assertThat(response.getHits().getAt(1).id(), equalTo("1")); - logger.info("running param1 * param2 * _score"); - response = client.search(searchRequest() + logger.info(" --> running param1 * param2 * _score"); + response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js"))) ).actionGet(); + assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); + assertThat(response.getHits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); } } From e2f9d02e5eba0ecc1b4ba173ca2c4431cd7d5620 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 15 Jan 2014 14:48:50 +0100 Subject: [PATCH 26/78] Move tests to elasticsearch test framework Relative to #10. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 81c7f9eeacf..6d851a6181b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /.project /.classpath /.settings +.local-execution-hints.log From 02790c74fed195d50f1f29507e2a49e2217a216e Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 15 Jan 2014 15:32:21 +0100 Subject: [PATCH 27/78] prepare branch 1.x --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 92cff3e541c..53798aec261 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ In order to install the plugin, simply run: `bin/plugin -install elasticsearch/e | JavaScript Lang Plugin | elasticsearch | rhino | Release date | |-----------------------------|---------------------|----------|:------------:| -| 1.5.0-SNAPSHOT (master) | 0.90 | 1.7R4 | | +| 2.0.0.RC1-SNAPSHOT (master) | 1.0.0.RC1 -> master | 1.7R4 | | +| 1.5.0-SNAPSHOT (1.x) | 0.90 | 1.7R4 | | | 1.4.0 | 0.90 | 1.7R4 | 2013-06-05 | | 1.3.0 | 0.90 | 1.7R4 | 2013-02-26 | | 1.2.0 | 0.19 -> 0.20 | 1.7R4 | 2012-06-23 | From 6567fdcaff8339246c6be7c1263f860cc06b5567 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 15 Jan 2014 15:33:48 +0100 Subject: [PATCH 28/78] Update to elasticsearch 1.0.0.RC1 Closes #9. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f99c33a40ec..37ca9b9d182 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ - 0.90.10 + 1.0.0.RC1-SNAPSHOT 4.6.0 1 true From 9ea52340b0dd498905afa851460e05051a040dc5 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 15 Jan 2014 18:45:46 +0100 Subject: [PATCH 29/78] prepare release elasticsearch-lang-javascript-2.0.0.RC1 --- README.md | 5 +++-- pom.xml | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 53798aec261..a6889dbd85d 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,12 @@ JavaScript lang Plugin for Elasticsearch The JavaScript language plugin allows to have `javascript` as the language of scripts to execute. -In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.4.0`. +In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.0.0.RC1`. | JavaScript Lang Plugin | elasticsearch | rhino | Release date | |-----------------------------|---------------------|----------|:------------:| -| 2.0.0.RC1-SNAPSHOT (master) | 1.0.0.RC1 -> master | 1.7R4 | | +| 2.0.0-SNAPSHOT (master) | 1.0.0.RC1 -> master | 1.7R4 | | +| 2.0.0.RC1 | 1.0.0.RC1 -> master | 1.7R4 | 2014-01-15 | | 1.5.0-SNAPSHOT (1.x) | 0.90 | 1.7R4 | | | 1.4.0 | 0.90 | 1.7R4 | 2013-06-05 | | 1.3.0 | 0.90 | 1.7R4 | 2013-02-26 | diff --git a/pom.xml b/pom.xml index 37ca9b9d182..6226517e739 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 1.5.0-SNAPSHOT + 2.0.0.RC1 jar JavaScript lang plugin for ElasticSearch 2009 @@ -31,7 +31,7 @@ - 1.0.0.RC1-SNAPSHOT + 1.0.0.RC1 4.6.0 1 true From 857ca09e33c01cb5febbf17ca2914ea5b65b2d07 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 15 Jan 2014 19:54:45 +0100 Subject: [PATCH 30/78] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6226517e739..096bfde42b4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 2.0.0.RC1 + 2.0.0-SNAPSHOT jar JavaScript lang plugin for ElasticSearch 2009 From c82c6530a0ffdcf564caf4b44d49000d5660701e Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 7 Mar 2014 15:41:46 +0100 Subject: [PATCH 31/78] Add plugin release semi-automatic script Closes #15. --- README.md | 11 +- dev-tools/build_release.py | 708 +++++++++++++++++++++++++++++++++++++ dev-tools/upload-s3.py | 67 ++++ pom.xml | 5 +- 4 files changed, 782 insertions(+), 9 deletions(-) create mode 100755 dev-tools/build_release.py create mode 100644 dev-tools/upload-s3.py diff --git a/README.md b/README.md index a6889dbd85d..bab656d7c72 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,13 @@ The JavaScript language plugin allows to have `javascript` as the language of sc In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.0.0.RC1`. +* For 1.0.x elasticsearch versions, look at [master branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/master). +* For 0.90.x elasticsearch versions, look at [1.x branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/1.x). + | JavaScript Lang Plugin | elasticsearch | rhino | Release date | |-----------------------------|---------------------|----------|:------------:| -| 2.0.0-SNAPSHOT (master) | 1.0.0.RC1 -> master | 1.7R4 | | +| 2.0.0-SNAPSHOT | 1.0.0.RC1 -> master | 1.7R4 | XXXX-XX-XX | | 2.0.0.RC1 | 1.0.0.RC1 -> master | 1.7R4 | 2014-01-15 | -| 1.5.0-SNAPSHOT (1.x) | 0.90 | 1.7R4 | | -| 1.4.0 | 0.90 | 1.7R4 | 2013-06-05 | -| 1.3.0 | 0.90 | 1.7R4 | 2013-02-26 | -| 1.2.0 | 0.19 -> 0.20 | 1.7R4 | 2012-06-23 | -| 1.1.0 | 0.19 | 1.7R3 | 2012-02-07 | -| 1.0.0 | 0.18 | 1.7R3 | 2011-12-05 | License ------- diff --git a/dev-tools/build_release.py b/dev-tools/build_release.py new file mode 100755 index 00000000000..9166b09e7e3 --- /dev/null +++ b/dev-tools/build_release.py @@ -0,0 +1,708 @@ +# 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. + +import re +import tempfile +import shutil +import os +import datetime +import argparse +import github3 +import smtplib + +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + +from os.path import dirname, abspath + +""" + This tool builds a release from the a given elasticsearch plugin branch. + In order to execute it go in the top level directory and run: + $ python3 dev_tools/build_release.py --branch master --publish --remote origin + + By default this script runs in 'dry' mode which essentially simulates a release. If the + '--publish' option is set the actual release is done. + If not in 'dry' mode, a mail will be automatically sent to the mailing list. + You can disable it with the option '--disable_mail' + + $ python3 dev_tools/build_release.py --publish --remote origin --disable_mail + + The script takes over almost all + steps necessary for a release from a high level point of view it does the following things: + + - run prerequisite checks ie. check for Java 1.6 being present or S3 credentials available as env variables + - detect the version to release from the specified branch (--branch) or the current branch + - creates a release branch & updates pom.xml and README.md to point to a release version rather than a snapshot + - builds the artifacts + - commits the new version and merges the release branch into the source branch + - creates a tag and pushes the commit to the specified origin (--remote) + - publishes the releases to sonatype and S3 + - send a mail based on github issues fixed by this version + +Once it's done it will print all the remaining steps. + + Prerequisites: + - Python 3k for script execution + - Boto for S3 Upload ($ apt-get install python-boto or pip-3.3 install boto) + - github3 module (pip-3.3 install github3.py) + - S3 keys exported via ENV Variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) + - GITHUB (login/password) or key exported via ENV Variables (GITHUB_LOGIN, GITHUB_PASSWORD or GITHUB_KEY) + (see https://github.com/settings/applications#personal-access-tokens) - Optional: default to no authentication + - SMTP_HOST - Optional: default to localhost + - MAIL_SENDER - Optional: default to 'david@pilato.fr': must be authorized to send emails to elasticsearch mailing list + - MAIL_TO - Optional: default to 'elasticsearch@googlegroups.com' +""" +env = os.environ + +LOG = env.get('ES_RELEASE_LOG', '/tmp/elasticsearch_release.log') +ROOT_DIR = os.path.join(abspath(dirname(__file__)), '../') +README_FILE = ROOT_DIR + 'README.md' +POM_FILE = ROOT_DIR + 'pom.xml' + +def log(msg): + log_plain('\n%s' % msg) + +def log_plain(msg): + f = open(LOG, mode='ab') + f.write(msg.encode('utf-8')) + f.close() + +def run(command, quiet=False): + log('%s: RUN: %s\n' % (datetime.datetime.now(), command)) + if os.system('%s >> %s 2>&1' % (command, LOG)): + msg = ' FAILED: %s [see log %s]' % (command, LOG) + if not quiet: + print(msg) + raise RuntimeError(msg) + +try: + JAVA_HOME = env['JAVA_HOME'] +except KeyError: + raise RuntimeError(""" + Please set JAVA_HOME in the env before running release tool + On OSX use: export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'`""") + +try: + MVN='mvn' + # make sure mvn3 is used if mvn3 is available + # some systems use maven 2 as default + run('mvn3 --version', quiet=True) + MVN='mvn3' +except RuntimeError: + pass + + +def java_exe(): + path = JAVA_HOME + return 'export JAVA_HOME="%s" PATH="%s/bin:$PATH" JAVACMD="%s/bin/java"' % (path, path, path) + +def verify_java_version(version): + s = os.popen('%s; java -version 2>&1' % java_exe()).read() + if s.find(' version "%s.' % version) == -1: + raise RuntimeError('got wrong version for java %s:\n%s' % (version, s)) + +# Verifies the java version. We guarantee that we run with Java 1.6 +# If 1.6 is not available fail the build! +def verify_mvn_java_version(version, mvn): + s = os.popen('%s; %s --version 2>&1' % (java_exe(), mvn)).read() + if s.find('Java version: %s' % version) == -1: + raise RuntimeError('got wrong java version for %s %s:\n%s' % (mvn, version, s)) + +# Returns the hash of the current git HEAD revision +def get_head_hash(): + return os.popen(' git rev-parse --verify HEAD 2>&1').read().strip() + +# Returns the hash of the given tag revision +def get_tag_hash(tag): + return os.popen('git show-ref --tags %s --hash 2>&1' % (tag)).read().strip() + +# Returns the name of the current branch +def get_current_branch(): + return os.popen('git rev-parse --abbrev-ref HEAD 2>&1').read().strip() + +verify_java_version('1.6') # we require to build with 1.6 +verify_mvn_java_version('1.6', MVN) + +# Utility that returns the name of the release branch for a given version +def release_branch(version): + return 'release_branch_%s' % version + +# runs get fetch on the given remote +def fetch(remote): + run('git fetch %s' % remote) + +# Creates a new release branch from the given source branch +# and rebases the source branch from the remote before creating +# the release branch. Note: This fails if the source branch +# doesn't exist on the provided remote. +def create_release_branch(remote, src_branch, release): + run('git checkout %s' % src_branch) + run('git pull --rebase %s %s' % (remote, src_branch)) + run('git checkout -b %s' % (release_branch(release))) + + +# Reads the given file and applies the +# callback to it. If the callback changed +# a line the given file is replaced with +# the modified input. +def process_file(file_path, line_callback): + fh, abs_path = tempfile.mkstemp() + modified = False + with open(abs_path,'w', encoding='utf-8') as new_file: + with open(file_path, encoding='utf-8') as old_file: + for line in old_file: + new_line = line_callback(line) + modified = modified or (new_line != line) + new_file.write(new_line) + os.close(fh) + if modified: + #Remove original file + os.remove(file_path) + #Move new file + shutil.move(abs_path, file_path) + return True + else: + # nothing to do - just remove the tmp file + os.remove(abs_path) + return False + +# Guess the next snapshot version number (increment second digit) +def guess_snapshot(version): + digits=list(map(int, re.findall(r'\d+', version))) + source='%s.%s' % (digits[0], digits[1]) + destination='%s.%s' % (digits[0], digits[1]+1) + return version.replace(source, destination) + +# Moves the pom.xml file from a snapshot to a release +def remove_maven_snapshot(pom, release): + pattern = '%s-SNAPSHOT' % release + replacement = '%s' % release + def callback(line): + return line.replace(pattern, replacement) + process_file(pom, callback) + +# Moves the README.md file from a snapshot to a release +def remove_version_snapshot(readme_file, release): + pattern = '%s-SNAPSHOT' % release + replacement = '%s ' % release + def callback(line): + return line.replace(pattern, replacement) + process_file(readme_file, callback) + +# Moves the pom.xml file to the next snapshot +def add_maven_snapshot(pom, release, snapshot): + pattern = '%s' % release + replacement = '%s-SNAPSHOT' % snapshot + def callback(line): + return line.replace(pattern, replacement) + process_file(pom, callback) + +# Add in README.md file the next snapshot +def add_version_snapshot(readme_file, release, snapshot): + pattern = '| %s ' % release + replacement = '| %s-SNAPSHOT' % snapshot + def callback(line): + # If we find pattern, we copy the line and replace its content + if line.find(pattern) >= 0: + return line.replace(pattern, replacement).replace('%s' % (datetime.datetime.now().strftime("%Y-%m-%d")), + 'XXXX-XX-XX')+line + else: + return line + process_file(readme_file, callback) + + +# Set release date in README.md file +def set_date(readme_file): + pattern = 'XXXX-XX-XX' + replacement = '%s' % (datetime.datetime.now().strftime("%Y-%m-%d")) + def callback(line): + return line.replace(pattern, replacement) + process_file(readme_file, callback) + +# Update installation instructions in README.md file +def set_install_instructions(readme_file, artifact_name, release): + pattern = '`bin/plugin -install elasticsearch/%s/.+`' % artifact_name + replacement = '`bin/plugin -install elasticsearch/%s/%s`' % (artifact_name, release) + def callback(line): + return re.sub(pattern, replacement, line) + process_file(readme_file, callback) + + +# Stages the given files for the next git commit +def add_pending_files(*files): + for file in files: + run('git add %s' % file) + +# Executes a git commit with 'release [version]' as the commit message +def commit_release(artifact_id, release): + run('git commit -m "prepare release %s-%s"' % (artifact_id, release)) + +def commit_snapshot(): + run('git commit -m "prepare for next development iteration"') + +def tag_release(release): + run('git tag -a v%s -m "Tag release version %s"' % (release, release)) + +def run_mvn(*cmd): + for c in cmd: + run('%s; %s -f %s %s' % (java_exe(), MVN, POM_FILE, c)) + +def build_release(run_tests=False, dry_run=True): + target = 'deploy' + if dry_run: + target = 'package' + if run_tests: + run_mvn('clean test') + run_mvn('clean %s -DskipTests' %(target)) + +# Checks the pom.xml for the release version. 2.0.0-SNAPSHOT +# This method fails if the pom file has no SNAPSHOT version set ie. +# if the version is already on a release version we fail. +# Returns the next version string ie. 0.90.7 +def find_release_version(src_branch): + run('git checkout %s' % src_branch) + with open(POM_FILE, encoding='utf-8') as file: + for line in file: + match = re.search(r'(.+)-SNAPSHOT', line) + if match: + return match.group(1) + raise RuntimeError('Could not find release version in branch %s' % src_branch) + +# extract a value from pom.xml +def find_from_pom(tag): + with open(POM_FILE, encoding='utf-8') as file: + for line in file: + match = re.search(r'<%s>(.+)' % (tag, tag), line) + if match: + return match.group(1) + raise RuntimeError('Could not find <%s> in pom.xml file' % (tag)) + +def get_artifacts(artifact_id, release): + artifact_path = ROOT_DIR + 'target/releases/%s-%s.zip' % (artifact_id, release) + print(' Path %s' % (artifact_path)) + if not os.path.isfile(artifact_path): + raise RuntimeError('Could not find required artifact at %s' % (artifact_path)) + return artifact_path + +# Generates sha1 for a file +# and returns the checksum files as well +# as the given files in a list +def generate_checksums(release_file): + res = [] + directory = os.path.dirname(release_file) + file = os.path.basename(release_file) + checksum_file = '%s.sha1.txt' % file + + if os.system('cd %s; shasum %s > %s' % (directory, file, checksum_file)): + raise RuntimeError('Failed to generate checksum for file %s' % release_file) + res = res + [os.path.join(directory, checksum_file), release_file] + return res + +def git_merge(src_branch, release_version): + run('git checkout %s' % src_branch) + run('git merge %s' % release_branch(release_version)) + +def git_push(remote, src_branch, release_version, dry_run): + if not dry_run: + run('git push %s %s' % (remote, src_branch)) # push the commit + run('git push %s v%s' % (remote, release_version)) # push the tag + else: + print(' dryrun [True] -- skipping push to remote %s' % remote) + +def publish_artifacts(artifacts, base='elasticsearch/elasticsearch', dry_run=True): + location = os.path.dirname(os.path.realpath(__file__)) + for artifact in artifacts: + if dry_run: + print('Skip Uploading %s to Amazon S3 in %s' % (artifact, base)) + else: + print('Uploading %s to Amazon S3' % artifact) + # requires boto to be installed but it is not available on python3k yet so we use a dedicated tool + run('python %s/upload-s3.py --file %s --path %s' % (location, os.path.abspath(artifact), base)) + + +################# +## +## +## Email and Github Management +## +## +################# +def format_issues_plain(issues, title='Fix'): + response = "" + + if len(issues) > 0: + response += '%s:\n' % title + for issue in issues: + response += ' * [%s] - %s (%s)\n' % (issue.number, issue.title, issue.html_url) + + return response + +def format_issues_html(issues, title='Fix'): + response = "" + + if len(issues) > 0: + response += '

%s

\n
    \n' % title + for issue in issues: + response += '[%s] - %s\n' % (issue.html_url, issue.number, issue.title) + response += '
\n' + + return response + +def get_github_repository(reponame, + login=env.get('GITHUB_LOGIN', None), + password=env.get('GITHUB_PASSWORD', None), + key=env.get('GITHUB_KEY', None)): + if login: + g = github3.login(login, password) + elif key: + g = github3.login(token=key) + else: + g = github3.GitHub() + + return g.repository("elasticsearch", reponame) + +# Check if there are some remaining open issues and fails +def check_opened_issues(version, repository, reponame): + opened_issues = [i for i in repository.iter_issues(state='open', labels='%s' % version)] + if len(opened_issues)>0: + raise NameError('Some issues [%s] are still opened. Check https://github.com/elasticsearch/%s/issues?labels=%s&state=open' + % (len(opened_issues), reponame, version)) + +# List issues from github: can be done anonymously if you don't +# exceed a given number of github API calls per day +# Check if there are some remaining open issues and fails +def list_issues(version, + repository, + severity='bug'): + issues = [i for i in repository.iter_issues(state='closed', labels='%s,%s' % (severity, version))] + return issues + +# Get issues from github and generates a Plain/HTML Multipart email +# And send it if dry_run=False +def prepare_email(artifact_id, release_version, repository, + artifact_name, artifact_description, project_url, + severity_labels_bug='bug', + severity_labels_update='update', + severity_labels_new='new', + severity_labels_doc='doc'): + + ## Get bugs from github + issues_bug = list_issues(release_version, repository, severity=severity_labels_bug) + issues_update = list_issues(release_version, repository, severity=severity_labels_update) + issues_new = list_issues(release_version, repository, severity=severity_labels_new) + issues_doc = list_issues(release_version, repository, severity=severity_labels_doc) + + ## Format content to plain text + plain_issues_bug = format_issues_plain(issues_bug, 'Fix') + plain_issues_update = format_issues_plain(issues_update, 'Update') + plain_issues_new = format_issues_plain(issues_new, 'New') + plain_issues_doc = format_issues_plain(issues_doc, 'Doc') + + ## Format content to html + html_issues_bug = format_issues_html(issues_bug, 'Fix') + html_issues_update = format_issues_html(issues_update, 'Update') + html_issues_new = format_issues_html(issues_new, 'New') + html_issues_doc = format_issues_html(issues_doc, 'Doc') + + if len(issues_bug)+len(issues_update)+len(issues_new)+len(issues_doc) > 0: + plain_empty_message = "" + html_empty_message = "" + + else: + plain_empty_message = "No issue listed for this release" + html_empty_message = "

No issue listed for this release

" + + msg = MIMEMultipart('alternative') + msg['Subject'] = '[ANN] %s %s released' % (artifact_name, release_version) + text = """ +Heya, + + +We are pleased to announce the release of the %(artifact_name)s, version %(release_version)s. + +%(artifact_description)s. + +%(project_url)s + +Release Notes - %(artifact_id)s - Version %(release_version)s + +%(empty_message)s +%(issues_bug)s +%(issues_update)s +%(issues_new)s +%(issues_doc)s + +Issues, Pull requests, Feature requests are warmly welcome on %(artifact_id)s project repository: %(project_url)s +For questions or comments around this plugin, feel free to use elasticsearch mailing list: https://groups.google.com/forum/#!forum/elasticsearch + +Enjoy, + +-The Elasticsearch team +""" % {'release_version': release_version, + 'artifact_id': artifact_id, + 'artifact_name': artifact_name, + 'artifact_description': artifact_description, + 'project_url': project_url, + 'empty_message': plain_empty_message, + 'issues_bug': plain_issues_bug, + 'issues_update': plain_issues_update, + 'issues_new': plain_issues_new, + 'issues_doc': plain_issues_doc} + + html = """ + + +

Heya,

+ +

We are pleased to announce the release of the %(artifact_name)s, version %(release_version)s

+ +
%(artifact_description)s.
+ +

Release Notes - Version %(release_version)s

+%(empty_message)s +%(issues_bug)s +%(issues_update)s +%(issues_new)s +%(issues_doc)s + +

Issues, Pull requests, Feature requests are warmly welcome on +%(artifact_id)s project repository!

+

For questions or comments around this plugin, feel free to use elasticsearch +mailing list!

+ +

Enjoy,

+ +

- The Elasticsearch team

+ +""" % {'release_version': release_version, + 'artifact_id': artifact_id, + 'artifact_name': artifact_name, + 'artifact_description': artifact_description, + 'project_url': project_url, + 'empty_message': html_empty_message, + 'issues_bug': html_issues_bug, + 'issues_update': html_issues_update, + 'issues_new': html_issues_new, + 'issues_doc': html_issues_doc} + + # Record the MIME types of both parts - text/plain and text/html. + part1 = MIMEText(text, 'plain') + part2 = MIMEText(html, 'html') + + # Attach parts into message container. + # According to RFC 2046, the last part of a multipart message, in this case + # the HTML message, is best and preferred. + msg.attach(part1) + msg.attach(part2) + + return msg + +def send_email(msg, + dry_run=True, + mail=True, + sender=env.get('MAIL_SENDER'), + to=env.get('MAIL_TO', 'elasticsearch@googlegroups.com'), + smtp_server=env.get('SMTP_SERVER', 'localhost')): + msg['From'] = 'Elasticsearch Team <%s>' % sender + msg['To'] = 'Elasticsearch Mailing List <%s>' % to + # save mail on disk + with open(ROOT_DIR+'target/email.txt', 'w') as email_file: + email_file.write(msg.as_string()) + if mail and not dry_run: + s = smtplib.SMTP(smtp_server, 25) + s.sendmail(sender, to, msg.as_string()) + s.quit() + else: + print('generated email: open %starget/email.txt' % ROOT_DIR) + +def print_sonatype_notice(): + settings = os.path.join(os.path.expanduser('~'), '.m2/settings.xml') + if os.path.isfile(settings): + with open(settings, encoding='utf-8') as settings_file: + for line in settings_file: + if line.strip() == 'sonatype-nexus-snapshots': + # moving out - we found the indicator no need to print the warning + return + print(""" + NOTE: No sonatype settings detected, make sure you have configured + your sonatype credentials in '~/.m2/settings.xml': + + + ... + + + sonatype-nexus-snapshots + your-jira-id + your-jira-pwd + + + sonatype-nexus-staging + your-jira-id + your-jira-pwd + + + ... + + """) + +def check_s3_credentials(): + if not env.get('AWS_ACCESS_KEY_ID', None) or not env.get('AWS_SECRET_ACCESS_KEY', None): + raise RuntimeError('Could not find "AWS_ACCESS_KEY_ID" / "AWS_SECRET_ACCESS_KEY" in the env variables please export in order to upload to S3') + +def check_github_credentials(): + if not env.get('GITHUB_KEY', None) and not env.get('GITHUB_LOGIN', None): + log('WARN: Could not find "GITHUB_LOGIN" / "GITHUB_PASSWORD" or "GITHUB_KEY" in the env variables. You could need it.') + +def check_email_settings(): + if not env.get('MAIL_SENDER', None): + raise RuntimeError('Could not find "MAIL_SENDER"') + +# we print a notice if we can not find the relevant infos in the ~/.m2/settings.xml +print_sonatype_notice() + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Builds and publishes a Elasticsearch Plugin Release') + parser.add_argument('--branch', '-b', metavar='master', default=get_current_branch(), + help='The branch to release from. Defaults to the current branch.') + parser.add_argument('--skiptests', '-t', dest='tests', action='store_false', + help='Skips tests before release. Tests are run by default.') + parser.set_defaults(tests=True) + parser.add_argument('--remote', '-r', metavar='origin', default='origin', + help='The remote to push the release commit and tag to. Default is [origin]') + parser.add_argument('--publish', '-p', dest='dryrun', action='store_false', + help='Publishes the release. Disable by default.') + parser.add_argument('--disable_mail', '-dm', dest='mail', action='store_false', + help='Do not send a release email. Email is sent by default.') + + parser.set_defaults(dryrun=True) + parser.set_defaults(mail=True) + args = parser.parse_args() + + src_branch = args.branch + remote = args.remote + run_tests = args.tests + dry_run = args.dryrun + mail = args.mail + + if not dry_run: + check_s3_credentials() + print('WARNING: dryrun is set to "false" - this will push and publish the release') + if mail: + check_email_settings() + print('An email to %s will be sent after the release' + % env.get('MAIL_TO', 'elasticsearch@googlegroups.com')) + input('Press Enter to continue...') + + check_github_credentials() + + print(''.join(['-' for _ in range(80)])) + print('Preparing Release from branch [%s] running tests: [%s] dryrun: [%s]' % (src_branch, run_tests, dry_run)) + print(' JAVA_HOME is [%s]' % JAVA_HOME) + print(' Running with maven command: [%s] ' % (MVN)) + + release_version = find_release_version(src_branch) + artifact_id = find_from_pom('artifactId') + artifact_name = find_from_pom('name') + artifact_description = find_from_pom('description') + project_url = find_from_pom('url') + print(' Artifact Id: [%s]' % artifact_id) + print(' Release version: [%s]' % release_version) + + # extract snapshot + default_snapshot_version = guess_snapshot(release_version) + snapshot_version = input('Enter next snapshot version [%s]:' % default_snapshot_version) + snapshot_version = snapshot_version or default_snapshot_version + + print(' Next version: [%s-SNAPSHOT]' % snapshot_version) + print(' Artifact Name: [%s]' % artifact_name) + print(' Artifact Description: [%s]' % artifact_description) + print(' Project URL: [%s]' % project_url) + + if not dry_run: + smoke_test_version = release_version + head_hash = get_head_hash() + run_mvn('clean') # clean the env! + create_release_branch(remote, src_branch, release_version) + print(' Created release branch [%s]' % (release_branch(release_version))) + success = False + try: + pending_files = [POM_FILE, README_FILE] + remove_maven_snapshot(POM_FILE, release_version) + remove_version_snapshot(README_FILE, release_version) + set_date(README_FILE) + set_install_instructions(README_FILE, artifact_id, release_version) + print(' Done removing snapshot version') + add_pending_files(*pending_files) # expects var args use * to expand + commit_release(artifact_id, release_version) + print(' Committed release version [%s]' % release_version) + print(''.join(['-' for _ in range(80)])) + print('Building Release candidate') + input('Press Enter to continue...') + print(' Checking github issues') + repository = get_github_repository(artifact_id) + check_opened_issues(release_version, repository, artifact_id) + if not dry_run: + print(' Running maven builds now and publish to sonatype - run-tests [%s]' % run_tests) + else: + print(' Running maven builds now run-tests [%s]' % run_tests) + build_release(run_tests=run_tests, dry_run=dry_run) + artifact = get_artifacts(artifact_id, release_version) + artifact_and_checksums = generate_checksums(artifact) + print(''.join(['-' for _ in range(80)])) + + print('Finish Release -- dry_run: %s' % dry_run) + input('Press Enter to continue...') + print(' merge release branch') + git_merge(src_branch, release_version) + print(' tag') + tag_release(release_version) + + add_maven_snapshot(POM_FILE, release_version, snapshot_version) + add_version_snapshot(README_FILE, release_version, snapshot_version) + add_pending_files(*pending_files) + commit_snapshot() + + print(' push to %s %s -- dry_run: %s' % (remote, src_branch, dry_run)) + git_push(remote, src_branch, release_version, dry_run) + print(' publish artifacts to S3 -- dry_run: %s' % dry_run) + publish_artifacts(artifact_and_checksums, base='elasticsearch/%s' % (artifact_id) , dry_run=dry_run) + print(' preparing email (from github issues)') + msg = prepare_email(artifact_id, release_version, repository, artifact_name, artifact_description, project_url) + print(' sending email -- dry_run: %s, mail: %s' % (dry_run, mail)) + send_email(msg, dry_run=dry_run, mail=mail) + + pending_msg = """ +Release successful pending steps: + * close and release sonatype repo: https://oss.sonatype.org/ + * check if the release is there https://oss.sonatype.org/content/repositories/releases/org/elasticsearch/%(artifact_id)s/%(version)s + * tweet about the release +""" + print(pending_msg % {'version': release_version, + 'artifact_id': artifact_id, + 'project_url': project_url}) + success = True + finally: + if not success: + run('git reset --hard HEAD') + run('git checkout %s' % src_branch) + elif dry_run: + print('End of dry_run') + input('Press Enter to reset changes...') + + run('git reset --hard %s' % head_hash) + run('git tag -d v%s' % release_version) + # we delete this one anyways + run('git branch -D %s' % (release_branch(release_version))) diff --git a/dev-tools/upload-s3.py b/dev-tools/upload-s3.py new file mode 100644 index 00000000000..95ea576e65c --- /dev/null +++ b/dev-tools/upload-s3.py @@ -0,0 +1,67 @@ +# 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. + +import os +import sys +import argparse +try: + import boto.s3 +except: + raise RuntimeError(""" + S3 upload requires boto to be installed + Use one of: + 'pip install -U boto' + 'apt-get install python-boto' + 'easy_install boto' + """) + +import boto.s3 + + +def list_buckets(conn): + return conn.get_all_buckets() + + +def upload_s3(conn, path, key, file, bucket): + print 'Uploading %s to Amazon S3 bucket %s/%s' % \ + (file, bucket, os.path.join(path, key)) + def percent_cb(complete, total): + sys.stdout.write('.') + sys.stdout.flush() + bucket = conn.create_bucket(bucket) + k = bucket.new_key(os.path.join(path, key)) + k.set_contents_from_filename(file, cb=percent_cb, num_cb=100) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Uploads files to Amazon S3') + parser.add_argument('--file', '-f', metavar='path to file', + help='the branch to release from', required=True) + parser.add_argument('--bucket', '-b', metavar='B42', default='download.elasticsearch.org', + help='The S3 Bucket to upload to') + parser.add_argument('--path', '-p', metavar='elasticsearch/elasticsearch', default='elasticsearch/elasticsearch', + help='The key path to use') + parser.add_argument('--key', '-k', metavar='key', default=None, + help='The key - uses the file name as default key') + args = parser.parse_args() + if args.key: + key = args.key + else: + key = os.path.basename(args.file) + + connection = boto.connect_s3() + upload_s3(connection, args.path, key, args.file, args.bucket); + diff --git a/pom.xml b/pom.xml index 096bfde42b4..a9c01af9df2 100644 --- a/pom.xml +++ b/pom.xml @@ -2,13 +2,14 @@ - elasticsearch-lang-javascript 4.0.0 org.elasticsearch elasticsearch-lang-javascript 2.0.0-SNAPSHOT jar - JavaScript lang plugin for ElasticSearch + Elasticsearch JavaScript language plugin + The JavaScript language plugin allows to have javascript as the language of scripts to execute. + https://github.com/elasticsearch/elasticsearch-lang-javascript/ 2009 From 4f617d180cd9286e13a84a33fd9d1afdd69b14d2 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 7 Mar 2014 15:43:37 +0100 Subject: [PATCH 32/78] Add plugin version in es-plugin.properties With https://github.com/elasticsearch/elasticsearch/issues/2784, we can now add plugin version in `es-plugin.properties` file. It will only be used with elasticsearch 1.0.0 and upper. No need to push it in 1.x branch. Closes #16. --- pom.xml | 9 +++++++++ src/main/resources/es-plugin.properties | 1 + 2 files changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index a9c01af9df2..8159815c0a2 100644 --- a/pom.xml +++ b/pom.xml @@ -102,6 +102,15 @@ + + + src/main/resources + true + + **/*.properties + + + org.apache.maven.plugins diff --git a/src/main/resources/es-plugin.properties b/src/main/resources/es-plugin.properties index e88bdca70c8..92f26b778d7 100644 --- a/src/main/resources/es-plugin.properties +++ b/src/main/resources/es-plugin.properties @@ -1 +1,2 @@ plugin=org.elasticsearch.plugin.javascript.JavaScriptPlugin +version=${project.version} From 4d90405ba961d6345a7b1a86507438a3244924c3 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 7 Mar 2014 15:48:49 +0100 Subject: [PATCH 33/78] Update to elasticsearch 1.0.0 Closes #14 --- README.md | 2 +- pom.xml | 4 +-- .../JavaScriptScriptSearchTests.java | 25 +++++++++++-------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bab656d7c72..4908f8e5f42 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ JavaScript lang Plugin for Elasticsearch ================================== -The JavaScript language plugin allows to have `javascript` as the language of scripts to execute. +The JavaScript language plugin allows to have `javascript` (or `js`) as the language of scripts to execute. In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.0.0.RC1`. diff --git a/pom.xml b/pom.xml index 8159815c0a2..453146d83a4 100644 --- a/pom.xml +++ b/pom.xml @@ -32,8 +32,8 @@ - 1.0.0.RC1 - 4.6.0 + 1.0.0 + 4.6.1 1 true onerror diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 68e6a5c7af4..77bffd5d389 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.script.javascript; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -112,11 +113,7 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { .addScriptField("s_obj2_arr2", "js", "_source.obj2.arr2", null) .execute().actionGet(); - Map sObj1 = (Map) response.getHits().getAt(0).field("_source.obj1").value(); - assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.getHits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - - sObj1 = (Map) response.getHits().getAt(0).field("s_obj1").value(); + Map sObj1 = (Map) response.getHits().getAt(0).field("s_obj1").value(); assertThat(sObj1.get("test").toString(), equalTo("something")); assertThat(response.getHits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); @@ -145,7 +142,8 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running doc['num1'].value"); SearchResponse response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("js"))) + .source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value")) + .add(ScoreFunctionBuilders.scriptFunction("doc['num1'].value").lang("js")))) ).actionGet(); assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); @@ -159,7 +157,8 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running -doc['num1'].value"); response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("js"))) + .source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value")) + .add(ScoreFunctionBuilders.scriptFunction("-doc['num1'].value").lang("js")))) ).actionGet(); assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); @@ -174,7 +173,8 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running pow(doc['num1'].value, 2)"); response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("js"))) + .source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value")) + .add(ScoreFunctionBuilders.scriptFunction("Math.pow(doc['num1'].value, 2)").lang("js")))) ).actionGet(); assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); @@ -188,7 +188,8 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running max(doc['num1'].value, 1)"); response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1)").lang("js"))) + .source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value")) + .add(ScoreFunctionBuilders.scriptFunction("Math.max(doc['num1'].value, 1)").lang("js")))) ).actionGet(); assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); @@ -202,7 +203,8 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running doc['num1'].value * _score"); response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("js"))) + .source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value")) + .add(ScoreFunctionBuilders.scriptFunction("doc['num1'].value * _score").lang("js")))) ).actionGet(); assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); @@ -216,7 +218,8 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running param1 * param2 * _score"); response = client().search(searchRequest() .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js"))) + .source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value")) + .add(ScoreFunctionBuilders.scriptFunction("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js")))) ).actionGet(); assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0)); From 2b61b004c44d400cd10591f57f25c1998b02b6dd Mon Sep 17 00:00:00 2001 From: Hugues Malphettes Date: Mon, 3 Mar 2014 16:05:17 +0800 Subject: [PATCH 34/78] Update to elasticsearch 1.0.1 (Lucene 4.7.0) Closes #12. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 453146d83a4..04910105863 100644 --- a/pom.xml +++ b/pom.xml @@ -32,8 +32,8 @@ - 1.0.0 - 4.6.1 + 1.0.1 + 4.7.0 1 true onerror From f5366da0bfd731991335446ab6857180af1d51e3 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 7 Mar 2014 16:40:46 +0100 Subject: [PATCH 35/78] Add Javascript examples Closes #8. --- README.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/README.md b/README.md index 4908f8e5f42..a5120e610c6 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,131 @@ In order to install the plugin, simply run: `bin/plugin -install elasticsearch/e | 2.0.0-SNAPSHOT | 1.0.0.RC1 -> master | 1.7R4 | XXXX-XX-XX | | 2.0.0.RC1 | 1.0.0.RC1 -> master | 1.7R4 | 2014-01-15 | +Using javascript with function_score +------------------------------------ + +Let's say you want to use `function_score` API using `javascript`. Here is +a way of doing it: + +```sh +curl -XDELETE "http://localhost:9200/test" + +curl -XPUT "http://localhost:9200/test/doc/1" -d '{ + "num": 1.0 +}' + +curl -XPUT "http://localhost:9200/test/doc/2?refresh" -d '{ + "num": 2.0 +}' + +curl -XGET "http://localhost:9200/test/_search?pretty" -d ' +{ + "query": { + "function_score": { + "script_score": { + "script": "doc[\"num\"].value", + "lang": "javascript" + } + } + } +}' +``` + +gives + +```javascript +{ + // ... + "hits": { + "total": 2, + "max_score": 4, + "hits": [ + { + // ... + "_score": 4 + }, + { + // ... + "_score": 1 + } + ] + } +} +``` + +Using javascript with script_fields +----------------------------------- + +```sh +curl -XDELETE "http://localhost:9200/test" + +curl -XPUT "http://localhost:9200/test/doc/1?refresh" -d' +{ + "obj1": { + "test": "something" + }, + "obj2": { + "arr2": [ "arr_value1", "arr_value2" ] + } +}' + +curl -XGET "http://localhost:9200/test/_search" -d' +{ + "script_fields": { + "s_obj1": { + "script": "_source.obj1", "lang": "js" + }, + "s_obj1_test": { + "script": "_source.obj1.test", "lang": "js" + }, + "s_obj2": { + "script": "_source.obj2", "lang": "js" + }, + "s_obj2_arr2": { + "script": "_source.obj2.arr2", "lang": "js" + } + } +}' +``` + +gives + +```javascript +{ + // ... + "hits": [ + { + // ... + "fields": { + "s_obj2_arr2": [ + [ + "arr_value1", + "arr_value2" + ] + ], + "s_obj1_test": [ + "something" + ], + "s_obj2": [ + { + "arr2": [ + "arr_value1", + "arr_value2" + ] + } + ], + "s_obj1": [ + { + "test": "something" + } + ] + } + } + ] +} +``` + + License ------- From 4a308a0223c51e2c5d8a5e9c63a86c26bc534f98 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 7 Mar 2014 16:42:29 +0100 Subject: [PATCH 36/78] Remove `_source.obj1` Related to #14. --- .../script/javascript/JavaScriptScriptSearchTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 77bffd5d389..f8918d4570f 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -106,7 +106,6 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { SearchResponse response = client().prepareSearch() .setQuery(matchAllQuery()) - .addField("_source.obj1") // we also automatically detect _source in fields .addScriptField("s_obj1", "js", "_source.obj1", null) .addScriptField("s_obj1_test", "js", "_source.obj1.test", null) .addScriptField("s_obj2", "js", "_source.obj2", null) From b54ba3a52488c9e31dfe2a6c37b7478591025f71 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 19 Mar 2014 22:45:17 +0100 Subject: [PATCH 37/78] Disable java and maven version checking And fix typo in email html --- dev-tools/build_release.py | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/dev-tools/build_release.py b/dev-tools/build_release.py index 9166b09e7e3..74acd8c5f4e 100755 --- a/dev-tools/build_release.py +++ b/dev-tools/build_release.py @@ -43,7 +43,7 @@ from os.path import dirname, abspath The script takes over almost all steps necessary for a release from a high level point of view it does the following things: - - run prerequisite checks ie. check for Java 1.6 being present or S3 credentials available as env variables + - run prerequisite checks ie. check for S3 credentials available as env variables - detect the version to release from the specified branch (--branch) or the current branch - creates a release branch & updates pom.xml and README.md to point to a release version rather than a snapshot - builds the artifacts @@ -109,18 +109,6 @@ def java_exe(): path = JAVA_HOME return 'export JAVA_HOME="%s" PATH="%s/bin:$PATH" JAVACMD="%s/bin/java"' % (path, path, path) -def verify_java_version(version): - s = os.popen('%s; java -version 2>&1' % java_exe()).read() - if s.find(' version "%s.' % version) == -1: - raise RuntimeError('got wrong version for java %s:\n%s' % (version, s)) - -# Verifies the java version. We guarantee that we run with Java 1.6 -# If 1.6 is not available fail the build! -def verify_mvn_java_version(version, mvn): - s = os.popen('%s; %s --version 2>&1' % (java_exe(), mvn)).read() - if s.find('Java version: %s' % version) == -1: - raise RuntimeError('got wrong java version for %s %s:\n%s' % (mvn, version, s)) - # Returns the hash of the current git HEAD revision def get_head_hash(): return os.popen(' git rev-parse --verify HEAD 2>&1').read().strip() @@ -133,9 +121,6 @@ def get_tag_hash(tag): def get_current_branch(): return os.popen('git rev-parse --abbrev-ref HEAD 2>&1').read().strip() -verify_java_version('1.6') # we require to build with 1.6 -verify_mvn_java_version('1.6', MVN) - # Utility that returns the name of the release branch for a given version def release_branch(version): return 'release_branch_%s' % version @@ -218,7 +203,7 @@ def add_version_snapshot(readme_file, release, snapshot): # If we find pattern, we copy the line and replace its content if line.find(pattern) >= 0: return line.replace(pattern, replacement).replace('%s' % (datetime.datetime.now().strftime("%Y-%m-%d")), - 'XXXX-XX-XX')+line + 'XXXX-XX-XX')+line else: return line process_file(readme_file, callback) @@ -356,15 +341,15 @@ def format_issues_html(issues, title='Fix'): if len(issues) > 0: response += '

%s

\n
    \n' % title for issue in issues: - response += '[%s] - %s\n' % (issue.html_url, issue.number, issue.title) + response += '
  • [%s] - %s\n' % (issue.html_url, issue.number, issue.title) response += '
\n' return response def get_github_repository(reponame, - login=env.get('GITHUB_LOGIN', None), - password=env.get('GITHUB_PASSWORD', None), - key=env.get('GITHUB_KEY', None)): + login=env.get('GITHUB_LOGIN', None), + password=env.get('GITHUB_PASSWORD', None), + key=env.get('GITHUB_KEY', None)): if login: g = github3.login(login, password) elif key: From 22465d23e7bcde7be84df5d3ee18703ff1ebfe1e Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 28 Mar 2014 18:35:10 +0100 Subject: [PATCH 38/78] Create branches according to elasticsearch versions We create branches: * es-0.90 for elasticsearch 0.90 * es-1.0 for elasticsearch 1.0 * es-1.1 for elasticsearch 1.1 * master for elasticsearch master We also check that before releasing we don't have a dependency to an elasticsearch SNAPSHOT version. Add links to each version in documentation --- README.md | 13 ++++++--- dev-tools/build_release.py | 29 +++++++++++++++++++ pom.xml | 4 +-- .../JavaScriptScriptSearchTests.java | 3 -- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a5120e610c6..a48e1942286 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,18 @@ The JavaScript language plugin allows to have `javascript` (or `js`) as the lang In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.0.0.RC1`. -* For 1.0.x elasticsearch versions, look at [master branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/master). -* For 0.90.x elasticsearch versions, look at [1.x branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/1.x). +* For master elasticsearch versions, look at [master branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/master). +* For 1.1.x elasticsearch versions, look at [es-1.1 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.1). +* For 1.0.x elasticsearch versions, look at [es-1.0 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.0). +* For 0.90.x elasticsearch versions, look at [es-0.90 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-0.90). | JavaScript Lang Plugin | elasticsearch | rhino | Release date | |-----------------------------|---------------------|----------|:------------:| -| 2.0.0-SNAPSHOT | 1.0.0.RC1 -> master | 1.7R4 | XXXX-XX-XX | -| 2.0.0.RC1 | 1.0.0.RC1 -> master | 1.7R4 | 2014-01-15 | +| 3.0.0-SNAPSHOT | master | 1.7R4 | XXXX-XX-XX | + +Please read documentation relative to the version you are using: + +* [3.0.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-lang-javascript/blob/master/README.md) Using javascript with function_score ------------------------------------ diff --git a/dev-tools/build_release.py b/dev-tools/build_release.py index 74acd8c5f4e..db8345440c7 100755 --- a/dev-tools/build_release.py +++ b/dev-tools/build_release.py @@ -208,6 +208,29 @@ def add_version_snapshot(readme_file, release, snapshot): return line process_file(readme_file, callback) +# Moves the README.md file from a snapshot to a release (documentation link) +def remove_documentation_snapshot(readme_file, repo_url, release, branch): + pattern = '* [%s-SNAPSHOT](%sblob/%s/README.md)' % (release, repo_url, branch) + replacement = '* [%s](%sblob/v%s/README.md)' % (release, repo_url, release) + def callback(line): + # If we find pattern, we replace its content + if line.find(pattern) >= 0: + return line.replace(pattern, replacement) + else: + return line + process_file(readme_file, callback) + +# Add in README.markdown file the documentation for the next version +def add_documentation_snapshot(readme_file, repo_url, release, snapshot, branch): + pattern = '* [%s](%sblob/v%s/README.md)' % (release, repo_url, release) + replacement = '* [%s-SNAPSHOT](%sblob/%s/README.md)' % (snapshot, repo_url, branch) + def callback(line): + # If we find pattern, we copy the line and replace its content + if line.find(pattern) >= 0: + return line.replace(pattern, replacement)+line + else: + return line + process_file(readme_file, callback) # Set release date in README.md file def set_date(readme_file): @@ -603,8 +626,12 @@ if __name__ == '__main__': artifact_name = find_from_pom('name') artifact_description = find_from_pom('description') project_url = find_from_pom('url') + elasticsearch_version = find_from_pom('elasticsearch.version') print(' Artifact Id: [%s]' % artifact_id) print(' Release version: [%s]' % release_version) + print(' Elasticsearch: [%s]' % elasticsearch_version) + if elasticsearch_version.find('-SNAPSHOT') != -1: + raise RuntimeError('Can not release with a SNAPSHOT elasticsearch dependency: %s' % elasticsearch_version) # extract snapshot default_snapshot_version = guess_snapshot(release_version) @@ -626,6 +653,7 @@ if __name__ == '__main__': try: pending_files = [POM_FILE, README_FILE] remove_maven_snapshot(POM_FILE, release_version) + remove_documentation_snapshot(README_FILE, project_url, release_version, src_branch) remove_version_snapshot(README_FILE, release_version) set_date(README_FILE) set_install_instructions(README_FILE, artifact_id, release_version) @@ -657,6 +685,7 @@ if __name__ == '__main__': add_maven_snapshot(POM_FILE, release_version, snapshot_version) add_version_snapshot(README_FILE, release_version, snapshot_version) + add_documentation_snapshot(README_FILE, project_url, release_version, snapshot_version, src_branch) add_pending_files(*pending_files) commit_snapshot() diff --git a/pom.xml b/pom.xml index 04910105863..eb8a73f1559 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.elasticsearch elasticsearch-lang-javascript - 2.0.0-SNAPSHOT + 3.0.0-SNAPSHOT jar Elasticsearch JavaScript language plugin The JavaScript language plugin allows to have javascript as the language of scripts to execute. @@ -32,7 +32,7 @@ - 1.0.1 + 2.0.0-SNAPSHOT 4.7.0 1 true diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index f8918d4570f..d8eebd7a463 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -44,7 +44,6 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { @Test public void testJavaScriptFilter() throws Exception { - wipeIndices("test"); createIndex("test"); index("test", "type1", "1", jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()); flush(); @@ -95,7 +94,6 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { @Test public void testScriptFieldUsingSource() throws Exception { - wipeIndices("test"); createIndex("test"); index("test", "type1", "1", jsonBuilder().startObject() @@ -130,7 +128,6 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { @Test public void testCustomScriptBoost() throws Exception { - wipeIndices("test"); createIndex("test"); index("test", "type1", "1", jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()); index("test", "type1", "2", jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject()); From 10b3c8900919d91c3637954aad259d453e189f35 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 23 May 2014 19:54:45 +0200 Subject: [PATCH 39/78] Update to elasticsearch 1.2.0 Closes #20 Fix #19 --- README.md | 3 ++- pom.xml | 6 +++--- .../script/javascript/JavaScriptScriptEngineService.java | 5 +++++ .../javascript/JavaScriptScriptMultiThreadedTest.java | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a48e1942286..af07a4e7757 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,10 @@ JavaScript lang Plugin for Elasticsearch The JavaScript language plugin allows to have `javascript` (or `js`) as the language of scripts to execute. -In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.0.0.RC1`. +In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.1.0`. * For master elasticsearch versions, look at [master branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/master). +* For 1.2.x elasticsearch versions, look at [es-1.2 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.2). * For 1.1.x elasticsearch versions, look at [es-1.1 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.1). * For 1.0.x elasticsearch versions, look at [es-1.0 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.0). * For 0.90.x elasticsearch versions, look at [es-0.90 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-0.90). diff --git a/pom.xml b/pom.xml index eb8a73f1559..c75544d35ba 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 2.0.0-SNAPSHOT - 4.7.0 + 4.8.1 1 true onerror @@ -117,8 +117,8 @@ maven-compiler-plugin 2.3.2 - 1.6 - 1.6 + 1.7 + 1.7
diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index eacc8f5f7cb..7b564e0fdf8 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -81,6 +81,11 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements return new String[]{"js"}; } + @Override + public boolean sandboxed() { + return false; + } + @Override public Object compile(String script) { Context ctx = Context.enter(); diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java index 26eab2091ce..381de8e5645 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java @@ -20,7 +20,6 @@ package org.elasticsearch.script.javascript; import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; @@ -29,6 +28,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicBoolean; import static org.hamcrest.Matchers.equalTo; From 4bb456815ac8d852f35e9c4973b480861ccd68ee Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 23 May 2014 19:57:16 +0200 Subject: [PATCH 40/78] Update to elasticsearch 1.3.0 Closes #21 --- README.md | 1 + .../javascript/JavaScriptScriptSearchTests.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index af07a4e7757..2735fe2c8f7 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ The JavaScript language plugin allows to have `javascript` (or `js`) as the lang In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.1.0`. * For master elasticsearch versions, look at [master branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/master). +* For 1.3.x elasticsearch versions, look at [es-1.3 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.3). * For 1.2.x elasticsearch versions, look at [es-1.2 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.2). * For 1.1.x elasticsearch versions, look at [es-1.1 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.1). * For 1.0.x elasticsearch versions, look at [es-1.0 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.0). diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index d8eebd7a463..1a04f5e8b8d 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -21,7 +21,10 @@ package org.elasticsearch.script.javascript; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; +import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -40,8 +43,17 @@ import static org.hamcrest.Matchers.equalTo; /** * */ +@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE) public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { + @Override + protected Settings nodeSettings(int nodeOrdinal) { + return ImmutableSettings.builder() + .put(super.nodeSettings(nodeOrdinal)) + .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true) + .build(); + } + @Test public void testJavaScriptFilter() throws Exception { createIndex("test"); From 858d4da43cbcab1c107e6c8e80cc50fb9478cc05 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Thu, 24 Jul 2014 00:12:53 +0200 Subject: [PATCH 41/78] Update to Lucene 4.9.0 / elasticsearch 1.3.0 Related to #21. Closes #22. (cherry picked from commit c3964ad) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c75544d35ba..9a8a32f3108 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 2.0.0-SNAPSHOT - 4.8.1 + 4.9.0 1 true onerror From a5c7089cf7390580f494028a1aeb9fcae3f9b0ef Mon Sep 17 00:00:00 2001 From: David Pilato Date: Thu, 24 Jul 2014 00:44:04 +0200 Subject: [PATCH 42/78] Update to elasticsearch 1.4.0 Closes #24. (cherry picked from commit e03a16b) --- README.md | 1 + .../script/javascript/JavaScriptScriptEngineService.java | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 2735fe2c8f7..38474e4b3fc 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ The JavaScript language plugin allows to have `javascript` (or `js`) as the lang In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.1.0`. * For master elasticsearch versions, look at [master branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/master). +* For 1.4.x elasticsearch versions, look at [es-1.4 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.4). * For 1.3.x elasticsearch versions, look at [es-1.3 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.3). * For 1.2.x elasticsearch versions, look at [es-1.2 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.2). * For 1.1.x elasticsearch versions, look at [es-1.1 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.1). diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 7b564e0fdf8..a434f1e3a94 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -234,11 +234,6 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements lookup.setNextDocId(doc); } - @Override - public void setNextScore(float score) { - ScriptableObject.putProperty(scope, "_score", score); - } - @Override public void setNextVar(String name, Object value) { ScriptableObject.putProperty(scope, name, value); From e113a308587e969b9e022039d7e1b897749c71e0 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Thu, 4 Sep 2014 15:09:02 +0200 Subject: [PATCH 43/78] Docs: make the welcome page more obvious Closes #25. --- .gitignore | 1 + README.md | 35 +- dev-tools/build_release.py | 722 ------------------------------------- dev-tools/release.py | 134 +++++++ dev-tools/upload-s3.py | 67 ---- 5 files changed, 157 insertions(+), 802 deletions(-) delete mode 100755 dev-tools/build_release.py create mode 100644 dev-tools/release.py delete mode 100644 dev-tools/upload-s3.py diff --git a/.gitignore b/.gitignore index 6d851a6181b..ee44051ee8f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /.classpath /.settings .local-execution-hints.log +/plugin_tools diff --git a/README.md b/README.md index 38474e4b3fc..4e5910b50c1 100644 --- a/README.md +++ b/README.md @@ -3,23 +3,32 @@ JavaScript lang Plugin for Elasticsearch The JavaScript language plugin allows to have `javascript` (or `js`) as the language of scripts to execute. -In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.1.0`. +In order to install the plugin, simply run: -* For master elasticsearch versions, look at [master branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/master). -* For 1.4.x elasticsearch versions, look at [es-1.4 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.4). -* For 1.3.x elasticsearch versions, look at [es-1.3 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.3). -* For 1.2.x elasticsearch versions, look at [es-1.2 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.2). -* For 1.1.x elasticsearch versions, look at [es-1.1 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.1). -* For 1.0.x elasticsearch versions, look at [es-1.0 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-1.0). -* For 0.90.x elasticsearch versions, look at [es-0.90 branch](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/es-0.90). +```sh +bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.3.0 +``` -| JavaScript Lang Plugin | elasticsearch | rhino | Release date | -|-----------------------------|---------------------|----------|:------------:| -| 3.0.0-SNAPSHOT | master | 1.7R4 | XXXX-XX-XX | +You need to install a version matching your Elasticsearch version: -Please read documentation relative to the version you are using: +| elasticsearch | JavaScript Plugin | Docs | +|---------------|-----------------------|------------| +| master | Build from source | See below | +| es-1.x | Build from source | [2.4.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-240-snapshot-for-elasticsearch-1x) | +| es-1.3 | 2.3.0 | [2.3.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.3.0/#javascript-lang-plugin-for-elasticsearch) | +| es-1.2 | 2.2.0 | [2.2.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.2.0/#javascript-lang-plugin-for-elasticsearch) | +| es-1.1 | 2.1.0 | [2.1.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.1.0/#javascript-lang-plugin-for-elasticsearch) | +| es-1.0 | 2.0.0 | [2.0.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.0.0/#javascript-lang-plugin-for-elasticsearch) | +| es-0.90 | 1.4.0 | [1.4.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v1.4.0/#javascript-lang-plugin-for-elasticsearch) | + +To build a `SNAPSHOT` version, you need to build it with Maven: + +```bash +mvn clean install +plugin --install lang-javascript \ + --url file:target/releases/elasticsearch-lang-javascript-X.X.X-SNAPSHOT.zip +``` -* [3.0.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-lang-javascript/blob/master/README.md) Using javascript with function_score ------------------------------------ diff --git a/dev-tools/build_release.py b/dev-tools/build_release.py deleted file mode 100755 index db8345440c7..00000000000 --- a/dev-tools/build_release.py +++ /dev/null @@ -1,722 +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. - -import re -import tempfile -import shutil -import os -import datetime -import argparse -import github3 -import smtplib - -from email.mime.multipart import MIMEMultipart -from email.mime.text import MIMEText - -from os.path import dirname, abspath - -""" - This tool builds a release from the a given elasticsearch plugin branch. - In order to execute it go in the top level directory and run: - $ python3 dev_tools/build_release.py --branch master --publish --remote origin - - By default this script runs in 'dry' mode which essentially simulates a release. If the - '--publish' option is set the actual release is done. - If not in 'dry' mode, a mail will be automatically sent to the mailing list. - You can disable it with the option '--disable_mail' - - $ python3 dev_tools/build_release.py --publish --remote origin --disable_mail - - The script takes over almost all - steps necessary for a release from a high level point of view it does the following things: - - - run prerequisite checks ie. check for S3 credentials available as env variables - - detect the version to release from the specified branch (--branch) or the current branch - - creates a release branch & updates pom.xml and README.md to point to a release version rather than a snapshot - - builds the artifacts - - commits the new version and merges the release branch into the source branch - - creates a tag and pushes the commit to the specified origin (--remote) - - publishes the releases to sonatype and S3 - - send a mail based on github issues fixed by this version - -Once it's done it will print all the remaining steps. - - Prerequisites: - - Python 3k for script execution - - Boto for S3 Upload ($ apt-get install python-boto or pip-3.3 install boto) - - github3 module (pip-3.3 install github3.py) - - S3 keys exported via ENV Variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) - - GITHUB (login/password) or key exported via ENV Variables (GITHUB_LOGIN, GITHUB_PASSWORD or GITHUB_KEY) - (see https://github.com/settings/applications#personal-access-tokens) - Optional: default to no authentication - - SMTP_HOST - Optional: default to localhost - - MAIL_SENDER - Optional: default to 'david@pilato.fr': must be authorized to send emails to elasticsearch mailing list - - MAIL_TO - Optional: default to 'elasticsearch@googlegroups.com' -""" -env = os.environ - -LOG = env.get('ES_RELEASE_LOG', '/tmp/elasticsearch_release.log') -ROOT_DIR = os.path.join(abspath(dirname(__file__)), '../') -README_FILE = ROOT_DIR + 'README.md' -POM_FILE = ROOT_DIR + 'pom.xml' - -def log(msg): - log_plain('\n%s' % msg) - -def log_plain(msg): - f = open(LOG, mode='ab') - f.write(msg.encode('utf-8')) - f.close() - -def run(command, quiet=False): - log('%s: RUN: %s\n' % (datetime.datetime.now(), command)) - if os.system('%s >> %s 2>&1' % (command, LOG)): - msg = ' FAILED: %s [see log %s]' % (command, LOG) - if not quiet: - print(msg) - raise RuntimeError(msg) - -try: - JAVA_HOME = env['JAVA_HOME'] -except KeyError: - raise RuntimeError(""" - Please set JAVA_HOME in the env before running release tool - On OSX use: export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'`""") - -try: - MVN='mvn' - # make sure mvn3 is used if mvn3 is available - # some systems use maven 2 as default - run('mvn3 --version', quiet=True) - MVN='mvn3' -except RuntimeError: - pass - - -def java_exe(): - path = JAVA_HOME - return 'export JAVA_HOME="%s" PATH="%s/bin:$PATH" JAVACMD="%s/bin/java"' % (path, path, path) - -# Returns the hash of the current git HEAD revision -def get_head_hash(): - return os.popen(' git rev-parse --verify HEAD 2>&1').read().strip() - -# Returns the hash of the given tag revision -def get_tag_hash(tag): - return os.popen('git show-ref --tags %s --hash 2>&1' % (tag)).read().strip() - -# Returns the name of the current branch -def get_current_branch(): - return os.popen('git rev-parse --abbrev-ref HEAD 2>&1').read().strip() - -# Utility that returns the name of the release branch for a given version -def release_branch(version): - return 'release_branch_%s' % version - -# runs get fetch on the given remote -def fetch(remote): - run('git fetch %s' % remote) - -# Creates a new release branch from the given source branch -# and rebases the source branch from the remote before creating -# the release branch. Note: This fails if the source branch -# doesn't exist on the provided remote. -def create_release_branch(remote, src_branch, release): - run('git checkout %s' % src_branch) - run('git pull --rebase %s %s' % (remote, src_branch)) - run('git checkout -b %s' % (release_branch(release))) - - -# Reads the given file and applies the -# callback to it. If the callback changed -# a line the given file is replaced with -# the modified input. -def process_file(file_path, line_callback): - fh, abs_path = tempfile.mkstemp() - modified = False - with open(abs_path,'w', encoding='utf-8') as new_file: - with open(file_path, encoding='utf-8') as old_file: - for line in old_file: - new_line = line_callback(line) - modified = modified or (new_line != line) - new_file.write(new_line) - os.close(fh) - if modified: - #Remove original file - os.remove(file_path) - #Move new file - shutil.move(abs_path, file_path) - return True - else: - # nothing to do - just remove the tmp file - os.remove(abs_path) - return False - -# Guess the next snapshot version number (increment second digit) -def guess_snapshot(version): - digits=list(map(int, re.findall(r'\d+', version))) - source='%s.%s' % (digits[0], digits[1]) - destination='%s.%s' % (digits[0], digits[1]+1) - return version.replace(source, destination) - -# Moves the pom.xml file from a snapshot to a release -def remove_maven_snapshot(pom, release): - pattern = '%s-SNAPSHOT' % release - replacement = '%s' % release - def callback(line): - return line.replace(pattern, replacement) - process_file(pom, callback) - -# Moves the README.md file from a snapshot to a release -def remove_version_snapshot(readme_file, release): - pattern = '%s-SNAPSHOT' % release - replacement = '%s ' % release - def callback(line): - return line.replace(pattern, replacement) - process_file(readme_file, callback) - -# Moves the pom.xml file to the next snapshot -def add_maven_snapshot(pom, release, snapshot): - pattern = '%s' % release - replacement = '%s-SNAPSHOT' % snapshot - def callback(line): - return line.replace(pattern, replacement) - process_file(pom, callback) - -# Add in README.md file the next snapshot -def add_version_snapshot(readme_file, release, snapshot): - pattern = '| %s ' % release - replacement = '| %s-SNAPSHOT' % snapshot - def callback(line): - # If we find pattern, we copy the line and replace its content - if line.find(pattern) >= 0: - return line.replace(pattern, replacement).replace('%s' % (datetime.datetime.now().strftime("%Y-%m-%d")), - 'XXXX-XX-XX')+line - else: - return line - process_file(readme_file, callback) - -# Moves the README.md file from a snapshot to a release (documentation link) -def remove_documentation_snapshot(readme_file, repo_url, release, branch): - pattern = '* [%s-SNAPSHOT](%sblob/%s/README.md)' % (release, repo_url, branch) - replacement = '* [%s](%sblob/v%s/README.md)' % (release, repo_url, release) - def callback(line): - # If we find pattern, we replace its content - if line.find(pattern) >= 0: - return line.replace(pattern, replacement) - else: - return line - process_file(readme_file, callback) - -# Add in README.markdown file the documentation for the next version -def add_documentation_snapshot(readme_file, repo_url, release, snapshot, branch): - pattern = '* [%s](%sblob/v%s/README.md)' % (release, repo_url, release) - replacement = '* [%s-SNAPSHOT](%sblob/%s/README.md)' % (snapshot, repo_url, branch) - def callback(line): - # If we find pattern, we copy the line and replace its content - if line.find(pattern) >= 0: - return line.replace(pattern, replacement)+line - else: - return line - process_file(readme_file, callback) - -# Set release date in README.md file -def set_date(readme_file): - pattern = 'XXXX-XX-XX' - replacement = '%s' % (datetime.datetime.now().strftime("%Y-%m-%d")) - def callback(line): - return line.replace(pattern, replacement) - process_file(readme_file, callback) - -# Update installation instructions in README.md file -def set_install_instructions(readme_file, artifact_name, release): - pattern = '`bin/plugin -install elasticsearch/%s/.+`' % artifact_name - replacement = '`bin/plugin -install elasticsearch/%s/%s`' % (artifact_name, release) - def callback(line): - return re.sub(pattern, replacement, line) - process_file(readme_file, callback) - - -# Stages the given files for the next git commit -def add_pending_files(*files): - for file in files: - run('git add %s' % file) - -# Executes a git commit with 'release [version]' as the commit message -def commit_release(artifact_id, release): - run('git commit -m "prepare release %s-%s"' % (artifact_id, release)) - -def commit_snapshot(): - run('git commit -m "prepare for next development iteration"') - -def tag_release(release): - run('git tag -a v%s -m "Tag release version %s"' % (release, release)) - -def run_mvn(*cmd): - for c in cmd: - run('%s; %s -f %s %s' % (java_exe(), MVN, POM_FILE, c)) - -def build_release(run_tests=False, dry_run=True): - target = 'deploy' - if dry_run: - target = 'package' - if run_tests: - run_mvn('clean test') - run_mvn('clean %s -DskipTests' %(target)) - -# Checks the pom.xml for the release version. 2.0.0-SNAPSHOT -# This method fails if the pom file has no SNAPSHOT version set ie. -# if the version is already on a release version we fail. -# Returns the next version string ie. 0.90.7 -def find_release_version(src_branch): - run('git checkout %s' % src_branch) - with open(POM_FILE, encoding='utf-8') as file: - for line in file: - match = re.search(r'(.+)-SNAPSHOT', line) - if match: - return match.group(1) - raise RuntimeError('Could not find release version in branch %s' % src_branch) - -# extract a value from pom.xml -def find_from_pom(tag): - with open(POM_FILE, encoding='utf-8') as file: - for line in file: - match = re.search(r'<%s>(.+)' % (tag, tag), line) - if match: - return match.group(1) - raise RuntimeError('Could not find <%s> in pom.xml file' % (tag)) - -def get_artifacts(artifact_id, release): - artifact_path = ROOT_DIR + 'target/releases/%s-%s.zip' % (artifact_id, release) - print(' Path %s' % (artifact_path)) - if not os.path.isfile(artifact_path): - raise RuntimeError('Could not find required artifact at %s' % (artifact_path)) - return artifact_path - -# Generates sha1 for a file -# and returns the checksum files as well -# as the given files in a list -def generate_checksums(release_file): - res = [] - directory = os.path.dirname(release_file) - file = os.path.basename(release_file) - checksum_file = '%s.sha1.txt' % file - - if os.system('cd %s; shasum %s > %s' % (directory, file, checksum_file)): - raise RuntimeError('Failed to generate checksum for file %s' % release_file) - res = res + [os.path.join(directory, checksum_file), release_file] - return res - -def git_merge(src_branch, release_version): - run('git checkout %s' % src_branch) - run('git merge %s' % release_branch(release_version)) - -def git_push(remote, src_branch, release_version, dry_run): - if not dry_run: - run('git push %s %s' % (remote, src_branch)) # push the commit - run('git push %s v%s' % (remote, release_version)) # push the tag - else: - print(' dryrun [True] -- skipping push to remote %s' % remote) - -def publish_artifacts(artifacts, base='elasticsearch/elasticsearch', dry_run=True): - location = os.path.dirname(os.path.realpath(__file__)) - for artifact in artifacts: - if dry_run: - print('Skip Uploading %s to Amazon S3 in %s' % (artifact, base)) - else: - print('Uploading %s to Amazon S3' % artifact) - # requires boto to be installed but it is not available on python3k yet so we use a dedicated tool - run('python %s/upload-s3.py --file %s --path %s' % (location, os.path.abspath(artifact), base)) - - -################# -## -## -## Email and Github Management -## -## -################# -def format_issues_plain(issues, title='Fix'): - response = "" - - if len(issues) > 0: - response += '%s:\n' % title - for issue in issues: - response += ' * [%s] - %s (%s)\n' % (issue.number, issue.title, issue.html_url) - - return response - -def format_issues_html(issues, title='Fix'): - response = "" - - if len(issues) > 0: - response += '

%s

\n
    \n' % title - for issue in issues: - response += '
  • [%s] - %s\n' % (issue.html_url, issue.number, issue.title) - response += '
\n' - - return response - -def get_github_repository(reponame, - login=env.get('GITHUB_LOGIN', None), - password=env.get('GITHUB_PASSWORD', None), - key=env.get('GITHUB_KEY', None)): - if login: - g = github3.login(login, password) - elif key: - g = github3.login(token=key) - else: - g = github3.GitHub() - - return g.repository("elasticsearch", reponame) - -# Check if there are some remaining open issues and fails -def check_opened_issues(version, repository, reponame): - opened_issues = [i for i in repository.iter_issues(state='open', labels='%s' % version)] - if len(opened_issues)>0: - raise NameError('Some issues [%s] are still opened. Check https://github.com/elasticsearch/%s/issues?labels=%s&state=open' - % (len(opened_issues), reponame, version)) - -# List issues from github: can be done anonymously if you don't -# exceed a given number of github API calls per day -# Check if there are some remaining open issues and fails -def list_issues(version, - repository, - severity='bug'): - issues = [i for i in repository.iter_issues(state='closed', labels='%s,%s' % (severity, version))] - return issues - -# Get issues from github and generates a Plain/HTML Multipart email -# And send it if dry_run=False -def prepare_email(artifact_id, release_version, repository, - artifact_name, artifact_description, project_url, - severity_labels_bug='bug', - severity_labels_update='update', - severity_labels_new='new', - severity_labels_doc='doc'): - - ## Get bugs from github - issues_bug = list_issues(release_version, repository, severity=severity_labels_bug) - issues_update = list_issues(release_version, repository, severity=severity_labels_update) - issues_new = list_issues(release_version, repository, severity=severity_labels_new) - issues_doc = list_issues(release_version, repository, severity=severity_labels_doc) - - ## Format content to plain text - plain_issues_bug = format_issues_plain(issues_bug, 'Fix') - plain_issues_update = format_issues_plain(issues_update, 'Update') - plain_issues_new = format_issues_plain(issues_new, 'New') - plain_issues_doc = format_issues_plain(issues_doc, 'Doc') - - ## Format content to html - html_issues_bug = format_issues_html(issues_bug, 'Fix') - html_issues_update = format_issues_html(issues_update, 'Update') - html_issues_new = format_issues_html(issues_new, 'New') - html_issues_doc = format_issues_html(issues_doc, 'Doc') - - if len(issues_bug)+len(issues_update)+len(issues_new)+len(issues_doc) > 0: - plain_empty_message = "" - html_empty_message = "" - - else: - plain_empty_message = "No issue listed for this release" - html_empty_message = "

No issue listed for this release

" - - msg = MIMEMultipart('alternative') - msg['Subject'] = '[ANN] %s %s released' % (artifact_name, release_version) - text = """ -Heya, - - -We are pleased to announce the release of the %(artifact_name)s, version %(release_version)s. - -%(artifact_description)s. - -%(project_url)s - -Release Notes - %(artifact_id)s - Version %(release_version)s - -%(empty_message)s -%(issues_bug)s -%(issues_update)s -%(issues_new)s -%(issues_doc)s - -Issues, Pull requests, Feature requests are warmly welcome on %(artifact_id)s project repository: %(project_url)s -For questions or comments around this plugin, feel free to use elasticsearch mailing list: https://groups.google.com/forum/#!forum/elasticsearch - -Enjoy, - --The Elasticsearch team -""" % {'release_version': release_version, - 'artifact_id': artifact_id, - 'artifact_name': artifact_name, - 'artifact_description': artifact_description, - 'project_url': project_url, - 'empty_message': plain_empty_message, - 'issues_bug': plain_issues_bug, - 'issues_update': plain_issues_update, - 'issues_new': plain_issues_new, - 'issues_doc': plain_issues_doc} - - html = """ - - -

Heya,

- -

We are pleased to announce the release of the %(artifact_name)s, version %(release_version)s

- -
%(artifact_description)s.
- -

Release Notes - Version %(release_version)s

-%(empty_message)s -%(issues_bug)s -%(issues_update)s -%(issues_new)s -%(issues_doc)s - -

Issues, Pull requests, Feature requests are warmly welcome on -%(artifact_id)s project repository!

-

For questions or comments around this plugin, feel free to use elasticsearch -mailing list!

- -

Enjoy,

- -

- The Elasticsearch team

- -""" % {'release_version': release_version, - 'artifact_id': artifact_id, - 'artifact_name': artifact_name, - 'artifact_description': artifact_description, - 'project_url': project_url, - 'empty_message': html_empty_message, - 'issues_bug': html_issues_bug, - 'issues_update': html_issues_update, - 'issues_new': html_issues_new, - 'issues_doc': html_issues_doc} - - # Record the MIME types of both parts - text/plain and text/html. - part1 = MIMEText(text, 'plain') - part2 = MIMEText(html, 'html') - - # Attach parts into message container. - # According to RFC 2046, the last part of a multipart message, in this case - # the HTML message, is best and preferred. - msg.attach(part1) - msg.attach(part2) - - return msg - -def send_email(msg, - dry_run=True, - mail=True, - sender=env.get('MAIL_SENDER'), - to=env.get('MAIL_TO', 'elasticsearch@googlegroups.com'), - smtp_server=env.get('SMTP_SERVER', 'localhost')): - msg['From'] = 'Elasticsearch Team <%s>' % sender - msg['To'] = 'Elasticsearch Mailing List <%s>' % to - # save mail on disk - with open(ROOT_DIR+'target/email.txt', 'w') as email_file: - email_file.write(msg.as_string()) - if mail and not dry_run: - s = smtplib.SMTP(smtp_server, 25) - s.sendmail(sender, to, msg.as_string()) - s.quit() - else: - print('generated email: open %starget/email.txt' % ROOT_DIR) - -def print_sonatype_notice(): - settings = os.path.join(os.path.expanduser('~'), '.m2/settings.xml') - if os.path.isfile(settings): - with open(settings, encoding='utf-8') as settings_file: - for line in settings_file: - if line.strip() == 'sonatype-nexus-snapshots': - # moving out - we found the indicator no need to print the warning - return - print(""" - NOTE: No sonatype settings detected, make sure you have configured - your sonatype credentials in '~/.m2/settings.xml': - - - ... - - - sonatype-nexus-snapshots - your-jira-id - your-jira-pwd - - - sonatype-nexus-staging - your-jira-id - your-jira-pwd - - - ... - - """) - -def check_s3_credentials(): - if not env.get('AWS_ACCESS_KEY_ID', None) or not env.get('AWS_SECRET_ACCESS_KEY', None): - raise RuntimeError('Could not find "AWS_ACCESS_KEY_ID" / "AWS_SECRET_ACCESS_KEY" in the env variables please export in order to upload to S3') - -def check_github_credentials(): - if not env.get('GITHUB_KEY', None) and not env.get('GITHUB_LOGIN', None): - log('WARN: Could not find "GITHUB_LOGIN" / "GITHUB_PASSWORD" or "GITHUB_KEY" in the env variables. You could need it.') - -def check_email_settings(): - if not env.get('MAIL_SENDER', None): - raise RuntimeError('Could not find "MAIL_SENDER"') - -# we print a notice if we can not find the relevant infos in the ~/.m2/settings.xml -print_sonatype_notice() - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Builds and publishes a Elasticsearch Plugin Release') - parser.add_argument('--branch', '-b', metavar='master', default=get_current_branch(), - help='The branch to release from. Defaults to the current branch.') - parser.add_argument('--skiptests', '-t', dest='tests', action='store_false', - help='Skips tests before release. Tests are run by default.') - parser.set_defaults(tests=True) - parser.add_argument('--remote', '-r', metavar='origin', default='origin', - help='The remote to push the release commit and tag to. Default is [origin]') - parser.add_argument('--publish', '-p', dest='dryrun', action='store_false', - help='Publishes the release. Disable by default.') - parser.add_argument('--disable_mail', '-dm', dest='mail', action='store_false', - help='Do not send a release email. Email is sent by default.') - - parser.set_defaults(dryrun=True) - parser.set_defaults(mail=True) - args = parser.parse_args() - - src_branch = args.branch - remote = args.remote - run_tests = args.tests - dry_run = args.dryrun - mail = args.mail - - if not dry_run: - check_s3_credentials() - print('WARNING: dryrun is set to "false" - this will push and publish the release') - if mail: - check_email_settings() - print('An email to %s will be sent after the release' - % env.get('MAIL_TO', 'elasticsearch@googlegroups.com')) - input('Press Enter to continue...') - - check_github_credentials() - - print(''.join(['-' for _ in range(80)])) - print('Preparing Release from branch [%s] running tests: [%s] dryrun: [%s]' % (src_branch, run_tests, dry_run)) - print(' JAVA_HOME is [%s]' % JAVA_HOME) - print(' Running with maven command: [%s] ' % (MVN)) - - release_version = find_release_version(src_branch) - artifact_id = find_from_pom('artifactId') - artifact_name = find_from_pom('name') - artifact_description = find_from_pom('description') - project_url = find_from_pom('url') - elasticsearch_version = find_from_pom('elasticsearch.version') - print(' Artifact Id: [%s]' % artifact_id) - print(' Release version: [%s]' % release_version) - print(' Elasticsearch: [%s]' % elasticsearch_version) - if elasticsearch_version.find('-SNAPSHOT') != -1: - raise RuntimeError('Can not release with a SNAPSHOT elasticsearch dependency: %s' % elasticsearch_version) - - # extract snapshot - default_snapshot_version = guess_snapshot(release_version) - snapshot_version = input('Enter next snapshot version [%s]:' % default_snapshot_version) - snapshot_version = snapshot_version or default_snapshot_version - - print(' Next version: [%s-SNAPSHOT]' % snapshot_version) - print(' Artifact Name: [%s]' % artifact_name) - print(' Artifact Description: [%s]' % artifact_description) - print(' Project URL: [%s]' % project_url) - - if not dry_run: - smoke_test_version = release_version - head_hash = get_head_hash() - run_mvn('clean') # clean the env! - create_release_branch(remote, src_branch, release_version) - print(' Created release branch [%s]' % (release_branch(release_version))) - success = False - try: - pending_files = [POM_FILE, README_FILE] - remove_maven_snapshot(POM_FILE, release_version) - remove_documentation_snapshot(README_FILE, project_url, release_version, src_branch) - remove_version_snapshot(README_FILE, release_version) - set_date(README_FILE) - set_install_instructions(README_FILE, artifact_id, release_version) - print(' Done removing snapshot version') - add_pending_files(*pending_files) # expects var args use * to expand - commit_release(artifact_id, release_version) - print(' Committed release version [%s]' % release_version) - print(''.join(['-' for _ in range(80)])) - print('Building Release candidate') - input('Press Enter to continue...') - print(' Checking github issues') - repository = get_github_repository(artifact_id) - check_opened_issues(release_version, repository, artifact_id) - if not dry_run: - print(' Running maven builds now and publish to sonatype - run-tests [%s]' % run_tests) - else: - print(' Running maven builds now run-tests [%s]' % run_tests) - build_release(run_tests=run_tests, dry_run=dry_run) - artifact = get_artifacts(artifact_id, release_version) - artifact_and_checksums = generate_checksums(artifact) - print(''.join(['-' for _ in range(80)])) - - print('Finish Release -- dry_run: %s' % dry_run) - input('Press Enter to continue...') - print(' merge release branch') - git_merge(src_branch, release_version) - print(' tag') - tag_release(release_version) - - add_maven_snapshot(POM_FILE, release_version, snapshot_version) - add_version_snapshot(README_FILE, release_version, snapshot_version) - add_documentation_snapshot(README_FILE, project_url, release_version, snapshot_version, src_branch) - add_pending_files(*pending_files) - commit_snapshot() - - print(' push to %s %s -- dry_run: %s' % (remote, src_branch, dry_run)) - git_push(remote, src_branch, release_version, dry_run) - print(' publish artifacts to S3 -- dry_run: %s' % dry_run) - publish_artifacts(artifact_and_checksums, base='elasticsearch/%s' % (artifact_id) , dry_run=dry_run) - print(' preparing email (from github issues)') - msg = prepare_email(artifact_id, release_version, repository, artifact_name, artifact_description, project_url) - print(' sending email -- dry_run: %s, mail: %s' % (dry_run, mail)) - send_email(msg, dry_run=dry_run, mail=mail) - - pending_msg = """ -Release successful pending steps: - * close and release sonatype repo: https://oss.sonatype.org/ - * check if the release is there https://oss.sonatype.org/content/repositories/releases/org/elasticsearch/%(artifact_id)s/%(version)s - * tweet about the release -""" - print(pending_msg % {'version': release_version, - 'artifact_id': artifact_id, - 'project_url': project_url}) - success = True - finally: - if not success: - run('git reset --hard HEAD') - run('git checkout %s' % src_branch) - elif dry_run: - print('End of dry_run') - input('Press Enter to reset changes...') - - run('git reset --hard %s' % head_hash) - run('git tag -d v%s' % release_version) - # we delete this one anyways - run('git branch -D %s' % (release_branch(release_version))) diff --git a/dev-tools/release.py b/dev-tools/release.py new file mode 100644 index 00000000000..edcc637d068 --- /dev/null +++ b/dev-tools/release.py @@ -0,0 +1,134 @@ +# 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. + +import datetime +import os +import shutil +import sys +import time +import urllib +import urllib.request +import zipfile + +from os.path import dirname, abspath + +""" + This tool builds a release from the a given elasticsearch plugin branch. + + It is basically a wrapper on top of launch_release.py which: + + - tries to get a more recent version of launch_release.py in ... + - download it if needed + - launch it passing all arguments to it, like: + + $ python3 dev_tools/release.py --branch master --publish --remote origin + + Important options: + + # Dry run + $ python3 dev_tools/release.py + + # Dry run without tests + python3 dev_tools/release.py --skiptests + + # Release, publish artifacts and announce + $ python3 dev_tools/release.py --publish + + See full documentation in launch_release.py +""" +env = os.environ + +# Change this if the source repository for your scripts is at a different location +SOURCE_REPO = 'elasticsearch/elasticsearch-plugins-script' +# We define that we should download again the script after 1 days +SCRIPT_OBSOLETE_DAYS = 1 +# We ignore in master.zip file the following files +IGNORED_FILES = ['.gitignore', 'README.md'] + + +ROOT_DIR = abspath(os.path.join(abspath(dirname(__file__)), '../')) +TARGET_TOOLS_DIR = ROOT_DIR + '/plugin_tools' +DEV_TOOLS_DIR = ROOT_DIR + '/dev-tools' +BUILD_RELEASE_FILENAME = 'release.zip' +BUILD_RELEASE_FILE = TARGET_TOOLS_DIR + '/' + BUILD_RELEASE_FILENAME +SOURCE_URL = 'https://github.com/%s/archive/master.zip' % SOURCE_REPO + +# Download a recent version of the release plugin tool +try: + os.mkdir(TARGET_TOOLS_DIR) + print('directory %s created' % TARGET_TOOLS_DIR) +except FileExistsError: + pass + + +try: + # we check latest update. If we ran an update recently, we + # are not going to check it again + download = True + + try: + last_download_time = datetime.datetime.fromtimestamp(os.path.getmtime(BUILD_RELEASE_FILE)) + if (datetime.datetime.now()-last_download_time).days < SCRIPT_OBSOLETE_DAYS: + download = False + except FileNotFoundError: + pass + + if download: + urllib.request.urlretrieve(SOURCE_URL, BUILD_RELEASE_FILE) + with zipfile.ZipFile(BUILD_RELEASE_FILE) as myzip: + for member in myzip.infolist(): + filename = os.path.basename(member.filename) + # skip directories + if not filename: + continue + if filename in IGNORED_FILES: + continue + + # copy file (taken from zipfile's extract) + source = myzip.open(member.filename) + target = open(os.path.join(TARGET_TOOLS_DIR, filename), "wb") + with source, target: + shutil.copyfileobj(source, target) + # We keep the original date + date_time = time.mktime(member.date_time + (0, 0, -1)) + os.utime(os.path.join(TARGET_TOOLS_DIR, filename), (date_time, date_time)) + print('plugin-tools updated from %s' % SOURCE_URL) +except urllib.error.HTTPError: + pass + + +# Let see if we need to update the release.py script itself +source_time = os.path.getmtime(TARGET_TOOLS_DIR + '/release.py') +repo_time = os.path.getmtime(DEV_TOOLS_DIR + '/release.py') +if source_time > repo_time: + input('release.py needs an update. Press a key to update it...') + shutil.copyfile(TARGET_TOOLS_DIR + '/release.py', DEV_TOOLS_DIR + '/release.py') + +# We can launch the build process +try: + PYTHON = 'python' + # make sure python3 is used if python3 is available + # some systems use python 2 as default + os.system('python3 --version > /dev/null 2>&1') + PYTHON = 'python3' +except RuntimeError: + pass + +release_args = '' +for x in range(1, len(sys.argv)): + release_args += ' ' + sys.argv[x] + +os.system('%s %s/build_release.py %s' % (PYTHON, TARGET_TOOLS_DIR, release_args)) diff --git a/dev-tools/upload-s3.py b/dev-tools/upload-s3.py deleted file mode 100644 index 95ea576e65c..00000000000 --- a/dev-tools/upload-s3.py +++ /dev/null @@ -1,67 +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. - -import os -import sys -import argparse -try: - import boto.s3 -except: - raise RuntimeError(""" - S3 upload requires boto to be installed - Use one of: - 'pip install -U boto' - 'apt-get install python-boto' - 'easy_install boto' - """) - -import boto.s3 - - -def list_buckets(conn): - return conn.get_all_buckets() - - -def upload_s3(conn, path, key, file, bucket): - print 'Uploading %s to Amazon S3 bucket %s/%s' % \ - (file, bucket, os.path.join(path, key)) - def percent_cb(complete, total): - sys.stdout.write('.') - sys.stdout.flush() - bucket = conn.create_bucket(bucket) - k = bucket.new_key(os.path.join(path, key)) - k.set_contents_from_filename(file, cb=percent_cb, num_cb=100) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Uploads files to Amazon S3') - parser.add_argument('--file', '-f', metavar='path to file', - help='the branch to release from', required=True) - parser.add_argument('--bucket', '-b', metavar='B42', default='download.elasticsearch.org', - help='The S3 Bucket to upload to') - parser.add_argument('--path', '-p', metavar='elasticsearch/elasticsearch', default='elasticsearch/elasticsearch', - help='The key path to use') - parser.add_argument('--key', '-k', metavar='key', default=None, - help='The key - uses the file name as default key') - args = parser.parse_args() - if args.key: - key = args.key - else: - key = os.path.basename(args.file) - - connection = boto.connect_s3() - upload_s3(connection, args.path, key, args.file, args.bucket); - From 02809f40be61d9ed449f68f9dce1be30045d9408 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Mon, 15 Sep 2014 16:28:28 +0200 Subject: [PATCH 44/78] Update to Lucene 4.10.0 Closes #27. (cherry picked from commit 1eb2352) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9a8a32f3108..34fe28379f1 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 2.0.0-SNAPSHOT - 4.9.0 + 4.10.0 1 true onerror From 4a5514801cfd5b08437a747c91dd2759b7df1839 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Mon, 15 Sep 2014 16:30:10 +0200 Subject: [PATCH 45/78] Create branch es-1.4 for elasticsearch 1.4.0 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e5910b50c1..2e93904934b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ You need to install a version matching your Elasticsearch version: | elasticsearch | JavaScript Plugin | Docs | |---------------|-----------------------|------------| | master | Build from source | See below | -| es-1.x | Build from source | [2.4.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-240-snapshot-for-elasticsearch-1x) | +| es-1.x | Build from source | [2.5.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-250-snapshot-for-elasticsearch-1x) | +| es-1.4 | Build from source | [2.4.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.4/#version-240-snapshot-for-elasticsearch-1x) | | es-1.3 | 2.3.0 | [2.3.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.3.0/#javascript-lang-plugin-for-elasticsearch) | | es-1.2 | 2.2.0 | [2.2.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.2.0/#javascript-lang-plugin-for-elasticsearch) | | es-1.1 | 2.1.0 | [2.1.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.1.0/#javascript-lang-plugin-for-elasticsearch) | From 33c6265581c3327d1d959554b2c7999c92993069 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 24 Sep 2014 18:04:14 -0400 Subject: [PATCH 46/78] Upgrade to Lucene 4.10.1 snapshot --- pom.xml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 34fe28379f1..dddf1bb7ddd 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,8 @@ 2.0.0-SNAPSHOT - 4.10.0 + 4.10.1 + 4.10.1-snapshot-1627368 1 true onerror @@ -42,6 +43,10 @@ + + Lucene snapshots + https://download.elasticsearch.org/lucenesnapshots/ + sonatype http://oss.sonatype.org/content/repositories/releases/ @@ -52,7 +57,7 @@ org.apache.lucene lucene-test-framework - ${lucene.version} + ${lucene.maven.version} test From e2d1ae40b02cb72da1551c434379db9ed996f5ce Mon Sep 17 00:00:00 2001 From: mikemccand Date: Sun, 28 Sep 2014 17:57:45 -0400 Subject: [PATCH 47/78] Upgrade to Lucene 4.10.1 --- pom.xml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index dddf1bb7ddd..bb9e8d45347 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 2.0.0-SNAPSHOT 4.10.1 - 4.10.1-snapshot-1627368 + 4.10.1 1 true onerror @@ -43,10 +43,6 @@ - - Lucene snapshots - https://download.elasticsearch.org/lucenesnapshots/ - sonatype http://oss.sonatype.org/content/repositories/releases/ From 37bac2d4b2ca1eddc98f8f20dd0ccc97b54deab3 Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Tue, 7 Oct 2014 12:29:13 +0200 Subject: [PATCH 48/78] Remove setNextScore in SearchScript Due to a change in elasticsearch 1.4.0, we need to apply a similar patch here. See https://github.com/elasticsearch/elasticsearch/pull/6864 See https://github.com/elasticsearch/elasticsearch/pull/7819 Closes #23. (cherry picked from commit 5e5c373) --- .../JavaScriptScriptEngineService.java | 5 +- .../JavaScriptScriptSearchTests.java | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index a434f1e3a94..2b8f696ba8a 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.ExecutableScript; +import org.elasticsearch.script.ScoreAccessor; import org.elasticsearch.script.ScriptEngineService; import org.elasticsearch.script.SearchScript; import org.elasticsearch.script.javascript.support.NativeList; @@ -221,7 +222,9 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements @Override public void setScorer(Scorer scorer) { - lookup.setScorer(scorer); + Context ctx = Context.enter(); + ScriptableObject.putProperty(scope, "_score", wrapFactory.wrapAsJavaObject(ctx, scope, new ScoreAccessor(scorer), ScoreAccessor.class)); + Context.exit(); } @Override diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 1a04f5e8b8d..ec41b103f52 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -25,10 +25,12 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; import org.elasticsearch.plugins.PluginsService; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; +import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -37,8 +39,12 @@ import static org.elasticsearch.client.Requests.searchRequest; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.FilterBuilders.scriptFilter; import static org.elasticsearch.index.query.QueryBuilders.*; +import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction; +import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; /** * @@ -236,4 +242,47 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); } + + @Test + public void testScriptScoresNested() throws IOException { + createIndex("index"); + ensureYellow(); + index("index", "testtype", "1", jsonBuilder().startObject().field("dummy_field", 1).endObject()); + refresh(); + SearchResponse response = client().search( + searchRequest().source( + searchSource().query( + functionScoreQuery( + functionScoreQuery( + functionScoreQuery().add(scriptFunction("1").lang("js"))) + .add(scriptFunction("_score.doubleValue()").lang("js"))) + .add(scriptFunction("_score.doubleValue()").lang("js") + ) + ) + ) + ).actionGet(); + assertSearchResponse(response); + assertThat(response.getHits().getAt(0).score(), equalTo(1.0f)); + } + + @Test + public void testScriptScoresWithAgg() throws IOException { + createIndex("index"); + ensureYellow(); + index("index", "testtype", "1", jsonBuilder().startObject().field("dummy_field", 1).endObject()); + refresh(); + SearchResponse response = client().search( + searchRequest().source( + searchSource().query( + functionScoreQuery() + .add(scriptFunction("_score.doubleValue()").lang("js") + ) + ).aggregation(terms("score_agg").script("_score.doubleValue()").lang("js")) + ) + ).actionGet(); + assertSearchResponse(response); + assertThat(response.getHits().getAt(0).score(), equalTo(1.0f)); + assertThat(((Terms) response.getAggregations().asMap().get("score_agg")).getBuckets().get(0).getKeyAsNumber().floatValue(), is(1f)); + assertThat(((Terms) response.getAggregations().asMap().get("score_agg")).getBuckets().get(0).getDocCount(), is(1l)); + } } From bf40ca660995c3fe323dde2809dbed05ae485093 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 7 Oct 2014 12:46:51 +0200 Subject: [PATCH 49/78] update documentation with release 2.4.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2e93904934b..fc0d388fefd 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The JavaScript language plugin allows to have `javascript` (or `js`) as the lang In order to install the plugin, simply run: ```sh -bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.3.0 +bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.4.0 ``` You need to install a version matching your Elasticsearch version: @@ -15,7 +15,7 @@ You need to install a version matching your Elasticsearch version: |---------------|-----------------------|------------| | master | Build from source | See below | | es-1.x | Build from source | [2.5.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-250-snapshot-for-elasticsearch-1x) | -| es-1.4 | Build from source | [2.4.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.4/#version-240-snapshot-for-elasticsearch-1x) | +| es-1.4 | 2.4.0 | [2.4.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.4.0/#version-240-for-elasticsearch-14) | | es-1.3 | 2.3.0 | [2.3.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.3.0/#javascript-lang-plugin-for-elasticsearch) | | es-1.2 | 2.2.0 | [2.2.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.2.0/#javascript-lang-plugin-for-elasticsearch) | | es-1.1 | 2.1.0 | [2.1.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.1.0/#javascript-lang-plugin-for-elasticsearch) | From 1950ad92f0da363e00f415eedf7ffde5dd29a2d0 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 15 Oct 2014 17:51:41 +0200 Subject: [PATCH 50/78] Implement new method `scriptRemoved(CompiledScript)` in `ScriptEngineService` This [PR](https://github.com/elasticsearch/elasticsearch/pull/8062) broke ScriptEngineService by adding a new method `scriptRemoved(CompiledScript)`. Closes #29. (cherry picked from commit 1fd05bc) --- .../javascript/JavaScriptScriptEngineService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 2b8f696ba8a..344b60ef2cc 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -25,10 +25,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScoreAccessor; -import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.SearchScript; +import org.elasticsearch.script.*; import org.elasticsearch.script.javascript.support.NativeList; import org.elasticsearch.script.javascript.support.NativeMap; import org.elasticsearch.script.javascript.support.ScriptValueConverter; @@ -72,6 +69,11 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements } + @Override + public void scriptRemoved(@Nullable CompiledScript compiledScript) { + // Nothing to do here + } + @Override public String[] types() { return new String[]{"js", "javascript"}; From 6254d2b6527cec7f30d56efd41f939e7259112e1 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 30 Oct 2014 05:55:55 -0400 Subject: [PATCH 51/78] Upgrade to Lucene 4.10.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bb9e8d45347..6bf37f27ea4 100644 --- a/pom.xml +++ b/pom.xml @@ -33,8 +33,8 @@ 2.0.0-SNAPSHOT - 4.10.1 - 4.10.1 + 4.10.2 + 4.10.2 1 true onerror From 1cd04206be014cea32b734312d58ffea157c7443 Mon Sep 17 00:00:00 2001 From: tlrx Date: Mon, 3 Nov 2014 11:29:22 +0100 Subject: [PATCH 52/78] [TESTS] Upgrade randomizedtesting-runner to 2.1.10 Closes #30 --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 6bf37f27ea4..a5caf99edbe 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,12 @@ 1.3.RC2 test + + com.carrotsearch.randomizedtesting + randomizedtesting-runner + 2.1.10 + test + From 00a1352d900cc803dfabc28cdafe465113d41837 Mon Sep 17 00:00:00 2001 From: tlrx Date: Wed, 5 Nov 2014 17:45:35 +0100 Subject: [PATCH 53/78] update documentation with release 2.4.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fc0d388fefd..b7e1897bcd2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The JavaScript language plugin allows to have `javascript` (or `js`) as the lang In order to install the plugin, simply run: ```sh -bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.4.0 +bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.4.1 ``` You need to install a version matching your Elasticsearch version: @@ -15,7 +15,7 @@ You need to install a version matching your Elasticsearch version: |---------------|-----------------------|------------| | master | Build from source | See below | | es-1.x | Build from source | [2.5.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-250-snapshot-for-elasticsearch-1x) | -| es-1.4 | 2.4.0 | [2.4.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.4.0/#version-240-for-elasticsearch-14) | +| es-1.4 | 2.4.1 | [2.4.1](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.4.1/#version-241-for-elasticsearch-14) | | es-1.3 | 2.3.0 | [2.3.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.3.0/#javascript-lang-plugin-for-elasticsearch) | | es-1.2 | 2.2.0 | [2.2.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.2.0/#javascript-lang-plugin-for-elasticsearch) | | es-1.1 | 2.1.0 | [2.1.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.1.0/#javascript-lang-plugin-for-elasticsearch) | From bb49554c33b310e0e615c12befe8846a7d27c951 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 5 Nov 2014 17:12:54 -0500 Subject: [PATCH 54/78] upgrade to lucene 5 snapshot --- pom.xml | 8 ++++++-- .../script/javascript/JavaScriptScriptEngineService.java | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index a5caf99edbe..469b5f1954f 100644 --- a/pom.xml +++ b/pom.xml @@ -33,8 +33,8 @@ 2.0.0-SNAPSHOT - 4.10.2 - 4.10.2 + 5.0.0 + 5.0.0-snapshot-1636426 1 true onerror @@ -47,6 +47,10 @@ sonatype http://oss.sonatype.org/content/repositories/releases/ + + Lucene snapshots + https://download.elasticsearch.org/lucenesnapshots/maven/ + diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 344b60ef2cc..efabd5fcca7 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -19,7 +19,7 @@ package org.elasticsearch.script.javascript; -import org.apache.lucene.index.AtomicReaderContext; +import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Scorer; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; @@ -230,7 +230,7 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements } @Override - public void setNextReader(AtomicReaderContext context) { + public void setNextReader(LeafReaderContext context) { lookup.setNextReader(context); } From d5d8ec886a4254637731a14d16676f15202c4597 Mon Sep 17 00:00:00 2001 From: tlrx Date: Fri, 7 Nov 2014 10:29:06 +0100 Subject: [PATCH 55/78] update documentation with release 2.3.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b7e1897bcd2..1b4a36172d5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The JavaScript language plugin allows to have `javascript` (or `js`) as the lang In order to install the plugin, simply run: ```sh -bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.4.1 +bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.3.1 ``` You need to install a version matching your Elasticsearch version: @@ -16,7 +16,7 @@ You need to install a version matching your Elasticsearch version: | master | Build from source | See below | | es-1.x | Build from source | [2.5.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-250-snapshot-for-elasticsearch-1x) | | es-1.4 | 2.4.1 | [2.4.1](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.4.1/#version-241-for-elasticsearch-14) | -| es-1.3 | 2.3.0 | [2.3.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.3.0/#javascript-lang-plugin-for-elasticsearch) | +| es-1.3 | 2.3.1 | [2.3.1](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.3.1/#version-231-for-elasticsearch-13) | | es-1.2 | 2.2.0 | [2.2.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.2.0/#javascript-lang-plugin-for-elasticsearch) | | es-1.1 | 2.1.0 | [2.1.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.1.0/#javascript-lang-plugin-for-elasticsearch) | | es-1.0 | 2.0.0 | [2.0.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.0.0/#javascript-lang-plugin-for-elasticsearch) | From ecb7f1830a7d05f69a355de79459c75f2a41ce75 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 10 Nov 2014 16:46:04 -0500 Subject: [PATCH 56/78] Upgrade to Lucene 5.0.0-snapshot-1637347 --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 469b5f1954f..f7c9a77fcec 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 2.0.0-SNAPSHOT 5.0.0 - 5.0.0-snapshot-1636426 + 5.0.0-snapshot-1637347 1 true onerror @@ -44,12 +44,12 @@ - sonatype - http://oss.sonatype.org/content/repositories/releases/ + Lucene snapshots + https://download.elasticsearch.org/lucenesnapshots/1637347/ - Lucene snapshots - https://download.elasticsearch.org/lucenesnapshots/maven/ + sonatype + http://oss.sonatype.org/content/repositories/releases/ From 46b84777f634c6262887e38ddc716f727467613e Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 24 Nov 2014 05:51:58 -0500 Subject: [PATCH 57/78] Upgrade to Lucene 5.0.0-snapshot-1641343 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f7c9a77fcec..c2d17d64a33 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 2.0.0-SNAPSHOT 5.0.0 - 5.0.0-snapshot-1637347 + 5.0.0-snapshot-1641343 1 true onerror @@ -45,7 +45,7 @@ Lucene snapshots - https://download.elasticsearch.org/lucenesnapshots/1637347/ + https://download.elasticsearch.org/lucenesnapshots/1641343/ sonatype From 4549a3b4ee27560f0970db0cbcdb35cc819a899a Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 27 Nov 2014 16:35:55 +0100 Subject: [PATCH 58/78] Fix expectations around script fields as a consequence of https://github.com/elasticsearch/elasticsearch/pull/8592. --- .../script/javascript/JavaScriptScriptSearchTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index ec41b103f52..31c5c2a8986 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -138,7 +138,7 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - sObj2Arr2 = (List) response.getHits().getAt(0).field("s_obj2_arr2").value(); + sObj2Arr2 = (List) response.getHits().getAt(0).field("s_obj2_arr2").values(); assertThat(sObj2Arr2.size(), equalTo(2)); assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); From 74178141544e94931a3a0c1c2577347c838ef0fb Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 27 Nov 2014 16:39:53 +0100 Subject: [PATCH 59/78] Improve wrapping of lists. With the current way that Java lists are wrapped into a Scriptable, all methods that are not defined on the java.util.List interface are hidden. This pull request makes NativeList extend NativeJavaObject in order to use reflection in order to look up properties that would not be defined on the List interface. Close #32 --- .../JavaScriptScriptEngineService.java | 4 +- .../script/javascript/support/NativeList.java | 92 ++++--------------- .../script/javascript/support/NativeMap.java | 2 +- .../support/ScriptValueConverter.java | 2 +- .../JavaScriptScriptSearchTests.java | 13 +++ 5 files changed, 34 insertions(+), 79 deletions(-) diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index efabd5fcca7..5fdf851a13e 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -292,10 +292,10 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) { if (javaObject instanceof Map) { - return new NativeMap(scope, (Map) javaObject); + return NativeMap.wrap(scope, (Map) javaObject); } if (javaObject instanceof List) { - return new NativeList(scope, (List) javaObject); + return NativeList.wrap(scope, (List) javaObject, staticType); } return super.wrapAsJavaObject(cx, scope, javaObject, staticType); } diff --git a/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java b/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java index bd1124fa4ba..1bf555db81e 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java @@ -19,29 +19,30 @@ package org.elasticsearch.script.javascript.support; +import org.mozilla.javascript.NativeJavaObject; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Undefined; import org.mozilla.javascript.Wrapper; +import java.util.Arrays; import java.util.List; /** * */ -public class NativeList implements Scriptable, Wrapper { +public class NativeList extends NativeJavaObject implements Scriptable, Wrapper { private static final long serialVersionUID = 3664761893203964569L; + private static final String LENGTH_PROPERTY = "length"; - private List list; - private Scriptable parentScope; - private Scriptable prototype; + private final List list; - public static NativeList wrap(Scriptable scope, List list) { - return new NativeList(scope, list); + public static NativeList wrap(Scriptable scope, List list, Class staticType) { + return new NativeList(scope, list, staticType); } - public NativeList(Scriptable scope, List list) { - this.parentScope = scope; + private NativeList(Scriptable scope, List list, Class staticType) { + super(scope, list, staticType); this.list = list; } @@ -66,10 +67,10 @@ public class NativeList implements Scriptable, Wrapper { */ public Object get(String name, Scriptable start) { - if ("length".equals(name)) { + if (LENGTH_PROPERTY.equals(name)) { return list.size(); } else { - return Undefined.instance; + return super.get(name, start); } } @@ -78,7 +79,7 @@ public class NativeList implements Scriptable, Wrapper { */ public Object get(int index, Scriptable start) { - if (index < 0 || index >= list.size()) { + if (has(index, start) == false) { return Undefined.instance; } return list.get(index); @@ -89,10 +90,7 @@ public class NativeList implements Scriptable, Wrapper { */ public boolean has(String name, Scriptable start) { - if ("length".equals(name)) { - return true; - } - return false; + return super.has(name, start) || LENGTH_PROPERTY.equals(name); } /* (non-Javadoc) @@ -103,15 +101,6 @@ public class NativeList implements Scriptable, Wrapper { return index >= 0 && index < list.size(); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - @SuppressWarnings("unchecked") - public void put(String name, Scriptable start, Object value) { - // do nothing here... - } - /* (non-Javadoc) * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) */ @@ -124,14 +113,6 @@ public class NativeList implements Scriptable, Wrapper { } } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) - */ - - public void delete(String name) { - // nothing here - } - /* (non-Javadoc) * @see org.mozilla.javascript.Scriptable#delete(int) */ @@ -140,59 +121,20 @@ public class NativeList implements Scriptable, Wrapper { list.remove(index); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getPrototype() - */ - - public Scriptable getPrototype() { - return this.prototype; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) - */ - - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getParentScope() - */ - - public Scriptable getParentScope() { - return this.parentScope; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) - */ - - public void setParentScope(Scriptable parent) { - this.parentScope = parent; - } - /* (non-Javadoc) * @see org.mozilla.javascript.Scriptable#getIds() */ public Object[] getIds() { - int size = list.size(); - Object[] ids = new Object[size]; + final Object[] javaObjectIds = super.getIds(); + final int size = list.size(); + final Object[] ids = Arrays.copyOf(javaObjectIds, javaObjectIds.length + size); for (int i = 0; i < size; ++i) { - ids[i] = i; + ids[javaObjectIds.length + i] = i; } return ids; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) - */ - - public Object getDefaultValue(Class hint) { - return null; - } - /* (non-Javadoc) * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) */ diff --git a/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java b/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java index efdbac86a04..a43ecec0ec8 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java @@ -55,7 +55,7 @@ public class NativeMap implements Scriptable, Wrapper { * @param scope * @param map */ - public NativeMap(Scriptable scope, Map map) { + private NativeMap(Scriptable scope, Map map) { this.parentScope = scope; this.map = map; } diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java b/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java index 726d25d616f..7f9c390b270 100644 --- a/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java +++ b/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java @@ -156,7 +156,7 @@ public final class ScriptValueConverter { // convert array to a native JavaScript Array value = Context.getCurrentContext().newArray(scope, array); } else if (value instanceof Map) { - value = new NativeMap(scope, (Map) value); + value = NativeMap.wrap(scope, (Map) value); } // simple numbers, strings and booleans are wrapped automatically by Rhino diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 31c5c2a8986..cebe5f013c6 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -43,6 +43,7 @@ import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders. import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -285,4 +286,16 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { assertThat(((Terms) response.getAggregations().asMap().get("score_agg")).getBuckets().get(0).getKeyAsNumber().floatValue(), is(1f)); assertThat(((Terms) response.getAggregations().asMap().get("score_agg")).getBuckets().get(0).getDocCount(), is(1l)); } + + @Test + public void testUseListLengthInScripts() throws Exception { + createIndex("index"); + index("index", "testtype", "1", jsonBuilder().startObject().field("f", 42).endObject()); + ensureSearchable("index"); + refresh(); + SearchResponse response = client().prepareSearch().addScriptField("foobar", "js", "doc['f'].values.length", null).get(); + assertSearchResponse(response); + assertHitCount(response, 1); + assertThat((Integer) response.getHits().getAt(0).getFields().get("foobar").value(), equalTo(1)); + } } From 2b63f291e34ad250a449f4b83aac068ec134899e Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 2 Dec 2014 18:18:27 +0100 Subject: [PATCH 60/78] Upgrade to Lucene 5.0.0-snapshot-1642891 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c2d17d64a33..f53e259347e 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 2.0.0-SNAPSHOT 5.0.0 - 5.0.0-snapshot-1641343 + 5.0.0-snapshot-1642891 1 true onerror @@ -45,7 +45,7 @@ Lucene snapshots - https://download.elasticsearch.org/lucenesnapshots/1641343/ + https://download.elasticsearch.org/lucenesnapshots/1642891/ sonatype From 663be3b6a33a061fdac5f17a407c979e0eced354 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 17 Dec 2014 09:49:39 +0100 Subject: [PATCH 61/78] Depend on elasticsearch-parent To simplify plugins maintenance and provide more value in the future, we are starting to build an `elasticsearch-parent` project. This commit is the first step for this plugin to depend on this new `pom` maven project. --- .gitignore | 5 +- dev-tools/tests.policy | 54 +++++++++++++ pom.xml | 171 +++++------------------------------------ 3 files changed, 75 insertions(+), 155 deletions(-) create mode 100644 dev-tools/tests.policy diff --git a/.gitignore b/.gitignore index ee44051ee8f..9533848e238 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,8 @@ .DS_Store *.iml /.project -/.classpath /.settings -.local-execution-hints.log +/.classpath /plugin_tools +/.local-execution-hints.log +/.local-*-execution-hints.log diff --git a/dev-tools/tests.policy b/dev-tools/tests.policy new file mode 100644 index 00000000000..6afb5025840 --- /dev/null +++ b/dev-tools/tests.policy @@ -0,0 +1,54 @@ +/* + * 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. + */ + +// Policy file to prevent tests from writing outside the test sandbox directory +// PLEASE NOTE: You may need to enable other permissions when new tests are added, +// everything not allowed here is forbidden! + +grant { + // permissions for file access, write access only to sandbox: + permission java.io.FilePermission "<>", "read,execute"; + permission java.io.FilePermission "${junit4.childvm.cwd}", "read,execute,write"; + permission java.io.FilePermission "${junit4.childvm.cwd}${/}-", "read,execute,write,delete"; + permission java.io.FilePermission "${junit4.tempDir}${/}*", "read,execute,write,delete"; + permission groovy.security.GroovyCodeSourcePermission "/groovy/script"; + + // Allow connecting to the internet anywhere + permission java.net.SocketPermission "*", "accept,listen,connect,resolve"; + + // Basic permissions needed for Lucene / Elasticsearch to work: + permission java.util.PropertyPermission "*", "read,write"; + permission java.lang.reflect.ReflectPermission "*"; + permission java.lang.RuntimePermission "*"; + + // These two *have* to be spelled out a separate + permission java.lang.management.ManagementPermission "control"; + permission java.lang.management.ManagementPermission "monitor"; + + permission java.net.NetPermission "*"; + permission java.util.logging.LoggingPermission "control"; + permission javax.management.MBeanPermission "*", "*"; + permission javax.management.MBeanServerPermission "*"; + permission javax.management.MBeanTrustPermission "*"; + + // Needed for some things in DNS caching in the JVM + permission java.security.SecurityPermission "getProperty.networkaddress.cache.ttl"; + permission java.security.SecurityPermission "getProperty.networkaddress.cache.negative.ttl"; + +}; diff --git a/pom.xml b/pom.xml index f53e259347e..cc9180a9b7f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,6 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + + org.elasticsearch + elasticsearch-parent + 2.0.0-SNAPSHOT + + org.elasticsearch elasticsearch-lang-javascript 3.0.0-SNAPSHOT @@ -20,51 +27,30 @@ scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git - scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git - + scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git http://github.com/elasticsearch/elasticsearch-lang-javascript - - org.sonatype.oss - oss-parent - 7 - - - 2.0.0-SNAPSHOT - 5.0.0 - 5.0.0-snapshot-1642891 - 1 - true - onerror - - INFO + - - - Lucene snapshots - https://download.elasticsearch.org/lucenesnapshots/1642891/ - - - sonatype - http://oss.sonatype.org/content/repositories/releases/ - - - + + org.hamcrest + hamcrest-all + + + com.carrotsearch.randomizedtesting + randomizedtesting-runner + org.apache.lucene lucene-test-framework - ${lucene.maven.version} - test - org.elasticsearch elasticsearch - ${elasticsearch.version} @@ -78,37 +64,13 @@ log4j log4j - 1.2.16 - runtime true org.elasticsearch elasticsearch - ${elasticsearch.version} test-jar - test - - - - org.hamcrest - hamcrest-core - 1.3.RC2 - test - - - - org.hamcrest - hamcrest-library - 1.3.RC2 - test - - - com.carrotsearch.randomizedtesting - randomizedtesting-runner - 2.1.10 - test @@ -126,120 +88,23 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - com.carrotsearch.randomizedtesting junit4-maven-plugin - 2.0.12 - - - tests - test - - junit4 - - - 20 - pipe,warn - true - - - - - - - - - ${tests.jvms} - - - - - - - **/*Tests.class - **/*Test.class - - - **/Abstract*.class - **/*StressTest.class - - - -Xmx512m - -XX:MaxDirectMemorySize=512m - -Des.logger.prefix= - - ${tests.shuffle} - ${tests.verbose} - ${tests.seed} - ${tests.failfast} - - - ${tests.iters} - ${tests.maxfailures} - ${tests.failfast} - ${tests.class} - ${tests.method} - ${tests.nightly} - ${tests.badapples} - ${tests.weekly} - ${tests.slow} - ${tests.awaitsfix} - ${tests.slow} - ${tests.timeoutSuite} - ${tests.showSuccess} - ${tests.integration} - ${tests.cluster_seed} - ${tests.client.ratio} - ${env.ES_TEST_LOCAL} - ${es.node.mode} - ${es.logger.level} - true - - - - org.apache.maven.plugins maven-surefire-plugin - 2.15 - - true - org.apache.maven.plugins maven-source-plugin - 2.1.2 - - - attach-sources - - jar - - - + org.apache.maven.plugins maven-assembly-plugin - 2.3 false ${project.build.directory}/releases/ From bbf1375c987f056098d39536f87b85f3975007a3 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 2 Jan 2015 18:39:08 +0100 Subject: [PATCH 62/78] Add sonatype snapshot repository --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index cc9180a9b7f..5cd637bedeb 100644 --- a/pom.xml +++ b/pom.xml @@ -123,4 +123,12 @@ + + + + oss-snapshots + Sonatype OSS Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + From 1fd0521a337fe2918213efd36443cb5fefd5c04e Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sat, 28 Feb 2015 13:44:02 +0100 Subject: [PATCH 63/78] Remove component settings from AbstractComponent Related to elasticsearch/elasticsearch#9919 Closes #35. --- .../script/javascript/JavaScriptScriptEngineService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 5fdf851a13e..83fb23ded53 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -53,7 +53,7 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements public JavaScriptScriptEngineService(Settings settings) { super(settings); - this.optimizationLevel = componentSettings.getAsInt("optimization_level", 1); + this.optimizationLevel = settings.getAsInt("script.javascript.optimization_level", 1); Context ctx = Context.enter(); try { From 8f038bd7be93f82c4f8b0be9f1923e43c1aed902 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Mon, 16 Mar 2015 13:46:38 -0700 Subject: [PATCH 64/78] Create `es-1.5` branch --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b4a36172d5..caea228ae81 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ You need to install a version matching your Elasticsearch version: | elasticsearch | JavaScript Plugin | Docs | |---------------|-----------------------|------------| | master | Build from source | See below | -| es-1.x | Build from source | [2.5.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-250-snapshot-for-elasticsearch-1x) | +| es-1.x | Build from source | [2.6.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-260-snapshot-for-elasticsearch-1x) | +| es-1.5 | Build from source | [2.5.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.5/#version-250-snapshot-for-elasticsearch-15) | | es-1.4 | 2.4.1 | [2.4.1](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.4.1/#version-241-for-elasticsearch-14) | | es-1.3 | 2.3.1 | [2.3.1](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.3.1/#version-231-for-elasticsearch-13) | | es-1.2 | 2.2.0 | [2.2.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.2.0/#javascript-lang-plugin-for-elasticsearch) | From bdf46a2ee8b71c28c1bc14dfb664b03634326468 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sat, 28 Mar 2015 16:48:30 +0100 Subject: [PATCH 65/78] Move parent after artifact coordinates --- pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 5cd637bedeb..0e88b9e31cc 100644 --- a/pom.xml +++ b/pom.xml @@ -4,12 +4,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.elasticsearch - elasticsearch-parent - 2.0.0-SNAPSHOT - - org.elasticsearch elasticsearch-lang-javascript 3.0.0-SNAPSHOT @@ -31,6 +25,12 @@ http://github.com/elasticsearch/elasticsearch-lang-javascript + + org.elasticsearch + elasticsearch-parent + 2.0.0-SNAPSHOT + + From b20af45de526232c7e08458c13eaafa37b77f2bb Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sat, 28 Mar 2015 16:47:10 +0100 Subject: [PATCH 66/78] Move to elastic owner (cherry picked from commit 3d3ce33) (cherry picked from commit c59f9ce) --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 0e88b9e31cc..8626eb8473c 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ jar Elasticsearch JavaScript language plugin The JavaScript language plugin allows to have javascript as the language of scripts to execute. - https://github.com/elasticsearch/elasticsearch-lang-javascript/ + https://github.com/elastic/elasticsearch-lang-javascript/ 2009 @@ -20,9 +20,9 @@ - scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git - scm:git:git@github.com:elasticsearch/elasticsearch-lang-javascript.git - http://github.com/elasticsearch/elasticsearch-lang-javascript + scm:git:git@github.com:elastic/elasticsearch-lang-javascript.git + scm:git:git@github.com:elastic/elasticsearch-lang-javascript.git + http://github.com/elastic/elasticsearch-lang-javascript From 9fd8d55f6bd9cfdca31ffc030014d86a10ce5516 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sat, 28 Mar 2015 16:55:00 +0100 Subject: [PATCH 67/78] update documentation with release 2.5.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index caea228ae81..7080d9397d2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The JavaScript language plugin allows to have `javascript` (or `js`) as the lang In order to install the plugin, simply run: ```sh -bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.3.1 +bin/plugin install elasticsearch/elasticsearch-lang-javascript/2.5.0 ``` You need to install a version matching your Elasticsearch version: @@ -15,7 +15,7 @@ You need to install a version matching your Elasticsearch version: |---------------|-----------------------|------------| | master | Build from source | See below | | es-1.x | Build from source | [2.6.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.x/#version-260-snapshot-for-elasticsearch-1x) | -| es-1.5 | Build from source | [2.5.0-SNAPSHOT](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/es-1.5/#version-250-snapshot-for-elasticsearch-15) | +| es-1.5 | 2.5.0 | [2.5.0](https://github.com/elastic/elasticsearch-lang-javascript/tree/v2.5.0/#version-250-for-elasticsearch-15) | | es-1.4 | 2.4.1 | [2.4.1](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.4.1/#version-241-for-elasticsearch-14) | | es-1.3 | 2.3.1 | [2.3.1](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.3.1/#version-231-for-elasticsearch-13) | | es-1.2 | 2.2.0 | [2.2.0](https://github.com/elasticsearch/elasticsearch-lang-javascript/tree/v2.2.0/#javascript-lang-plugin-for-elasticsearch) | From eb7cb63b5faf8a27a90eb82a9fdc9c240e8fc934 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 9 Apr 2015 14:30:15 +0200 Subject: [PATCH 68/78] Fix compilation. See https://github.com/elastic/elasticsearch/pull/10389 for background. --- .../JavaScriptScriptEngineService.java | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 83fb23ded53..75504fe42ef 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -29,9 +29,11 @@ import org.elasticsearch.script.*; import org.elasticsearch.script.javascript.support.NativeList; import org.elasticsearch.script.javascript.support.NativeMap; import org.elasticsearch.script.javascript.support.ScriptValueConverter; +import org.elasticsearch.search.lookup.LeafSearchLookup; import org.elasticsearch.search.lookup.SearchLookup; import org.mozilla.javascript.*; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; @@ -121,26 +123,33 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements } @Override - public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map vars) { + public SearchScript search(final Object compiledScript, final SearchLookup lookup, @Nullable final Map vars) { Context ctx = Context.enter(); try { ctx.setWrapFactory(wrapFactory); - Scriptable scope = ctx.newObject(globalScope); + final Scriptable scope = ctx.newObject(globalScope); scope.setPrototype(globalScope); scope.setParentScope(null); - for (Map.Entry entry : lookup.asMap().entrySet()) { - ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); - } + return new SearchScript() { - if (vars != null) { - for (Map.Entry entry : vars.entrySet()) { + @Override + public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException { + final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context); + for (Map.Entry entry : leafLookup.asMap().entrySet()) { ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); } - } - return new JavaScriptSearchScript((Script) compiledScript, scope, lookup); + if (vars != null) { + for (Map.Entry entry : vars.entrySet()) { + ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); + } + } + + return new JavaScriptSearchScript((Script) compiledScript, scope, leafLookup); + } + }; } finally { Context.exit(); } @@ -208,15 +217,15 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements } } - public static class JavaScriptSearchScript implements SearchScript { + public static class JavaScriptSearchScript implements LeafSearchScript { private final Script script; private final Scriptable scope; - private final SearchLookup lookup; + private final LeafSearchLookup lookup; - public JavaScriptSearchScript(Script script, Scriptable scope, SearchLookup lookup) { + public JavaScriptSearchScript(Script script, Scriptable scope, LeafSearchLookup lookup) { this.script = script; this.scope = scope; this.lookup = lookup; @@ -225,18 +234,16 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements @Override public void setScorer(Scorer scorer) { Context ctx = Context.enter(); - ScriptableObject.putProperty(scope, "_score", wrapFactory.wrapAsJavaObject(ctx, scope, new ScoreAccessor(scorer), ScoreAccessor.class)); - Context.exit(); + try { + ScriptableObject.putProperty(scope, "_score", wrapFactory.wrapAsJavaObject(ctx, scope, new ScoreAccessor(scorer), ScoreAccessor.class)); + } finally { + Context.exit(); + } } @Override - public void setNextReader(LeafReaderContext context) { - lookup.setNextReader(context); - } - - @Override - public void setNextDocId(int doc) { - lookup.setNextDocId(doc); + public void setDocument(int doc) { + lookup.setDocument(doc); } @Override @@ -245,8 +252,8 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements } @Override - public void setNextSource(Map source) { - lookup.source().setNextSource(source); + public void setSource(Map source) { + lookup.source().setSource(source); } @Override From ddfd7c2c9530d6659e80faf38fb8d263ce364d82 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sat, 25 Apr 2015 17:22:39 +0200 Subject: [PATCH 69/78] Import explicitly org.mozilla.javascript.Script Because we have now a new class in elasticsearch master branch which conflicts. --- .../script/javascript/JavaScriptScriptEngineService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 75504fe42ef..7aa8b2bbf3f 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -32,6 +32,7 @@ import org.elasticsearch.script.javascript.support.ScriptValueConverter; import org.elasticsearch.search.lookup.LeafSearchLookup; import org.elasticsearch.search.lookup.SearchLookup; import org.mozilla.javascript.*; +import org.mozilla.javascript.Script; import java.io.IOException; import java.util.List; From 81f682ddbe4497c1b0d50f1a7a214b2b53acf57d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 11 May 2015 20:46:56 -0400 Subject: [PATCH 70/78] enable security manager in tests --- dev-tools/tests.policy | 54 ------------------- pom.xml | 1 + .../JavaScriptScriptSearchTests.java | 7 ++- 3 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 dev-tools/tests.policy diff --git a/dev-tools/tests.policy b/dev-tools/tests.policy deleted file mode 100644 index 6afb5025840..00000000000 --- a/dev-tools/tests.policy +++ /dev/null @@ -1,54 +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. - */ - -// Policy file to prevent tests from writing outside the test sandbox directory -// PLEASE NOTE: You may need to enable other permissions when new tests are added, -// everything not allowed here is forbidden! - -grant { - // permissions for file access, write access only to sandbox: - permission java.io.FilePermission "<>", "read,execute"; - permission java.io.FilePermission "${junit4.childvm.cwd}", "read,execute,write"; - permission java.io.FilePermission "${junit4.childvm.cwd}${/}-", "read,execute,write,delete"; - permission java.io.FilePermission "${junit4.tempDir}${/}*", "read,execute,write,delete"; - permission groovy.security.GroovyCodeSourcePermission "/groovy/script"; - - // Allow connecting to the internet anywhere - permission java.net.SocketPermission "*", "accept,listen,connect,resolve"; - - // Basic permissions needed for Lucene / Elasticsearch to work: - permission java.util.PropertyPermission "*", "read,write"; - permission java.lang.reflect.ReflectPermission "*"; - permission java.lang.RuntimePermission "*"; - - // These two *have* to be spelled out a separate - permission java.lang.management.ManagementPermission "control"; - permission java.lang.management.ManagementPermission "monitor"; - - permission java.net.NetPermission "*"; - permission java.util.logging.LoggingPermission "control"; - permission javax.management.MBeanPermission "*", "*"; - permission javax.management.MBeanServerPermission "*"; - permission javax.management.MBeanTrustPermission "*"; - - // Needed for some things in DNS caching in the JVM - permission java.security.SecurityPermission "getProperty.networkaddress.cache.ttl"; - permission java.security.SecurityPermission "getProperty.networkaddress.cache.negative.ttl"; - -}; diff --git a/pom.xml b/pom.xml index 8626eb8473c..d41c9f30bfc 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,7 @@ + true diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index cebe5f013c6..6324dd44334 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -37,7 +37,6 @@ import java.util.Map; import static org.elasticsearch.client.Requests.searchRequest; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.index.query.FilterBuilders.scriptFilter; import static org.elasticsearch.index.query.QueryBuilders.*; import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; @@ -73,7 +72,7 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running doc['num1'].value > 1"); SearchResponse response = client().prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > 1").lang("js"))) + .setQuery(filteredQuery(matchAllQuery(), scriptQuery("doc['num1'].value > 1").lang("js"))) .addSort("num1", SortOrder.ASC) .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); @@ -86,7 +85,7 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running doc['num1'].value > param1"); response = client().prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", 2))) + .setQuery(filteredQuery(matchAllQuery(), scriptQuery("doc['num1'].value > param1").lang("js").addParam("param1", 2))) .addSort("num1", SortOrder.ASC) .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); @@ -97,7 +96,7 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { logger.info(" --> running doc['num1'].value > param1"); response = client().prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", -1))) + .setQuery(filteredQuery(matchAllQuery(), scriptQuery("doc['num1'].value > param1").lang("js").addParam("param1", -1))) .addSort("num1", SortOrder.ASC) .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); From 92deb89e253777b8ee1bbed6b5cab6558f31877d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 13 May 2015 23:34:52 -0400 Subject: [PATCH 71/78] remove unnecessary property --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index d41c9f30bfc..8626eb8473c 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,6 @@ - true From 9bc7f34da2be959e8f27628dc4e5ba34c7803954 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 21 May 2015 10:36:54 -0400 Subject: [PATCH 72/78] engage forbidden apis --- pom.xml | 47 ++--------------------------------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 8626eb8473c..349067f5361 100644 --- a/pom.xml +++ b/pom.xml @@ -40,14 +40,12 @@ org.hamcrest hamcrest-all - - com.carrotsearch.randomizedtesting - randomizedtesting-runner - + org.apache.lucene lucene-test-framework + org.elasticsearch elasticsearch @@ -75,51 +73,10 @@ - - - src/main/resources - true - - **/*.properties - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - com.carrotsearch.randomizedtesting - junit4-maven-plugin - - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.apache.maven.plugins - maven-source-plugin - org.apache.maven.plugins maven-assembly-plugin - - false - ${project.build.directory}/releases/ - - ${basedir}/src/main/assemblies/plugin.xml - - - - - package - - single - - - From 304daebfdbcf4727826de372921121ef781dd7b7 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 21 May 2015 16:51:53 -0400 Subject: [PATCH 73/78] remove duplicate test config --- pom.xml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/pom.xml b/pom.xml index 349067f5361..dad9831102f 100644 --- a/pom.xml +++ b/pom.xml @@ -36,21 +36,6 @@ - - org.hamcrest - hamcrest-all - - - - org.apache.lucene - lucene-test-framework - - - - org.elasticsearch - elasticsearch - - org.mozilla rhino @@ -58,18 +43,6 @@ - - - log4j - log4j - true - - - - org.elasticsearch - elasticsearch - test-jar - From 3f56eadbd98dd04b0f97eb094cd93fb5c4efd373 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 21 May 2015 22:55:28 -0400 Subject: [PATCH 74/78] switch to plugin pom --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dad9831102f..6183087d914 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ org.elasticsearch - elasticsearch-parent + elasticsearch-plugin 2.0.0-SNAPSHOT From ee179af1b88c11e23f62269301df8860f050b0fa Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 22 May 2015 09:31:35 -0400 Subject: [PATCH 75/78] remove logging properties --- src/test/resources/log4j.properties | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/test/resources/log4j.properties diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties deleted file mode 100644 index 497c97f9959..00000000000 --- a/src/test/resources/log4j.properties +++ /dev/null @@ -1,5 +0,0 @@ -log4j.rootLogger=INFO, out - -log4j.appender.out=org.apache.log4j.ConsoleAppender -log4j.appender.out.layout=org.apache.log4j.PatternLayout -log4j.appender.out.layout.conversionPattern=[%d{ISO8601}][%-5p][%-25c] %m%n From 5af8412fc90d7e6584f9e4e77899d1a06afeaaa6 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Tue, 26 May 2015 09:32:38 -0400 Subject: [PATCH 76/78] Absorb ImmutableSettings into Settings --- .../script/javascript/JavaScriptScriptEngineTests.java | 4 ++-- .../javascript/JavaScriptScriptMultiThreadedTest.java | 8 ++++---- .../script/javascript/JavaScriptScriptSearchTests.java | 3 +-- .../org/elasticsearch/script/javascript/SimpleBench.java | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java index e343de9159b..a4e43a97f29 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.script.javascript; import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.After; @@ -44,7 +44,7 @@ public class JavaScriptScriptEngineTests extends ElasticsearchTestCase { @Before public void setup() { - se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + se = new JavaScriptScriptEngineService(Settings.Builder.EMPTY_SETTINGS); } @After diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java index 381de8e5645..c235128e83f 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java @@ -19,7 +19,7 @@ package org.elasticsearch.script.javascript; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; @@ -40,7 +40,7 @@ public class JavaScriptScriptMultiThreadedTest extends ElasticsearchTestCase { @Test public void testExecutableNoRuntimeParams() throws Exception { - final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(Settings.Builder.EMPTY_SETTINGS); final Object compiled = se.compile("x + y"); final AtomicBoolean failed = new AtomicBoolean(); @@ -84,7 +84,7 @@ public class JavaScriptScriptMultiThreadedTest extends ElasticsearchTestCase { @Test public void testExecutableWithRuntimeParams() throws Exception { - final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(Settings.Builder.EMPTY_SETTINGS); final Object compiled = se.compile("x + y"); final AtomicBoolean failed = new AtomicBoolean(); @@ -127,7 +127,7 @@ public class JavaScriptScriptMultiThreadedTest extends ElasticsearchTestCase { @Test public void testExecute() throws Exception { - final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(Settings.Builder.EMPTY_SETTINGS); final Object compiled = se.compile("x + y"); final AtomicBoolean failed = new AtomicBoolean(); diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 6324dd44334..53cf8d198da 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.script.javascript; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; import org.elasticsearch.plugins.PluginsService; @@ -54,7 +53,7 @@ public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest { @Override protected Settings nodeSettings(int nodeOrdinal) { - return ImmutableSettings.builder() + return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true) .build(); diff --git a/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java b/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java index 49f8e401074..e0b47c8a919 100644 --- a/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java +++ b/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java @@ -20,7 +20,7 @@ package org.elasticsearch.script.javascript; import org.elasticsearch.common.StopWatch; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.ExecutableScript; import java.util.HashMap; @@ -32,7 +32,7 @@ import java.util.Map; public class SimpleBench { public static void main(String[] args) { - JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); + JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(Settings.Builder.EMPTY_SETTINGS); Object compiled = se.compile("x + y"); Map vars = new HashMap(); From 26b0dae19fc1cb44013a05d8079f62708fb90a4d Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 8 Jun 2015 12:04:39 +0200 Subject: [PATCH 77/78] [TEST] Don't use shaded API --- .../script/javascript/JavaScriptScriptEngineTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java index a4e43a97f29..9bb3543b012 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.script.javascript; -import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.ExecutableScript; @@ -28,6 +27,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -64,7 +64,7 @@ public class JavaScriptScriptEngineTests extends ElasticsearchTestCase { Map vars = new HashMap(); Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); - Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).put("l", Lists.newArrayList("2", "1")).map(); + Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).put("l", Arrays.asList("2", "1")).map(); vars.put("obj1", obj1); Object o = se.execute(se.compile("obj1"), vars); assertThat(o, instanceOf(Map.class)); @@ -123,7 +123,7 @@ public class JavaScriptScriptEngineTests extends ElasticsearchTestCase { Map vars = new HashMap(); Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).map(); - vars.put("l", Lists.newArrayList("1", "2", "3", obj1)); + vars.put("l", Arrays.asList("1", "2", "3", obj1)); Object o = se.execute(se.compile("l.length"), vars); assertThat(((Number) o).intValue(), equalTo(4)); From a24c10c703ab8fe790eb4504992d16e8f0551273 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 9 Jun 2015 15:17:25 +0200 Subject: [PATCH 78/78] add lang-javascript module --- .gitignore | 13 -- CONTRIBUTING.md | 98 --------- LICENSE.txt | 202 ------------------ dev-tools/release.py | 134 ------------ .../lang-javascript/README.md | 0 pom.xml => plugins/lang-javascript/pom.xml | 25 +-- .../src}/main/assemblies/plugin.xml | 0 .../plugin/javascript/JavaScriptPlugin.java | 0 .../JavaScriptScriptEngineService.java | 0 .../script/javascript/support/NativeList.java | 0 .../script/javascript/support/NativeMap.java | 0 .../support/ScriptValueConverter.java | 0 .../support/ScriptableLinkedHashMap.java | 0 .../javascript/support/ScriptableMap.java | 0 .../support/ScriptableWrappedMap.java | 0 .../src}/main/resources/es-plugin.properties | 0 .../JavaScriptScriptEngineTests.java | 0 .../JavaScriptScriptMultiThreadedTest.java | 0 .../JavaScriptScriptSearchTests.java | 0 .../script/javascript/SimpleBench.java | 0 20 files changed, 2 insertions(+), 470 deletions(-) delete mode 100644 .gitignore delete mode 100644 CONTRIBUTING.md delete mode 100644 LICENSE.txt delete mode 100644 dev-tools/release.py rename README.md => plugins/lang-javascript/README.md (100%) rename pom.xml => plugins/lang-javascript/pom.xml (57%) rename {src => plugins/lang-javascript/src}/main/assemblies/plugin.xml (100%) rename {src => plugins/lang-javascript/src}/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java (100%) rename {src => plugins/lang-javascript/src}/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java (100%) rename {src => plugins/lang-javascript/src}/main/java/org/elasticsearch/script/javascript/support/NativeList.java (100%) rename {src => plugins/lang-javascript/src}/main/java/org/elasticsearch/script/javascript/support/NativeMap.java (100%) rename {src => plugins/lang-javascript/src}/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java (100%) rename {src => plugins/lang-javascript/src}/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java (100%) rename {src => plugins/lang-javascript/src}/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java (100%) rename {src => plugins/lang-javascript/src}/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java (100%) rename {src => plugins/lang-javascript/src}/main/resources/es-plugin.properties (100%) rename {src => plugins/lang-javascript/src}/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java (100%) rename {src => plugins/lang-javascript/src}/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java (100%) rename {src => plugins/lang-javascript/src}/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java (100%) rename {src => plugins/lang-javascript/src}/test/java/org/elasticsearch/script/javascript/SimpleBench.java (100%) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 9533848e238..00000000000 --- a/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/data -/work -/logs -/.idea -/target -.DS_Store -*.iml -/.project -/.settings -/.classpath -/plugin_tools -/.local-execution-hints.log -/.local-*-execution-hints.log diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 923342ad6ad..00000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,98 +0,0 @@ -Contributing to elasticsearch -============================= - -Elasticsearch is an open source project and we love to receive contributions from our community — you! There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be incorporated into Elasticsearch itself. - -Bug reports ------------ - -If you think you have found a bug in Elasticsearch, first make sure that you are testing against the [latest version of Elasticsearch](http://www.elasticsearch.org/download/) - your issue may already have been fixed. If not, search our [issues list](https://github.com/elasticsearch/elasticsearch/issues) on GitHub in case a similar issue has already been opened. - -It is very helpful if you can prepare a reproduction of the bug. In other words, provide a small test case which we can run to confirm your bug. It makes it easier to find the problem and to fix it. Test cases should be provided as `curl` commands which we can copy and paste into a terminal to run it locally, for example: - -```sh -# delete the index -curl -XDELETE localhost:9200/test - -# insert a document -curl -XPUT localhost:9200/test/test/1 -d '{ - "title": "test document" -}' - -# this should return XXXX but instead returns YYY -curl .... -``` - -Provide as much information as you can. You may think that the problem lies with your query, when actually it depends on how your data is indexed. The easier it is for us to recreate your problem, the faster it is likely to be fixed. - -Feature requests ----------------- - -If you find yourself wishing for a feature that doesn't exist in Elasticsearch, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Elasticsearch has today have been added because our users saw the need. -Open an issue on our [issues list](https://github.com/elasticsearch/elasticsearch/issues) on GitHub which describes the feature you would like to see, why you need it, and how it should work. - -Contributing code and documentation changes -------------------------------------------- - -If you have a bugfix or new feature that you would like to contribute to Elasticsearch, please find or open an issue about it first. Talk about what you would like to do. It may be that somebody is already working on it, or that there are particular issues that you should know about before implementing the change. - -We enjoy working with contributors to get their code accepted. There are many approaches to fixing a problem and it is important to find the best approach before writing too much code. - -The process for contributing to any of the [Elasticsearch repositories](https://github.com/elasticsearch/) is similar. Details for individual projects can be found below. - -### Fork and clone the repository - -You will need to fork the main Elasticsearch code or documentation repository and clone it to your local machine. See -[github help page](https://help.github.com/articles/fork-a-repo) for help. - -Further instructions for specific projects are given below. - -### Submitting your changes - -Once your changes and tests are ready to submit for review: - -1. Test your changes -Run the test suite to make sure that nothing is broken. - -2. Sign the Contributor License Agreement -Please make sure you have signed our [Contributor License Agreement](http://www.elasticsearch.org/contributor-agreement/). We are not asking you to assign copyright to us, but to give us the right to distribute your code without restriction. We ask this of all contributors in order to assure our users of the origin and continuing existence of the code. You only need to sign the CLA once. - -3. Rebase your changes -Update your local repository with the most recent code from the main Elasticsearch repository, and rebase your branch on top of the latest master branch. We prefer your changes to be squashed into a single commit. - -4. Submit a pull request -Push your local changes to your forked copy of the repository and [submit a pull request](https://help.github.com/articles/using-pull-requests). In the pull request, describe what your changes do and mention the number of the issue where discussion has taken place, eg "Closes #123". - -Then sit back and wait. There will probably be discussion about the pull request and, if any changes are needed, we would love to work with you to get your pull request merged into Elasticsearch. - - -Contributing to the Elasticsearch plugin ----------------------------------------- - -**Repository:** [https://github.com/elasticsearch/elasticsearch-lang-javascript](https://github.com/elasticsearch/elasticsearch-lang-javascript) - -Make sure you have [Maven](http://maven.apache.org) installed, as Elasticsearch uses it as its build system. Integration with IntelliJ and Eclipse should work out of the box. Eclipse users can automatically configure their IDE by running `mvn eclipse:eclipse` and then importing the project into their workspace: `File > Import > Existing project into workspace`. - -Please follow these formatting guidelines: - -* Java indent is 4 spaces -* Line width is 140 characters -* The rest is left to Java coding standards -* Disable “auto-format on save” to prevent unnecessary format changes. This makes reviews much harder as it generates unnecessary formatting changes. If your IDE supports formatting only modified chunks that is fine to do. - -To create a distribution from the source, simply run: - -```sh -cd elasticsearch-lang-javascript/ -mvn clean package -DskipTests -``` - -You will find the newly built packages under: `./target/releases/`. - -Before submitting your changes, run the test suite to make sure that nothing is broken, with: - -```sh -mvn clean test -``` - -Source: [Contributing to elasticsearch](http://www.elasticsearch.org/contributing-to-elasticsearch/) diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index d6456956733..00000000000 --- a/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed 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. diff --git a/dev-tools/release.py b/dev-tools/release.py deleted file mode 100644 index edcc637d068..00000000000 --- a/dev-tools/release.py +++ /dev/null @@ -1,134 +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. - -import datetime -import os -import shutil -import sys -import time -import urllib -import urllib.request -import zipfile - -from os.path import dirname, abspath - -""" - This tool builds a release from the a given elasticsearch plugin branch. - - It is basically a wrapper on top of launch_release.py which: - - - tries to get a more recent version of launch_release.py in ... - - download it if needed - - launch it passing all arguments to it, like: - - $ python3 dev_tools/release.py --branch master --publish --remote origin - - Important options: - - # Dry run - $ python3 dev_tools/release.py - - # Dry run without tests - python3 dev_tools/release.py --skiptests - - # Release, publish artifacts and announce - $ python3 dev_tools/release.py --publish - - See full documentation in launch_release.py -""" -env = os.environ - -# Change this if the source repository for your scripts is at a different location -SOURCE_REPO = 'elasticsearch/elasticsearch-plugins-script' -# We define that we should download again the script after 1 days -SCRIPT_OBSOLETE_DAYS = 1 -# We ignore in master.zip file the following files -IGNORED_FILES = ['.gitignore', 'README.md'] - - -ROOT_DIR = abspath(os.path.join(abspath(dirname(__file__)), '../')) -TARGET_TOOLS_DIR = ROOT_DIR + '/plugin_tools' -DEV_TOOLS_DIR = ROOT_DIR + '/dev-tools' -BUILD_RELEASE_FILENAME = 'release.zip' -BUILD_RELEASE_FILE = TARGET_TOOLS_DIR + '/' + BUILD_RELEASE_FILENAME -SOURCE_URL = 'https://github.com/%s/archive/master.zip' % SOURCE_REPO - -# Download a recent version of the release plugin tool -try: - os.mkdir(TARGET_TOOLS_DIR) - print('directory %s created' % TARGET_TOOLS_DIR) -except FileExistsError: - pass - - -try: - # we check latest update. If we ran an update recently, we - # are not going to check it again - download = True - - try: - last_download_time = datetime.datetime.fromtimestamp(os.path.getmtime(BUILD_RELEASE_FILE)) - if (datetime.datetime.now()-last_download_time).days < SCRIPT_OBSOLETE_DAYS: - download = False - except FileNotFoundError: - pass - - if download: - urllib.request.urlretrieve(SOURCE_URL, BUILD_RELEASE_FILE) - with zipfile.ZipFile(BUILD_RELEASE_FILE) as myzip: - for member in myzip.infolist(): - filename = os.path.basename(member.filename) - # skip directories - if not filename: - continue - if filename in IGNORED_FILES: - continue - - # copy file (taken from zipfile's extract) - source = myzip.open(member.filename) - target = open(os.path.join(TARGET_TOOLS_DIR, filename), "wb") - with source, target: - shutil.copyfileobj(source, target) - # We keep the original date - date_time = time.mktime(member.date_time + (0, 0, -1)) - os.utime(os.path.join(TARGET_TOOLS_DIR, filename), (date_time, date_time)) - print('plugin-tools updated from %s' % SOURCE_URL) -except urllib.error.HTTPError: - pass - - -# Let see if we need to update the release.py script itself -source_time = os.path.getmtime(TARGET_TOOLS_DIR + '/release.py') -repo_time = os.path.getmtime(DEV_TOOLS_DIR + '/release.py') -if source_time > repo_time: - input('release.py needs an update. Press a key to update it...') - shutil.copyfile(TARGET_TOOLS_DIR + '/release.py', DEV_TOOLS_DIR + '/release.py') - -# We can launch the build process -try: - PYTHON = 'python' - # make sure python3 is used if python3 is available - # some systems use python 2 as default - os.system('python3 --version > /dev/null 2>&1') - PYTHON = 'python3' -except RuntimeError: - pass - -release_args = '' -for x in range(1, len(sys.argv)): - release_args += ' ' + sys.argv[x] - -os.system('%s %s/build_release.py %s' % (PYTHON, TARGET_TOOLS_DIR, release_args)) diff --git a/README.md b/plugins/lang-javascript/README.md similarity index 100% rename from README.md rename to plugins/lang-javascript/README.md diff --git a/pom.xml b/plugins/lang-javascript/pom.xml similarity index 57% rename from pom.xml rename to plugins/lang-javascript/pom.xml index 6183087d914..7179582953c 100644 --- a/pom.xml +++ b/plugins/lang-javascript/pom.xml @@ -4,26 +4,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.elasticsearch + org.elasticsearch.plugin elasticsearch-lang-javascript - 3.0.0-SNAPSHOT + jar Elasticsearch JavaScript language plugin The JavaScript language plugin allows to have javascript as the language of scripts to execute. - https://github.com/elastic/elasticsearch-lang-javascript/ - 2009 - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - scm:git:git@github.com:elastic/elasticsearch-lang-javascript.git - scm:git:git@github.com:elastic/elasticsearch-lang-javascript.git - http://github.com/elastic/elasticsearch-lang-javascript - org.elasticsearch @@ -54,11 +40,4 @@ - - - oss-snapshots - Sonatype OSS Snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - - diff --git a/src/main/assemblies/plugin.xml b/plugins/lang-javascript/src/main/assemblies/plugin.xml similarity index 100% rename from src/main/assemblies/plugin.xml rename to plugins/lang-javascript/src/main/assemblies/plugin.xml diff --git a/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java similarity index 100% rename from src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java rename to plugins/lang-javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java similarity index 100% rename from src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java rename to plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java diff --git a/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java similarity index 100% rename from src/main/java/org/elasticsearch/script/javascript/support/NativeList.java rename to plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java diff --git a/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java similarity index 100% rename from src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java rename to plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java similarity index 100% rename from src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java rename to plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java similarity index 100% rename from src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java rename to plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java similarity index 100% rename from src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java rename to plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java diff --git a/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java similarity index 100% rename from src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java rename to plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java diff --git a/src/main/resources/es-plugin.properties b/plugins/lang-javascript/src/main/resources/es-plugin.properties similarity index 100% rename from src/main/resources/es-plugin.properties rename to plugins/lang-javascript/src/main/resources/es-plugin.properties diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java similarity index 100% rename from src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java rename to plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java similarity index 100% rename from src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java rename to plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java similarity index 100% rename from src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java rename to plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java diff --git a/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java similarity index 100% rename from src/test/java/org/elasticsearch/script/javascript/SimpleBench.java rename to plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java