You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/07/15 23:21:09 UTC
[01/46] incubator-tinkerpop git commit: Refactoring
GremlinGroovyScriptEngine constructor.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 2c480424e -> 97a67ed59
Refactoring GremlinGroovyScriptEngine constructor.
Allows multiple CompilationCustomizerProviders to be supplied.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/fc825931
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/fc825931
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/fc825931
Branch: refs/heads/master
Commit: fc82593105e97ba97c6f6410ba0347a4fddc9cac
Parents: 6ea202c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 10:31:16 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 10:31:16 2015 -0400
----------------------------------------------------------------------
.../GremlinGroovyScriptEngineOverGraphTest.java | 2 +-
.../groovy/NoImportCustomizerProvider.java | 7 +-
.../jsr223/GremlinGroovyScriptEngine.java | 30 ++++---
.../VariableIdentificationCustomizer.java | 91 ++++++++++++++++++++
.../jsr223/GremlinGroovyScriptEngineTest.java | 14 +--
.../structure/io/script/ScriptRecordReader.java | 2 +-
.../structure/io/script/ScriptRecordWriter.java | 2 +-
7 files changed, 126 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fc825931/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
index 7eb892b..babcf1b 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
@@ -70,7 +70,7 @@ public class GremlinGroovyScriptEngineOverGraphTest extends AbstractGremlinTest
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldLoadImports() throws Exception {
- final ScriptEngine engineNoImports = new GremlinGroovyScriptEngine(new NoImportCustomizerProvider());
+ final ScriptEngine engineNoImports = new GremlinGroovyScriptEngine(NoImportCustomizerProvider.INSTANCE);
try {
engineNoImports.eval("Vertex.class.getName()");
fail("Should have thrown an exception because no imports were supplied");
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fc825931/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java
index 91816b8..343c8a6 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java
@@ -29,7 +29,12 @@ import java.util.Set;
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class NoImportCustomizerProvider implements ImportCustomizerProvider {
+public final class NoImportCustomizerProvider implements ImportCustomizerProvider {
+
+ public static final NoImportCustomizerProvider INSTANCE = new NoImportCustomizerProvider();
+
+ private NoImportCustomizerProvider() {}
+
@Override
public CompilationCustomizer getCompilationCustomizer() {
return new ImportCustomizer();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fc825931/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 be9e436..f86498e 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
@@ -19,9 +19,11 @@
package org.apache.tinkerpop.gremlin.groovy.jsr223;
import groovy.transform.ThreadInterrupt;
+import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.EmptyImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.ImportCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader;
import org.apache.tinkerpop.gremlin.groovy.plugin.Artifact;
@@ -62,6 +64,7 @@ import java.io.Writer;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -138,21 +141,26 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
this(new DefaultImportCustomizerProvider());
}
- public GremlinGroovyScriptEngine(final ImportCustomizerProvider importCustomizerProvider) {
- this(importCustomizerProvider, null);
+ public GremlinGroovyScriptEngine(final CompilerCustomizerProvider... compilerCustomizerProviders) {
+ this(DEFAULT_SCRIPT_EVALUATION_TIMEOUT, compilerCustomizerProviders);
}
- public GremlinGroovyScriptEngine(final ImportCustomizerProvider importCustomizerProvider,
- final SecurityCustomizerProvider securityCustomizerProvider) {
- this(importCustomizerProvider, securityCustomizerProvider, DEFAULT_SCRIPT_EVALUATION_TIMEOUT);
- }
+ public GremlinGroovyScriptEngine(final long scriptEvaluationTimeout,
+ final CompilerCustomizerProvider... compilerCustomizerProviders) {
+ final List<CompilerCustomizerProvider> providers = Arrays.asList(compilerCustomizerProviders);
- public GremlinGroovyScriptEngine(final ImportCustomizerProvider importCustomizerProvider,
- final SecurityCustomizerProvider securityCustomizerProvider,
- final long scriptEvaluationTimeout) {
GremlinLoader.load();
- this.importCustomizerProvider = importCustomizerProvider;
- this.securityProvider = Optional.ofNullable(securityCustomizerProvider);
+
+ this.importCustomizerProvider = providers.stream()
+ .filter(p -> p instanceof ImportCustomizerProvider)
+ .map(p -> (ImportCustomizerProvider) p)
+ .findFirst().orElse(NoImportCustomizerProvider.INSTANCE);
+
+ this.securityProvider = providers.stream()
+ .filter(p -> p instanceof SecurityCustomizerProvider)
+ .map(p -> (SecurityCustomizerProvider) p)
+ .findFirst();
+
this.scriptEvaluationTimeout = scriptEvaluationTimeout;
createClassLoader();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fc825931/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/VariableIdentificationCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/VariableIdentificationCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/VariableIdentificationCustomizer.java
new file mode 100644
index 0000000..4606bde
--- /dev/null
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/VariableIdentificationCustomizer.java
@@ -0,0 +1,91 @@
+/*
+ * 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.codehaus.groovy.ast.ClassCodeVisitorSupport;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.expr.VariableExpression;
+import org.codehaus.groovy.classgen.GeneratorContext;
+import org.codehaus.groovy.control.CompilationFailedException;
+import org.codehaus.groovy.control.CompilePhase;
+import org.codehaus.groovy.control.SourceUnit;
+import org.codehaus.groovy.control.customizers.CompilationCustomizer;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class VariableIdentificationCustomizer extends CompilationCustomizer {
+
+ private static final ThreadLocal<Set<String>> variables = new ThreadLocal<Set<String>>() {
+ @Override
+ protected Set<String> initialValue() {
+ return new TreeSet<>();
+ }
+ };
+
+ private static final List<String> variablesToIgnore = new ArrayList<>(Arrays.asList("this", "args", "context", "super"));
+
+ public VariableIdentificationCustomizer() {
+ super(CompilePhase.CLASS_GENERATION);
+ }
+
+ public Set<String> getVariables() {
+ return variables.get();
+ }
+
+ public void clearVariables() {
+ variables.get().clear();
+ }
+
+ @Override
+ public void call(final SourceUnit sourceUnit, final GeneratorContext generatorContext,
+ final ClassNode classNode) throws CompilationFailedException {
+ classNode.visitContents(new Visitor(sourceUnit));
+ }
+
+ class Visitor extends ClassCodeVisitorSupport {
+
+ private SourceUnit sourceUnit;
+
+ public Visitor(final SourceUnit sourceUnit) {
+ this.sourceUnit = sourceUnit;
+ }
+
+ @Override
+ public void visitVariableExpression(final VariableExpression expression) {
+ if (!variablesToIgnore.contains(expression.getName())
+ && expression.getAccessedVariable().isDynamicTyped()) {
+ variables.get().add(expression.getName());
+ }
+
+ super.visitVariableExpression(expression);
+ }
+
+ @Override
+ protected SourceUnit getSourceUnit() {
+ return sourceUnit;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fc825931/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index c88a2ec..d60154d 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -87,7 +87,7 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldLoadImportsViaDependencyManagerInterface() throws Exception {
- final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new NoImportCustomizerProvider());
+ final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(NoImportCustomizerProvider.INSTANCE);
try {
engine.eval("Vertex.class.getName()");
fail("Should have thrown an exception because no imports were supplied");
@@ -101,7 +101,7 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldLoadImportsViaDependencyManagerInterfaceAdditively() throws Exception {
- final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new NoImportCustomizerProvider());
+ final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(NoImportCustomizerProvider.INSTANCE);
try {
engine.eval("Vertex.class.getName()");
fail("Should have thrown an exception because no imports were supplied");
@@ -133,7 +133,7 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldLoadImportsViaDependencyManagerFromDependencyGatheredByUse() throws Exception {
- final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new NoImportCustomizerProvider());
+ final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(NoImportCustomizerProvider.INSTANCE);
try {
engine.eval("org.apache.commons.math3.util.FastMath.abs(-1235)");
fail("Should have thrown an exception because no imports were supplied");
@@ -148,7 +148,7 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldAllowsUseToBeExecutedAfterImport() throws Exception {
- final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new NoImportCustomizerProvider());
+ final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(NoImportCustomizerProvider.INSTANCE);
try {
engine.eval("org.apache.commons.math3.util.FastMath.abs(-1235)");
fail("Should have thrown an exception because no imports were supplied");
@@ -310,7 +310,7 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldTimeoutScriptOnTimedWhile() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, 3000);
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(3000, new DefaultImportCustomizerProvider());
try {
engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
fail("This should have timed out");
@@ -321,7 +321,7 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeout() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, 3000);
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(3000, new DefaultImportCustomizerProvider());
Thread.sleep(4000);
try {
engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
@@ -336,7 +336,7 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldNotTimeoutStandaloneFunction() throws Exception {
// use a super fast timeout which should not prevent the call of a cached function
- final ScriptEngine engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, 1);
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(1, new DefaultImportCustomizerProvider());
engine.eval("def addItUp(x,y) { x + y }");
assertEquals(3, engine.eval("addItUp(1,2)"));
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fc825931/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
index 191c249..aec6aff 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
@@ -64,7 +64,7 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
public void initialize(final InputSplit genericSplit, final TaskAttemptContext context) throws IOException {
this.lineRecordReader.initialize(genericSplit, context);
final Configuration configuration = context.getConfiguration();
- this.engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, Integer.MAX_VALUE);
+ this.engine = new GremlinGroovyScriptEngine(Integer.MAX_VALUE, new DefaultImportCustomizerProvider());
//this.engine = ScriptEngineCache.get(configuration.get(SCRIPT_ENGINE, ScriptEngineCache.DEFAULT_SCRIPT_ENGINE));
final FileSystem fs = FileSystem.get(configuration);
try {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fc825931/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java
index e0a9ece..b9bd068 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java
@@ -61,7 +61,7 @@ public final class ScriptRecordWriter extends RecordWriter<NullWritable, VertexW
public ScriptRecordWriter(final DataOutputStream out, final TaskAttemptContext context) throws IOException {
this.out = out;
final Configuration configuration = context.getConfiguration();
- this.engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, Integer.MAX_VALUE);
+ this.engine = new GremlinGroovyScriptEngine(Integer.MAX_VALUE, new DefaultImportCustomizerProvider());
//this.engine = ScriptEngineCache.get(configuration.get(SCRIPT_ENGINE, ScriptEngineCache.DEFAULT_SCRIPT_ENGINE));
final FileSystem fs = FileSystem.get(configuration);
try {
[44/46] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/tp30-582' into tp30
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/tp30-582' into tp30
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/cacba0d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/cacba0d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/cacba0d7
Branch: refs/heads/master
Commit: cacba0d78a8e969598e558bd110215210b849986
Parents: 99e89be 12eb58b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 16:46:39 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 16:46:39 2015 -0400
----------------------------------------------------------------------
.../jsr223/AllowColorSandboxExtension.groovy | 35 ++++
.../BlockSomeVariablesSandboxExtension.groovy | 41 +++++
...ebindAllVariableTypesSandboxExtension.groovy | 29 +++
.../gremlin/groovy/GroovyEnvironmentSuite.java | 11 +-
.../GremlinGroovyScriptEngineOverGraphTest.java | 9 +-
...mlinGroovyScriptEngineSandboxCustomTest.java | 126 +++++++++++++
...GroovyScriptEngineSandboxedStandardTest.java | 131 ++++++++++++++
...nGroovyScriptEngineTinkerPopSandboxTest.java | 98 +++++++++++
gremlin-groovy/pom.xml | 11 --
.../groovy/jsr223/SandboxExtension.groovy | 176 +++++++++++++++++++
.../jsr223/TinkerPopSandboxExtension.groovy | 47 +++++
.../AbstractImportCustomizerProvider.java | 2 +-
.../groovy/CompileStaticCustomizerProvider.java | 60 +++++++
.../groovy/CompilerCustomizerProvider.java | 10 +-
.../groovy/EmptyImportCustomizerProvider.java | 5 +-
.../groovy/NoImportCustomizerProvider.java | 9 +-
.../groovy/SecurityCustomizerProvider.java | 66 -------
.../ThreadInterruptCustomizerProvider.java | 35 ++++
.../TimedInterruptCustomizerProvider.java | 61 +++++++
.../groovy/TypeCheckedCustomizerProvider.java | 64 +++++++
.../gremlin/groovy/engine/ScriptEngines.java | 50 ++++--
.../groovy/jsr223/DependencyManager.java | 10 +-
.../jsr223/GremlinGroovyScriptEngine.java | 122 ++++++-------
.../jsr223/ManagedConcurrentValueMap.java | 7 +-
.../VariableIdentificationCustomizer.java | 91 ++++++++++
.../groovy/engine/GremlinExecutorTest.java | 74 ++++----
...mlinGroovyScriptEngineCompileStaticTest.java | 99 +++++++++++
.../jsr223/GremlinGroovyScriptEngineTest.java | 132 +-------------
...inGroovyScriptEngineThreadInterruptTest.java | 78 ++++++++
...linGroovyScriptEngineTimedInterruptTest.java | 94 ++++++++++
...remlinGroovyScriptEngineTypeCheckedTest.java | 100 +++++++++++
.../groovy/jsr223/PrecompiledExtensions.java | 58 ++++++
.../structure/io/script/ScriptRecordReader.java | 2 +-
.../structure/io/script/ScriptRecordWriter.java | 2 +-
34 files changed, 1587 insertions(+), 358 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cacba0d7/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
----------------------------------------------------------------------
[20/46] incubator-tinkerpop git commit: Add a SandboxExtension.
Posted by sp...@apache.org.
Add a SandboxExtension.
Provide a way to use the ASTTransformer to validate incoming variables and types.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/c47426dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/c47426dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/c47426dd
Branch: refs/heads/master
Commit: c47426dd7c9c18b8aed2d2565cf046ad47ea9a43
Parents: 6252cfa
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 9 15:18:13 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 9 15:18:13 2015 -0400
----------------------------------------------------------------------
.../GremlinGroovyScriptEngineOverGraphTest.java | 143 ++++++++++++++++++-
.../groovy/jsr223/SandboxExtension.groovy | 66 +++++++++
.../jsr223/GremlinGroovyScriptEngine.java | 28 ++++
3 files changed, 236 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c47426dd/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
index babcf1b..c72bfd5 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
@@ -23,12 +23,15 @@ import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.groovy.CompileStaticCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.TypeCheckedCustomizerProvider;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.config.YamlConfiguration;
+import org.codehaus.groovy.control.MultipleCompilationErrorsException;
import org.junit.Assert;
import org.junit.Test;
@@ -43,10 +46,12 @@ import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
+import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -145,7 +150,7 @@ public class GremlinGroovyScriptEngineOverGraphTest extends AbstractGremlinTest
public void shouldClearBindingsBetweenEvals() throws Exception {
final ScriptEngine engine = new GremlinGroovyScriptEngine();
engine.put("g", g);
- Assert.assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()"));
+ assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()"));
final Bindings bindings = engine.createBindings();
bindings.put("g", g);
@@ -234,6 +239,142 @@ public class GremlinGroovyScriptEngineOverGraphTest extends AbstractGremlinTest
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldEvalGraphTraversalSourceWithTypeChecked() throws Exception {
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+
+ final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings);
+ fail("Type checking should have forced an error as 'g' is not defined");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
+ }
+
+ final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider(
+ SandboxExtension.class.getName());
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+ assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
+ }
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldEvalGraphWithTypeChecked() throws Exception {
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+
+ final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ fail("Type checking should have forced an error as 'graph' is not defined");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
+ }
+
+ final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider(
+ SandboxExtension.class.getName());
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldEvalGraphTraversalSourceWithCompileStatic() throws Exception {
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+
+ final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings);
+ fail("Type checking should have forced an error as 'g' is not defined");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
+ }
+
+ final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
+ SandboxExtension.class.getName());
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+ assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
+ }
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldEvalGraphWithCompileStatic() throws Exception {
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+
+ final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ fail("Type checking should have forced an error as 'graph' is not defined");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
+ }
+
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ bindings.put("x", convertToVertexId("marko"));
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
+ fail("Type checking should have forced an error as 'graph' is not defined");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
+ }
+
+ final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
+ SandboxExtension.class.getName());
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ bindings.put("x", convertToVertexId("marko"));
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
+ }
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldEvalGlobalClosuresEvenAfterEvictionOfClass() throws ScriptException {
final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c47426dd/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
new file mode 100644
index 0000000..4888f8c
--- /dev/null
+++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
@@ -0,0 +1,66 @@
+/*
+ * 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.process.traversal.dsl.graph.GraphTraversalSource
+import org.apache.tinkerpop.gremlin.structure.Graph
+import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.expr.VariableExpression
+import org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport
+
+import java.util.function.BiPredicate
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDSL {
+
+ protected boolean graphIsAlwaysGraphInstance = true
+ protected boolean gIsAlwaysGraphTraversalSource = true
+ protected BiPredicate<VariableExpression, Map<String,ClassNode>> filter = USE_ALL
+
+ public static final BiPredicate<VariableExpression, Map<String,ClassNode>> USE_ALL = { var, types -> true }
+
+ @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)
+ if (varTypes.containsKey(var.name) && filter.test(var, varTypes)
+ || (var.name == "graph" && !graphIsAlwaysGraphInstance
+ || var.name == "g" && !gIsAlwaysGraphTraversalSource)) {
+ storeType(var, varTypes.get(var.name))
+ handled = true
+ return
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c47426dd/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 9042e6d..09af47f 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
@@ -37,6 +37,8 @@ import groovy.lang.MissingMethodException;
import groovy.lang.MissingPropertyException;
import groovy.lang.Script;
import groovy.lang.Tuple;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.jsr223.GroovyCompiledScript;
@@ -81,6 +83,7 @@ import java.util.stream.Collectors;
*/
public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements DependencyManager, AutoCloseable {
+ public static final String COMPILE_OPTIONS_VAR_TYPES = "sandbox.bindings";
public static final String KEY_REFERENCE_TYPE = "#jsr223.groovy.engine.keep.globals";
public static final String REFERENCE_TYPE_PHANTOM = "phantom";
public static final String REFERENCE_TYPE_WEAK = "weak";
@@ -96,6 +99,13 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
}
};
+ public static final ThreadLocal<Map<String, Object>> COMPILE_OPTIONS = new ThreadLocal<Map<String, Object>>(){
+ @Override
+ protected Map<String, Object> initialValue() {
+ return new HashMap<>();
+ }
+ };
+
/**
* Script to generated Class map.
*/
@@ -287,6 +297,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
} catch (ClassCastException cce) { /*ignore.*/ }
try {
+ registerBindingTypes(context);
final Class clazz = getScriptClass(script);
if (null == clazz) throw new ScriptException("Script class is null");
return eval(clazz, context);
@@ -447,6 +458,23 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
}
}
+ private void registerBindingTypes(final ScriptContext context) {
+ final Map<String,ClassNode> variableTypes = new HashMap<>();
+ clearVarTypes();
+ context.getBindings(ScriptContext.ENGINE_SCOPE).forEach((k, v) -> {
+ final Class clazz = v.getClass();
+ variableTypes.put(k, ClassHelper.make(clazz));
+ });
+
+ COMPILE_OPTIONS.get().put(COMPILE_OPTIONS_VAR_TYPES, variableTypes);
+ }
+
+ private static void clearVarTypes() {
+ final Map<String,Object> m = COMPILE_OPTIONS.get();
+ if (m.containsKey(COMPILE_OPTIONS_VAR_TYPES))
+ ((Map<String,ClassNode>) m.get(COMPILE_OPTIONS_VAR_TYPES)).clear();
+ }
+
private void ensureSandbox() {
if (securityProvider.isPresent() && !this.registeredSandbox.get()) {
this.securityProvider.get().registerInterceptors();
[03/46] incubator-tinkerpop git commit: Fix compile errors after
merge.
Posted by sp...@apache.org.
Fix compile errors after merge.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/569ef03a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/569ef03a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/569ef03a
Branch: refs/heads/master
Commit: 569ef03a0042342a659d9bac19738e6ed46c04a4
Parents: 0e1c86b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 11:56:30 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 11:56:30 2015 -0400
----------------------------------------------------------------------
.../apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java | 5 ++---
.../gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/569ef03a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
index 5ff4494..3e884ae 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
@@ -345,9 +345,8 @@ public class ScriptEngines implements AutoCloseable {
final long interruptionTimeout = ((Number) config.getOrDefault("interruptionTimeout",
GremlinGroovyScriptEngine.DEFAULT_SCRIPT_EVALUATION_TIMEOUT)).longValue();
- return Optional.of((ScriptEngine) new GremlinGroovyScriptEngine(
- new DefaultImportCustomizerProvider(imports, staticImports), securityCustomizerProvider,
- interruptionTimeout));
+ return Optional.of((ScriptEngine) new GremlinGroovyScriptEngine(interruptionTimeout,
+ new DefaultImportCustomizerProvider(imports, staticImports), securityCustomizerProvider));
} else {
return Optional.ofNullable(SCRIPT_ENGINE_MANAGER.getEngineByName(language));
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/569ef03a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index 2bdbda3..ee6abe9 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -335,7 +335,7 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, 50);
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(50, new DefaultImportCustomizerProvider());
for (int ix = 0; ix < 10; ix++) {
try {
[12/46] incubator-tinkerpop git commit: Minor code cleanup - optimize
imports.
Posted by sp...@apache.org.
Minor code cleanup - optimize imports.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/17ed3cee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/17ed3cee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/17ed3cee
Branch: refs/heads/master
Commit: 17ed3ceec1003f06821d4ebc314c64bea9a516e6
Parents: 2a319f0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 14:45:33 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 14:45:33 2015 -0400
----------------------------------------------------------------------
.../gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/17ed3cee/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 59a0530..9042e6d 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
@@ -18,7 +18,6 @@
*/
package org.apache.tinkerpop.gremlin.groovy.jsr223;
-import groovy.transform.ThreadInterrupt;
import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.EmptyImportCustomizerProvider;
@@ -40,7 +39,6 @@ import groovy.lang.Script;
import groovy.lang.Tuple;
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.CompilerConfiguration;
-import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
import org.codehaus.groovy.jsr223.GroovyCompiledScript;
import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl;
import org.codehaus.groovy.runtime.InvokerHelper;
@@ -322,10 +320,8 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
return new GroovyCompiledScript(this, getScriptClass(scriptSource));
} catch (SyntaxException e) {
throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine());
- } catch (IOException e) {
+ } catch (IOException | CompilationFailedException e) {
throw new ScriptException(e);
- } catch (CompilationFailedException ee) {
- throw new ScriptException(ee);
}
}
@@ -526,7 +522,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
if (c == groovy.lang.Script.class) {
return ctxtLoader;
}
- } catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException ignored) {
}
return groovy.lang.Script.class.getClassLoader();
}
[24/46] incubator-tinkerpop git commit: Add more tests for variable
filtering in GremlinGroovyScriptEngine sandbox.
Posted by sp...@apache.org.
Add more tests for variable filtering in GremlinGroovyScriptEngine sandbox.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/2af2c3dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/2af2c3dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/2af2c3dd
Branch: refs/heads/master
Commit: 2af2c3ddecd188bbf400acf910c2f73fcf21da84
Parents: 6af00c6
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 10 09:23:00 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 10 09:23:12 2015 -0400
----------------------------------------------------------------------
.../BlockSomeVariablesSandboxExtension.groovy | 41 +++++++++++++++++
...mlinGroovyScriptEngineSandboxCustomTest.java | 46 +++++++++++++++++++-
.../groovy/jsr223/SandboxExtension.groovy | 13 +++---
3 files changed, 92 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2af2c3dd/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
new file mode 100644
index 0000000..fcbbc51
--- /dev/null
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/BlockSomeVariablesSandboxExtension.groovy
@@ -0,0 +1,41 @@
+/*
+ * 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.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/incubator-tinkerpop/blob/2af2c3dd/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
index b9f8fcf..648e688 100644
--- 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
@@ -37,7 +37,6 @@ import static org.junit.Assert.fail;
*/
public class GremlinGroovyScriptEngineSandboxCustomTest extends AbstractGremlinTest {
@Test
- @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldEvalGVariableAsSomethingOtherThanGraphTraversalSource() throws Exception {
final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(SandboxExtension.class.getName());
try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) {
@@ -60,7 +59,6 @@ public class GremlinGroovyScriptEngineSandboxCustomTest extends AbstractGremlinT
}
@Test
- @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldEvalGraphVariableAsSomethingOtherThanGraph() throws Exception {
final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(SandboxExtension.class.getName());
try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) {
@@ -81,4 +79,48 @@ public class GremlinGroovyScriptEngineSandboxCustomTest extends AbstractGremlinT
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/incubator-tinkerpop/blob/2af2c3dd/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
index d62ccb3..be0cbca 100644
--- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
+++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
@@ -73,12 +73,13 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
final Map<String,ClassNode> varTypes = (Map<String,ClassNode>) GremlinGroovyScriptEngine.COMPILE_OPTIONS.get()
.get(GremlinGroovyScriptEngine.COMPILE_OPTIONS_VAR_TYPES)
- if (varTypes.containsKey(var.name) && variableFilter.test(var, varTypes)
- || (var.name == "graph" && !graphIsAlwaysGraphInstance
- || var.name == "g" && !gIsAlwaysGraphTraversalSource)) {
- storeType(var, varTypes.get(var.name))
- handled = true
- return
+ 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
+ }
}
}
[34/46] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/tp3-610' into tp30-610
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/tp3-610' into tp30-610
Conflicts:
gremlin-console/pom.xml
gremlin-core/pom.xml
gremlin-driver/pom.xml
gremlin-groovy-test/pom.xml
gremlin-groovy/pom.xml
gremlin-server/pom.xml
gremlin-shaded/pom.xml
gremlin-test/pom.xml
hadoop-gremlin/pom.xml
neo4j-gremlin/pom.xml
pom.xml
tinkergraph-gremlin/pom.xml
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/3c45b7d0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/3c45b7d0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/3c45b7d0
Branch: refs/heads/master
Commit: 3c45b7d05e3a708bc719543d3c80f80e7d7f4c4f
Parents: 3f5405a fa994d3
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Jul 14 08:31:33 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Jul 14 08:31:33 2015 -0400
----------------------------------------------------------------------
.../apache/tinkerpop/gremlin/structure/FeatureSupportTest.java | 6 +++---
.../org/apache/tinkerpop/gremlin/structure/PropertyTest.java | 6 +++---
.../org/apache/tinkerpop/gremlin/structure/VertexTest.java | 6 +++---
3 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
[42/46] incubator-tinkerpop git commit: Provided a way for graphs to
opt out of specific engine executions of a test.
Posted by sp...@apache.org.
Provided a way for graphs to opt out of specific engine executions of a test.
Introduced GraphProvider.Descriptor and and "computers" attribute on the OptOut annotation. Added the appropriate settings for HadoopGraph to only exclude tests based on GiraphGraphComputer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/7f143f05
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/7f143f05
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/7f143f05
Branch: refs/heads/master
Commit: 7f143f055f1b4764487e36f25de4db75133df737
Parents: 4a92027
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 16:23:24 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 16:23:24 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 4 +-
.../tinkerpop/gremlin/structure/Graph.java | 10 +++
.../tinkerpop/gremlin/AbstractGremlinSuite.java | 95 ++++++++++++++------
.../apache/tinkerpop/gremlin/GraphProvider.java | 25 ++++++
.../gremlin/hadoop/structure/HadoopGraph.java | 27 ++++--
.../giraph/HadoopGiraphGraphProvider.java | 2 +
.../spark/HadoopSparkGraphProvider.java | 3 +
.../process/TinkerGraphComputerProvider.java | 2 +
8 files changed, 132 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7f143f05/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 8b607cd..830144e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,8 +25,10 @@ image::http://www.tinkerpop.com/docs/current/images/gremlin-hindu.png[width=225]
TinkerPop 3.0.1 (NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-* Adjust configuration for javadoc generation to eliminate error messages.
+* Adjusted configuration for javadoc generation to eliminate error messages.
* Removed "reserved" graph concept names from tests (e.g. "label", "edge", "value") to support the convention of avoiding these strings for property names.
+* Introduced `GraphProvider.Descriptor` which annotates a `GraphProvider` implementation to describe what `GraphComputer` implementation will be used.
+* Modified `OptOut` to include a `computers` attribute which allows the `Graph` to opt-out of computer-based tests for specific computation engines.
TinkerPop 3.0.0 (Release Date: July 9, 2015)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7f143f05/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index c4a19a7..e950a23 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.engine.ComputerTraversalEngine;
import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEngine;
import org.apache.tinkerpop.gremlin.structure.io.Io;
import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
@@ -1121,6 +1122,15 @@ public interface Graph extends AutoCloseable, Host {
* For parameterized tests specify the name of the test itself without its "square brackets".
*/
public String specific() default "";
+
+ /**
+ * The list of {@link GraphComputer} implementations that a test should opt-out from using (i.e. other
+ * graph computers not in this list will execute the test). This setting should only be included when
+ * the test is one that uses the {@link ComputerTraversalEngine} - it will otherwise be ignored. By
+ * default, an empty array is assigned and it is thus assumed that all computers are excluded when an
+ * {@code OptOut} annotation is used, therefore this value must be overridden to be more specific.
+ */
+ public Class<? extends GraphComputer>[] computers() default { };
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7f143f05/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
index 43c24dd..186d4c8 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
@@ -26,17 +26,17 @@ import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
-import java.lang.annotation.*;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -82,10 +82,15 @@ public abstract class AbstractGremlinSuite extends Suite {
// this class should be annotated with GraphProviderClass. Failure to do so will toss an InitializationError
final Pair<Class<? extends GraphProvider>, Class<? extends Graph>> pair = getGraphProviderClass(klass);
+ // the GraphProvider.Descriptor is only needed right now if the test if for a computer engine - an
+ // exception is thrown if it isn't present.
+ final Optional<GraphProvider.Descriptor> graphProviderDescriptor = getGraphProviderDescriptor(traversalEngineType, pair.getValue0());
+
// validate public acknowledgement of the test suite and filter out tests ignored by the implementation
validateOptInToSuite(pair.getValue1());
validateOptInAndOutAnnotationsOnGraph(pair.getValue1());
- registerOptOuts(pair.getValue1());
+
+ registerOptOuts(pair.getValue1(), graphProviderDescriptor, traversalEngineType);
try {
final GraphProvider graphProvider = pair.getValue0().newInstance();
@@ -96,6 +101,18 @@ public abstract class AbstractGremlinSuite extends Suite {
}
}
+ private Optional<GraphProvider.Descriptor> getGraphProviderDescriptor(final TraversalEngine.Type traversalEngineType,
+ final Class<? extends GraphProvider> klass) throws InitializationError {
+ final GraphProvider.Descriptor descriptorAnnotation = klass.getAnnotation(GraphProvider.Descriptor.class);
+ if (traversalEngineType == TraversalEngine.Type.COMPUTER) {
+ // can't be null if this is graph computer business
+ if (null == descriptorAnnotation)
+ throw new InitializationError(String.format("For 'computer' tests, '%s' must have a GraphProvider.Descriptor annotation", klass.getName()));
+ }
+
+ return Optional.ofNullable(descriptorAnnotation);
+ }
+
private void validateOptInToSuite(final Class<? extends Graph> klass) throws InitializationError {
final Graph.OptIn[] optIns = klass.getAnnotationsByType(Graph.OptIn.class);
if (!Arrays.stream(optIns).anyMatch(optIn -> optIn.value().equals(this.getClass().getCanonicalName())))
@@ -105,8 +122,10 @@ public abstract class AbstractGremlinSuite extends Suite {
throw new InitializationError(String.format("The %s will not run for this Graph until it is publicly acknowledged with the @OptIn annotation on the Graph instance itself", this.getClass().getSimpleName()));
}
- private void registerOptOuts(final Class<? extends Graph> klass) throws InitializationError {
- final Graph.OptOut[] optOuts = klass.getAnnotationsByType(Graph.OptOut.class);
+ private void registerOptOuts(final Class<? extends Graph> graphClass,
+ final Optional<GraphProvider.Descriptor> graphProviderDescriptor,
+ final TraversalEngine.Type traversalEngineType) throws InitializationError {
+ final Graph.OptOut[] optOuts = graphClass.getAnnotationsByType(Graph.OptOut.class);
if (optOuts != null && optOuts.length > 0) {
// validate annotation - test class and reason must be set
@@ -114,7 +133,7 @@ public abstract class AbstractGremlinSuite extends Suite {
throw new InitializationError("Check @IgnoreTest annotations - all must have a 'test' and 'reason' set");
try {
- filter(new OptOutTestFilter(optOuts));
+ filter(new OptOutTestFilter(optOuts, graphProviderDescriptor, traversalEngineType));
} catch (NoTestsRemainException ex) {
throw new InitializationError(ex);
}
@@ -144,7 +163,7 @@ public abstract class AbstractGremlinSuite extends Suite {
* Filter a list of test classes through the GREMLIN_TESTS environment variable list.
*/
private static Class<?>[] filterSpecifiedTests(final Class<?>[] allTests) {
- if (null == allTests) return allTests;
+ if (null == allTests) return null;
Class<?>[] filteredTests;
final String override = System.getenv().getOrDefault("GREMLIN_TESTS", "");
@@ -226,36 +245,31 @@ public abstract class AbstractGremlinSuite extends Suite {
*/
private final List<Graph.OptOut> entireTestCaseToIgnore;
- public OptOutTestFilter(final Graph.OptOut[] optOuts) {
+ private final Optional<GraphProvider.Descriptor> graphProviderDescriptor;
+ private final TraversalEngine.Type traversalEngineType;
+
+ public OptOutTestFilter(final Graph.OptOut[] optOuts,
+ final Optional<GraphProvider.Descriptor> graphProviderDescriptor,
+ final TraversalEngine.Type traversalEngineType) {
+ this.graphProviderDescriptor = graphProviderDescriptor;
+ this.traversalEngineType = traversalEngineType;
+
// split the tests to filter into two groups - true represents those that should ignore a whole
- final Map<Boolean, List<Graph.OptOut>> split = Arrays.stream(optOuts).collect(
- Collectors.groupingBy(optOut -> optOut.method().equals("*")));
+ final Map<Boolean, List<Graph.OptOut>> split = Arrays.stream(optOuts)
+ .filter(this::checkGraphProviderDescriptorForComputer)
+ .collect(Collectors.groupingBy(optOut -> optOut.method().equals("*")));
final List<Graph.OptOut> optOutsOfIndividualTests = split.getOrDefault(Boolean.FALSE, Collections.emptyList());
individualSpecificTestsToIgnore = optOutsOfIndividualTests.stream()
.filter(ignoreTest -> !ignoreTest.method().equals("*"))
- .filter(ignoreTest -> {
- try {
- final Class testClass = Class.forName(ignoreTest.test());
- return !Modifier.isAbstract(testClass.getModifiers());
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- })
+ .filter(allowAbstractMethod(false))
.<Pair>map(ignoreTest -> Pair.with(ignoreTest.test(), ignoreTest.specific().isEmpty() ? ignoreTest.method() : String.format("%s[%s]", ignoreTest.method(), ignoreTest.specific())))
.<Description>map(p -> Description.createTestDescription(p.getValue0().toString(), p.getValue1().toString()))
.collect(Collectors.toList());
testGroupToIgnore = optOutsOfIndividualTests.stream()
.filter(ignoreTest -> !ignoreTest.method().equals("*"))
- .filter(ignoreTest -> {
- try {
- final Class testClass = Class.forName(ignoreTest.test());
- return Modifier.isAbstract(testClass.getModifiers());
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- })
+ .filter(allowAbstractMethod(true))
.<Pair>map(ignoreTest -> Pair.with(ignoreTest.test(), ignoreTest.specific().isEmpty() ? ignoreTest.method() : String.format("%s[%s]", ignoreTest.method(), ignoreTest.specific())))
.<Description>map(p -> Description.createTestDescription(p.getValue0().toString(), p.getValue1().toString()))
.collect(Collectors.toList());
@@ -296,5 +310,34 @@ public abstract class AbstractGremlinSuite extends Suite {
return String.format("Method %s",
String.join(",", individualSpecificTestsToIgnore.stream().map(Description::getDisplayName).collect(Collectors.toList())));
}
+
+ private Predicate<Graph.OptOut> allowAbstractMethod(final boolean allow) {
+ return optOut -> {
+ try {
+ // ignore those methods in process that are defined as abstract methods
+ final Class testClass = Class.forName(optOut.test());
+ if (allow)
+ return Modifier.isAbstract(testClass.getModifiers());
+ else
+ return !Modifier.isAbstract(testClass.getModifiers());
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ };
+ }
+
+ private boolean checkGraphProviderDescriptorForComputer(final Graph.OptOut optOut) {
+ // immediately include the ignore if this is a standard tests suite (i.e. not computer)
+ // or if the OptOut doesn't specify any computers to filter
+ if (traversalEngineType == TraversalEngine.Type.STANDARD
+ || optOut.computers().length == 0) {
+ return true;
+ }
+
+ // can assume that that GraphProvider.Descriptor is not null at this point. a test should
+ // only opt out if it matches the expected computer
+ final boolean x = Stream.of(optOut.computers()).anyMatch(c -> c == graphProviderDescriptor.get().computer());
+ return Stream.of(optOut.computers()).anyMatch(c -> c == graphProviderDescriptor.get().computer());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7f143f05/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
index 7961d36..766e70d 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
@@ -19,7 +19,9 @@
package org.apache.tinkerpop.gremlin;
import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
@@ -39,6 +41,11 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -258,4 +265,22 @@ public interface GraphProvider {
* by the vendor implementations.
*/
public Set<Class> getImplementations();
+
+ /**
+ * An annotation to be applied to a {@code GraphProvider} implementation that provides additional information
+ * about its intentions. The {@code Descriptor} is required by those {@code GraphProvider} implementations
+ * that will be assigned to test suites that use {@link TraversalEngine.Type#COMPUTER}.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(ElementType.TYPE)
+ @Inherited
+ public @interface Descriptor {
+
+ /**
+ * The {@link GraphComputer} implementation that the {@code GraphProvider} will use when it constructs
+ * a {@link Traversal} with {@link #traversal(Graph)} or {@link #traversal(Graph, TraversalStrategy[])}.
+ * This value should be null if a {@link GraphComputer} is not being used.
+ */
+ public Class<? extends GraphComputer> computer();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7f143f05/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java
index 32051ec..ee258d0 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java
@@ -67,15 +67,18 @@ import java.util.stream.Stream;
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest$Traversals",
method = "g_V_matchXa_knows_b__c_knows_bX",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest$Traversals",
method = "g_V_matchXa_created_b__c_created_bX_selectXa_b_cX_byXnameX",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest$Traversals",
method = "g_V_out_asXcX_matchXb_knows_a__c_created_eX_selectXcX",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest$Traversals",
method = "g_V_matchXa_hasXname_GarciaX__a_0writtenBy_b__a_0sungBy_bX",
@@ -83,15 +86,18 @@ import java.util.stream.Stream;
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyMatchTest$Traversals",
method = "g_V_matchXa_knows_b__c_knows_bX",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyMatchTest$Traversals",
method = "g_V_matchXa_created_b__c_created_bX_selectXa_b_cX_byXnameX",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyMatchTest$Traversals",
method = "g_V_out_asXcX_matchXb_knows_a__c_created_eX_selectXcX",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyMatchTest$Traversals",
method = "g_V_matchXa_0sungBy_b__a_0sungBy_c__b_writtenBy_d__c_writtenBy_e__d_hasXname_George_HarisonX__e_hasXname_Bob_MarleyXX",
@@ -127,15 +133,18 @@ import java.util.stream.Stream;
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.computer.GraphComputerTest",
method = "shouldNotAllowNullMemoryKeys",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.computer.GraphComputerTest",
method = "shouldNotAllowSettingUndeclaredMemoryKeys",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.computer.GraphComputerTest",
method = "shouldHaveConsistentMemoryVertexPropertiesAndExceptions",
- reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.")
+ reason = "Giraph does a hard kill on failure and stops threads which stops test cases. Exception handling semantics are correct though.",
+ computers = {GiraphGraphComputer.class})
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.ProfileTest$Traversals",
method = "g_V_out_out_profile_grateful",
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7f143f05/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/giraph/HadoopGiraphGraphProvider.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/giraph/HadoopGiraphGraphProvider.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/giraph/HadoopGiraphGraphProvider.java
index 45a5d5b..ae3e484 100644
--- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/giraph/HadoopGiraphGraphProvider.java
+++ b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/giraph/HadoopGiraphGraphProvider.java
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.hadoop.process.computer.giraph;
+import org.apache.tinkerpop.gremlin.GraphProvider;
import org.apache.tinkerpop.gremlin.hadoop.HadoopGraphProvider;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.engine.ComputerTraversalEngine;
@@ -26,6 +27,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
+@GraphProvider.Descriptor(computer = GiraphGraphComputer.class)
public final class HadoopGiraphGraphProvider extends HadoopGraphProvider {
public GraphTraversalSource traversal(final Graph graph) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7f143f05/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/HadoopSparkGraphProvider.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/HadoopSparkGraphProvider.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/HadoopSparkGraphProvider.java
index a48b4ba..af0d745 100644
--- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/HadoopSparkGraphProvider.java
+++ b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/HadoopSparkGraphProvider.java
@@ -18,7 +18,9 @@
*/
package org.apache.tinkerpop.gremlin.hadoop.process.computer.spark;
+import org.apache.tinkerpop.gremlin.GraphProvider;
import org.apache.tinkerpop.gremlin.hadoop.HadoopGraphProvider;
+import org.apache.tinkerpop.gremlin.hadoop.process.computer.giraph.GiraphGraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.engine.ComputerTraversalEngine;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -26,6 +28,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
+@GraphProvider.Descriptor(computer = SparkGraphComputer.class)
public final class HadoopSparkGraphProvider extends HadoopGraphProvider {
public GraphTraversalSource traversal(final Graph graph) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7f143f05/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
index ca3d017..1c46d0b 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.tinkergraph.process;
+import org.apache.tinkerpop.gremlin.GraphProvider;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.engine.ComputerTraversalEngine;
@@ -30,6 +31,7 @@ import java.util.stream.Stream;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
+@GraphProvider.Descriptor(computer = TinkerGraphComputer.class)
public class TinkerGraphComputerProvider extends TinkerGraphProvider {
@Override
[02/46] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/master' into variables-id
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/master' into variables-id
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/0e1c86bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/0e1c86bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/0e1c86bd
Branch: refs/heads/master
Commit: 0e1c86bd627e25708a26c6fe23a2f7be4e0b47e3
Parents: fc82593 46fc989
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 11:21:37 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 11:21:37 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../gremlin/groovy/engine/ScriptEngines.java | 9 ++++--
.../groovy/engine/GremlinExecutorTest.java | 31 ++++++++++++++++++++
.../jsr223/GremlinGroovyScriptEngineTest.java | 20 +++++++++++++
4 files changed, 59 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0e1c86bd/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --cc gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index d60154d,6c6ade0..2bdbda3
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@@ -334,9 -334,29 +334,29 @@@ public class GremlinGroovyScriptEngineT
}
@Test
+ public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, 50);
+
+ for (int ix = 0; ix < 10; ix++) {
+ try {
+ // this script takes 10 ms longer than the interruptionTimeout
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 60) {}");
+ fail("This should have timed out");
+ } catch (ScriptException se) {
+ assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
+ }
+
+ // this script takes 10 ms less than the interruptionTimeout
+ assertEquals("test", engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 40) {};'test'"));
+ }
+
+ assertEquals(2, engine.eval("1+1"));
+ }
+
+ @Test
public void shouldNotTimeoutStandaloneFunction() throws Exception {
// use a super fast timeout which should not prevent the call of a cached function
- final ScriptEngine engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, 1);
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(1, new DefaultImportCustomizerProvider());
engine.eval("def addItUp(x,y) { x + y }");
assertEquals(3, engine.eval("addItUp(1,2)"));
[26/46] incubator-tinkerpop git commit: Removed groovy-sandbox
dependency.
Posted by sp...@apache.org.
Removed groovy-sandbox dependency.
Now that there's a more straightforward way to sandbox using AST transformations, this dependency can go. It was based on older version of groovy and potentially used class/methods that could be deprecated. The new approach with AST more closely fits with groovy's public API.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/3173d9ea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/3173d9ea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/3173d9ea
Branch: refs/heads/master
Commit: 3173d9ea7f8f4fd94fe2721620f078691dc19364
Parents: 84701fa
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 10 13:53:03 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 10 13:53:03 2015 -0400
----------------------------------------------------------------------
gremlin-groovy/pom.xml | 11 ---
.../groovy/SecurityCustomizerProvider.java | 66 ------------------
.../gremlin/groovy/engine/ScriptEngines.java | 17 +----
.../jsr223/GremlinGroovyScriptEngine.java | 35 +---------
.../groovy/engine/GremlinExecutorTest.java | 54 ---------------
.../jsr223/GremlinGroovyScriptEngineTest.java | 71 --------------------
6 files changed, 2 insertions(+), 252 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3173d9ea/gremlin-groovy/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-groovy/pom.xml b/gremlin-groovy/pom.xml
index 2baa511..6d28501 100644
--- a/gremlin-groovy/pom.xml
+++ b/gremlin-groovy/pom.xml
@@ -66,17 +66,6 @@ limitations under the License.
<version>3.3.1</version>
</dependency>
<dependency>
- <groupId>org.kohsuke</groupId>
- <artifactId>groovy-sandbox</artifactId>
- <version>1.6</version>
- <exclusions>
- <exclusion>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-test</artifactId>
<version>${project.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3173d9ea/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java
deleted file mode 100644
index bef0c2c..0000000
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java
+++ /dev/null
@@ -1,66 +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;
-
-import org.codehaus.groovy.control.customizers.CompilationCustomizer;
-import org.kohsuke.groovy.sandbox.GroovyInterceptor;
-import org.kohsuke.groovy.sandbox.SandboxTransformer;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class SecurityCustomizerProvider implements CompilerCustomizerProvider {
-
- private final List<GroovyInterceptor> interceptors;
-
- public SecurityCustomizerProvider() {
- this.interceptors = new ArrayList<>();
- }
-
- public SecurityCustomizerProvider(final GroovyInterceptor... interceptors) {
- this.interceptors = Arrays.asList(interceptors);
- }
-
- public void addInterceptor(final GroovyInterceptor interceptor) {
- this.interceptors.add(interceptor);
- }
-
- public void removeInterceptor(final GroovyInterceptor interceptor) {
- this.interceptors.remove(interceptor);
- }
-
- @Override
- public CompilationCustomizer create() {
- return new SandboxTransformer();
- }
-
- public void registerInterceptors() {
- interceptors.forEach(GroovyInterceptor::register);
- }
-
- public void unregisterInterceptors() {
- interceptors.forEach(GroovyInterceptor::unregister);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3173d9ea/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
index ba7157e..c83a532 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
@@ -20,15 +20,11 @@ package org.apache.tinkerpop.gremlin.groovy.engine;
import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.ThreadInterruptCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.jsr223.DependencyManager;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFactory;
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin;
import org.apache.tinkerpop.gremlin.groovy.plugin.IllegalEnvironmentException;
-import org.kohsuke.groovy.sandbox.GroovyInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -338,17 +334,6 @@ public class ScriptEngines implements AutoCloseable {
final List<CompilerCustomizerProvider> providers = new ArrayList<>();
providers.add(new DefaultImportCustomizerProvider(imports, staticImports));
- final String clazz = (String) config.getOrDefault("sandbox", "");
- if (!clazz.isEmpty()) {
- try {
- final Class providerClass = Class.forName(clazz);
- final GroovyInterceptor interceptor = (GroovyInterceptor) providerClass.newInstance();
- providers.add(new SecurityCustomizerProvider(interceptor));
- } catch (Exception ex) {
- logger.warn("Could not instantiate GroovyInterceptor implementation [{}] for the SecurityCustomizerProvider. It will not be applied.", clazz);
- }
- }
-
// the key to the config of the compilerCustomizerProvider is the fully qualified classname of a
// CompilerCustomizerProvider. the value is a list of arguments to pass to an available constructor.
// the arguments must match in terms of type, so given that configuration typically comes from yaml
@@ -371,7 +356,7 @@ public class ScriptEngines implements AutoCloseable {
providers.add((CompilerCustomizerProvider) providerClass.newInstance());
}
} catch(Exception ex) {
- logger.warn("Could not instantiate CompilerCustomizerProvider implementation [{}]. It will not be applied.", clazz);
+ logger.warn("Could not instantiate CompilerCustomizerProvider implementation [{}]. It will not be applied.", k);
}
});
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3173d9ea/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 d484d4e..dae19e5 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
@@ -23,7 +23,6 @@ import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.EmptyImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.ImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader;
import org.apache.tinkerpop.gremlin.groovy.plugin.Artifact;
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin;
@@ -67,7 +66,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
@@ -84,7 +82,6 @@ import java.util.stream.Collectors;
public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements DependencyManager, AutoCloseable {
public static final String COMPILE_OPTIONS_VAR_TYPES = "sandbox.bindings";
- public static final String COMPILE_OPTIONS_WHITELIST = "sandbox.whitelist";
public static final String KEY_REFERENCE_TYPE = "#jsr223.groovy.engine.keep.globals";
public static final String REFERENCE_TYPE_PHANTOM = "phantom";
public static final String REFERENCE_TYPE_WEAK = "weak";
@@ -93,13 +90,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
private static final Pattern patternImportStatic = Pattern.compile("\\Aimport\\sstatic.*");
- private ThreadLocal<Boolean> registeredSandbox = new ThreadLocal<Boolean>() {
- @Override
- protected Boolean initialValue() {
- return false;
- }
- };
-
public static final ThreadLocal<Map<String, Object>> COMPILE_OPTIONS = new ThreadLocal<Map<String, Object>>(){
@Override
protected Map<String, Object> initialValue() {
@@ -134,7 +124,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
private static final String GROOVY_LANG_SCRIPT = "groovy.lang.Script";
private ImportCustomizerProvider importCustomizerProvider;
- private Optional<SecurityCustomizerProvider> securityProvider;
private final Set<Artifact> artifactsToUse = new HashSet<>();
@@ -154,14 +143,9 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
.map(p -> (ImportCustomizerProvider) p)
.findFirst().orElse(NoImportCustomizerProvider.INSTANCE);
- securityProvider = providers.stream()
- .filter(p -> p instanceof SecurityCustomizerProvider)
- .map(p -> (SecurityCustomizerProvider) p)
- .findFirst();
-
// remove used providers as the rest will be applied directly
customizerProviders = providers.stream()
- .filter(p -> p != null && !(p instanceof SecurityCustomizerProvider || p instanceof ImportCustomizerProvider))
+ .filter(p -> p != null && !(p instanceof ImportCustomizerProvider))
.collect(Collectors.toList());
createClassLoader();
@@ -249,12 +233,10 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
@Override
public void close() throws Exception {
- securityProvider.ifPresent(SecurityCustomizerProvider::unregisterInterceptors);
}
@Override
public void reset() {
- securityProvider.ifPresent(SecurityCustomizerProvider::unregisterInterceptors);
createClassLoader();
// must clear the local cache here because the the classloader has been reset. therefore, classes previously
@@ -368,8 +350,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
}
Class getScriptClass(final String script) throws SyntaxException, CompilationFailedException, IOException {
- ensureSandbox();
-
Class clazz = classMap.get(script);
if (clazz != null) return clazz;
@@ -383,8 +363,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
}
Object eval(final Class scriptClass, final ScriptContext context) throws ScriptException {
- ensureSandbox();
-
context.setAttribute("context", context, ScriptContext.ENGINE_SCOPE);
final Writer writer = context.getWriter();
context.setAttribute("out", writer instanceof PrintWriter ? writer : new PrintWriter(writer), ScriptContext.ENGINE_SCOPE);
@@ -475,13 +453,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
((Map<String,ClassNode>) m.get(COMPILE_OPTIONS_VAR_TYPES)).clear();
}
- private void ensureSandbox() {
- if (securityProvider.isPresent() && !registeredSandbox.get()) {
- securityProvider.get().registerInterceptors();
- registeredSandbox.set(true);
- }
- }
-
private Object invokeImpl(final Object thiz, final String name, final Object args[]) throws ScriptException, NoSuchMethodException {
if (name == null) {
throw new NullPointerException("Method name can not be null");
@@ -502,13 +473,9 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
final CompilerConfiguration conf = new CompilerConfiguration();
conf.addCompilationCustomizers(this.importCustomizerProvider.create());
- if (this.securityProvider.isPresent())
- conf.addCompilationCustomizers(this.securityProvider.get().create());
-
customizerProviders.forEach(p -> conf.addCompilationCustomizers(p.create()));
this.loader = new GremlinGroovyClassLoader(getParentLoader(), conf);
- this.securityProvider.ifPresent(SecurityCustomizerProvider::registerInterceptors);
}
private Object callGlobal(final String name, final Object args[]) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3173d9ea/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
index 6604b78..6fd3d01 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
@@ -22,13 +22,10 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.apache.tinkerpop.gremlin.TestHelper;
import org.apache.tinkerpop.gremlin.groovy.ThreadInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineTest;
import org.junit.Test;
-import org.kohsuke.groovy.sandbox.GroovyInterceptor;
import javax.script.Bindings;
import javax.script.CompiledScript;
-import javax.script.ScriptException;
import javax.script.SimpleBindings;
import java.util.ArrayList;
import java.util.Arrays;
@@ -504,57 +501,6 @@ public class GremlinExecutorTest {
}
@Test
- public void shouldSecureAll() throws Exception {
- GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
- final Map<String, Object> config = new HashMap<>();
- config.put("sandbox", GremlinGroovyScriptEngineTest.DenyAll.class.getName());
- final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
- .addEngineSettings("gremlin-groovy",
- Collections.emptyList(),
- Collections.emptyList(),
- Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")),
- config)
- .create();
- try {
- gremlinExecutor.eval("c = new java.awt.Color(255, 255, 255)").get();
- fail("Should have failed security");
- } catch (Exception se) {
- assertEquals(SecurityException.class, se.getCause().getClass());
- } finally {
- gremlinExecutor.close();
- }
- }
-
- @Test
- public void shouldSecureSome() throws Exception {
- GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
- final Map<String, Object> config = new HashMap<>();
- config.put("sandbox", GremlinGroovyScriptEngineTest.AllowSome.class.getName());
- final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
- .addEngineSettings("gremlin-groovy",
- Collections.emptyList(),
- Collections.emptyList(),
- Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")),
- config)
- .create();
- try {
- gremlinExecutor.eval("c = 'new java.awt.Color(255, 255, 255)'").get();
- fail("Should have failed security");
- } catch (Exception se) {
- assertEquals(SecurityException.class, se.getCause().getClass());
- }
-
- try {
- final java.awt.Color c = (java.awt.Color) gremlinExecutor.eval("g = new java.awt.Color(255, 255, 255)").get();
- assertEquals(java.awt.Color.class, c.getClass());
- } catch (Exception ignored) {
- fail("Should not have tossed an exception");
- } finally {
- gremlinExecutor.close();
- }
- }
-
- @Test
public void shouldInitializeWithScriptAndWorkAfterReset() throws Exception {
final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
.addEngineSettings("gremlin-groovy",
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3173d9ea/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index 3fda86b..5ca078a 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -19,16 +19,10 @@
package org.apache.tinkerpop.gremlin.groovy.jsr223;
import groovy.lang.Closure;
-import groovy.lang.Script;
-import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.junit.Test;
-import org.kohsuke.groovy.sandbox.GroovyInterceptor;
-import org.kohsuke.groovy.sandbox.GroovyValueFilter;
import javax.script.Bindings;
import javax.script.ScriptContext;
@@ -38,7 +32,6 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.Assert.assertEquals;
@@ -265,72 +258,8 @@ public class GremlinGroovyScriptEngineTest {
}
@Test
- public void shouldSecureAll() throws Exception {
- GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
- final SecurityCustomizerProvider provider = new SecurityCustomizerProvider(new DenyAll());
- final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(
- new DefaultImportCustomizerProvider(), provider);
- try {
- scriptEngine.eval("g = new java.awt.Color(255, 255, 255)");
- fail("Should have failed security");
- } catch (ScriptException se) {
- assertEquals(SecurityException.class, se.getCause().getCause().getClass());
- } finally {
- provider.unregisterInterceptors();
- }
- }
-
- @Test
- public void shouldSecureSome() throws Exception {
- GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
- final SecurityCustomizerProvider provider = new SecurityCustomizerProvider(new AllowSome());
- final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(
- new DefaultImportCustomizerProvider(), provider);
- try {
- scriptEngine.eval("g = 'new java.awt.Color(255, 255, 255)'");
- fail("Should have failed security");
- } catch (ScriptException se) {
- assertEquals(SecurityException.class, se.getCause().getCause().getClass());
- }
-
- try {
- final java.awt.Color c = (java.awt.Color) scriptEngine.eval("c = new java.awt.Color(255, 255, 255)");
- assertEquals(java.awt.Color.class, c.getClass());
- } catch (Exception ex) {
- fail("Should not have tossed an exception");
- } finally {
- provider.unregisterInterceptors();
- }
- }
-
- @Test
public void shouldProcessScriptWithUTF8Characters() throws Exception {
final ScriptEngine engine = new GremlinGroovyScriptEngine();
assertEquals("轉注", engine.eval("'轉注'"));
}
-
- public static class DenyAll extends GroovyValueFilter {
- @Override
- public Object filter(final Object o) {
- throw new SecurityException("Denied!");
- }
- }
-
- public static class AllowSome extends GroovyValueFilter {
-
- public static final Set<Class> ALLOWED_TYPES = new HashSet<Class>() {{
- add(java.awt.Color.class);
- add(Integer.class);
- add(Class.class);
- }};
-
- @Override
- public Object filter(final Object o) {
- if (null == o || ALLOWED_TYPES.contains(o.getClass()))
- return o;
- if (o instanceof Script || o instanceof Closure)
- return o; // access to properties of compiled groovy script
- throw new SecurityException("Unexpected type: " + o.getClass());
- }
- }
}
[08/46] incubator-tinkerpop git commit: Rename
CompilationCustomizerProvider method from get to create.
Posted by sp...@apache.org.
Rename CompilationCustomizerProvider method from get to create.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/47c0fa3d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/47c0fa3d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/47c0fa3d
Branch: refs/heads/master
Commit: 47c0fa3d1e67fb29ee001b841303e3b732f89161
Parents: f19a65f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 13:06:55 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 13:06:55 2015 -0400
----------------------------------------------------------------------
.../gremlin/groovy/AbstractImportCustomizerProvider.java | 2 +-
.../gremlin/groovy/CompilerCustomizerProvider.java | 2 +-
.../gremlin/groovy/EmptyImportCustomizerProvider.java | 2 +-
.../gremlin/groovy/NoImportCustomizerProvider.java | 2 +-
.../gremlin/groovy/SecurityCustomizerProvider.java | 2 +-
.../gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java | 10 ++++++----
6 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/47c0fa3d/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
index e0c6670..f50395c 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
@@ -136,7 +136,7 @@ public abstract class AbstractImportCustomizerProvider implements ImportCustomiz
}
@Override
- public CompilationCustomizer getCompilationCustomizer() {
+ public CompilationCustomizer create() {
final ImportCustomizer ic = new ImportCustomizer();
processImports(ic, imports);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/47c0fa3d/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java
index a633ff2..9980911 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java
@@ -32,5 +32,5 @@ public interface CompilerCustomizerProvider {
/**
* Create a new instance of a {@code CompilationCustomizer} to add to the {@link GremlinGroovyScriptEngine}.
*/
- public CompilationCustomizer getCompilationCustomizer();
+ public CompilationCustomizer create();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/47c0fa3d/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java
index 03e86c9..36d5f93 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java
@@ -55,7 +55,7 @@ public class EmptyImportCustomizerProvider extends DefaultImportCustomizerProvid
}
@Override
- public CompilationCustomizer getCompilationCustomizer() {
+ public CompilationCustomizer create() {
final ImportCustomizer ic = new ImportCustomizer();
processImports(ic, extraImports);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/47c0fa3d/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java
index 343c8a6..9ded2b4 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java
@@ -36,7 +36,7 @@ public final class NoImportCustomizerProvider implements ImportCustomizerProvide
private NoImportCustomizerProvider() {}
@Override
- public CompilationCustomizer getCompilationCustomizer() {
+ public CompilationCustomizer create() {
return new ImportCustomizer();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/47c0fa3d/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java
index 67d0674..bef0c2c 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/SecurityCustomizerProvider.java
@@ -50,7 +50,7 @@ public class SecurityCustomizerProvider implements CompilerCustomizerProvider {
}
@Override
- public CompilationCustomizer getCompilationCustomizer() {
+ public CompilationCustomizer create() {
return new SandboxTransformer();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/47c0fa3d/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 d3a8155..68083e7 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
@@ -75,6 +75,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
/**
* This {@code ScriptEngine} implementation is heavily adapted from the {@code GroovyScriptEngineImpl} to include
@@ -164,8 +165,9 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
.findFirst();
// remove used providers as the rest will be applied directly
- providers.removeIf(p -> p instanceof SecurityCustomizerProvider || p instanceof ImportCustomizerProvider);
- customizerProviders = providers;
+ customizerProviders = providers.stream()
+ .filter(p -> !(p instanceof SecurityCustomizerProvider || p instanceof ImportCustomizerProvider))
+ .collect(Collectors.toList());
this.scriptEvaluationTimeout = scriptEvaluationTimeout;
createClassLoader();
@@ -489,10 +491,10 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
private synchronized void createClassLoader() {
final CompilerConfiguration conf = new CompilerConfiguration();
- conf.addCompilationCustomizers(this.importCustomizerProvider.getCompilationCustomizer());
+ conf.addCompilationCustomizers(this.importCustomizerProvider.create());
if (this.securityProvider.isPresent())
- conf.addCompilationCustomizers(this.securityProvider.get().getCompilationCustomizer());
+ conf.addCompilationCustomizers(this.securityProvider.get().create());
if (scriptEvaluationTimeout > 0) {
final Map<String, Object> timedInterruptAnnotationParams = new HashMap<>();
[27/46] incubator-tinkerpop git commit: Add sandboxing checks for
groovy properties.
Posted by sp...@apache.org.
Add sandboxing checks for groovy properties.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/69e39ee7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/69e39ee7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/69e39ee7
Branch: refs/heads/master
Commit: 69e39ee7a0595530110119f4e215c6f1aa1f092d
Parents: 3173d9e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 10 15:18:18 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 10 15:18:18 2015 -0400
----------------------------------------------------------------------
.../jsr223/AllowColorSandboxExtension.groovy | 35 +++++++++++++
...nGroovyScriptEngineTinkerPopSandboxTest.java | 34 +++++++++++++
.../groovy/jsr223/SandboxExtension.groovy | 53 +++++++++++++++++---
.../jsr223/TinkerPopSandboxExtension.groovy | 5 +-
4 files changed, 118 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/69e39ee7/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
new file mode 100644
index 0000000..7a1911f
--- /dev/null
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/AllowColorSandboxExtension.groovy
@@ -0,0 +1,35 @@
+/*
+ * 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.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/incubator-tinkerpop/blob/69e39ee7/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 6908078..5299857 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,4 +61,38 @@ public class GremlinGroovyScriptEngineTinkerPopSandboxTest extends AbstractGreml
assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("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/incubator-tinkerpop/blob/69e39ee7/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
index a2960f0..f2027f4 100644
--- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
+++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
@@ -20,13 +20,18 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223
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.Expression
+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
@@ -43,12 +48,12 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
public static final BiPredicate<VariableExpression, Map<String,ClassNode>> VARIABLES_ALLOW_ALL = { var, types -> true }
- public static final BiPredicate<VariableExpression, Map<String,ClassNode>> METHODS_ALLOW_ALL = { exp, method -> true }
+ public static final BiPredicate<String, MethodNode> METHODS_ALLOW_ALL = { exp, method -> true }
protected boolean graphIsAlwaysGraphInstance = true
protected boolean gIsAlwaysGraphTraversalSource = true
protected BiPredicate<VariableExpression, Map<String,ClassNode>> variableFilter = VARIABLES_ALLOW_ALL
- protected BiPredicate<Expression, MethodNode> methodFilter = METHODS_ALLOW_ALL
+ protected BiPredicate<String, MethodNode> methodFilter = METHODS_ALLOW_ALL
@Override
Object run() {
@@ -82,10 +87,15 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
}
onMethodSelection { expr, MethodNode methodNode ->
- if (!methodFilter.test(expr, methodNode)) {
- def descriptor = toMethodDescriptor(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)
}
}
@@ -114,4 +124,35 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
static String prettyPrint(final ClassNode node) {
node.isArray()?"${prettyPrint(node.componentType)}[]":node.toString(false)
}
+
+ 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/incubator-tinkerpop/blob/69e39ee7/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy
index 3b60e1d..940101c 100644
--- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy
+++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy
@@ -19,7 +19,6 @@
package org.apache.tinkerpop.gremlin.groovy.jsr223
import org.codehaus.groovy.ast.MethodNode
-import org.codehaus.groovy.ast.expr.Expression
import java.util.function.BiPredicate
@@ -36,12 +35,12 @@ class TinkerPopSandboxExtension extends SandboxExtension {
def gremlinRootStructure = "$gremlinRoot\\.structure"
def gremlinRootProcess = "$gremlinRoot\\.process"
def methodWhiteList = ["java\\.util\\..*",
+ "org\\.codehaus\\.groovy\\.runtime\\.DefaultGroovyMethods",
"$gremlinRootStructure\\..*",
"$gremlinRootProcess\\..*",
"$gremlinRootProcess\\.traversal\\.dsl\\.graph\\..*"]
- methodFilter = (BiPredicate<Expression, MethodNode>) { exp, method ->
- def descriptor = toMethodDescriptor(method)
+ methodFilter = (BiPredicate<String, MethodNode>) { descriptor, method ->
methodWhiteList.any { descriptor =~ it }
}
}
[11/46] incubator-tinkerpop git commit: Add a
ThreadInterruptCustomizerProvider.
Posted by sp...@apache.org.
Add a ThreadInterruptCustomizerProvider.
Now all configuration of the compiler is done through CompilerCustomizerProvider implementations.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/2a319f0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/2a319f0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/2a319f0e
Branch: refs/heads/master
Commit: 2a319f0eaa9af73187aad607780b189dd75c5b9a
Parents: 95b6eb8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 14:36:37 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 14:36:37 2015 -0400
----------------------------------------------------------------------
.../ThreadInterruptCustomizerProvider.java | 35 ++++++++++++++++
.../gremlin/groovy/engine/ScriptEngines.java | 4 ++
.../jsr223/GremlinGroovyScriptEngine.java | 5 ---
.../jsr223/GremlinGroovyScriptEngineTest.java | 43 ++++++++++++++++++++
.../structure/io/script/ScriptRecordReader.java | 2 +-
.../structure/io/script/ScriptRecordWriter.java | 2 +-
6 files changed, 84 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2a319f0e/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/ThreadInterruptCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/ThreadInterruptCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/ThreadInterruptCustomizerProvider.java
new file mode 100644
index 0000000..f8f46a7
--- /dev/null
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/ThreadInterruptCustomizerProvider.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import groovy.transform.ThreadInterrupt;
+import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
+import org.codehaus.groovy.control.customizers.CompilationCustomizer;
+
+/**
+ * Injects checks for thread interruption into scripts.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ThreadInterruptCustomizerProvider implements CompilerCustomizerProvider {
+ @Override
+ public CompilationCustomizer create() {
+ return new ASTTransformationCustomizer(ThreadInterrupt.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2a319f0e/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
index ba310ec..24b9f58 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.groovy.engine;
import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.ThreadInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.jsr223.DependencyManager;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
@@ -349,6 +350,9 @@ public class ScriptEngines implements AutoCloseable {
TimedInterruptCustomizerProvider.DEFAULT_INTERRUPTION_TIMEOUT)).longValue();
if (interruptionTimeout > 0) providers.add(new TimedInterruptCustomizerProvider(interruptionTimeout));
+ final boolean threadInterrupt = (boolean) config.getOrDefault("enableThreadInterrupt", true);
+ if (threadInterrupt) providers.add(new ThreadInterruptCustomizerProvider());
+
final CompilerCustomizerProvider[] providerArray = new CompilerCustomizerProvider[providers.size()];
return Optional.of((ScriptEngine) new GremlinGroovyScriptEngine(providers.toArray(providerArray)));
} else {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2a319f0e/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 d93fd01..59a0530 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
@@ -38,8 +38,6 @@ import groovy.lang.MissingMethodException;
import groovy.lang.MissingPropertyException;
import groovy.lang.Script;
import groovy.lang.Tuple;
-import groovy.transform.TimedInterrupt;
-import org.codehaus.groovy.ast.tools.GeneralUtils;
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
@@ -72,7 +70,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -484,8 +481,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
if (this.securityProvider.isPresent())
conf.addCompilationCustomizers(this.securityProvider.get().create());
- conf.addCompilationCustomizers(new ASTTransformationCustomizer(ThreadInterrupt.class));
-
customizerProviders.forEach(p -> conf.addCompilationCustomizers(p.create()));
this.loader = new GremlinGroovyClassLoader(getParentLoader(), conf);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2a319f0e/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index 15c4cb4..8f71588 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -23,6 +23,7 @@ import groovy.lang.Script;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.ThreadInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -358,6 +359,48 @@ public class GremlinGroovyScriptEngineTest {
}
@Test
+ public void shouldInterruptWhile() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(new ThreadInterruptCustomizerProvider());
+ final AtomicBoolean asserted = new AtomicBoolean(false);
+
+ final Thread t = new Thread(() -> {
+ try {
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
+ } catch (ScriptException se) {
+ asserted.set(se.getCause().getCause() instanceof InterruptedException);
+ }
+ });
+
+ t.start();
+ t.interrupt();
+ while(t.isAlive()) {}
+
+ assertTrue(asserted.get());
+ }
+
+ @Test
+ public void shouldNotInterruptWhile() throws Exception {
+ // companion to shouldInterruptWhile t
+ final ScriptEngine engine = new GremlinGroovyScriptEngine();
+ final AtomicBoolean exceptionFired = new AtomicBoolean(true);
+
+ final Thread t = new Thread(() -> {
+ try {
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 2000) {};'test'");
+ exceptionFired.set(false);
+ } catch (ScriptException se) {
+ se.printStackTrace();
+ }
+ });
+
+ t.start();
+ t.interrupt();
+ while(t.isAlive()) {}
+
+ assertFalse(exceptionFired.get());
+ }
+
+ @Test
public void shouldNotTimeoutStandaloneFunction() throws Exception {
// use a super fast timeout which should not prevent the call of a cached function
final ScriptEngine engine = new GremlinGroovyScriptEngine(
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2a319f0e/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
index aec6aff..e56eb1a 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
@@ -64,7 +64,7 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
public void initialize(final InputSplit genericSplit, final TaskAttemptContext context) throws IOException {
this.lineRecordReader.initialize(genericSplit, context);
final Configuration configuration = context.getConfiguration();
- this.engine = new GremlinGroovyScriptEngine(Integer.MAX_VALUE, new DefaultImportCustomizerProvider());
+ this.engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider());
//this.engine = ScriptEngineCache.get(configuration.get(SCRIPT_ENGINE, ScriptEngineCache.DEFAULT_SCRIPT_ENGINE));
final FileSystem fs = FileSystem.get(configuration);
try {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2a319f0e/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java
index b9bd068..5cf6170 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordWriter.java
@@ -61,7 +61,7 @@ public final class ScriptRecordWriter extends RecordWriter<NullWritable, VertexW
public ScriptRecordWriter(final DataOutputStream out, final TaskAttemptContext context) throws IOException {
this.out = out;
final Configuration configuration = context.getConfiguration();
- this.engine = new GremlinGroovyScriptEngine(Integer.MAX_VALUE, new DefaultImportCustomizerProvider());
+ this.engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider());
//this.engine = ScriptEngineCache.get(configuration.get(SCRIPT_ENGINE, ScriptEngineCache.DEFAULT_SCRIPT_ENGINE));
final FileSystem fs = FileSystem.get(configuration);
try {
[16/46] incubator-tinkerpop git commit: Pulled out TimedInterrupt
compiler provider tests to their own case
Posted by sp...@apache.org.
Pulled out TimedInterrupt compiler provider tests to their own case
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/9149c205
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/9149c205
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/9149c205
Branch: refs/heads/master
Commit: 9149c2058577c9c7fc5b0c3f703ac8baeb5ab884
Parents: 6b8628b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 9 08:31:47 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 9 08:31:47 2015 -0400
----------------------------------------------------------------------
.../jsr223/GremlinGroovyScriptEngineTest.java | 58 ------------
...linGroovyScriptEngineTimedInterruptTest.java | 94 ++++++++++++++++++++
2 files changed, 94 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9149c205/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index 15c4cb4..3fda86b 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -309,64 +309,6 @@ public class GremlinGroovyScriptEngineTest {
assertEquals("轉注", engine.eval("'轉注'"));
}
- @Test
- public void shouldTimeoutScriptOnTimedWhile() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(
- new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
- try {
- engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
- fail("This should have timed out");
- } catch (ScriptException se) {
- assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
- }
- }
-
- @Test
- public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeout() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(
- new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
- Thread.sleep(2000);
- try {
- engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
- fail("This should have timed out");
- } catch (ScriptException se) {
- assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
- }
-
- assertEquals(2, engine.eval("1+1"));
- }
-
- @Test
- public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(
- new TimedInterruptCustomizerProvider(50), new DefaultImportCustomizerProvider());
-
- for (int ix = 0; ix < 10; ix++) {
- try {
- // this script takes 10 ms longer than the interruptionTimeout
- engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 60) {}");
- fail("This should have timed out");
- } catch (ScriptException se) {
- assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
- }
-
- // this script takes 10 ms less than the interruptionTimeout
- assertEquals("test", engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 40) {};'test'"));
- }
-
- assertEquals(2, engine.eval("1+1"));
- }
-
- @Test
- public void shouldNotTimeoutStandaloneFunction() throws Exception {
- // use a super fast timeout which should not prevent the call of a cached function
- final ScriptEngine engine = new GremlinGroovyScriptEngine(
- new TimedInterruptCustomizerProvider(1), new DefaultImportCustomizerProvider());
- engine.eval("def addItUp(x,y) { x + y }");
-
- assertEquals(3, engine.eval("addItUp(1,2)"));
- }
-
public static class DenyAll extends GroovyValueFilter {
@Override
public Object filter(final Object o) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9149c205/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java
new file mode 100644
index 0000000..40d0104
--- /dev/null
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.DefaultImportCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
+import org.junit.Test;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GremlinGroovyScriptEngineTimedInterruptTest {
+
+ @Test
+ public void shouldTimeoutScriptOnTimedWhile() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
+ try {
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
+ fail("This should have timed out");
+ } catch (ScriptException se) {
+ assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
+ }
+ }
+
+ @Test
+ public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeout() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
+ Thread.sleep(2000);
+ try {
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
+ fail("This should have timed out");
+ } catch (ScriptException se) {
+ assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
+ }
+
+ assertEquals(2, engine.eval("1+1"));
+ }
+
+ @Test
+ public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(50), new DefaultImportCustomizerProvider());
+
+ for (int ix = 0; ix < 10; ix++) {
+ try {
+ // this script takes 10 ms longer than the interruptionTimeout
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 60) {}");
+ fail("This should have timed out");
+ } catch (ScriptException se) {
+ assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
+ }
+
+ // this script takes 10 ms less than the interruptionTimeout
+ assertEquals("test", engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 40) {};'test'"));
+ }
+
+ assertEquals(2, engine.eval("1+1"));
+ }
+
+ @Test
+ public void shouldNotTimeoutStandaloneFunction() throws Exception {
+ // use a super fast timeout which should not prevent the call of a cached function
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1), new DefaultImportCustomizerProvider());
+ engine.eval("def addItUp(x,y) { x + y }");
+
+ assertEquals(3, engine.eval("addItUp(1,2)"));
+ }
+}
[07/46] incubator-tinkerpop git commit: Ensure that import/security
compilation providers are removed.
Posted by sp...@apache.org.
Ensure that import/security compilation providers are removed.
This way they are not re-applied later as they have implementation specific requirements.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/f19a65f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/f19a65f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/f19a65f1
Branch: refs/heads/master
Commit: f19a65f129b07bd7b11aa10c5bfebb97415a0c33
Parents: 8b4f3df
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 12:58:18 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 12:58:18 2015 -0400
----------------------------------------------------------------------
.../gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f19a65f1/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 f86498e..d3a8155 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
@@ -137,6 +137,8 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
private final Set<Artifact> artifactsToUse = new HashSet<>();
+ private final List<CompilerCustomizerProvider> customizerProviders;
+
public GremlinGroovyScriptEngine() {
this(new DefaultImportCustomizerProvider());
}
@@ -161,6 +163,10 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
.map(p -> (SecurityCustomizerProvider) p)
.findFirst();
+ // remove used providers as the rest will be applied directly
+ providers.removeIf(p -> p instanceof SecurityCustomizerProvider || p instanceof ImportCustomizerProvider);
+ customizerProviders = providers;
+
this.scriptEvaluationTimeout = scriptEvaluationTimeout;
createClassLoader();
}
[18/46] incubator-tinkerpop git commit: Add test for multiple
extensions on TypeChecking
Posted by sp...@apache.org.
Add test for multiple extensions on TypeChecking
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/f9333087
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/f9333087
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/f9333087
Branch: refs/heads/master
Commit: f93330870fad731c9a4af4eb06e0bb27c78171f3
Parents: 8665a0f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 9 09:51:22 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 9 09:51:22 2015 -0400
----------------------------------------------------------------------
...remlinGroovyScriptEngineTypeCheckedTest.java | 26 ++++++++++++++++++++
1 file changed, 26 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f9333087/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
index 0a7639e..b298750 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
@@ -63,4 +63,30 @@ public class GremlinGroovyScriptEngineTypeCheckedTest {
assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
}
}
+
+ @Test
+ public void shouldTypeCheckWithMultipleExtension() throws Exception {
+ // with no type checking extension this should pass
+ final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
+ assertEquals(1l, scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count"));
+ }
+
+ final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider(
+ "PreventColorUsageExtension.groovy,PreventCountDownLatchUsageExtension.groovy");
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
+ fail("Should have failed type checking");
+ } catch (ScriptException se) {
+ assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ }
+
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count");
+ fail("Should have failed type checking");
+ } catch (ScriptException se) {
+ assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ }
+ }
}
[06/46] incubator-tinkerpop git commit: Update javadoc.
Posted by sp...@apache.org.
Update javadoc.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/8b4f3df0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/8b4f3df0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/8b4f3df0
Branch: refs/heads/master
Commit: 8b4f3df05defd73a5300a45196eede6a346e2544
Parents: e41b52c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 12:45:45 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 12:45:45 2015 -0400
----------------------------------------------------------------------
.../gremlin/groovy/jsr223/DependencyManager.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8b4f3df0/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/DependencyManager.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/DependencyManager.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/DependencyManager.java
index e182ac8..5c1b8fe 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/DependencyManager.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/DependencyManager.java
@@ -18,8 +18,10 @@
*/
package org.apache.tinkerpop.gremlin.groovy.jsr223;
+import org.apache.tinkerpop.gremlin.groovy.ImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin;
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPluginException;
+import org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor;
import java.util.List;
import java.util.Map;
@@ -36,16 +38,16 @@ public interface DependencyManager {
/**
* Take maven coordinates and load the classes into the classloader used by the ScriptEngine. Those ScriptEngines
* that can support script engine plugins should check if there are any new {@link GremlinPlugin}
- * implementations in the classloader. The {@link org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine}
+ * implementations in the classloader. The {@link GremlinGroovyScriptEngine}
* implementation uses ServiceLoader to figure out if there are such classes to return.
* <p/>
* It is up to the caller to execute the
* {@link GremlinPlugin#pluginTo(org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor)} method. The reason for
* this has to do with conflicts that can occur with mapper imports that are added via the
- * {@link org.apache.tinkerpop.gremlin.groovy.ImportCustomizerProvider} and scripts executed through the
- * {@link org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor}. Generally speaking, all calls to this "use" method
+ * {@link ImportCustomizerProvider} and scripts executed through the
+ * {@link PluginAcceptor}. Generally speaking, all calls to this "use" method
* should be complete prior to calling
- * {@link GremlinPlugin#pluginTo(org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor)}.
+ * {@link GremlinPlugin#pluginTo(PluginAcceptor)}.
*/
List<GremlinPlugin> use(final String group, final String artifact, final String version);
[25/46] incubator-tinkerpop git commit: Implement a basic TinkerPop
sandbox implementation and add tests.
Posted by sp...@apache.org.
Implement a basic TinkerPop sandbox implementation and add tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/84701fa0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/84701fa0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/84701fa0
Branch: refs/heads/master
Commit: 84701fa0fbc7c052ac50b192bba4ff968db66a12
Parents: 2af2c3d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 10 10:53:26 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 10 10:53:26 2015 -0400
----------------------------------------------------------------------
.../gremlin/groovy/GroovyEnvironmentSuite.java | 2 +
...nGroovyScriptEngineTinkerPopSandboxTest.java | 64 ++++++++++++++++++++
.../groovy/jsr223/SandboxExtension.groovy | 32 ++++++----
.../jsr223/TinkerPopSandboxExtension.groovy | 48 +++++++++++++++
4 files changed, 133 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/84701fa0/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 67c6ff6..2fb9e8e 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
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorOverGraphTest;
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.loaders.SugarLoader;
import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoaderTest;
import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper;
@@ -54,6 +55,7 @@ public class GroovyEnvironmentSuite extends AbstractGremlinSuite {
GremlinGroovyScriptEngineOverGraphTest.class,
GremlinGroovyScriptEngineSandboxCustomTest.class,
GremlinGroovyScriptEngineSandboxedStandardTest.class,
+ GremlinGroovyScriptEngineTinkerPopSandboxTest.class,
GremlinExecutorOverGraphTest.class,
SugarLoaderTest.class,
};
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/84701fa0/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
new file mode 100644
index 0000000..6908078
--- /dev/null
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.CompileStaticCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.codehaus.groovy.control.MultipleCompilationErrorsException;
+import org.junit.Test;
+
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
+
+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 GremlinGroovyScriptEngineTinkerPopSandboxTest extends AbstractGremlinTest {
+ @Test
+ public void shouldNotEvalAsTheMethodIsNotWhiteListed() throws Exception {
+ final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(TinkerPopSandboxExtension.class.getName());
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) {
+ engine.eval("java.lang.Math.abs(123)");
+ fail("Should have a compile error because class/method is not white listed");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getCause().getMessage(), containsString("Not authorized to call this method"));
+ }
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldEvalOnGAsTheMethodIsWhiteListed() throws Exception {
+ final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(TinkerPopSandboxExtension.class.getName());
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+ assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/84701fa0/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
index be0cbca..a2960f0 100644
--- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
+++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
@@ -44,17 +44,11 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
public static final BiPredicate<VariableExpression, Map<String,ClassNode>> VARIABLES_ALLOW_ALL = { var, types -> true }
public static final BiPredicate<VariableExpression, Map<String,ClassNode>> METHODS_ALLOW_ALL = { exp, method -> true }
- public static final BiPredicate<Expression, MethodNode> METHODS_REGEX_WHITELIST = { exp, method ->
- def descriptor = toMethodDescriptor(method)
- !methodList.any { descriptor =~ it }
- }
- public static final BiPredicate<Expression, MethodNode> METHODS_REGEX_BLACKLIST = { exp, method -> !METHODS_REGEX_WHITELIST.test(exp, method) }
protected boolean graphIsAlwaysGraphInstance = true
protected boolean gIsAlwaysGraphTraversalSource = true
protected BiPredicate<VariableExpression, Map<String,ClassNode>> variableFilter = VARIABLES_ALLOW_ALL
protected BiPredicate<Expression, MethodNode> methodFilter = METHODS_ALLOW_ALL
- protected List<String> methodList = new ArrayList<String>();
@Override
Object run() {
@@ -73,6 +67,10 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
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)) {
@@ -84,16 +82,17 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
}
onMethodSelection { expr, MethodNode methodNode ->
- if (!methodFilter.test(expr, methodNode))
- addStaticTypeError("Not authorized to call this method: $descr", expr)
+ if (!methodFilter.test(expr, methodNode)) {
+ def descriptor = toMethodDescriptor(methodNode)
+ addStaticTypeError("Not authorized to call this method: $descriptor", expr)
+ }
}
}
- private static String prettyPrint(ClassNode node) {
- node.isArray()?"${prettyPrint(node.componentType)}[]":node.toString(false)
- }
-
- private static String toMethodDescriptor(final MethodNode node) {
+ /**
+ * 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)
@@ -108,4 +107,11 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
sb.append(')')
sb
}
+
+ /**
+ * Helper method for those extending the sandbox.
+ */
+ static String prettyPrint(final ClassNode node) {
+ node.isArray()?"${prettyPrint(node.componentType)}[]":node.toString(false)
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/84701fa0/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy
new file mode 100644
index 0000000..3b60e1d
--- /dev/null
+++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/TinkerPopSandboxExtension.groovy
@@ -0,0 +1,48 @@
+/*
+ * 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.codehaus.groovy.ast.MethodNode
+import org.codehaus.groovy.ast.expr.Expression
+
+import java.util.function.BiPredicate
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+class TinkerPopSandboxExtension extends SandboxExtension {
+
+ TinkerPopSandboxExtension() {
+ gIsAlwaysGraphTraversalSource = false
+ graphIsAlwaysGraphInstance = false
+
+ def gremlinRoot = "org\\.apache\\.tinkerpop\\.gremlin"
+ def gremlinRootStructure = "$gremlinRoot\\.structure"
+ def gremlinRootProcess = "$gremlinRoot\\.process"
+ def methodWhiteList = ["java\\.util\\..*",
+ "$gremlinRootStructure\\..*",
+ "$gremlinRootProcess\\..*",
+ "$gremlinRootProcess\\.traversal\\.dsl\\.graph\\..*"]
+
+ methodFilter = (BiPredicate<Expression, MethodNode>) { exp, method ->
+ def descriptor = toMethodDescriptor(method)
+ methodWhiteList.any { descriptor =~ it }
+ }
+ }
+}
[22/46] incubator-tinkerpop git commit: More tests for sandboxing the
GremlinGroovyScriptEngine.
Posted by sp...@apache.org.
More tests for sandboxing the GremlinGroovyScriptEngine.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/e5988298
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/e5988298
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/e5988298
Branch: refs/heads/master
Commit: e5988298766095b8ef6e4f5a287221d4bd850c75
Parents: 927b5ef
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 10 08:02:21 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 10 08:02:21 2015 -0400
----------------------------------------------------------------------
...ebindAllVariableTypesSandboxExtension.groovy | 29 +++++++
.../gremlin/groovy/GroovyEnvironmentSuite.java | 2 +
...mlinGroovyScriptEngineSandboxCustomTest.java | 84 ++++++++++++++++++++
3 files changed, 115 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e5988298/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
new file mode 100644
index 0000000..c475016
--- /dev/null
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/RebindAllVariableTypesSandboxExtension.groovy
@@ -0,0 +1,29 @@
+/*
+ * 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
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+class RebindAllVariableTypesSandboxExtension extends SandboxExtension {
+ RebindAllVariableTypesSandboxExtension() {
+ gIsAlwaysGraphTraversalSource = false
+ graphIsAlwaysGraphInstance = false
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e5988298/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 c553542..67c6ff6 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
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.GraphManager;
import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorOverGraphTest;
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.loaders.SugarLoader;
import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoaderTest;
@@ -51,6 +52,7 @@ public class GroovyEnvironmentSuite extends AbstractGremlinSuite {
*/
private static final Class<?>[] allTests = new Class<?>[]{
GremlinGroovyScriptEngineOverGraphTest.class,
+ GremlinGroovyScriptEngineSandboxCustomTest.class,
GremlinGroovyScriptEngineSandboxedStandardTest.class,
GremlinExecutorOverGraphTest.class,
SugarLoaderTest.class,
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e5988298/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
new file mode 100644
index 0000000..b9f8fcf
--- /dev/null
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxCustomTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.CompileStaticCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
+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
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ 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
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ 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));
+ }
+ }
+}
[10/46] incubator-tinkerpop git commit: Created a
TimedInterruptCustomizerProvider.
Posted by sp...@apache.org.
Created a TimedInterruptCustomizerProvider.
Add the TimedInterrupt compilation customizer via the same mechanism as other customizers. No longer treat this as a special case with the timeout in millis passed directly to the GremlinGroovyScriptEngine.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/95b6eb8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/95b6eb8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/95b6eb8a
Branch: refs/heads/master
Commit: 95b6eb8a954b534aba289803872660faae81ac18
Parents: 3df735b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 13:51:35 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 13:51:35 2015 -0400
----------------------------------------------------------------------
.../TimedInterruptCustomizerProvider.java | 57 ++++++++++++++++++++
.../gremlin/groovy/engine/ScriptEngines.java | 16 +++---
.../jsr223/GremlinGroovyScriptEngine.java | 20 -------
.../jsr223/GremlinGroovyScriptEngineTest.java | 15 ++++--
4 files changed, 77 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/95b6eb8a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java
new file mode 100644
index 0000000..a8c8eb1
--- /dev/null
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import groovy.transform.TimedInterrupt;
+import org.codehaus.groovy.ast.tools.GeneralUtils;
+import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
+import org.codehaus.groovy.control.customizers.CompilationCustomizer;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Injects a check in loops and other areas of code to interrupt script execution if the run time exceeds the
+ * specified time.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class TimedInterruptCustomizerProvider implements CompilerCustomizerProvider {
+ public static final long DEFAULT_INTERRUPTION_TIMEOUT = 60000;
+
+ private final long interruptionTimeout;
+
+ public TimedInterruptCustomizerProvider() {
+ this(DEFAULT_INTERRUPTION_TIMEOUT);
+ }
+
+ public TimedInterruptCustomizerProvider(final long interruptionTimeout) {
+ this.interruptionTimeout = interruptionTimeout;
+ }
+
+ @Override
+ public CompilationCustomizer create() {
+ final Map<String, Object> timedInterruptAnnotationParams = new HashMap<>();
+ timedInterruptAnnotationParams.put("value", interruptionTimeout);
+ timedInterruptAnnotationParams.put("unit", GeneralUtils.propX(GeneralUtils.classX(TimeUnit.class), TimeUnit.MILLISECONDS.toString()));
+ timedInterruptAnnotationParams.put("checkOnMethodStart", false);
+ return new ASTTransformationCustomizer(timedInterruptAnnotationParams, TimedInterrupt.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/95b6eb8a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
index 3e884ae..ba310ec 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
@@ -18,8 +18,10 @@
*/
package org.apache.tinkerpop.gremlin.groovy.engine;
+import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.jsr223.DependencyManager;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFactory;
@@ -329,24 +331,26 @@ public class ScriptEngines implements AutoCloseable {
// generically with the DependencyManager interface, but going to wait to see how other ScriptEngines
// develop for TinkerPop3 before committing too deeply here to any specific way of doing this.
if (language.equals(gremlinGroovyScriptEngineFactory.getLanguageName())) {
+ final List<CompilerCustomizerProvider> providers = new ArrayList<>();
+ providers.add(new DefaultImportCustomizerProvider(imports, staticImports));
+
final String clazz = (String) config.getOrDefault("sandbox", "");
- SecurityCustomizerProvider securityCustomizerProvider = null;
if (!clazz.isEmpty()) {
try {
final Class providerClass = Class.forName(clazz);
final GroovyInterceptor interceptor = (GroovyInterceptor) providerClass.newInstance();
- securityCustomizerProvider = new SecurityCustomizerProvider(interceptor);
+ providers.add(new SecurityCustomizerProvider(interceptor));
} catch (Exception ex) {
logger.warn("Could not instantiate GroovyInterceptor implementation [%s] for the SecurityCustomizerProvider. It will not be applied.", clazz);
- securityCustomizerProvider = null;
}
}
final long interruptionTimeout = ((Number) config.getOrDefault("interruptionTimeout",
- GremlinGroovyScriptEngine.DEFAULT_SCRIPT_EVALUATION_TIMEOUT)).longValue();
+ TimedInterruptCustomizerProvider.DEFAULT_INTERRUPTION_TIMEOUT)).longValue();
+ if (interruptionTimeout > 0) providers.add(new TimedInterruptCustomizerProvider(interruptionTimeout));
- return Optional.of((ScriptEngine) new GremlinGroovyScriptEngine(interruptionTimeout,
- new DefaultImportCustomizerProvider(imports, staticImports), securityCustomizerProvider));
+ final CompilerCustomizerProvider[] providerArray = new CompilerCustomizerProvider[providers.size()];
+ return Optional.of((ScriptEngine) new GremlinGroovyScriptEngine(providers.toArray(providerArray)));
} else {
return Optional.ofNullable(SCRIPT_ENGINE_MANAGER.getEngineByName(language));
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/95b6eb8a/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 bb8b912..d93fd01 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
@@ -86,7 +86,6 @@ import java.util.stream.Collectors;
*/
public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements DependencyManager, AutoCloseable {
- public static final long DEFAULT_SCRIPT_EVALUATION_TIMEOUT = 60000;
public static final String KEY_REFERENCE_TYPE = "#jsr223.groovy.engine.keep.globals";
public static final String REFERENCE_TYPE_PHANTOM = "phantom";
public static final String REFERENCE_TYPE_WEAK = "weak";
@@ -131,11 +130,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
private ImportCustomizerProvider importCustomizerProvider;
private Optional<SecurityCustomizerProvider> securityProvider;
- /**
- * If this value is zero then no timeout is applied.
- */
- private final long scriptEvaluationTimeout;
-
private final Set<Artifact> artifactsToUse = new HashSet<>();
private final List<CompilerCustomizerProvider> customizerProviders;
@@ -145,11 +139,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
}
public GremlinGroovyScriptEngine(final CompilerCustomizerProvider... compilerCustomizerProviders) {
- this(DEFAULT_SCRIPT_EVALUATION_TIMEOUT, compilerCustomizerProviders);
- }
-
- public GremlinGroovyScriptEngine(final long scriptEvaluationTimeout,
- final CompilerCustomizerProvider... compilerCustomizerProviders) {
final List<CompilerCustomizerProvider> providers = Arrays.asList(compilerCustomizerProviders);
GremlinLoader.load();
@@ -169,7 +158,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
.filter(p -> p != null && !(p instanceof SecurityCustomizerProvider || p instanceof ImportCustomizerProvider))
.collect(Collectors.toList());
- this.scriptEvaluationTimeout = scriptEvaluationTimeout;
createClassLoader();
}
@@ -496,14 +484,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
if (this.securityProvider.isPresent())
conf.addCompilationCustomizers(this.securityProvider.get().create());
- if (scriptEvaluationTimeout > 0) {
- final Map<String, Object> timedInterruptAnnotationParams = new HashMap<>();
- timedInterruptAnnotationParams.put("value", scriptEvaluationTimeout);
- timedInterruptAnnotationParams.put("unit", GeneralUtils.propX(GeneralUtils.classX(TimeUnit.class), TimeUnit.MILLISECONDS.toString()));
- timedInterruptAnnotationParams.put("checkOnMethodStart", false);
- conf.addCompilationCustomizers(new ASTTransformationCustomizer(timedInterruptAnnotationParams, TimedInterrupt.class));
- }
-
conf.addCompilationCustomizers(new ASTTransformationCustomizer(ThreadInterrupt.class));
customizerProviders.forEach(p -> conf.addCompilationCustomizers(p.create()));
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/95b6eb8a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index ee6abe9..15c4cb4 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -23,6 +23,7 @@ import groovy.lang.Script;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.junit.Test;
@@ -310,7 +311,8 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldTimeoutScriptOnTimedWhile() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(3000, new DefaultImportCustomizerProvider());
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
try {
engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
fail("This should have timed out");
@@ -321,8 +323,9 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeout() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(3000, new DefaultImportCustomizerProvider());
- Thread.sleep(4000);
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
+ Thread.sleep(2000);
try {
engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
fail("This should have timed out");
@@ -335,7 +338,8 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(50, new DefaultImportCustomizerProvider());
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(50), new DefaultImportCustomizerProvider());
for (int ix = 0; ix < 10; ix++) {
try {
@@ -356,7 +360,8 @@ public class GremlinGroovyScriptEngineTest {
@Test
public void shouldNotTimeoutStandaloneFunction() throws Exception {
// use a super fast timeout which should not prevent the call of a cached function
- final ScriptEngine engine = new GremlinGroovyScriptEngine(1, new DefaultImportCustomizerProvider());
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1), new DefaultImportCustomizerProvider());
engine.eval("def addItUp(x,y) { x + y }");
assertEquals(3, engine.eval("addItUp(1,2)"));
[13/46] incubator-tinkerpop git commit: Both TimedInterrupt and
ThreadInterrupt compiler customizers are configurable.
Posted by sp...@apache.org.
Both TimedInterrupt and ThreadInterrupt compiler customizers are configurable.
In other words, they can be configured from yaml/properties into the GremlinExecutor which further unifies this model. This design also allows for arbitrary and custom CompilerCustomizerProviders to be added.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/37796826
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/37796826
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/37796826
Branch: refs/heads/master
Commit: 37796826dce643648b3148807fe82d13e9790190
Parents: 17ed3ce
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 17:07:34 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 17:07:34 2015 -0400
----------------------------------------------------------------------
.../TimedInterruptCustomizerProvider.java | 6 ++-
.../gremlin/groovy/engine/ScriptEngines.java | 36 ++++++++++++----
.../groovy/engine/GremlinExecutorTest.java | 44 +++++++++++++++++++-
.../jsr223/GremlinGroovyScriptEngineTest.java | 2 +
4 files changed, 78 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/37796826/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java
index a8c8eb1..44dfe21 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TimedInterruptCustomizerProvider.java
@@ -42,10 +42,14 @@ public class TimedInterruptCustomizerProvider implements CompilerCustomizerProvi
this(DEFAULT_INTERRUPTION_TIMEOUT);
}
- public TimedInterruptCustomizerProvider(final long interruptionTimeout) {
+ public TimedInterruptCustomizerProvider(final Long interruptionTimeout) {
this.interruptionTimeout = interruptionTimeout;
}
+ public TimedInterruptCustomizerProvider(final Integer interruptionTimeout) {
+ this.interruptionTimeout = interruptionTimeout.longValue();
+ }
+
@Override
public CompilationCustomizer create() {
final Map<String, Object> timedInterruptAnnotationParams = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/37796826/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
index 24b9f58..ba7157e 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
@@ -41,8 +41,10 @@ import javax.script.ScriptException;
import java.io.Closeable;
import java.io.IOException;
import java.io.Reader;
+import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -52,6 +54,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Holds a batch of the configured {@code ScriptEngine} objects for the server.
@@ -342,16 +345,35 @@ public class ScriptEngines implements AutoCloseable {
final GroovyInterceptor interceptor = (GroovyInterceptor) providerClass.newInstance();
providers.add(new SecurityCustomizerProvider(interceptor));
} catch (Exception ex) {
- logger.warn("Could not instantiate GroovyInterceptor implementation [%s] for the SecurityCustomizerProvider. It will not be applied.", clazz);
+ logger.warn("Could not instantiate GroovyInterceptor implementation [{}] for the SecurityCustomizerProvider. It will not be applied.", clazz);
}
}
- final long interruptionTimeout = ((Number) config.getOrDefault("interruptionTimeout",
- TimedInterruptCustomizerProvider.DEFAULT_INTERRUPTION_TIMEOUT)).longValue();
- if (interruptionTimeout > 0) providers.add(new TimedInterruptCustomizerProvider(interruptionTimeout));
-
- final boolean threadInterrupt = (boolean) config.getOrDefault("enableThreadInterrupt", true);
- if (threadInterrupt) providers.add(new ThreadInterruptCustomizerProvider());
+ // the key to the config of the compilerCustomizerProvider is the fully qualified classname of a
+ // CompilerCustomizerProvider. the value is a list of arguments to pass to an available constructor.
+ // the arguments must match in terms of type, so given that configuration typically comes from yaml
+ // or properties file, it is best to stick to primitive values when possible here for simplicity.
+ final Map<String,Object> compilerCustomizerProviders = (Map<String,Object>) config.getOrDefault(
+ "compilerCustomizerProviders", Collections.emptyMap());
+ compilerCustomizerProviders.forEach((k,v) -> {
+ try {
+ final Class providerClass = Class.forName(k);
+ if (v != null && v instanceof List && ((List) v).size() > 0) {
+ final List<Object> l = (List) v;
+ final Object[] args = new Object[l.size()];
+ l.toArray(args);
+
+ final Class<?>[] argClasses = new Class<?>[args.length];
+ Stream.of(args).map(a -> a.getClass()).collect(Collectors.toList()).toArray(argClasses);
+ final Constructor constructor = providerClass.getConstructor(argClasses);
+ providers.add((CompilerCustomizerProvider) constructor.newInstance(args));
+ } else {
+ providers.add((CompilerCustomizerProvider) providerClass.newInstance());
+ }
+ } catch(Exception ex) {
+ logger.warn("Could not instantiate CompilerCustomizerProvider implementation [{}]. It will not be applied.", clazz);
+ }
+ });
final CompilerCustomizerProvider[] providerArray = new CompilerCustomizerProvider[providers.size()];
return Optional.of((ScriptEngine) new GremlinGroovyScriptEngine(providers.toArray(providerArray)));
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/37796826/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
index 480c72f..6604b78 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
@@ -20,6 +20,8 @@ package org.apache.tinkerpop.gremlin.groovy.engine;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.groovy.ThreadInterruptCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineTest;
import org.junit.Test;
import org.kohsuke.groovy.sandbox.GroovyInterceptor;
@@ -28,6 +30,7 @@ import javax.script.Bindings;
import javax.script.CompiledScript;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -435,9 +438,14 @@ public class GremlinExecutorTest {
@Test
public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
- GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
+ final Map<String,List<Object>> compilerCustomizerConfig = new HashMap<>();
+ final List<Object> args = new ArrayList<>();
+ args.add(50);
+ compilerCustomizerConfig.put(TimedInterruptCustomizerProvider.class.getName(), args);
+
final Map<String, Object> config = new HashMap<>();
- config.put("interruptionTimeout", 50l);
+ config.put("compilerCustomizerProviders", compilerCustomizerConfig);
+
final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
.addEngineSettings("gremlin-groovy",
Collections.emptyList(),
@@ -462,6 +470,38 @@ public class GremlinExecutorTest {
gremlinExecutor.close();
}
+ @Test
+ public void shouldInterruptWhile() throws Exception {
+ final Map<String,List<Object>> compilerCustomizerConfig = new HashMap<>();
+ compilerCustomizerConfig.put(ThreadInterruptCustomizerProvider.class.getName(), new ArrayList<>());
+
+ final Map<String, Object> config = new HashMap<>();
+ config.put("compilerCustomizerProviders", compilerCustomizerConfig);
+
+ final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
+ .addEngineSettings("gremlin-groovy",
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")),
+ config)
+ .create();
+ final AtomicBoolean asserted = new AtomicBoolean(false);
+
+ final Thread t = new Thread(() -> {
+ try {
+ gremlinExecutor.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}").get();
+ } catch (Exception se) {
+ asserted.set(se instanceof InterruptedException);
+ }
+ });
+
+ t.start();
+ Thread.sleep(100);
+ t.interrupt();
+ while(t.isAlive()) {}
+
+ assertTrue(asserted.get());
+ }
@Test
public void shouldSecureAll() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/37796826/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index 8f71588..19f56d8 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -372,6 +372,7 @@ public class GremlinGroovyScriptEngineTest {
});
t.start();
+ Thread.sleep(100);
t.interrupt();
while(t.isAlive()) {}
@@ -394,6 +395,7 @@ public class GremlinGroovyScriptEngineTest {
});
t.start();
+ Thread.sleep(100);
t.interrupt();
while(t.isAlive()) {}
[33/46] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/fix-javadoc-errors' into tp30-javadoc-fix
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/fix-javadoc-errors' into tp30-javadoc-fix
Conflicts:
gremlin-console/pom.xml
gremlin-core/pom.xml
gremlin-driver/pom.xml
gremlin-groovy-test/pom.xml
gremlin-groovy/pom.xml
gremlin-server/pom.xml
gremlin-shaded/pom.xml
gremlin-test/pom.xml
hadoop-gremlin/pom.xml
neo4j-gremlin/pom.xml
pom.xml
tinkergraph-gremlin/pom.xml
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d5466aa8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d5466aa8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d5466aa8
Branch: refs/heads/master
Commit: d5466aa89f16a941c2f318cabf1411ee9c4be4a0
Parents: 3f5405a 712c7b3
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Jul 14 08:21:14 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Jul 14 08:21:14 2015 -0400
----------------------------------------------------------------------
gremlin-core/pom.xml | 4 +-
pom.xml | 151 ++++++++++++++++++++++++----------------------
2 files changed, 80 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d5466aa8/gremlin-core/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d5466aa8/pom.xml
----------------------------------------------------------------------
[38/46] incubator-tinkerpop git commit: Update changelog to include
version 3.0.1
Posted by sp...@apache.org.
Update changelog to include version 3.0.1
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/02c2af29
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/02c2af29
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/02c2af29
Branch: refs/heads/master
Commit: 02c2af29d2865f1c01a49c326007efdd4fc083a7
Parents: 35af2a1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 08:57:36 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 08:57:36 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/02c2af29/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index f33be5a..1d015e8 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -22,6 +22,11 @@ TinkerPop 3.0.0 (A Gremlin Rāga in 7/16 Time)
image::http://www.tinkerpop.com/docs/current/images/gremlin-hindu.png[width=225]
+TinkerPop 3.0.1 (NOT OFFICIALLY RELEASED YET)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+* Adjust configuration for javadoc generation to eliminate error messages.
+
TinkerPop 3.0.0 (Release Date: July 9, 2015)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[05/46] incubator-tinkerpop git commit: Change scope of
ManagedConcurrentValueMap.
Posted by sp...@apache.org.
Change scope of ManagedConcurrentValueMap.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/e41b52c1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/e41b52c1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/e41b52c1
Branch: refs/heads/master
Commit: e41b52c1b6cf9c4d3becc504de9e3a5c4217da84
Parents: ce9d090
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 12:45:10 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 12:45:10 2015 -0400
----------------------------------------------------------------------
.../gremlin/groovy/jsr223/ManagedConcurrentValueMap.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e41b52c1/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ManagedConcurrentValueMap.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ManagedConcurrentValueMap.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ManagedConcurrentValueMap.java
index 8f38604..dce056b 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ManagedConcurrentValueMap.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ManagedConcurrentValueMap.java
@@ -28,13 +28,13 @@ import java.util.concurrent.ConcurrentHashMap;
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class ManagedConcurrentValueMap<K, V> {
+class ManagedConcurrentValueMap<K, V> {
private final ConcurrentHashMap<K, ManagedReference<V>> internalMap;
private ReferenceBundle bundle;
public ManagedConcurrentValueMap(final ReferenceBundle bundle) {
this.bundle = bundle;
- internalMap = new ConcurrentHashMap<K, ManagedReference<V>>();
+ internalMap = new ConcurrentHashMap<>();
}
/**
@@ -76,6 +76,9 @@ public class ManagedConcurrentValueMap<K, V> {
internalMap.put(key, ref);
}
+ /**
+ * Clear the map.
+ */
public void clear() {
internalMap.clear();
}
[46/46] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/tp30'
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/tp30'
Conflicts:
gremlin-console/pom.xml
gremlin-core/pom.xml
gremlin-driver/pom.xml
gremlin-groovy-test/pom.xml
gremlin-groovy/pom.xml
gremlin-server/pom.xml
gremlin-shaded/pom.xml
gremlin-test/pom.xml
hadoop-gremlin/pom.xml
neo4j-gremlin/pom.xml
pom.xml
tinkergraph-gremlin/pom.xml
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/97a67ed5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/97a67ed5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/97a67ed5
Branch: refs/heads/master
Commit: 97a67ed596daae523658dc78c748d1615700fd71
Parents: 2c48042 2cf9f5e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 17:14:09 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 17:14:09 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 14 +-
README.asciidoc | 1 -
docs/src/implementations.asciidoc | 1 +
gremlin-core/pom.xml | 4 +-
.../tinkerpop/gremlin/structure/Graph.java | 10 ++
.../jsr223/AllowColorSandboxExtension.groovy | 35 ++++
.../BlockSomeVariablesSandboxExtension.groovy | 41 +++++
...ebindAllVariableTypesSandboxExtension.groovy | 29 +++
.../gremlin/groovy/GroovyEnvironmentSuite.java | 11 +-
.../GremlinGroovyScriptEngineOverGraphTest.java | 9 +-
...mlinGroovyScriptEngineSandboxCustomTest.java | 126 +++++++++++++
...GroovyScriptEngineSandboxedStandardTest.java | 131 ++++++++++++++
...nGroovyScriptEngineTinkerPopSandboxTest.java | 98 +++++++++++
gremlin-groovy/pom.xml | 11 --
.../groovy/jsr223/SandboxExtension.groovy | 176 +++++++++++++++++++
.../jsr223/TinkerPopSandboxExtension.groovy | 47 +++++
.../AbstractImportCustomizerProvider.java | 2 +-
.../groovy/CompileStaticCustomizerProvider.java | 60 +++++++
.../groovy/CompilerCustomizerProvider.java | 10 +-
.../groovy/EmptyImportCustomizerProvider.java | 5 +-
.../groovy/NoImportCustomizerProvider.java | 9 +-
.../groovy/SecurityCustomizerProvider.java | 66 -------
.../ThreadInterruptCustomizerProvider.java | 35 ++++
.../TimedInterruptCustomizerProvider.java | 61 +++++++
.../groovy/TypeCheckedCustomizerProvider.java | 64 +++++++
.../gremlin/groovy/engine/ScriptEngines.java | 50 ++++--
.../groovy/jsr223/DependencyManager.java | 10 +-
.../jsr223/GremlinGroovyScriptEngine.java | 122 ++++++-------
.../jsr223/ManagedConcurrentValueMap.java | 7 +-
.../VariableIdentificationCustomizer.java | 91 ++++++++++
.../groovy/engine/GremlinExecutorTest.java | 74 ++++----
...mlinGroovyScriptEngineCompileStaticTest.java | 99 +++++++++++
.../jsr223/GremlinGroovyScriptEngineTest.java | 132 +-------------
...inGroovyScriptEngineThreadInterruptTest.java | 78 ++++++++
...linGroovyScriptEngineTimedInterruptTest.java | 94 ++++++++++
...remlinGroovyScriptEngineTypeCheckedTest.java | 100 +++++++++++
.../groovy/jsr223/PrecompiledExtensions.java | 58 ++++++
.../tinkerpop/gremlin/AbstractGremlinSuite.java | 95 +++++++---
.../apache/tinkerpop/gremlin/GraphProvider.java | 25 +++
.../gremlin/structure/FeatureSupportTest.java | 6 +-
.../gremlin/structure/PropertyTest.java | 6 +-
.../tinkerpop/gremlin/structure/VertexTest.java | 6 +-
.../gremlin/hadoop/structure/HadoopGraph.java | 27 ++-
.../structure/io/script/ScriptRecordReader.java | 2 +-
.../structure/io/script/ScriptRecordWriter.java | 2 +-
.../giraph/HadoopGiraphGraphProvider.java | 2 +
.../spark/HadoopSparkGraphProvider.java | 3 +
pom.xml | 151 ++++++++--------
.../process/TinkerGraphComputerProvider.java | 2 +
49 files changed, 1819 insertions(+), 479 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/97a67ed5/gremlin-core/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/97a67ed5/gremlin-groovy/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/97a67ed5/pom.xml
----------------------------------------------------------------------
[39/46] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/tp30-610' into tp30
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/tp30-610' into tp30
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/67d62fc3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/67d62fc3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/67d62fc3
Branch: refs/heads/master
Commit: 67d62fc3ef0f1fffa4e73b08974a6e4c1ce2361c
Parents: 02c2af2 3c45b7d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 09:02:14 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 09:02:14 2015 -0400
----------------------------------------------------------------------
.../apache/tinkerpop/gremlin/structure/FeatureSupportTest.java | 6 +++---
.../org/apache/tinkerpop/gremlin/structure/PropertyTest.java | 6 +++---
.../org/apache/tinkerpop/gremlin/structure/VertexTest.java | 6 +++---
3 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
[35/46] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/compiler-customizer' into tp30-582
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/compiler-customizer' into tp30-582
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/12eb58bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/12eb58bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/12eb58bf
Branch: refs/heads/master
Commit: 12eb58bf3742a549c9cacda11204dac1d21b264d
Parents: 3f5405a 1a3a32d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Jul 14 08:38:50 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Jul 14 08:38:50 2015 -0400
----------------------------------------------------------------------
.../jsr223/AllowColorSandboxExtension.groovy | 35 ++++
.../BlockSomeVariablesSandboxExtension.groovy | 41 +++++
...ebindAllVariableTypesSandboxExtension.groovy | 29 +++
.../gremlin/groovy/GroovyEnvironmentSuite.java | 11 +-
.../GremlinGroovyScriptEngineOverGraphTest.java | 9 +-
...mlinGroovyScriptEngineSandboxCustomTest.java | 126 +++++++++++++
...GroovyScriptEngineSandboxedStandardTest.java | 131 ++++++++++++++
...nGroovyScriptEngineTinkerPopSandboxTest.java | 98 +++++++++++
gremlin-groovy/pom.xml | 11 --
.../groovy/jsr223/SandboxExtension.groovy | 176 +++++++++++++++++++
.../jsr223/TinkerPopSandboxExtension.groovy | 47 +++++
.../AbstractImportCustomizerProvider.java | 2 +-
.../groovy/CompileStaticCustomizerProvider.java | 60 +++++++
.../groovy/CompilerCustomizerProvider.java | 10 +-
.../groovy/EmptyImportCustomizerProvider.java | 5 +-
.../groovy/NoImportCustomizerProvider.java | 9 +-
.../groovy/SecurityCustomizerProvider.java | 66 -------
.../ThreadInterruptCustomizerProvider.java | 35 ++++
.../TimedInterruptCustomizerProvider.java | 61 +++++++
.../groovy/TypeCheckedCustomizerProvider.java | 64 +++++++
.../gremlin/groovy/engine/ScriptEngines.java | 50 ++++--
.../groovy/jsr223/DependencyManager.java | 10 +-
.../jsr223/GremlinGroovyScriptEngine.java | 122 ++++++-------
.../jsr223/ManagedConcurrentValueMap.java | 7 +-
.../VariableIdentificationCustomizer.java | 91 ++++++++++
.../groovy/engine/GremlinExecutorTest.java | 74 ++++----
...mlinGroovyScriptEngineCompileStaticTest.java | 99 +++++++++++
.../jsr223/GremlinGroovyScriptEngineTest.java | 132 +-------------
...inGroovyScriptEngineThreadInterruptTest.java | 78 ++++++++
...linGroovyScriptEngineTimedInterruptTest.java | 94 ++++++++++
...remlinGroovyScriptEngineTypeCheckedTest.java | 100 +++++++++++
.../groovy/jsr223/PrecompiledExtensions.java | 58 ++++++
.../structure/io/script/ScriptRecordReader.java | 2 +-
.../structure/io/script/ScriptRecordWriter.java | 2 +-
34 files changed, 1587 insertions(+), 358 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/12eb58bf/gremlin-groovy/pom.xml
----------------------------------------------------------------------
[09/46] incubator-tinkerpop git commit: Apply remaining custom
CompilationCustomizers to GremlinGroovyScriptEngine
Posted by sp...@apache.org.
Apply remaining custom CompilationCustomizers to GremlinGroovyScriptEngine
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/3df735b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/3df735b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/3df735b3
Branch: refs/heads/master
Commit: 3df735b371e7c67024e2c6deb989ef1eefc4bb4f
Parents: 47c0fa3
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 13:19:31 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 13:19:31 2015 -0400
----------------------------------------------------------------------
.../gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3df735b3/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 68083e7..bb8b912 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
@@ -166,7 +166,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
// remove used providers as the rest will be applied directly
customizerProviders = providers.stream()
- .filter(p -> !(p instanceof SecurityCustomizerProvider || p instanceof ImportCustomizerProvider))
+ .filter(p -> p != null && !(p instanceof SecurityCustomizerProvider || p instanceof ImportCustomizerProvider))
.collect(Collectors.toList());
this.scriptEvaluationTimeout = scriptEvaluationTimeout;
@@ -506,6 +506,8 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
conf.addCompilationCustomizers(new ASTTransformationCustomizer(ThreadInterrupt.class));
+ customizerProviders.forEach(p -> conf.addCompilationCustomizers(p.create()));
+
this.loader = new GremlinGroovyClassLoader(getParentLoader(), conf);
this.securityProvider.ifPresent(SecurityCustomizerProvider::registerInterceptors);
}
[29/46] incubator-tinkerpop git commit: Javadoc warns/errors on
"successful" generation no longer occur.
Posted by sp...@apache.org.
Javadoc warns/errors on "successful" generation no longer occur.
Also fixed some typos in the core API for class names. Can't believe that was never noticed.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/9f280201
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/9f280201
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/9f280201
Branch: refs/heads/master
Commit: 9f2802012809b1d4d99eb9f07c4c1876ea8ea064
Parents: be3aa54
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jul 13 09:56:50 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 13 09:56:50 2015 -0400
----------------------------------------------------------------------
gremlin-core/pom.xml | 1 +
pom.xml | 74 +++++++++++++++++------------------------------
2 files changed, 27 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f280201/gremlin-core/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-core/pom.xml b/gremlin-core/pom.xml
index fe56b30..08fcf16 100644
--- a/gremlin-core/pom.xml
+++ b/gremlin-core/pom.xml
@@ -33,6 +33,7 @@ limitations under the License.
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
+ <version>1.10</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f280201/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2fbe013..d50c663 100644
--- a/pom.xml
+++ b/pom.xml
@@ -200,14 +200,10 @@ limitations under the License.
<phase>site</phase>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
- <additionalDependencies>
- <!-- all that exclusion work in hadoop-gremlin seems to dump dependencies needed for javadoc -->
- <additionalDependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-core</artifactId>
- <version>1.2.1</version>
- </additionalDependency>
- </additionalDependencies>
+ <includeDependencySources>true</includeDependencySources>
+ <dependencySourceIncludes>
+ <dependencySourceInclude>org.apache.tinkerpop:*</dependencySourceInclude>
+ </dependencySourceIncludes>
</configuration>
</execution>
<execution>
@@ -437,14 +433,10 @@ limitations under the License.
<id>non-aggregate</id>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
- <additionalDependencies>
- <!-- all that exclusion work in hadoop-gremlin seems to dump dependencies needed for javadoc -->
- <additionalDependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-core</artifactId>
- <version>1.2.1</version>
- </additionalDependency>
- </additionalDependencies>
+ <includeDependencySources>true</includeDependencySources>
+ <dependencySourceIncludes>
+ <dependencySourceInclude>org.apache.tinkerpop:*</dependencySourceInclude>
+ </dependencySourceIncludes>
</configuration>
<reports>
<report>javadoc</report>
@@ -454,14 +446,10 @@ limitations under the License.
<id>aggregate</id>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
- <additionalDependencies>
- <!-- all that exclusion work in hadoop-gremlin seems to dump dependencies needed for javadoc -->
- <additionalDependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-core</artifactId>
- <version>1.2.1</version>
- </additionalDependency>
- </additionalDependencies>
+ <includeDependencySources>true</includeDependencySources>
+ <dependencySourceIncludes>
+ <dependencySourceInclude>org.apache.tinkerpop:*</dependencySourceInclude>
+ </dependencySourceIncludes>
</configuration>
<reports>
<report>aggregate</report>
@@ -761,18 +749,13 @@ limitations under the License.
<configuration>
<destDir>full</destDir>
<additionalparam>-Xdoclint:none</additionalparam>
- <sourcepath>
- hadoop-gremlin/src/main/java:gremlin-core/src/main/java:gremlin-driver/src/main/java:gremlin-groovy/src/main/java:gremlin-server/src/main/java:gremlin-test/src/main/java:tinkergraph-gremlin/src/main/java
- </sourcepath>
<quiet>true</quiet>
- <additionalDependencies>
- <!-- all that exclusion work in hadoop-gremlin seems to dump dependencies needed for javadoc -->
- <additionalDependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-core</artifactId>
- <version>1.2.1</version>
- </additionalDependency>
- </additionalDependencies>
+ <includeDependencySources>true</includeDependencySources>
+ <dependencySourceIncludes>
+ <dependencySourceInclude>org.apache.tinkerpop:*</dependencySourceInclude>
+ </dependencySourceIncludes>
+ <detectLinks>false</detectLinks>
+ <detectOfflineLinks>false</detectOfflineLinks>
</configuration>
</execution>
<execution>
@@ -785,9 +768,6 @@ limitations under the License.
<configuration>
<destDir>core</destDir>
<additionalparam>-Xdoclint:none</additionalparam>
- <sourcepath>
- gremlin-core/src/main/java:gremlin-driver/src/main/java
- </sourcepath>
<quiet>true</quiet>
<sourceFileIncludes>
<!-- structure -->
@@ -806,13 +786,13 @@ limitations under the License.
org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
</sourceFileInclude>
<sourceFileInclude>
- org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWrtier.java
+ org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWriter.java
</sourceFileInclude>
<sourceFileInclude>
org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
</sourceFileInclude>
<sourceFileInclude>
- org/apache/tinkerpop/gremlin/structure/io/gryo/GryoWrtier.java
+ org/apache/tinkerpop/gremlin/structure/io/gryo/GryoWriter.java
</sourceFileInclude>
<!-- process -->
<sourceFileInclude>org/apache/tinkerpop/gremlin/process/*.java
@@ -839,14 +819,12 @@ limitations under the License.
<sourceFileInclude>org/apache/tinkerpop/gremlin/driver/*.java
</sourceFileInclude>
</sourceFileIncludes>
- <additionalDependencies>
- <!-- all that exclusion work in hadoop-gremlin seems to dump dependencies needed for javadoc -->
- <additionalDependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-core</artifactId>
- <version>1.2.1</version>
- </additionalDependency>
- </additionalDependencies>
+ <includeDependencySources>true</includeDependencySources>
+ <dependencySourceIncludes>
+ <dependencySourceInclude>org.apache.tinkerpop:*</dependencySourceInclude>
+ </dependencySourceIncludes>
+ <detectLinks>false</detectLinks>
+ <detectOfflineLinks>false</detectOfflineLinks>
</configuration>
</execution>
</executions>
[28/46] incubator-tinkerpop git commit: Add some javadoc to the
SandboxExtension.
Posted by sp...@apache.org.
Add some javadoc to the SandboxExtension.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/1a3a32d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/1a3a32d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/1a3a32d8
Branch: refs/heads/master
Commit: 1a3a32d8454ff8bcd8da6c57fa59e9ecf3b90db6
Parents: 69e39ee
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jul 13 08:20:44 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 13 08:20:44 2015 -0400
----------------------------------------------------------------------
.../groovy/jsr223/SandboxExtension.groovy | 22 ++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1a3a32d8/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
index f2027f4..505f921 100644
--- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
+++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
@@ -40,18 +40,33 @@ import java.util.function.BiPredicate
* 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 typically extend this class to modify features.
+ * 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)
*/
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
@@ -122,9 +137,12 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
* Helper method for those extending the sandbox.
*/
static String prettyPrint(final ClassNode node) {
- node.isArray()?"${prettyPrint(node.componentType)}[]":node.toString(false)
+ 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
[41/46] incubator-tinkerpop git commit: Update README with respect to
issue tracker conventions.
Posted by sp...@apache.org.
Update README with respect to issue tracker conventions.
Now that a release is present we can assign the "affected version".
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/4a92027a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/4a92027a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/4a92027a
Branch: refs/heads/master
Commit: 4a92027a32bcee3543d93b41ff6958b0d94028b3
Parents: 746d0f0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 09:06:00 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 09:06:00 2015 -0400
----------------------------------------------------------------------
README.asciidoc | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4a92027a/README.asciidoc
----------------------------------------------------------------------
diff --git a/README.asciidoc b/README.asciidoc
index 87d8707..e9af622 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -98,7 +98,6 @@ TinkerPop3 uses Apache JIRA as its link:https://issues.apache.org/jira/browse/TI
** Everything else is an `improvement` in the sense that any other work is an enhancement to the current codebase.
* The "component" should be representative of the primary area of code that it applies to and all issues should have this property set.
* Issues are not assigned "labels".
-* Until there is an official release "affected version" should be left empty.
Release Process
~~~~~~~~~~~~~~~
[14/46] incubator-tinkerpop git commit: Add a
TypeCheckedCompilerCustomizerProvider.
Posted by sp...@apache.org.
Add a TypeCheckedCompilerCustomizerProvider.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/44d8f377
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/44d8f377
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/44d8f377
Branch: refs/heads/master
Commit: 44d8f3772f18ff1613613579cd0d1ef5b28d20ef
Parents: 3779682
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 9 08:24:08 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 9 08:24:08 2015 -0400
----------------------------------------------------------------------
.../groovy/TypeCheckedCustomizerProvider.java | 51 +++++++++++++++
...remlinGroovyScriptEngineTypeCheckedTest.java | 66 ++++++++++++++++++++
.../resources/PreventColorUsageExtension.groovy | 23 +++++++
3 files changed, 140 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/44d8f377/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java
new file mode 100644
index 0000000..14ff7ca
--- /dev/null
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+import groovy.transform.TypeChecked;
+import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
+import org.codehaus.groovy.control.customizers.CompilationCustomizer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Injects the {@code TypeChecked} transformer to enable type validation on script execution.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class TypeCheckedCustomizerProvider implements CompilerCustomizerProvider {
+
+ private final String extensions;
+
+ public TypeCheckedCustomizerProvider() {
+ this(null);
+ }
+
+ public TypeCheckedCustomizerProvider(final String extensions) {
+ this.extensions = extensions;
+ }
+
+ @Override
+ public CompilationCustomizer create() {
+ final Map<String, Object> timedInterruptAnnotationParams = new HashMap<>();
+ if (extensions != null && !extensions.isEmpty()) timedInterruptAnnotationParams.put("extensions", extensions);
+ return new ASTTransformationCustomizer(timedInterruptAnnotationParams, TypeChecked.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/44d8f377/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
new file mode 100644
index 0000000..0a7639e
--- /dev/null
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.TypeCheckedCustomizerProvider;
+import org.codehaus.groovy.control.MultipleCompilationErrorsException;
+import org.junit.Test;
+
+import javax.script.ScriptException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GremlinGroovyScriptEngineTypeCheckedTest {
+ @Test
+ public void shouldTypeCheck() throws Exception {
+ // with no type checking this should pass
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine()) {
+ assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).red"));
+ }
+
+ final TypeCheckedCustomizerProvider provider = new TypeCheckedCustomizerProvider();
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) {
+ scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).red");
+ fail("Should have failed type checking");
+ } catch (ScriptException se) {
+ assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ }
+ }
+
+ @Test
+ public void shouldTypeCheckWithExtension() throws Exception {
+ // with no type checking extension this should pass
+ final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
+ }
+
+ final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider("PreventColorUsageExtension.groovy");
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
+ fail("Should have failed type checking");
+ } catch (ScriptException se) {
+ assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/44d8f377/gremlin-groovy/src/test/resources/PreventColorUsageExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/resources/PreventColorUsageExtension.groovy b/gremlin-groovy/src/test/resources/PreventColorUsageExtension.groovy
new file mode 100644
index 0000000..38eac69
--- /dev/null
+++ b/gremlin-groovy/src/test/resources/PreventColorUsageExtension.groovy
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+onMethodSelection { expr, methodNode ->
+ if (methodNode.declaringClass.name=='java.awt.Color') {
+ addStaticTypeError("Method call is not allowed!", expr)
+ }
+}
\ No newline at end of file
[30/46] incubator-tinkerpop git commit: Rename "reserved" property
keys in tests.
Posted by sp...@apache.org.
Rename "reserved" property keys in tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/fa994d33
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/fa994d33
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/fa994d33
Branch: refs/heads/master
Commit: fa994d3304a885bc52725e2890e53b2a1186c92b
Parents: be3aa54
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jul 13 15:16:20 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 13 15:16:20 2015 -0400
----------------------------------------------------------------------
.../apache/tinkerpop/gremlin/structure/FeatureSupportTest.java | 6 +++---
.../org/apache/tinkerpop/gremlin/structure/PropertyTest.java | 6 +++---
.../org/apache/tinkerpop/gremlin/structure/VertexTest.java | 6 +++---
3 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fa994d33/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
index 1971b28..d416797 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
@@ -584,7 +584,7 @@ public class FeatureSupportTest {
public void shouldSupportRemovePropertyIfAPropertyCanBeRemoved() throws Exception {
try {
final Vertex v = graph.addVertex();
- final Edge e = v.addEdge("label", v);
+ final Edge e = v.addEdge("self", v);
e.property("name").remove();
fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), EdgeFeatures.FEATURE_REMOVE_PROPERTY));
} catch (Exception ex) {
@@ -891,7 +891,7 @@ public class FeatureSupportTest {
public void shouldSupportMetaPropertyIfPropertiesCanBePutOnProperties() throws Exception {
try {
final Vertex v = graph.addVertex();
- v.property(VertexProperty.Cardinality.single, "name", "stephen", "property", "on-property");
+ v.property(VertexProperty.Cardinality.single, "name", "stephen", "p", "on-property");
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), VertexFeatures.FEATURE_META_PROPERTIES));
} catch (Exception ex) {
validateException(VertexProperty.Exceptions.metaPropertiesNotSupported(), ex);
@@ -906,7 +906,7 @@ public class FeatureSupportTest {
public void shouldSupportMetaPropertyIfPropertiesCanBePutOnPropertiesViaVertexProperty() throws Exception {
try {
final Vertex v = graph.addVertex("name", "stephen");
- v.property("name").property("property", "on-property");
+ v.property("name").property("p", "on-property");
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), VertexFeatures.FEATURE_META_PROPERTIES));
} catch (Exception ex) {
validateException(VertexProperty.Exceptions.metaPropertiesNotSupported(), ex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fa994d33/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/PropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/PropertyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/PropertyTest.java
index 42083b8..6d48961 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/PropertyTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/PropertyTest.java
@@ -170,7 +170,7 @@ public class PropertyTest {
public void shouldThrowOnGraphAddEdge() throws Exception {
try {
final Vertex v = this.graph.addVertex();
- v.addEdge("label", v, arguments);
+ v.addEdge("self", v, arguments);
fail(String.format("Call to addVertex should have thrown an exception with these arguments [%s]", arguments));
} catch (Exception ex) {
validateException(expectedException, ex);
@@ -205,7 +205,7 @@ public class PropertyTest {
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = FEATURE_PROPERTIES)
public void shouldGetValueThatIsNotPresentOnEdge() {
final Vertex v = graph.addVertex();
- final Edge e = v.addEdge("label", v);
+ final Edge e = v.addEdge("self", v);
try {
e.value("does-not-exist");
fail("Call to Element.value() with a key that is not present should throw an exception");
@@ -274,7 +274,7 @@ public class PropertyTest {
public void shouldThrowOnGraphEdgeSetPropertyStandard() throws Exception {
try {
final Vertex v = this.graph.addVertex();
- v.addEdge("label", v).property(key, val);
+ v.addEdge("self", v).property(key, val);
fail(String.format("Call to Edge.setProperty should have thrown an exception with these arguments [%s, %s]", key, val));
} catch (Exception ex) {
validateException(expectedException, ex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fa994d33/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
index a958b07..d891d14 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
@@ -260,10 +260,10 @@ public class VertexTest {
public void shouldHaveExceptionConsistencyWhenAssigningSameIdOnEdge() {
final Vertex v = graph.addVertex();
final Object o = GraphManager.getGraphProvider().convertId("1", Edge.class);
- v.addEdge("label", v, T.id, o);
+ v.addEdge("self", v, T.id, o);
try {
- v.addEdge("label", v, T.id, o);
+ v.addEdge("self", v, T.id, o);
fail("Assigning the same ID to an Element should throw an exception");
} catch (Exception ex) {
validateException(Graph.Exceptions.edgeWithIdAlreadyExists(o), ex);
@@ -278,7 +278,7 @@ public class VertexTest {
public void shouldHaveExceptionConsistencyWhenIdNotSupportedForAddEdge() throws Exception {
try {
final Vertex v = this.graph.addVertex();
- v.addEdge("label", v, T.id, "");
+ v.addEdge("self", v, T.id, "");
fail("Call to addEdge should have thrown an exception when ID was specified as it is not supported");
} catch (Exception ex) {
validateException(Edge.Exceptions.userSuppliedIdsNotSupported(), ex);
[17/46] incubator-tinkerpop git commit: Add CompileStatic compiler
customizer provider.
Posted by sp...@apache.org.
Add CompileStatic compiler customizer provider.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/8665a0fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/8665a0fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/8665a0fc
Branch: refs/heads/master
Commit: 8665a0fcd5cb74d38d59c37560ccf0ac7623b0dd
Parents: 9149c20
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 9 09:49:39 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 9 09:49:39 2015 -0400
----------------------------------------------------------------------
.../groovy/CompileStaticCustomizerProvider.java | 40 +++++++++
...mlinGroovyScriptEngineCompileStaticTest.java | 92 ++++++++++++++++++++
.../PreventCountDownLatchUsageExtension.groovy | 23 +++++
3 files changed, 155 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8665a0fc/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java
new file mode 100644
index 0000000..c7cdbeb
--- /dev/null
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java
@@ -0,0 +1,40 @@
+package org.apache.tinkerpop.gremlin.groovy;
+
+import groovy.transform.CompileStatic;
+import groovy.transform.TypeChecked;
+import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
+import org.codehaus.groovy.control.customizers.CompilationCustomizer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Injects the {@code CompileStatic} transformer to enable type validation on script execution.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class CompileStaticCustomizerProvider implements CompilerCustomizerProvider {
+
+ private final String extensions;
+
+ public CompileStaticCustomizerProvider() {
+ this(null);
+ }
+
+ public CompileStaticCustomizerProvider(final String extensions) {
+ this.extensions = extensions;
+ }
+
+ @Override
+ public CompilationCustomizer create() {
+ final Map<String, Object> compileStaticAnnotationParams = new HashMap<>();
+ if (extensions != null && !extensions.isEmpty()) {
+ if (extensions.contains(","))
+ compileStaticAnnotationParams.put("extensions", extensions.split(","));
+ else
+ compileStaticAnnotationParams.put("extensions", extensions);
+ }
+
+ return new ASTTransformationCustomizer(compileStaticAnnotationParams, CompileStatic.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8665a0fc/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java
new file mode 100644
index 0000000..d5ebc09
--- /dev/null
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.CompileStaticCustomizerProvider;
+import org.codehaus.groovy.control.MultipleCompilationErrorsException;
+import org.junit.Test;
+
+import javax.script.ScriptException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GremlinGroovyScriptEngineCompileStaticTest {
+ @Test
+ public void shouldCompileStatic() throws Exception {
+ // with no type checking this should pass
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine()) {
+ assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).red"));
+ }
+
+ final CompileStaticCustomizerProvider provider = new CompileStaticCustomizerProvider();
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) {
+ scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).red");
+ fail("Should have failed type checking");
+ } catch (ScriptException se) {
+ assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ }
+ }
+
+ @Test
+ public void shouldCompileStaticWithExtension() throws Exception {
+ // with no type checking extension this should pass
+ final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
+ }
+
+ final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider("PreventColorUsageExtension.groovy");
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
+ fail("Should have failed type checking");
+ } catch (ScriptException se) {
+ assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ }
+ }
+
+ @Test
+ public void shouldCompileStaticWithMultipleExtension() throws Exception {
+ // with no type checking extension this should pass
+ final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) {
+ assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
+ assertEquals(1l, scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count"));
+ }
+
+ final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
+ "PreventColorUsageExtension.groovy,PreventCountDownLatchUsageExtension.groovy");
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
+ fail("Should have failed type checking");
+ } catch (ScriptException se) {
+ assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ }
+
+ try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
+ scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count");
+ fail("Should have failed type checking");
+ } catch (ScriptException se) {
+ assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8665a0fc/gremlin-groovy/src/test/resources/PreventCountDownLatchUsageExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/resources/PreventCountDownLatchUsageExtension.groovy b/gremlin-groovy/src/test/resources/PreventCountDownLatchUsageExtension.groovy
new file mode 100644
index 0000000..74af460
--- /dev/null
+++ b/gremlin-groovy/src/test/resources/PreventCountDownLatchUsageExtension.groovy
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+onMethodSelection { expr, methodNode ->
+ if (methodNode.declaringClass.name=='java.util.concurrent.CountDownLatch') {
+ addStaticTypeError("Method call is not allowed!", expr)
+ }
+}
\ No newline at end of file
[40/46] incubator-tinkerpop git commit: Update changelog.
Posted by sp...@apache.org.
Update changelog.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/746d0f0f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/746d0f0f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/746d0f0f
Branch: refs/heads/master
Commit: 746d0f0fd16bf64392e7ca7dbc9600e7c2bd0425
Parents: 67d62fc
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 09:04:14 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 09:04:14 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/746d0f0f/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 1d015e8..8b607cd 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ TinkerPop 3.0.1 (NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Adjust configuration for javadoc generation to eliminate error messages.
+* Removed "reserved" graph concept names from tests (e.g. "label", "edge", "value") to support the convention of avoiding these strings for property names.
TinkerPop 3.0.0 (Release Date: July 9, 2015)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[36/46] incubator-tinkerpop git commit: Fixed incorrect spelling of
"changelog" - jeez
Posted by sp...@apache.org.
Fixed incorrect spelling of "changelog" - jeez
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/53c7cd97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/53c7cd97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/53c7cd97
Branch: refs/heads/master
Commit: 53c7cd97eaca275aa0a48e2ba653a99e4ca9a367
Parents: 248393d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 07:39:56 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 07:39:56 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/53c7cd97/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index fee028c..f33be5a 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -14,7 +14,7 @@ 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.
////
-TinkerPop3 CHANGEGLOG
+TinkerPop3 CHANGELOG
=====================
TinkerPop 3.0.0 (A Gremlin Rāga in 7/16 Time)
[19/46] incubator-tinkerpop git commit: Fixed a bug in how typecheck
extensions were registering.
Posted by sp...@apache.org.
Fixed a bug in how typecheck extensions were registering.
Was fooled into thinking this was working before because of a faulty test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/6252cfa9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/6252cfa9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/6252cfa9
Branch: refs/heads/master
Commit: 6252cfa96fb90d4a255cf4b5af9f51f57b7eab33
Parents: f933308
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 9 11:16:57 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 9 11:16:57 2015 -0400
----------------------------------------------------------------------
.../groovy/CompileStaticCustomizerProvider.java | 30 ++++++++--
.../groovy/TypeCheckedCustomizerProvider.java | 19 ++++++-
...mlinGroovyScriptEngineCompileStaticTest.java | 11 +++-
...remlinGroovyScriptEngineTypeCheckedTest.java | 12 +++-
.../groovy/jsr223/PrecompiledExtensions.java | 58 ++++++++++++++++++++
.../resources/PreventColorUsageExtension.groovy | 23 --------
.../PreventCountDownLatchUsageExtension.groovy | 23 --------
7 files changed, 118 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6252cfa9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java
index c7cdbeb..928f6cd 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompileStaticCustomizerProvider.java
@@ -1,12 +1,32 @@
+/*
+ * 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;
import groovy.transform.CompileStatic;
-import groovy.transform.TypeChecked;
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
import org.codehaus.groovy.control.customizers.CompilationCustomizer;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Injects the {@code CompileStatic} transformer to enable type validation on script execution.
@@ -27,14 +47,14 @@ public class CompileStaticCustomizerProvider implements CompilerCustomizerProvid
@Override
public CompilationCustomizer create() {
- final Map<String, Object> compileStaticAnnotationParams = new HashMap<>();
+ final Map<String, Object> annotationParams = new HashMap<>();
if (extensions != null && !extensions.isEmpty()) {
if (extensions.contains(","))
- compileStaticAnnotationParams.put("extensions", extensions.split(","));
+ annotationParams.put("extensions", Stream.of(extensions.split(",")).collect(Collectors.toList()));
else
- compileStaticAnnotationParams.put("extensions", extensions);
+ annotationParams.put("extensions", Collections.singletonList(extensions));
}
- return new ASTTransformationCustomizer(compileStaticAnnotationParams, CompileStatic.class);
+ return new ASTTransformationCustomizer(annotationParams, CompileStatic.class);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6252cfa9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java
index 14ff7ca..73f6434 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/TypeCheckedCustomizerProvider.java
@@ -22,8 +22,11 @@ import groovy.transform.TypeChecked;
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
import org.codehaus.groovy.control.customizers.CompilationCustomizer;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Injects the {@code TypeChecked} transformer to enable type validation on script execution.
@@ -38,14 +41,24 @@ public class TypeCheckedCustomizerProvider implements CompilerCustomizerProvider
this(null);
}
+ /**
+ * Configures the {@code TypeChecked} annotation to use optional extensions. The argument should be one or more
+ * groovy scripts on the classpath or the fully qualified classname of a precompiled extension. If there are
+ * multiple extensions then extensions should be comma separated.
+ */
public TypeCheckedCustomizerProvider(final String extensions) {
this.extensions = extensions;
}
@Override
public CompilationCustomizer create() {
- final Map<String, Object> timedInterruptAnnotationParams = new HashMap<>();
- if (extensions != null && !extensions.isEmpty()) timedInterruptAnnotationParams.put("extensions", extensions);
- return new ASTTransformationCustomizer(timedInterruptAnnotationParams, TypeChecked.class);
+ final Map<String, Object> annotationParams = new HashMap<>();
+ if (extensions != null && !extensions.isEmpty()) {
+ if (extensions.contains(","))
+ annotationParams.put("extensions", Stream.of(extensions.split(",")).collect(Collectors.toList()));
+ else
+ annotationParams.put("extensions", Collections.singletonList(extensions));
+ }
+ return new ASTTransformationCustomizer(annotationParams, TypeChecked.class);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6252cfa9/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java
index d5ebc09..466d223 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java
@@ -24,7 +24,9 @@ import org.junit.Test;
import javax.script.ScriptException;
+import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
@@ -55,12 +57,14 @@ public class GremlinGroovyScriptEngineCompileStaticTest {
assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
}
- final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider("PreventColorUsageExtension.groovy");
+ final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
+ PrecompiledExtensions.PreventColorUsageExtension.class.getName());
try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
fail("Should have failed type checking");
} catch (ScriptException se) {
assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ assertThat(se.getMessage(), containsString("Method call is not allowed!"));
}
}
@@ -74,12 +78,14 @@ public class GremlinGroovyScriptEngineCompileStaticTest {
}
final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
- "PreventColorUsageExtension.groovy,PreventCountDownLatchUsageExtension.groovy");
+ PrecompiledExtensions.PreventColorUsageExtension.class.getName() +
+ "," + PrecompiledExtensions.PreventCountDownLatchUsageExtension.class.getName());
try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
fail("Should have failed type checking");
} catch (ScriptException se) {
assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ assertThat(se.getMessage(), containsString("Method call is not allowed!"));
}
try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
@@ -87,6 +93,7 @@ public class GremlinGroovyScriptEngineCompileStaticTest {
fail("Should have failed type checking");
} catch (ScriptException se) {
assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ assertThat(se.getMessage(), containsString("Method call is not allowed!"));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6252cfa9/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
index b298750..97367e1 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java
@@ -18,13 +18,16 @@
*/
package org.apache.tinkerpop.gremlin.groovy.jsr223;
+import org.apache.tinkerpop.gremlin.groovy.CompileStaticCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.TypeCheckedCustomizerProvider;
import org.codehaus.groovy.control.MultipleCompilationErrorsException;
import org.junit.Test;
import javax.script.ScriptException;
+import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
@@ -55,12 +58,14 @@ public class GremlinGroovyScriptEngineTypeCheckedTest {
assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"));
}
- final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider("PreventColorUsageExtension.groovy");
+ final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
+ PrecompiledExtensions.PreventColorUsageExtension.class.getName());
try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
fail("Should have failed type checking");
} catch (ScriptException se) {
assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ assertThat(se.getMessage(), containsString("Method call is not allowed!"));
}
}
@@ -74,12 +79,14 @@ public class GremlinGroovyScriptEngineTypeCheckedTest {
}
final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider(
- "PreventColorUsageExtension.groovy,PreventCountDownLatchUsageExtension.groovy");
+ PrecompiledExtensions.PreventColorUsageExtension.class.getName() +
+ "," + PrecompiledExtensions.PreventCountDownLatchUsageExtension.class.getName());
try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red");
fail("Should have failed type checking");
} catch (ScriptException se) {
assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ assertThat(se.getMessage(), containsString("Method call is not allowed!"));
}
try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) {
@@ -87,6 +94,7 @@ public class GremlinGroovyScriptEngineTypeCheckedTest {
fail("Should have failed type checking");
} catch (ScriptException se) {
assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass());
+ assertThat(se.getMessage(), containsString("Method call is not allowed!"));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6252cfa9/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/PrecompiledExtensions.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/PrecompiledExtensions.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/PrecompiledExtensions.java
new file mode 100644
index 0000000..d9e6a5c
--- /dev/null
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/PrecompiledExtensions.java
@@ -0,0 +1,58 @@
+/*
+ * 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.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension;
+import org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class PrecompiledExtensions {
+ public static class PreventColorUsageExtension extends AbstractTypeCheckingExtension {
+
+ public PreventColorUsageExtension(final StaticTypeCheckingVisitor typeCheckingVisitor) {
+ super(typeCheckingVisitor);
+ }
+
+ @Override
+ public void onMethodSelection(final Expression expression, final MethodNode target) {
+ if (target.getDeclaringClass().getName().equals("java.awt.Color")) {
+ addStaticTypeError("Method call is not allowed!", expression);
+ }
+ }
+ }
+
+ public static class PreventCountDownLatchUsageExtension extends AbstractTypeCheckingExtension {
+
+ public PreventCountDownLatchUsageExtension(final StaticTypeCheckingVisitor typeCheckingVisitor) {
+ super(typeCheckingVisitor);
+ }
+
+ @Override
+ public void onMethodSelection(final Expression expression, final MethodNode target) {
+ if (target.getDeclaringClass().getName().equals("java.util.concurrent.CountDownLatch")) {
+ addStaticTypeError("Method call is not allowed!", expression);
+ }
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6252cfa9/gremlin-groovy/src/test/resources/PreventColorUsageExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/resources/PreventColorUsageExtension.groovy b/gremlin-groovy/src/test/resources/PreventColorUsageExtension.groovy
deleted file mode 100644
index 38eac69..0000000
--- a/gremlin-groovy/src/test/resources/PreventColorUsageExtension.groovy
+++ /dev/null
@@ -1,23 +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.
- */
-onMethodSelection { expr, methodNode ->
- if (methodNode.declaringClass.name=='java.awt.Color') {
- addStaticTypeError("Method call is not allowed!", expr)
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6252cfa9/gremlin-groovy/src/test/resources/PreventCountDownLatchUsageExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/resources/PreventCountDownLatchUsageExtension.groovy b/gremlin-groovy/src/test/resources/PreventCountDownLatchUsageExtension.groovy
deleted file mode 100644
index 74af460..0000000
--- a/gremlin-groovy/src/test/resources/PreventCountDownLatchUsageExtension.groovy
+++ /dev/null
@@ -1,23 +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.
- */
-onMethodSelection { expr, methodNode ->
- if (methodNode.declaringClass.name=='java.util.concurrent.CountDownLatch') {
- addStaticTypeError("Method call is not allowed!", expr)
- }
-}
\ No newline at end of file
[45/46] incubator-tinkerpop git commit: Update changelog.
Posted by sp...@apache.org.
Update changelog.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/2cf9f5e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/2cf9f5e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/2cf9f5e3
Branch: refs/heads/master
Commit: 2cf9f5e3e27991f5e50e49d66480f269287e573d
Parents: cacba0d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 16:59:56 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 16:59:56 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 4 ++++
1 file changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2cf9f5e3/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 830144e..cf7304d 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -29,6 +29,10 @@ TinkerPop 3.0.1 (NOT OFFICIALLY RELEASED YET)
* Removed "reserved" graph concept names from tests (e.g. "label", "edge", "value") to support the convention of avoiding these strings for property names.
* Introduced `GraphProvider.Descriptor` which annotates a `GraphProvider` implementation to describe what `GraphComputer` implementation will be used.
* Modified `OptOut` to include a `computers` attribute which allows the `Graph` to opt-out of computer-based tests for specific computation engines.
+* Added a `SandboxExtension` that can be plugged into `TypeCheckedCustomizerProvider` and `CompileStaticCustomizerProvider` to control classes and methods that can be used in the `GremlinGroovyScriptEngine`.
+* Added a number of new `ImportCustomizerProvider` implementations such as, `TimedInterruptCustomizerProvider`, `TypeCheckedCustomizerProvider` and others.
+* Refactored `GremlinGroovyScriptEngine` to make more general use of `ImportCustomizerProvider` implementations.
+* Removed dependency on `groovy-sandbox` from the `gremlin-groovy` module.
TinkerPop 3.0.0 (Release Date: July 9, 2015)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[15/46] incubator-tinkerpop git commit: Pull ThreadInterrupt compiler
provider tests to their own case.
Posted by sp...@apache.org.
Pull ThreadInterrupt compiler provider tests to their own case.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/6b8628be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/6b8628be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/6b8628be
Branch: refs/heads/master
Commit: 6b8628be701558ba1bf91f8713639f6d9fe33694
Parents: 44d8f37
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 9 08:29:07 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 9 08:29:07 2015 -0400
----------------------------------------------------------------------
.../jsr223/GremlinGroovyScriptEngineTest.java | 45 -----------
...inGroovyScriptEngineThreadInterruptTest.java | 78 ++++++++++++++++++++
2 files changed, 78 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6b8628be/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index 19f56d8..15c4cb4 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -23,7 +23,6 @@ import groovy.lang.Script;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.SecurityCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.ThreadInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -359,50 +358,6 @@ public class GremlinGroovyScriptEngineTest {
}
@Test
- public void shouldInterruptWhile() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(new ThreadInterruptCustomizerProvider());
- final AtomicBoolean asserted = new AtomicBoolean(false);
-
- final Thread t = new Thread(() -> {
- try {
- engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
- } catch (ScriptException se) {
- asserted.set(se.getCause().getCause() instanceof InterruptedException);
- }
- });
-
- t.start();
- Thread.sleep(100);
- t.interrupt();
- while(t.isAlive()) {}
-
- assertTrue(asserted.get());
- }
-
- @Test
- public void shouldNotInterruptWhile() throws Exception {
- // companion to shouldInterruptWhile t
- final ScriptEngine engine = new GremlinGroovyScriptEngine();
- final AtomicBoolean exceptionFired = new AtomicBoolean(true);
-
- final Thread t = new Thread(() -> {
- try {
- engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 2000) {};'test'");
- exceptionFired.set(false);
- } catch (ScriptException se) {
- se.printStackTrace();
- }
- });
-
- t.start();
- Thread.sleep(100);
- t.interrupt();
- while(t.isAlive()) {}
-
- assertFalse(exceptionFired.get());
- }
-
- @Test
public void shouldNotTimeoutStandaloneFunction() throws Exception {
// use a super fast timeout which should not prevent the call of a cached function
final ScriptEngine engine = new GremlinGroovyScriptEngine(
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6b8628be/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java
new file mode 100644
index 0000000..939453f
--- /dev/null
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.ThreadInterruptCustomizerProvider;
+import org.junit.Test;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GremlinGroovyScriptEngineThreadInterruptTest {
+ @Test
+ public void shouldInterruptWhile() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(new ThreadInterruptCustomizerProvider());
+ final AtomicBoolean asserted = new AtomicBoolean(false);
+
+ final Thread t = new Thread(() -> {
+ try {
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
+ } catch (ScriptException se) {
+ asserted.set(se.getCause().getCause() instanceof InterruptedException);
+ }
+ });
+
+ t.start();
+ Thread.sleep(100);
+ t.interrupt();
+ while(t.isAlive()) {}
+
+ assertTrue(asserted.get());
+ }
+
+ @Test
+ public void shouldNotInterruptWhile() throws Exception {
+ // companion to shouldInterruptWhile t
+ final ScriptEngine engine = new GremlinGroovyScriptEngine();
+ final AtomicBoolean exceptionFired = new AtomicBoolean(true);
+
+ final Thread t = new Thread(() -> {
+ try {
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 2000) {};'test'");
+ exceptionFired.set(false);
+ } catch (ScriptException se) {
+ se.printStackTrace();
+ }
+ });
+
+ t.start();
+ Thread.sleep(100);
+ t.interrupt();
+ while(t.isAlive()) {}
+
+ assertFalse(exceptionFired.get());
+ }
+}
[23/46] incubator-tinkerpop git commit: Lay some foundations for
method whitelisting in the sandbox.
Posted by sp...@apache.org.
Lay some foundations for method whitelisting in the sandbox.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/6af00c69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/6af00c69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/6af00c69
Branch: refs/heads/master
Commit: 6af00c6984c206e1fea2cb30305a877c54ef1e73
Parents: e598829
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 10 08:50:28 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 10 08:50:28 2015 -0400
----------------------------------------------------------------------
.../groovy/jsr223/SandboxExtension.groovy | 52 ++++++++++++++++++--
.../jsr223/GremlinGroovyScriptEngine.java | 32 ++++++------
2 files changed, 64 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6af00c69/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
index 4888f8c..d62ccb3 100644
--- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
+++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/jsr223/SandboxExtension.groovy
@@ -21,21 +21,40 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
import org.apache.tinkerpop.gremlin.structure.Graph
import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.MethodNode
+import org.codehaus.groovy.ast.Parameter
+import org.codehaus.groovy.ast.expr.Expression
import org.codehaus.groovy.ast.expr.VariableExpression
+import org.codehaus.groovy.transform.stc.ExtensionMethodNode
import org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport
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 typically extend this class to modify features.
+ *
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDSL {
+ public static final BiPredicate<VariableExpression, Map<String,ClassNode>> VARIABLES_ALLOW_ALL = { var, types -> true }
+
+ public static final BiPredicate<VariableExpression, Map<String,ClassNode>> METHODS_ALLOW_ALL = { exp, method -> true }
+ public static final BiPredicate<Expression, MethodNode> METHODS_REGEX_WHITELIST = { exp, method ->
+ def descriptor = toMethodDescriptor(method)
+ !methodList.any { descriptor =~ it }
+ }
+ public static final BiPredicate<Expression, MethodNode> METHODS_REGEX_BLACKLIST = { exp, method -> !METHODS_REGEX_WHITELIST.test(exp, method) }
+
protected boolean graphIsAlwaysGraphInstance = true
protected boolean gIsAlwaysGraphTraversalSource = true
- protected BiPredicate<VariableExpression, Map<String,ClassNode>> filter = USE_ALL
-
- public static final BiPredicate<VariableExpression, Map<String,ClassNode>> USE_ALL = { var, types -> true }
+ protected BiPredicate<VariableExpression, Map<String,ClassNode>> variableFilter = VARIABLES_ALLOW_ALL
+ protected BiPredicate<Expression, MethodNode> methodFilter = METHODS_ALLOW_ALL
+ protected List<String> methodList = new ArrayList<String>();
@Override
Object run() {
@@ -54,7 +73,7 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
final Map<String,ClassNode> varTypes = (Map<String,ClassNode>) GremlinGroovyScriptEngine.COMPILE_OPTIONS.get()
.get(GremlinGroovyScriptEngine.COMPILE_OPTIONS_VAR_TYPES)
- if (varTypes.containsKey(var.name) && filter.test(var, varTypes)
+ if (varTypes.containsKey(var.name) && variableFilter.test(var, varTypes)
|| (var.name == "graph" && !graphIsAlwaysGraphInstance
|| var.name == "g" && !gIsAlwaysGraphTraversalSource)) {
storeType(var, varTypes.get(var.name))
@@ -62,5 +81,30 @@ class SandboxExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDS
return
}
}
+
+ onMethodSelection { expr, MethodNode methodNode ->
+ if (!methodFilter.test(expr, methodNode))
+ addStaticTypeError("Not authorized to call this method: $descr", expr)
+ }
+ }
+
+ private static String prettyPrint(ClassNode node) {
+ node.isArray()?"${prettyPrint(node.componentType)}[]":node.toString(false)
+ }
+
+ private 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
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6af00c69/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 09af47f..d484d4e 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
@@ -84,6 +84,7 @@ import java.util.stream.Collectors;
public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements DependencyManager, AutoCloseable {
public static final String COMPILE_OPTIONS_VAR_TYPES = "sandbox.bindings";
+ public static final String COMPILE_OPTIONS_WHITELIST = "sandbox.whitelist";
public static final String KEY_REFERENCE_TYPE = "#jsr223.groovy.engine.keep.globals";
public static final String REFERENCE_TYPE_PHANTOM = "phantom";
public static final String REFERENCE_TYPE_WEAK = "weak";
@@ -148,12 +149,12 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
GremlinLoader.load();
- this.importCustomizerProvider = providers.stream()
+ importCustomizerProvider = providers.stream()
.filter(p -> p instanceof ImportCustomizerProvider)
.map(p -> (ImportCustomizerProvider) p)
.findFirst().orElse(NoImportCustomizerProvider.INSTANCE);
- this.securityProvider = providers.stream()
+ securityProvider = providers.stream()
.filter(p -> p instanceof SecurityCustomizerProvider)
.map(p -> (SecurityCustomizerProvider) p)
.findFirst();
@@ -238,8 +239,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
// use the EmptyImportCustomizer because it doesn't come with static initializers containing
// existing imports.
- this.importCustomizerProvider = new EmptyImportCustomizerProvider(
- this.importCustomizerProvider, imports, staticImports);
+ importCustomizerProvider = new EmptyImportCustomizerProvider(importCustomizerProvider, imports, staticImports);
reset();
}
@@ -249,25 +249,25 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
@Override
public void close() throws Exception {
- this.securityProvider.ifPresent(SecurityCustomizerProvider::unregisterInterceptors);
+ securityProvider.ifPresent(SecurityCustomizerProvider::unregisterInterceptors);
}
@Override
public void reset() {
- this.securityProvider.ifPresent(SecurityCustomizerProvider::unregisterInterceptors);
+ securityProvider.ifPresent(SecurityCustomizerProvider::unregisterInterceptors);
createClassLoader();
// must clear the local cache here because the the classloader has been reset. therefore, classes previously
// referenced before that might not have evaluated might cleanly evaluate now.
- this.classMap.clear();
- this.globalClosures.clear();
+ classMap.clear();
+ globalClosures.clear();
- this.loadedPlugins.clear();
+ loadedPlugins.clear();
final Set<Artifact> toReuse = new HashSet<>(artifactsToUse);
toReuse.forEach(this::use);
- this.getContext().getBindings(ScriptContext.ENGINE_SCOPE).clear();
+ getContext().getBindings(ScriptContext.ENGINE_SCOPE).clear();
}
private void use(final Artifact artifact) {
@@ -315,10 +315,10 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
@Override
public ScriptEngineFactory getFactory() {
- if (this.factory == null) {
+ if (factory == null) {
synchronized (this) {
- if (this.factory == null) {
- this.factory = new GremlinGroovyScriptEngineFactory();
+ if (factory == null) {
+ factory = new GremlinGroovyScriptEngineFactory();
}
}
}
@@ -476,9 +476,9 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
}
private void ensureSandbox() {
- if (securityProvider.isPresent() && !this.registeredSandbox.get()) {
- this.securityProvider.get().registerInterceptors();
- this.registeredSandbox.set(true);
+ if (securityProvider.isPresent() && !registeredSandbox.get()) {
+ securityProvider.get().registerInterceptors();
+ registeredSandbox.set(true);
}
}
[32/46] incubator-tinkerpop git commit: A bit more pom.xml cleanup to
centralize version definitions.
Posted by sp...@apache.org.
A bit more pom.xml cleanup to centralize version definitions.
Dependency management doesn't seem to stretch to javadoc <additionalDependencies> - version must be explicit there.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/712c7b3a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/712c7b3a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/712c7b3a
Branch: refs/heads/master
Commit: 712c7b3a4a672638400c276599dcb1dc5ed970d5
Parents: 8ca05b2
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Jul 14 07:26:33 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Jul 14 07:26:33 2015 -0400
----------------------------------------------------------------------
gremlin-core/pom.xml | 5 ++---
pom.xml | 13 ++++++++-----
2 files changed, 10 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/712c7b3a/gremlin-core/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-core/pom.xml b/gremlin-core/pom.xml
index 08fcf16..f739355 100644
--- a/gremlin-core/pom.xml
+++ b/gremlin-core/pom.xml
@@ -33,7 +33,6 @@ limitations under the License.
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
- <version>1.10</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
@@ -44,7 +43,7 @@ limitations under the License.
<dependency>
<groupId>org.javatuples</groupId>
<artifactId>javatuples</artifactId>
- <version>1.2</version>
+ <version>${java.tuples.version}</version>
</dependency>
<dependency>
<groupId>com.carrotsearch</groupId>
@@ -54,7 +53,7 @@ limitations under the License.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
- <version>2.5.3</version>
+ <version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/712c7b3a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0418ead..769f84f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -139,6 +139,9 @@ limitations under the License.
<skipPerformanceTests>true</skipPerformanceTests>
<slf4j.version>1.7.12</slf4j.version>
<hadoop.version>1.2.1</hadoop.version>
+ <commons.configuration.version>1.10</commons.configuration.version>
+ <java.tuples.version>1.2</java.tuples.version>
+ <jackson.version>2.5.3</jackson.version>
<javadoc-plugin.version>2.10.1</javadoc-plugin.version>
<muteTestLogs>false</muteTestLogs>
</properties>
@@ -465,7 +468,7 @@ limitations under the License.
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
- <version>1.10</version>
+ <version>${commons.configuration.version}</version>
<exclusions>
<!-- self-conflict -->
<exclusion>
@@ -826,22 +829,22 @@ limitations under the License.
<additionalDependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
- <version>1.10</version>
+ <version>${commons.configuration.version}</version>
</additionalDependency>
<additionalDependency>
<groupId>org.javatuples</groupId>
<artifactId>javatuples</artifactId>
- <version>1.2</version>
+ <version>${java.tuples.version}</version>
</additionalDependency>
<additionalDependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
- <version>2.5.3</version>
+ <version>${jackson.version}</version>
</additionalDependency>
<additionalDependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
- <version>2.5.3</version>
+ <version>${jackson.version}</version>
</additionalDependency>
<additionalDependency>
<groupId>org.apache.tinkerpop</groupId>
[31/46] incubator-tinkerpop git commit: More adjustments to pom
around javadoc generation.
Posted by sp...@apache.org.
More adjustments to pom around javadoc generation.
Now it's really working without error/warns - was a bit fooled on previous attempts by accident. Still unsure why it is necessary to apply <additionalDependencies> the javadoc plugin, but it must have something to do with file exclusion because the "full" javadocs don't seem to have WARN/ERROR messages - just "core". Anyway, appears to be working properly now.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/8ca05b26
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/8ca05b26
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/8ca05b26
Branch: refs/heads/master
Commit: 8ca05b262c40504273f767388850f90f0e0cb044
Parents: 9f28020
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jul 13 17:13:49 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 13 17:13:49 2015 -0400
----------------------------------------------------------------------
pom.xml | 112 ++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 68 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8ca05b26/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d50c663..0418ead 100644
--- a/pom.xml
+++ b/pom.xml
@@ -750,12 +750,9 @@ limitations under the License.
<destDir>full</destDir>
<additionalparam>-Xdoclint:none</additionalparam>
<quiet>true</quiet>
- <includeDependencySources>true</includeDependencySources>
- <dependencySourceIncludes>
- <dependencySourceInclude>org.apache.tinkerpop:*</dependencySourceInclude>
- </dependencySourceIncludes>
- <detectLinks>false</detectLinks>
- <detectOfflineLinks>false</detectOfflineLinks>
+ <sourcepath>
+ hadoop-gremlin/src/main/java:gremlin-core/src/main/java:gremlin-driver/src/main/java:gremlin-groovy/src/main/java:gremlin-server/src/main/java:gremlin-test/src/main/java:tinkergraph-gremlin/src/main/java
+ </sourcepath>
</configuration>
</execution>
<execution>
@@ -769,62 +766,89 @@ limitations under the License.
<destDir>core</destDir>
<additionalparam>-Xdoclint:none</additionalparam>
<quiet>true</quiet>
+ <sourcepath>
+ gremlin-core/src/main/java:gremlin-driver/src/main/java
+ </sourcepath>
<sourceFileIncludes>
<!-- structure -->
- <sourceFileInclude>org/apache/tinkerpop/gremlin/structure/*.java
- </sourceFileInclude>
+ <include>org/apache/tinkerpop/gremlin/structure/*.java
+ </include>
<!-- io -->
- <sourceFileInclude>org/apache/tinkerpop/gremlin/structure/io/*.java
- </sourceFileInclude>
- <sourceFileInclude>
+ <include>org/apache/tinkerpop/gremlin/structure/io/*.java
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
- </sourceFileInclude>
- <sourceFileInclude>
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
- </sourceFileInclude>
- <sourceFileInclude>
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
- </sourceFileInclude>
- <sourceFileInclude>
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWriter.java
- </sourceFileInclude>
- <sourceFileInclude>
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
- </sourceFileInclude>
- <sourceFileInclude>
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/structure/io/gryo/GryoWriter.java
- </sourceFileInclude>
+ </include>
<!-- process -->
- <sourceFileInclude>org/apache/tinkerpop/gremlin/process/*.java
- </sourceFileInclude>
+ <include>org/apache/tinkerpop/gremlin/process/*.java
+ </include>
<!-- computer -->
- <sourceFileInclude>org/apache/tinkerpop/gremlin/process/computer/*.java
- </sourceFileInclude>
- <sourceFileInclude>
+ <include>org/apache/tinkerpop/gremlin/process/computer/*.java
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
- </sourceFileInclude>
- <sourceFileInclude>
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
- </sourceFileInclude>
- <sourceFileInclude>
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/process/computer/traversal/TraversalVertexProgram.java
- </sourceFileInclude>
+ </include>
<!-- traversal -->
- <sourceFileInclude>org/apache/tinkerpop/gremlin/process/traversal/*.java
- </sourceFileInclude>
- <sourceFileInclude>
+ <include>org/apache/tinkerpop/gremlin/process/traversal/*.java
+ </include>
+ <include>
org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
- </sourceFileInclude>
+ </include>
<!-- driver -->
- <sourceFileInclude>org/apache/tinkerpop/gremlin/driver/*.java
- </sourceFileInclude>
+ <include>org/apache/tinkerpop/gremlin/driver/*.java
+ </include>
</sourceFileIncludes>
- <includeDependencySources>true</includeDependencySources>
- <dependencySourceIncludes>
- <dependencySourceInclude>org.apache.tinkerpop:*</dependencySourceInclude>
- </dependencySourceIncludes>
- <detectLinks>false</detectLinks>
- <detectOfflineLinks>false</detectOfflineLinks>
+ <!-- add dependencies as necessary here - not sure why this is necessary, but assume
+ it is related to the <sourceFileIncludes> as ERROR messages do not appear on
+ build for the "full" javadocs -->
+ <additionalDependencies>
+ <additionalDependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.10</version>
+ </additionalDependency>
+ <additionalDependency>
+ <groupId>org.javatuples</groupId>
+ <artifactId>javatuples</artifactId>
+ <version>1.2</version>
+ </additionalDependency>
+ <additionalDependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.5.3</version>
+ </additionalDependency>
+ <additionalDependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.5.3</version>
+ </additionalDependency>
+ <additionalDependency>
+ <groupId>org.apache.tinkerpop</groupId>
+ <artifactId>gremlin-shaded</artifactId>
+ <version>${project.version}</version>
+ </additionalDependency>
+ </additionalDependencies>
</configuration>
</execution>
</executions>
[04/46] incubator-tinkerpop git commit: Update javadoc.
Posted by sp...@apache.org.
Update javadoc.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/ce9d090f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/ce9d090f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/ce9d090f
Branch: refs/heads/master
Commit: ce9d090f9f8a79fc51f247b73a3315be37b776c8
Parents: 569ef03
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 12:02:27 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 12:02:27 2015 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java | 8 ++++++++
.../gremlin/groovy/EmptyImportCustomizerProvider.java | 3 +--
2 files changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ce9d090f/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java
index b0b6f29..a633ff2 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java
@@ -18,11 +18,19 @@
*/
package org.apache.tinkerpop.gremlin.groovy;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
import org.codehaus.groovy.control.customizers.CompilationCustomizer;
/**
+ * Provides a way to plugin Groovy {@code CompilationCustomizer} implementations to the
+ * {@link GremlinGroovyScriptEngine}.
+ *
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public interface CompilerCustomizerProvider {
+
+ /**
+ * Create a new instance of a {@code CompilationCustomizer} to add to the {@link GremlinGroovyScriptEngine}.
+ */
public CompilationCustomizer getCompilationCustomizer();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ce9d090f/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java
index 4400e8f..03e86c9 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java
@@ -26,8 +26,7 @@ import java.util.HashSet;
import java.util.Set;
/**
- * This {@link org.apache.tinkerpop.gremlin.groovy.ImportCustomizerProvider} is empty and comes with no pre-defined imports
- * at all.
+ * This {@link ImportCustomizerProvider} is empty and comes with no pre-defined imports at all.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
[43/46] incubator-tinkerpop git commit: Update docs around the new
OptOut options.
Posted by sp...@apache.org.
Update docs around the new OptOut options.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/99e89be3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/99e89be3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/99e89be3
Branch: refs/heads/master
Commit: 99e89be3555dd50ad7795db977a6034dad74658d
Parents: 7f143f0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 16:29:19 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 16:29:19 2015 -0400
----------------------------------------------------------------------
docs/src/implementations.asciidoc | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/99e89be3/docs/src/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/implementations.asciidoc b/docs/src/implementations.asciidoc
index 8dc2247..3e9e5c5 100644
--- a/docs/src/implementations.asciidoc
+++ b/docs/src/implementations.asciidoc
@@ -369,6 +369,7 @@ The above examples show how to ignore individual tests. It is also possible to:
* Ignore an entire test case (i.e. all the methods within the test) by setting the `method` to "*".
* Ignore a "base" test class such that test that extend from those classes will all be ignored. This style of ignoring is useful for Gremlin "process" tests that have bases classes that are extended by various Gremlin flavors (e.g. groovy).
+* Ignore a `GraphComputer` test based on the type of `GraphComputer` being used. Specify the "computer" attribute on the `OptOut` (which is an array specification) which should have a value of the `GraphComputer` implementation class that should ignore that test. This attribute should be left empty for "standard" execution and by default all `GraphComputer` implementations will be included in the `OptOut` so if there are multiple implementations, explicitly specify the ones that should be excluded.
Also note that some of the tests in the Gremlin Test Suite are parameterized tests and require an additional level of specificity to be properly ignored. To ignore these types of tests, examine the name template of the parameterized tests. It is defined by a Java annotation that looks like this:
[37/46] incubator-tinkerpop git commit: Merge branch
'tp30-javadoc-fix' into tp30
Posted by sp...@apache.org.
Merge branch 'tp30-javadoc-fix' into tp30
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/35af2a11
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/35af2a11
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/35af2a11
Branch: refs/heads/master
Commit: 35af2a11ddc65f6a7eb38efed1c7822cc39a01c4
Parents: 53c7cd9 d5466aa8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 15 08:56:47 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 15 08:56:47 2015 -0400
----------------------------------------------------------------------
gremlin-core/pom.xml | 4 +-
pom.xml | 151 ++++++++++++++++++++++++----------------------
2 files changed, 80 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
[21/46] incubator-tinkerpop git commit: Break out sandboxed
scriptengine tests to their own case.
Posted by sp...@apache.org.
Break out sandboxed scriptengine tests to their own case.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/927b5ef4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/927b5ef4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/927b5ef4
Branch: refs/heads/master
Commit: 927b5ef4966bec02e65a8fec6698ce094d05764b
Parents: c47426d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 10 07:43:05 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 10 07:43:05 2015 -0400
----------------------------------------------------------------------
.../gremlin/groovy/GroovyEnvironmentSuite.java | 7 +-
.../GremlinGroovyScriptEngineOverGraphTest.java | 136 -------------------
...GroovyScriptEngineSandboxedStandardTest.java | 131 ++++++++++++++++++
3 files changed, 133 insertions(+), 141 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/927b5ef4/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 4a775f4..c553542 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
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.GraphManager;
import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorOverGraphTest;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineOverGraphTest;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineSandboxedStandardTest;
import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader;
import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoaderTest;
import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper;
@@ -32,11 +33,6 @@ import org.apache.tinkerpop.gremlin.structure.StructureStandardSuite;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
/**
* The {@code GroovyEnvironmentSuite} is a JUnit test runner that executes the Gremlin Test Suite over a
* {@link Graph} implementation. This test suite covers ensures that a vendor implementation is compliant with
@@ -55,6 +51,7 @@ public class GroovyEnvironmentSuite extends AbstractGremlinSuite {
*/
private static final Class<?>[] allTests = new Class<?>[]{
GremlinGroovyScriptEngineOverGraphTest.class,
+ GremlinGroovyScriptEngineSandboxedStandardTest.class,
GremlinExecutorOverGraphTest.class,
SugarLoaderTest.class,
};
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/927b5ef4/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
index c72bfd5..a8899c7 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
@@ -239,142 +239,6 @@ public class GremlinGroovyScriptEngineOverGraphTest extends AbstractGremlinTest
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldEvalGraphTraversalSourceWithTypeChecked() throws Exception {
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
- final Bindings bindings = engine.createBindings();
- bindings.put("g", g);
- assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
- }
-
- final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("g", g);
- engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings);
- fail("Type checking should have forced an error as 'g' is not defined");
- } catch (Exception ex) {
- assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
- assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
- }
-
- final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider(
- SandboxExtension.class.getName());
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("g", g);
- assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
- assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
- }
- }
-
- @Test
- @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldEvalGraphWithTypeChecked() throws Exception {
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
- final Bindings bindings = engine.createBindings();
- bindings.put("graph", graph);
- assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
- }
-
- final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("graph", graph);
- assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
- fail("Type checking should have forced an error as 'graph' is not defined");
- } catch (Exception ex) {
- assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
- assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
- }
-
- final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider(
- SandboxExtension.class.getName());
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("graph", graph);
- assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
- }
- }
-
- @Test
- @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldEvalGraphTraversalSourceWithCompileStatic() throws Exception {
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
- final Bindings bindings = engine.createBindings();
- bindings.put("g", g);
- assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
- }
-
- final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("g", g);
- engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings);
- fail("Type checking should have forced an error as 'g' is not defined");
- } catch (Exception ex) {
- assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
- assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
- }
-
- final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
- SandboxExtension.class.getName());
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("g", g);
- assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
- assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
- }
- }
-
- @Test
- @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldEvalGraphWithCompileStatic() throws Exception {
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
- final Bindings bindings = engine.createBindings();
- bindings.put("graph", graph);
- assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
- }
-
- final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("graph", graph);
- assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
- fail("Type checking should have forced an error as 'graph' is not defined");
- } catch (Exception ex) {
- assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
- assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
- }
-
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("graph", graph);
- bindings.put("x", convertToVertexId("marko"));
- assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
- fail("Type checking should have forced an error as 'graph' is not defined");
- } catch (Exception ex) {
- assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
- assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
- }
-
- final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
- SandboxExtension.class.getName());
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("graph", graph);
- assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
- }
-
- try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
- final Bindings bindings = engine.createBindings();
- bindings.put("graph", graph);
- bindings.put("x", convertToVertexId("marko"));
- assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
- }
- }
-
- @Test
- @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldEvalGlobalClosuresEvenAfterEvictionOfClass() throws ScriptException {
final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/927b5ef4/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
new file mode 100644
index 0000000..7f55e78
--- /dev/null
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.CompileStaticCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.TypeCheckedCustomizerProvider;
+import org.codehaus.groovy.control.MultipleCompilationErrorsException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import javax.script.Bindings;
+
+import java.util.Arrays;
+
+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)
+ */
+@RunWith(Parameterized.class)
+public class GremlinGroovyScriptEngineSandboxedStandardTest extends AbstractGremlinTest {
+ @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())}});
+ }
+
+ @Parameterized.Parameter(value = 0)
+ public String name;
+
+ @Parameterized.Parameter(value = 1)
+ public CompilerCustomizerProvider notSandboxed;
+
+ @Parameterized.Parameter(value = 2)
+ public CompilerCustomizerProvider sandboxed;
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldEvalGraphTraversalSource() throws Exception {
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings);
+ fail("Type checking should have forced an error as 'g' is not defined");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
+ }
+
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", g);
+ assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+ assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
+ }
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldEvalGraph() throws Exception {
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ fail("Type checking should have forced an error as 'graph' is not defined");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
+ }
+
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ bindings.put("x", convertToVertexId("marko"));
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
+ fail("Type checking should have forced an error as 'graph' is not defined");
+ } catch (Exception ex) {
+ assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+ assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
+ }
+
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+ }
+
+ try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) {
+ final Bindings bindings = engine.createBindings();
+ bindings.put("graph", graph);
+ bindings.put("x", convertToVertexId("marko"));
+ assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
+ }
+ }
+}