Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1420 [created] 6c72a9684
TINKERPOP-1420 Removal of previously deprecated gremlin-groovy classes/methods. While this commit is bound to TINKERPOP-1420 it actually also covers TINKERPOP-1283, TINKERPOP-1040 and TINKERPOP-833. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6c72a968 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6c72a968 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6c72a968 Branch: refs/heads/TINKERPOP-1420 Commit: 6c72a9684a8db6b189970d89bca42c7275782019 Parents: e5f2f6d Author: Stephen Mallette <[email protected]> Authored: Thu Oct 27 12:22:49 2016 -0400 Committer: Stephen Mallette <[email protected]> Committed: Thu Oct 27 13:34:33 2016 -0400 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 5 + docs/src/upgrade/release-3.3.x.asciidoc | 15 ++ .../jsr223/AllowColorSandboxExtension.groovy | 36 ---- .../BlockSomeVariablesSandboxExtension.groovy | 42 ----- ...ebindAllVariableTypesSandboxExtension.groovy | 31 ---- .../gremlin/groovy/GroovyEnvironmentSuite.java | 2 - ...mlinGroovyScriptEngineSandboxCustomTest.java | 127 ------------- ...GroovyScriptEngineSandboxedStandardTest.java | 6 +- ...nGroovyScriptEngineTinkerPopSandboxTest.java | 34 ---- .../jsr223/customizer/SandboxExtension.groovy | 180 ------------------- .../customizer/SimpleSandboxExtension.groovy | 1 - .../groovy/engine/ConcurrentBindings.java | 44 ----- .../jsr223/GremlinGroovyScriptEngine.java | 18 -- .../gremlin/groovy/jsr223/ScriptExecutor.java | 60 ------- 14 files changed, 23 insertions(+), 578 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 5c76514..76b3495 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,6 +26,11 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima TinkerPop 3.3.0 (Release Date: NOT OFFICIALLY RELEASED YET) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* Removed previously deprecated `ConcurrentBindings` from `gremlin-groovy`. +* Removed previously deprecated `ScriptExecutor` from `gremlin-groovy`. +* Removed previously deprecated `SandboxExtension` from `gremlin-groovy`. +* Removed previously deprecated `GremlinGroovyScriptEngine` constructor that took `ImportCustomizerProvider` as an argument from `gremlin-groovy`. +* Removed previously deprecated `GremlinGroovyScriptEngine#plugins()` from `gremlin-groovy`. * Moved the source for the "home page" into the repository under `/site` so that it easier to accept contributions. * Replaced term `REST` with `HTTP` to remove any confusion as to the design of the API. * Moved `gremlin-benchmark` under `gremlin-tools` module. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/docs/src/upgrade/release-3.3.x.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc index a026771..045a0cf 100644 --- a/docs/src/upgrade/release-3.3.x.asciidoc +++ b/docs/src/upgrade/release-3.3.x.asciidoc @@ -31,3 +31,18 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.3.3/CHANGELOG.asc Upgrading for Users ~~~~~~~~~~~~~~~~~~~ + +Deprecation Removal +^^^^^^^^^^^^^^^^^^^ + +The following deprecated classes, methods or fields have been removed in this version: + +* `gremlin-groovy` +** `org.apache.tinkerpop.gremlin.groovy.engine.ConcurrentBindings` +** `org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine(ImportCustomizerProvider)` +** `org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine#plugins()` +** `org.apache.tinkerpop.gremlin.groovy.jsr223.ScriptExecutor` +** `org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SandboxExtension` + +Please see the javadoc deprecation notes or upgrade documentation specific to when the deprecation took place to +understand how to resolve this breaking change. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/AllowColorSandboxExtension.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/AllowColorSandboxExtension.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/AllowColorSandboxExtension.groovy deleted file mode 100644 index a00fb26..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/AllowColorSandboxExtension.groovy +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.tinkerpop.gremlin.groovy.jsr223 - -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SandboxExtension -import org.codehaus.groovy.ast.MethodNode - -import java.util.function.BiPredicate - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -class AllowColorSandboxExtension extends SandboxExtension { - AllowColorSandboxExtension() { - def methodWhiteList = ["java\\.awt\\.Color#<init>"] - methodFilter = (BiPredicate<String, MethodNode>) { descriptor, method -> - methodWhiteList.any { descriptor =~ it } - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/BlockSomeVariablesSandboxExtension.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/BlockSomeVariablesSandboxExtension.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/BlockSomeVariablesSandboxExtension.groovy deleted file mode 100644 index e5d9a3b..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/BlockSomeVariablesSandboxExtension.groovy +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.tinkerpop.gremlin.groovy.jsr223 - -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SandboxExtension -import org.apache.tinkerpop.gremlin.structure.Graph -import org.codehaus.groovy.ast.ClassNode -import org.codehaus.groovy.ast.expr.VariableExpression - -import java.util.function.BiPredicate - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -class BlockSomeVariablesSandboxExtension extends SandboxExtension { - BlockSomeVariablesSandboxExtension() { - gIsAlwaysGraphTraversalSource = false - graphIsAlwaysGraphInstance = false - - // variable names must have a length of 3 and they can't be Graph instances - variableFilter = (BiPredicate<VariableExpression, Map<String,ClassNode>>) { v, m -> - def varType = m[v.name].getTypeClass() - v.name.length() > 3 && !Graph.isAssignableFrom(varType) - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/RebindAllVariableTypesSandboxExtension.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/RebindAllVariableTypesSandboxExtension.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/RebindAllVariableTypesSandboxExtension.groovy deleted file mode 100644 index d0d20ba..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/RebindAllVariableTypesSandboxExtension.groovy +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.tinkerpop.gremlin.groovy.jsr223 - -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SandboxExtension - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -class RebindAllVariableTypesSandboxExtension extends SandboxExtension { - RebindAllVariableTypesSandboxExtension() { - gIsAlwaysGraphTraversalSource = false - graphIsAlwaysGraphInstance = false - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java index be89f65..7770283 100644 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java +++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java @@ -24,7 +24,6 @@ import org.apache.tinkerpop.gremlin.GraphManager; import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorOverGraphTest; import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFileSandboxTest; import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineOverGraphTest; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineSandboxCustomTest; import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineSandboxedStandardTest; import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineTinkerPopSandboxTest; import org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslatorTest; @@ -57,7 +56,6 @@ public class GroovyEnvironmentSuite extends AbstractGremlinSuite { private static final Class<?>[] allTests = new Class<?>[]{ CredentialGraphTest.class, GremlinGroovyScriptEngineOverGraphTest.class, - GremlinGroovyScriptEngineSandboxCustomTest.class, GremlinGroovyScriptEngineSandboxedStandardTest.class, GremlinGroovyScriptEngineTinkerPopSandboxTest.class, GremlinGroovyScriptEngineFileSandboxTest.class, http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxCustomTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxCustomTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxCustomTest.java deleted file mode 100644 index f4e35ba..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxCustomTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.tinkerpop.gremlin.groovy.jsr223; - -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SandboxExtension; -import org.codehaus.groovy.control.MultipleCompilationErrorsException; -import org.junit.Test; - -import javax.script.Bindings; - -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class GremlinGroovyScriptEngineSandboxCustomTest extends AbstractGremlinTest { - @Test - public void shouldEvalGVariableAsSomethingOtherThanGraphTraversalSource() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(SandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", 1); - engine.eval("g+1", bindings); - fail("Should have a compile error because 'g' is expected to be GraphTraversalSource"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getCause().getMessage(), containsString("Cannot find matching method")); - } - - final CompilerCustomizerProvider customSandbox = new CompileStaticCustomizerProvider( - RebindAllVariableTypesSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(customSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", 1); - assertEquals(2, engine.eval("g+1", bindings)); - } - } - - @Test - public void shouldEvalGraphVariableAsSomethingOtherThanGraph() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(SandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", 1); - engine.eval("graph+1", bindings); - fail("Should have a compile error because 'graph' is expected to be Graph"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getCause().getMessage(), containsString("Cannot find matching method")); - } - - final CompilerCustomizerProvider customSandbox = new CompileStaticCustomizerProvider( - RebindAllVariableTypesSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(customSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", 1); - assertEquals(2, engine.eval("graph+1", bindings)); - } - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldNotEvalBecauseSandboxIsConfiguredToNotAcceptGraphInstances() throws Exception { - final CompilerCustomizerProvider customSandbox = new CompileStaticCustomizerProvider( - BlockSomeVariablesSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(customSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", graph); - engine.eval("graph.vertices()", bindings); - fail("Should have a compile error because sandbox does not allow Graph"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared.")); - } - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldNotEvalBecauseSandboxIsConfiguredToNotAcceptShortVarNames() throws Exception { - final CompilerCustomizerProvider customSandbox = new CompileStaticCustomizerProvider( - BlockSomeVariablesSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(customSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", 1); - engine.eval("g+1", bindings); - fail("Should have a compile error because sandbox wants names > 3"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getMessage(), containsString("The variable [g] is undeclared.")); - } - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldEvalAsVariableRequirementsAreInRangeOfSandbox() throws Exception { - final CompilerCustomizerProvider customSandbox = new CompileStaticCustomizerProvider( - BlockSomeVariablesSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(customSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", 1); - assertEquals(2, engine.eval("graph+1", bindings)); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java index 53f3814..b9fd1be 100644 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java +++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java @@ -22,7 +22,7 @@ import org.apache.tinkerpop.gremlin.AbstractGremlinTest; import org.apache.tinkerpop.gremlin.LoadGraphWith; import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SandboxExtension; +import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension; import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TypeCheckedCustomizerProvider; import org.codehaus.groovy.control.MultipleCompilationErrorsException; import org.junit.Test; @@ -46,8 +46,8 @@ public class GremlinGroovyScriptEngineSandboxedStandardTest extends AbstractGrem @Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ - {TypeCheckedCustomizerProvider.class.getSimpleName(), new TypeCheckedCustomizerProvider(), new TypeCheckedCustomizerProvider(SandboxExtension.class.getName())}, - {CompileStaticCustomizerProvider.class.getSimpleName(), new CompileStaticCustomizerProvider(), new CompileStaticCustomizerProvider(SandboxExtension.class.getName())}}); + {TypeCheckedCustomizerProvider.class.getSimpleName(), new TypeCheckedCustomizerProvider(), new TypeCheckedCustomizerProvider(SimpleSandboxExtension.class.getName())}, + {CompileStaticCustomizerProvider.class.getSimpleName(), new CompileStaticCustomizerProvider(), new CompileStaticCustomizerProvider(SimpleSandboxExtension.class.getName())}}); } @Parameterized.Parameter(value = 0) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java index ae90b78..5adca8c 100644 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java +++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java @@ -61,38 +61,4 @@ public class GremlinGroovyScriptEngineTinkerPopSandboxTest extends AbstractGreml assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(marko).out(\"created\").count().next()", bindings)); } } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldNotEvalColorWhenCallingMethods() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(AllowColorSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - assertEquals(new java.awt.Color(255,255,255), engine.eval("new java.awt.Color(255,255,255)")); - } - - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - engine.eval("new java.awt.Color(255,255,255).getRed()"); - fail("Type checking should have forced an error as 'getRed()' is not authorized - just Color construction"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getMessage(), containsString("Not authorized to call this method")); - } - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldNotEvalColorWhenCallingProperties() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(AllowColorSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - assertEquals(new java.awt.Color(255,255,255), engine.eval("new java.awt.Color(255,255,255)")); - } - - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - engine.eval("new java.awt.Color(255,255,255).red"); - fail("Type checking should have forced an error as 'red' is not authorized - just Color construction"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getMessage(), containsString("Not authorized to call this method")); - } - } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SandboxExtension.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SandboxExtension.groovy deleted file mode 100644 index 80350fd..0000000 --- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SandboxExtension.groovy +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.tinkerpop.gremlin.groovy.jsr223.customizer - -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource -import org.apache.tinkerpop.gremlin.structure.Graph -import org.codehaus.groovy.ast.ClassCodeVisitorSupport -import org.codehaus.groovy.ast.ClassHelper -import org.codehaus.groovy.ast.ClassNode -import org.codehaus.groovy.ast.MethodNode -import org.codehaus.groovy.ast.Parameter -import org.codehaus.groovy.ast.expr.PropertyExpression -import org.codehaus.groovy.ast.expr.VariableExpression -import org.codehaus.groovy.control.SourceUnit -import org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys -import org.codehaus.groovy.transform.stc.ExtensionMethodNode -import org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport -import org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport - -import java.util.function.BiPredicate - -/** - * A sandbox for the {@link GremlinGroovyScriptEngine} that provides base functionality for securing evaluated scripts. - * By default, this implementation ensures that the variable "graph" is always a {@link Graph} instance and the - * variable "g" is always a {@link GraphTraversalSource}. - * <p/> - * Users should extend this class to modify features as it has some helper methods to make developing a - * sandbox extension a bit easier than starting from a base groovy type checking extension. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.1.1-incubating, replaced by {@link AbstractSandboxExtension} - * @see <a href="https://issues.apache.org/jira/browse/TINKERPOP-891">TINKERPOP-891</a> - */ -@Deprecated -class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDSL { - - /** - * When assigned to the {@code #variableFilter} all variables are allowed. - */ - public static final BiPredicate<VariableExpression, Map<String,ClassNode>> VARIABLES_ALLOW_ALL = { var, types -> true } - - /** - * When assigned to the {@code methodFilter} all methods are allowed. - */ - public static final BiPredicate<String, MethodNode> METHODS_ALLOW_ALL = { exp, method -> true } - - /** - * Forces any variable named "graph" to be of type {@link Graph}. - */ - protected boolean graphIsAlwaysGraphInstance = true - - /** - * Forces any variable named "g" to be of type {@link GraphTraversalSource}. - */ - protected boolean gIsAlwaysGraphTraversalSource = true - - protected BiPredicate<VariableExpression, Map<String,ClassNode>> variableFilter = VARIABLES_ALLOW_ALL - protected BiPredicate<String, MethodNode> methodFilter = METHODS_ALLOW_ALL - - @Override - Object run() { - unresolvedVariable { var -> - if (var.name == "graph" && graphIsAlwaysGraphInstance) { - storeType(var, classNodeFor(Graph)) - handled = true - return - } - - if (var.name == "g" && gIsAlwaysGraphTraversalSource) { - storeType(var, classNodeFor(GraphTraversalSource)) - handled = true - return - } - - final Map<String,ClassNode> varTypes = (Map<String,ClassNode>) GremlinGroovyScriptEngine.COMPILE_OPTIONS.get() - .get(GremlinGroovyScriptEngine.COMPILE_OPTIONS_VAR_TYPES) - - // use the types of the bound variables. filter as necessary and provide special treatment for - // "g" and "graph" as they are potentially handled above already and don't need to be bound - // implicitly by the binding variables - if (varTypes.containsKey(var.name) && variableFilter.test(var, varTypes)) { - if (!(var.name in ["graph", "g"]) || (var.name == "graph" && !graphIsAlwaysGraphInstance - || var.name == "g" && !gIsAlwaysGraphTraversalSource)) { - storeType(var, varTypes.get(var.name)) - handled = true - return - } - } - } - - onMethodSelection { expr, MethodNode methodNode -> - def descriptor = toMethodDescriptor(methodNode) - if (!methodFilter.test(descriptor,methodNode)) - addStaticTypeError("Not authorized to call this method: $descriptor", expr) - } - - // handles calls to properties - afterVisitMethod { methodNode -> - def visitor = new PropertyExpressionEvaluator(context.source) - visitor.visitMethod(methodNode) - } - } - - /** - * Helper method for those extending the sandbox and useful in turning methods into regex matchable strings. - */ - static String toMethodDescriptor(final MethodNode node) { - if (node instanceof ExtensionMethodNode) - return toMethodDescriptor(node.extensionMethodNode) - - def sb = new StringBuilder() - sb.append(node.declaringClass.toString(false)) - sb.append("#") - sb.append(node.name) - sb.append('(') - sb.append(node.parameters.collect { Parameter it -> - prettyPrint(it.originType) - }.join(',')) - sb.append(')') - sb - } - - /** - * Helper method for those extending the sandbox. - */ - static String prettyPrint(final ClassNode node) { - node.isArray() ? "${prettyPrint(node.componentType)}[]" : node.toString(false) - } - - /** - * Evaluates methods selected by groovy property magic (i.e. {@code Person.name} -> {@code Person.getName()}) - */ - class PropertyExpressionEvaluator extends ClassCodeVisitorSupport { - private final SourceUnit unit - private final List<String> whiteList - - public PropertyExpressionEvaluator(final SourceUnit unit) { - this.unit = unit - this.whiteList = whiteList - } - - @Override - protected SourceUnit getSourceUnit() { - unit - } - - @Override - void visitPropertyExpression(final PropertyExpression expression) { - super.visitPropertyExpression(expression) - - ClassNode owner = expression.objectExpression.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER) - if (owner) { - if (expression.spreadSafe && StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(owner, classNodeFor(Collection))) - owner = typeCheckingVisitor.inferComponentType(owner, ClassHelper.int_TYPE) - - def descriptor = "${prettyPrint(owner)}#${expression.propertyAsString}" - if (!methodFilter.test(descriptor, expression)) - addStaticTypeError("Not authorized to call this method: $descriptor", expression) - } - } - } - -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SimpleSandboxExtension.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SimpleSandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SimpleSandboxExtension.groovy index e6a8046..72ee7e8 100644 --- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SimpleSandboxExtension.groovy +++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/SimpleSandboxExtension.groovy @@ -49,5 +49,4 @@ class SimpleSandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeChec } } } - } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java deleted file mode 100644 index fe68773..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.tinkerpop.gremlin.groovy.engine; - -import javax.script.SimpleBindings; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * A {@code Bindings} that can be accessed concurrently by multiple threads. It is needed in cases where "global" - * bindings are required for the {@code ScriptEngine}. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.2, replaced by {@link org.apache.tinkerpop.gremlin.jsr223.ConcurrentBindings}. - */ -@Deprecated -public class ConcurrentBindings extends SimpleBindings { - - public ConcurrentBindings() { - super(new ConcurrentHashMap<>()); - } - - public ConcurrentBindings(final Map<String, Object> m) { - // initialize the bindings first with a ConcurrentHashMap and then copy in the bindings - this(); - this.putAll(m); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java index 3ce400e..20e6a2d 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java @@ -187,14 +187,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl this((CompilerCustomizerProvider) new DefaultImportCustomizerProvider()); } - /** - * @deprecated As of release 3.0.1, replaced by {@link #GremlinGroovyScriptEngine(CompilerCustomizerProvider...)} - */ - @Deprecated - public GremlinGroovyScriptEngine(final ImportCustomizerProvider importCustomizerProvider) { - this((CompilerCustomizerProvider) importCustomizerProvider); - } - public GremlinGroovyScriptEngine(final Customizer... customizers) { final List<Customizer> listOfCustomizers = Arrays.asList(customizers); @@ -352,16 +344,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl /** * Get the list of loaded plugins. - * - * @deprecated As of release 3.0.1, replaced by {@link #getPlugins()} - */ - @Deprecated - public Set plugins() { - return loadedPlugins; - } - - /** - * Get the list of loaded plugins. */ public Set getPlugins() { return loadedPlugins; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c72a968/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java deleted file mode 100644 index 8b0b7fd..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.tinkerpop.gremlin.groovy.jsr223; - -import javax.script.Bindings; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; -import java.util.Arrays; -import java.util.List; - -/** - * Executes a Gremlin script from the command line. Takes a path to the Gremlin script file as the first argument. - * Remaining arguments are treated as parameters to the script, where they are batched up into an array and passed - * in as a single parameter to the script named "args". - * - * @author Pavel A. Yaskevich - * @author Marko A. Rodriguez (http://markorodriguez.com) - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.1, replaced by direct execution via gremlin.sh - */ -@Deprecated -public class ScriptExecutor { - public static void main(final String[] arguments) throws IOException { - if (arguments.length == 0) { - System.out.println("Usage: <path_to_gremlin_script> <argument1> <argument2> ..."); - } else { - evaluate(new FileReader(arguments[0]), Arrays.asList(arguments).subList(1, arguments.length)); - } - } - - protected static void evaluate(final Reader reader, final List<String> arguments) { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(); - - final Bindings bindings = engine.createBindings(); - bindings.put("args", arguments.toArray()); - - try { - engine.eval(reader, bindings); - } catch (Exception e) { - System.err.println(e.getMessage()); - } - } -}
