Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 39D73200BE2 for ; Thu, 1 Dec 2016 00:46:12 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 386C2160B13; Wed, 30 Nov 2016 23:46:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3CEAC160B28 for ; Thu, 1 Dec 2016 00:46:10 +0100 (CET) Received: (qmail 3557 invoked by uid 500); 30 Nov 2016 23:46:09 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 3544 invoked by uid 99); 30 Nov 2016 23:46:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Nov 2016 23:46:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3375AF1823; Wed, 30 Nov 2016 23:46:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: spmallette@apache.org To: commits@tinkerpop.apache.org Date: Wed, 30 Nov 2016 23:46:12 -0000 Message-Id: <5002d88c9bd6420faaebedf0b59fce92@git.apache.org> In-Reply-To: <568f4f58c274426a83fbc2020be7e34a@git.apache.org> References: <568f4f58c274426a83fbc2020be7e34a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/4] tinkerpop git commit: TINKERPOP-1562 Make all groovy customizer providers straight Customizer instances archived-at: Wed, 30 Nov 2016 23:46:12 -0000 TINKERPOP-1562 Make all groovy customizer providers straight Customizer instances Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6b8eb7f9 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6b8eb7f9 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6b8eb7f9 Branch: refs/heads/TINKERPOP-1562 Commit: 6b8eb7f9eb974ad9fbbd62f5baecc76056795677 Parents: 4a12593 Author: Stephen Mallette Authored: Wed Nov 30 18:43:13 2016 -0500 Committer: Stephen Mallette Committed: Wed Nov 30 18:43:13 2016 -0500 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + .../tinkerpop/gremlin/util/CoreImports.java | 34 +++++-- .../jsr223/CompileStaticGroovyCustomizer.java | 60 ++++++++++++ .../jsr223/ConfigurationGroovyCustomizer.java | 82 +++++++++++++++++ .../jsr223/CustomizerProviderCustomizer.java | 40 -------- .../jsr223/GremlinGroovyScriptEngine.java | 97 ++++++++++---------- .../jsr223/GroovyCompilerGremlinPlugin.java | 18 ++-- .../gremlin/groovy/jsr223/GroovyCustomizer.java | 33 +++++++ .../groovy/jsr223/ImportGroovyCustomizer.java | 66 +++++++++++++ .../jsr223/InterpreterModeGroovyCustomizer.java | 36 ++++++++ .../jsr223/ThreadInterruptGroovyCustomizer.java | 35 +++++++ .../jsr223/TimedInterruptGroovyCustomizer.java | 62 +++++++++++++ .../jsr223/TimedInterruptTimeoutException.java | 38 ++++++++ .../jsr223/TypeCheckedGroovyCustomizer.java | 65 +++++++++++++ .../CompileStaticCustomizerProvider.java | 2 + .../ConfigurationCustomizerProvider.java | 2 + .../InterpreterModeCustomizerProvider.java | 4 + .../ThreadInterruptCustomizerProvider.java | 2 + .../TimedInterruptCustomizerProvider.java | 2 + .../TimedInterruptTimeoutException.java | 4 + .../TypeCheckedCustomizerProvider.java | 2 + .../VariableIdentificationCustomizer.java | 2 + ...mlinGroovyScriptEngineCompileStaticTest.java | 20 ++-- .../GremlinGroovyScriptEngineConfigTest.java | 5 +- .../jsr223/GremlinGroovyScriptEngineTest.java | 6 +- ...inGroovyScriptEngineThreadInterruptTest.java | 2 +- ...linGroovyScriptEngineTimedInterruptTest.java | 22 ++--- ...remlinGroovyScriptEngineTypeCheckedTest.java | 18 ++-- .../jsr223/GroovyCompilerGremlinPluginTest.java | 14 +-- .../server/op/AbstractEvalOpProcessor.java | 5 + 30 files changed, 625 insertions(+), 154 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 39fb56a..18415d2 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -42,6 +42,7 @@ TinkerPop 3.2.4 (Release Date: NOT OFFICIALLY RELEASED YET) * Fixed a `NoSuchElementException` bug with `GroupXXXStep` where if the reduced `TraverserSet` is empty, don't add the key/value. * Fixed a `NullPointerException` bug with profiling `GroupSideEffectStep` in OLTP. * Improved ability to release resources in `GraphProvider` instances in the test suite. +* Factored `GremlinPlugin` functionality out of gremlin-groovy and into gremlin-core - related classes were deprecated. * Added a `force` option for killing sessions without waiting for transaction close or timeout of a currently running job or multiple jobs. * Deprecated `Session.kill()` and `Session.manualKill()`. * Added `choose(predicate,traversal)` and `choose(traversal,traversal)` to effect if/then-semantics (no else). Equivalent to `choose(x,y,identity())`. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/CoreImports.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/CoreImports.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/CoreImports.java index e6c64fd..1c6a6e6 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/CoreImports.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/CoreImports.java @@ -83,12 +83,15 @@ import org.apache.tinkerpop.gremlin.structure.io.Io; import org.apache.tinkerpop.gremlin.structure.io.IoCore; import org.apache.tinkerpop.gremlin.structure.io.Storage; import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; +import org.javatuples.Pair; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -187,11 +190,11 @@ public final class CoreImports { // METHODS // ///////////// - Stream.of(IoCore.class.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).forEach(METHOD_IMPORTS::add); - Stream.of(P.class.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).forEach(METHOD_IMPORTS::add); - Stream.of(__.class.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).filter(m -> !m.getName().equals("__")).forEach(METHOD_IMPORTS::add); - Stream.of(Computer.class.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).forEach(METHOD_IMPORTS::add); - Stream.of(TimeUtil.class.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).forEach(METHOD_IMPORTS::add); + uniqueMethods(IoCore.class).forEach(METHOD_IMPORTS::add); + uniqueMethods(P.class).forEach(METHOD_IMPORTS::add); + uniqueMethods(__.class).filter(m -> !m.getName().equals("__")).forEach(METHOD_IMPORTS::add); + uniqueMethods(Computer.class).forEach(METHOD_IMPORTS::add); + uniqueMethods(TimeUtil.class).forEach(METHOD_IMPORTS::add); /////////// // ENUMS // @@ -207,7 +210,6 @@ public final class CoreImports { Collections.addAll(ENUM_IMPORTS, Scope.values()); Collections.addAll(ENUM_IMPORTS, T.values()); Collections.addAll(ENUM_IMPORTS, TraversalOptionParent.Pick.values()); - } private CoreImports() { @@ -225,4 +227,24 @@ public final class CoreImports { public static Set getEnumImports() { return Collections.unmodifiableSet(ENUM_IMPORTS); } + + /** + * Filters to unique method names on each class. + */ + private static Stream uniqueMethods(final Class clazz) { + final Set unique = new HashSet<>(); + return Stream.of(clazz.getMethods()) + .filter(m -> Modifier.isStatic(m.getModifiers())) + .map(m -> Pair.with(generateMethodDescriptor(m), m)) + .filter(p -> { + final boolean exists = unique.contains(p.getValue0()); + if (!exists) unique.add(p.getValue0()); + return !exists; + }) + .map(Pair::getValue1); + } + + private static String generateMethodDescriptor(final Method m) { + return m.getDeclaringClass().getCanonicalName() + "." + m.getName(); + } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompileStaticGroovyCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompileStaticGroovyCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompileStaticGroovyCustomizer.java new file mode 100644 index 0000000..c57e64b --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompileStaticGroovyCustomizer.java @@ -0,0 +1,60 @@ +/* + * 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 groovy.transform.CompileStatic; +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. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +class CompileStaticGroovyCustomizer implements GroovyCustomizer { + + private final String extensions; + + CompileStaticGroovyCustomizer() { + this(null); + } + + CompileStaticGroovyCustomizer(final String extensions) { + this.extensions = extensions; + } + + @Override + public CompilationCustomizer create() { + final Map 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, CompileStatic.class); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ConfigurationGroovyCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ConfigurationGroovyCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ConfigurationGroovyCustomizer.java new file mode 100644 index 0000000..23fe002 --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ConfigurationGroovyCustomizer.java @@ -0,0 +1,82 @@ +/* + * 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.util.ElementHelper; +import org.codehaus.groovy.control.CompilerConfiguration; +import org.codehaus.groovy.control.customizers.CompilationCustomizer; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * Allows configurations to be directly supplied to a groovy {@code CompilerConfiguration} when a + * {@link GremlinGroovyScriptEngine} is initialized, providing fine-grained + * control over its internals. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +class ConfigurationGroovyCustomizer implements GroovyCustomizer { + + private final Map properties; + + /** + * Creates a new instance using configuration values specified + */ + ConfigurationGroovyCustomizer(final Object... keyValues) { + if (null == keyValues || keyValues.length == 0) + throw new IllegalArgumentException("ConfigurationCustomizerProvider must have key/values specified"); + + if (keyValues.length % 2 != 0) + throw new IllegalArgumentException("The keyValues must have an even number of values"); + + properties = ElementHelper.asMap(keyValues); + } + + /** + * Creates a new instance using configuration values specified + */ + ConfigurationGroovyCustomizer(final Map keyValues) { + properties = keyValues; + } + + public CompilerConfiguration applyCustomization(final CompilerConfiguration compilerConfiguration) { + final Class clazz = CompilerConfiguration.class; + final List methods = Arrays.asList(clazz.getMethods()); + for (Map.Entry entry : properties.entrySet()) { + final Method method = methods.stream().filter(m -> m.getName().equals("set" + entry.getKey())).findFirst() + .orElseThrow(() -> new IllegalStateException("Invalid setting [" + entry.getKey() + "] for CompilerConfiguration")); + + try { + method.invoke(compilerConfiguration, entry.getValue()); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + + return compilerConfiguration; + } + + @Override + public CompilationCustomizer create() { + throw new UnsupportedOperationException("This is a marker implementation that does not create a CompilationCustomizer instance"); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CustomizerProviderCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CustomizerProviderCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CustomizerProviderCustomizer.java deleted file mode 100644 index 73614a1..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CustomizerProviderCustomizer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tinkerpop.gremlin.groovy.jsr223; - -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.jsr223.Customizer; - -/** - * An adapter that allows existing {@link CompilerCustomizerProvider} instances to behave as a {#link Customizer}. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -class CustomizerProviderCustomizer implements Customizer { - - private final CompilerCustomizerProvider customizerProvider; - - CustomizerProviderCustomizer(final CompilerCustomizerProvider customizerProvider) { - this.customizerProvider = customizerProvider; - } - - CompilerCustomizerProvider getCustomizerProvider() { - return customizerProvider; - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/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 2996792..0f36dbf 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 @@ -70,6 +70,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -177,6 +178,9 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl private ImportCustomizerProvider importCustomizerProvider; private final List customizerProviders; + private final ImportGroovyCustomizer importGroovyCustomizer; + private final List groovyCustomizers; + private final Set artifactsToUse = new HashSet<>(); private final boolean interpreterModeEnabled; @@ -207,46 +211,21 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl .filter(p -> p instanceof ImportCustomizer) .map(p -> (ImportCustomizer) p) .collect(Collectors.toList()); - if (importCustomizers.isEmpty()) { - importCustomizerProvider = NoImportCustomizerProvider.INSTANCE; - } else { - final Set imports = new HashSet<>(); - final Set staticImports = new HashSet<>(); - importCustomizers.forEach(ic -> { - ic.getClassImports().forEach(c -> { - final String importStatement = c.getName(); - imports.add(importStatement); - }); - - ic.getEnumImports().forEach(e -> { - final String importStatement = e.getDeclaringClass().getCanonicalName() + ".*"; - staticImports.add(importStatement); - }); + final ImportCustomizer[] importCustomizerArray = new ImportCustomizer[importCustomizers.size()]; + importGroovyCustomizer = new ImportGroovyCustomizer(importCustomizers.toArray(importCustomizerArray)); - ic.getMethodImports().forEach(m -> { - final String importStatement = m.getDeclaringClass().getCanonicalName() + ".*"; - staticImports.add(importStatement); - }); - }); - - importCustomizerProvider = new EmptyImportCustomizerProvider(imports, staticImports); - } - - // this is a bit temporary - until CompilerCustomizerProvider is gone - final List customizerProviderCustomizer = listOfCustomizers.stream() - .filter(p -> p instanceof CustomizerProviderCustomizer) - .map(p -> ((CustomizerProviderCustomizer) p).getCustomizerProvider()) + groovyCustomizers = listOfCustomizers.stream() + .filter(p -> p instanceof GroovyCustomizer) + .map(p -> ((GroovyCustomizer) p)) .collect(Collectors.toList()); // determine if interpreter mode should be enabled - interpreterModeEnabled = customizerProviderCustomizer.stream() - .anyMatch(p -> p.getClass().equals(InterpreterModeCustomizerProvider.class)); + interpreterModeEnabled = groovyCustomizers.stream() + .anyMatch(p -> p.getClass().equals(InterpreterModeGroovyCustomizer.class)); - // remove used providers as the rest will be applied directly - customizerProviders = customizerProviderCustomizer.stream() - .filter(p -> p != null && - !((p instanceof ImportCustomizerProvider))) - .collect(Collectors.toList()); + // not using the old provider model so set that to empty list so that when createClassLoader is called + // it knows to use groovyCustomizers instead + customizerProviders = Collections.emptyList(); createClassLoader(); } @@ -273,10 +252,14 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl // remove used providers as the rest will be applied directly customizerProviders = providers.stream() - .filter(p -> p != null && - !((p instanceof ImportCustomizerProvider))) + .filter(p -> p != null && !(p instanceof ImportCustomizerProvider)) .collect(Collectors.toList()); + // groovy customizers are not used here - set to empty list so that the customizerProviders get used + // in createClassLoader + groovyCustomizers = Collections.emptyList(); + importGroovyCustomizer = null; + createClassLoader(); } @@ -350,7 +333,11 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl */ @Override public synchronized void addImports(final Set importStatements) { - final Set staticImports = new HashSet<>(); + // can't use this feature because imports can't come in as String for the revised model + if (null == importCustomizerProvider) + throw new IllegalStateException("Imports cannot be added to a GremlinGroovyScriptEngine that uses Customizer instances"); + + final Set staticImports = new HashSet<>(); final Set imports = new HashSet<>(); importStatements.forEach(s -> { @@ -362,9 +349,8 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl imports.add(s.substring(6).trim()); }); - // use the EmptyImportCustomizer because it doesn't come with static initializers containing - // existing imports. importCustomizerProvider = new EmptyImportCustomizerProvider(importCustomizerProvider, imports, staticImports); + internalReset(); } @@ -697,17 +683,32 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl } private synchronized void createClassLoader() { - final CompilerConfiguration conf = new CompilerConfiguration(CompilerConfiguration.DEFAULT); - conf.addCompilationCustomizers(this.importCustomizerProvider.create()); + // check for customizerProviders temporarily until this deprecated stuff is gone + if (groovyCustomizers.isEmpty() && null == importGroovyCustomizer) { + final CompilerConfiguration conf = new CompilerConfiguration(CompilerConfiguration.DEFAULT); + conf.addCompilationCustomizers(this.importCustomizerProvider.create()); - // ConfigurationCustomizerProvider is treated separately - customizerProviders.stream().filter(cp -> !(cp instanceof ConfigurationCustomizerProvider)) - .forEach(p -> conf.addCompilationCustomizers(p.create())); + // ConfigurationCustomizerProvider is treated separately + customizerProviders.stream().filter(cp -> !(cp instanceof ConfigurationCustomizerProvider)) + .forEach(p -> conf.addCompilationCustomizers(p.create())); - customizerProviders.stream().filter(cp -> cp instanceof ConfigurationCustomizerProvider).findFirst() - .ifPresent(cp -> ((ConfigurationCustomizerProvider) cp).applyCustomization(conf)); + customizerProviders.stream().filter(cp -> cp instanceof ConfigurationCustomizerProvider).findFirst() + .ifPresent(cp -> ((ConfigurationCustomizerProvider) cp).applyCustomization(conf)); - this.loader = new GremlinGroovyClassLoader(getParentLoader(), conf); + this.loader = new GremlinGroovyClassLoader(getParentLoader(), conf); + } else { + final CompilerConfiguration conf = new CompilerConfiguration(CompilerConfiguration.DEFAULT); + conf.addCompilationCustomizers(this.importGroovyCustomizer.create()); + + // ConfigurationCustomizerProvider is treated separately + groovyCustomizers.stream().filter(cp -> !(cp instanceof ConfigurationGroovyCustomizer)) + .forEach(p -> conf.addCompilationCustomizers(p.create())); + + groovyCustomizers.stream().filter(cp -> cp instanceof ConfigurationGroovyCustomizer).findFirst() + .ifPresent(cp -> ((ConfigurationGroovyCustomizer) cp).applyCustomization(conf)); + + this.loader = new GremlinGroovyClassLoader(getParentLoader(), conf); + } } private void use(final Artifact artifact) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java index 0d2e9c6..71f5dc7 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java @@ -18,12 +18,6 @@ */ package org.apache.tinkerpop.gremlin.groovy.jsr223; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ConfigurationCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.InterpreterModeCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ThreadInterruptCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TypeCheckedCustomizerProvider; import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin; import org.apache.tinkerpop.gremlin.jsr223.Customizer; import org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin; @@ -106,21 +100,21 @@ public class GroovyCompilerGremlinPlugin extends AbstractGremlinPlugin { final List list = new ArrayList<>(); if (interpreterMode) - list.add(new CustomizerProviderCustomizer(new InterpreterModeCustomizerProvider())); + list.add(new InterpreterModeGroovyCustomizer()); if (!keyValues.isEmpty()) - list.add(new CustomizerProviderCustomizer(new ConfigurationCustomizerProvider(keyValues))); + list.add(new ConfigurationGroovyCustomizer(keyValues)); if (threadInterrupt) - list.add(new CustomizerProviderCustomizer(new ThreadInterruptCustomizerProvider())); + list.add(new ThreadInterruptGroovyCustomizer()); if (timeInMillis > 0) - list.add(new CustomizerProviderCustomizer(new TimedInterruptCustomizerProvider(timeInMillis))); + list.add(new TimedInterruptGroovyCustomizer(timeInMillis)); if (compilation == Compilation.COMPILE_STATIC) - list.add(new CustomizerProviderCustomizer(new CompileStaticCustomizerProvider(extensions))); + list.add(new CompileStaticGroovyCustomizer(extensions)); else if (compilation == Compilation.TYPE_CHECKED) - list.add(new CustomizerProviderCustomizer(new TypeCheckedCustomizerProvider(extensions))); + list.add(new TypeCheckedGroovyCustomizer(extensions)); else if (compilation != Compilation.NONE) throw new IllegalStateException("Use of unknown compilation type: " + compilation); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCustomizer.java new file mode 100644 index 0000000..94426c0 --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCustomizer.java @@ -0,0 +1,33 @@ +/* + * 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.jsr223.Customizer; +import org.codehaus.groovy.control.customizers.CompilationCustomizer; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public interface GroovyCustomizer extends Customizer { + + /** + * Create a new instance of a {@code CompilationCustomizer} to add to the {@link GremlinGroovyScriptEngine}. + */ + public CompilationCustomizer create(); +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ImportGroovyCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ImportGroovyCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ImportGroovyCustomizer.java new file mode 100644 index 0000000..79243a0 --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ImportGroovyCustomizer.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.jsr223.ImportCustomizer; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; +import org.codehaus.groovy.control.customizers.CompilationCustomizer; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +class ImportGroovyCustomizer implements GroovyCustomizer { + + private final List customizers; + + ImportGroovyCustomizer(final ImportCustomizer... customizers) { + this.customizers = Arrays.asList(customizers); + } + + ImportGroovyCustomizer(final ImportGroovyCustomizer ic, final ImportCustomizer... customizers) { + this.customizers = new ArrayList<>(Arrays.asList(customizers)); + this.customizers.addAll(ic.customizers); + } + + @Override + public CompilationCustomizer create() { + final org.codehaus.groovy.control.customizers.ImportCustomizer ic = new org.codehaus.groovy.control.customizers.ImportCustomizer(); + + // there's something weird in groovy about doing specific imports instead of wildcard imports. with wildcard + // imports groovy seems to allow methods to be overloaded with enums such that things like Column.values and + // __.values() can be resolved by the compiler. if they are both directly in the imports then one or the other + // can't be found. the temporary fix is to hardcode a wildcard import __ and then filter out the core imports + // from the incoming customizer. ultimately, the fix should be to resolve the naming conflicts to ensure a + // unique space somehow. + ic.addStaticStars(__.class.getCanonicalName()); + for (ImportCustomizer customizer : customizers) { + customizer.getClassImports().forEach(i -> ic.addImports(i.getCanonicalName())); + customizer.getMethodImports().stream() + .filter(m -> !m.getDeclaringClass().equals(__.class)) + .forEach(m -> ic.addStaticImport(m.getDeclaringClass().getCanonicalName(), m.getName())); + customizer.getEnumImports().forEach(m -> ic.addStaticImport(m.getDeclaringClass().getCanonicalName(), m.name())); + } + + return ic; + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/InterpreterModeGroovyCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/InterpreterModeGroovyCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/InterpreterModeGroovyCustomizer.java new file mode 100644 index 0000000..89b471e --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/InterpreterModeGroovyCustomizer.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.groovy.jsr223; + +import org.apache.tinkerpop.gremlin.groovy.jsr223.ast.InterpreterMode; +import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; +import org.codehaus.groovy.control.customizers.CompilationCustomizer; + +/** + * Places the {@code ScriptEngine} in "interpreter mode" where local variables of a script are treated as global + * bindings. This implementation is technically not a true {@link GroovyCustomizer} instance as the + * "interpreter mode" feature does not require a {@code CompilerCustomizer}. This class merely acts as a flag that + * tells the {@link GremlinGroovyScriptEngine} to turn this feature on. + */ +class InterpreterModeGroovyCustomizer implements GroovyCustomizer { + @Override + public CompilationCustomizer create() { + return new ASTTransformationCustomizer(InterpreterMode.class); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ThreadInterruptGroovyCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ThreadInterruptGroovyCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ThreadInterruptGroovyCustomizer.java new file mode 100644 index 0000000..4492c3c --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ThreadInterruptGroovyCustomizer.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.jsr223; + +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) + */ +class ThreadInterruptGroovyCustomizer implements GroovyCustomizer { + @Override + public CompilationCustomizer create() { + return new ASTTransformationCustomizer(ThreadInterrupt.class); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TimedInterruptGroovyCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TimedInterruptGroovyCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TimedInterruptGroovyCustomizer.java new file mode 100644 index 0000000..c432164 --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TimedInterruptGroovyCustomizer.java @@ -0,0 +1,62 @@ +/* + * 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 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) + */ +class TimedInterruptGroovyCustomizer implements GroovyCustomizer { + private static final long DEFAULT_INTERRUPTION_TIMEOUT = 60000; + + private final long interruptionTimeout; + + TimedInterruptGroovyCustomizer() { + this(DEFAULT_INTERRUPTION_TIMEOUT); + } + + TimedInterruptGroovyCustomizer(final Long interruptionTimeout) { + this.interruptionTimeout = interruptionTimeout; + } + + TimedInterruptGroovyCustomizer(final Integer interruptionTimeout) { + this.interruptionTimeout = interruptionTimeout.longValue(); + } + + @Override + public CompilationCustomizer create() { + final Map timedInterruptAnnotationParams = new HashMap<>(); + timedInterruptAnnotationParams.put("value", interruptionTimeout); + timedInterruptAnnotationParams.put("unit", GeneralUtils.propX(GeneralUtils.classX(TimeUnit.class), TimeUnit.MILLISECONDS.toString())); + timedInterruptAnnotationParams.put("checkOnMethodStart", false); + timedInterruptAnnotationParams.put("thrown", GeneralUtils.classX(TimedInterruptTimeoutException.class)); + return new ASTTransformationCustomizer(timedInterruptAnnotationParams, TimedInterrupt.class); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TimedInterruptTimeoutException.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TimedInterruptTimeoutException.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TimedInterruptTimeoutException.java new file mode 100644 index 0000000..bdd49b3 --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TimedInterruptTimeoutException.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.groovy.jsr223; + +import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider; + +import java.util.concurrent.TimeoutException; + +/** + * An exception thrown from the {@link TimedInterruptCustomizerProvider} when the timeout is exceeded. This exception + * allows differentiation from other "timeout exceptions" that might occur. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public class TimedInterruptTimeoutException extends TimeoutException { + public TimedInterruptTimeoutException() { + } + + public TimedInterruptTimeoutException(final String message) { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TypeCheckedGroovyCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TypeCheckedGroovyCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TypeCheckedGroovyCustomizer.java new file mode 100644 index 0000000..ac8dd1d --- /dev/null +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/TypeCheckedGroovyCustomizer.java @@ -0,0 +1,65 @@ +/* + * 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 groovy.transform.TypeChecked; +import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; +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. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +class TypeCheckedGroovyCustomizer implements GroovyCustomizer { + + private final String extensions; + + TypeCheckedGroovyCustomizer() { + 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. + */ + TypeCheckedGroovyCustomizer(final String extensions) { + this.extensions = extensions; + } + + @Override + public CompilationCustomizer create() { + final Map 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/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompileStaticCustomizerProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompileStaticCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompileStaticCustomizerProvider.java index ab0bff5..4371e8a 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompileStaticCustomizerProvider.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompileStaticCustomizerProvider.java @@ -34,7 +34,9 @@ import java.util.stream.Stream; * Injects the {@code CompileStatic} transformer to enable type validation on script execution. * * @author Stephen Mallette (http://stephen.genoprime.com) + * @deprecated As of release 3.2.4, not replaced by a public class. */ +@Deprecated public class CompileStaticCustomizerProvider implements CompilerCustomizerProvider { private final String extensions; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProvider.java index 78357cb..3c8b673 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProvider.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProvider.java @@ -35,7 +35,9 @@ import java.util.Map; * control over its internals. * * @author Stephen Mallette (http://stephen.genoprime.com) + * @deprecated As of release 3.2.4, not replaced by a public class. */ +@Deprecated public class ConfigurationCustomizerProvider implements CompilerCustomizerProvider { private final Map properties; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/InterpreterModeCustomizerProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/InterpreterModeCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/InterpreterModeCustomizerProvider.java index 013ba8b..3044474 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/InterpreterModeCustomizerProvider.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/InterpreterModeCustomizerProvider.java @@ -29,7 +29,11 @@ import org.codehaus.groovy.control.customizers.CompilationCustomizer; * bindings. This implementation is technically not a true {@link CompilerCustomizerProvider} instance as the * "interpreter mode" feature does not require a {@code CompilerCustomizer}. This class merely acts as a flag that * tells the {@link org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine} to turn this feature on. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + * @deprecated As of release 3.2.4, not replaced by a public class. */ +@Deprecated public class InterpreterModeCustomizerProvider implements CompilerCustomizerProvider { @Override public CompilationCustomizer create() { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ThreadInterruptCustomizerProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ThreadInterruptCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ThreadInterruptCustomizerProvider.java index e46e9b7..c5fc60c 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ThreadInterruptCustomizerProvider.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ThreadInterruptCustomizerProvider.java @@ -28,7 +28,9 @@ import org.codehaus.groovy.control.customizers.CompilationCustomizer; * Injects checks for thread interruption into scripts. * * @author Stephen Mallette (http://stephen.genoprime.com) + * @deprecated As of release 3.2.4, not replaced by a public class. */ +@Deprecated public class ThreadInterruptCustomizerProvider implements CompilerCustomizerProvider { @Override public CompilationCustomizer create() { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptCustomizerProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptCustomizerProvider.java index 9913088..f0e1080 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptCustomizerProvider.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptCustomizerProvider.java @@ -34,7 +34,9 @@ import java.util.concurrent.TimeUnit; * specified time. * * @author Stephen Mallette (http://stephen.genoprime.com) + * @deprecated As of release 3.2.4, not replaced by a public class. */ +@Deprecated public class TimedInterruptCustomizerProvider implements CompilerCustomizerProvider { public static final long DEFAULT_INTERRUPTION_TIMEOUT = 60000; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptTimeoutException.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptTimeoutException.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptTimeoutException.java index 40abd59..4063d4f 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptTimeoutException.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TimedInterruptTimeoutException.java @@ -23,7 +23,11 @@ import java.util.concurrent.TimeoutException; /** * An exception thrown from the {@link TimedInterruptCustomizerProvider} when the timeout is exceeded. This exception * allows differentiation from other "timeout exceptions" that might occur. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + * @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException}. */ +@Deprecated public class TimedInterruptTimeoutException extends TimeoutException { public TimedInterruptTimeoutException() { } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TypeCheckedCustomizerProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TypeCheckedCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TypeCheckedCustomizerProvider.java index cf9147b..b5c2729 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TypeCheckedCustomizerProvider.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/TypeCheckedCustomizerProvider.java @@ -34,7 +34,9 @@ import java.util.stream.Stream; * Injects the {@code TypeChecked} transformer to enable type validation on script execution. * * @author Stephen Mallette (http://stephen.genoprime.com) + * @deprecated As of release 3.2.4, not replaced by a public class. */ +@Deprecated public class TypeCheckedCustomizerProvider implements CompilerCustomizerProvider { private final String extensions; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/VariableIdentificationCustomizer.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/VariableIdentificationCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/VariableIdentificationCustomizer.java index 79df578..2c216d7 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/VariableIdentificationCustomizer.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/VariableIdentificationCustomizer.java @@ -35,7 +35,9 @@ import java.util.TreeSet; /** * @author Stephen Mallette (http://stephen.genoprime.com) + * @deprecated As of release 3.2.4, not replaced. */ +@Deprecated public class VariableIdentificationCustomizer extends CompilationCustomizer { private static final ThreadLocal> variables = new ThreadLocal>() { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/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 b62f3f3..6f3383e 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 @@ -59,8 +59,8 @@ public class GremlinGroovyScriptEngineCompileStaticTest { assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()")); } - final CompileStaticCustomizerProvider provider = new CompileStaticCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(provider))) { + final CompileStaticGroovyCustomizer provider = new CompileStaticGroovyCustomizer(); + try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) { scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()"); fail("Should have failed type checking"); } catch (ScriptException se) { @@ -92,14 +92,14 @@ public class GremlinGroovyScriptEngineCompileStaticTest { @Test public void shouldCompileStaticWithExtension() throws Exception { // with no type checking extension this should pass - final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(providerNoExtension))) { + final CompileStaticGroovyCustomizer providerNoExtension = new CompileStaticGroovyCustomizer(); + 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( + final CompileStaticGroovyCustomizer providerWithExtension = new CompileStaticGroovyCustomizer( PrecompiledExtensions.PreventColorUsageExtension.class.getName()); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(providerWithExtension))) { + 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) { @@ -140,16 +140,16 @@ public class GremlinGroovyScriptEngineCompileStaticTest { @Test public void shouldCompileStaticWithMultipleExtension() throws Exception { // with no type checking extension this should pass - final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(providerNoExtension))) { + final CompileStaticGroovyCustomizer providerNoExtension = new CompileStaticGroovyCustomizer(); + 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( + final CompileStaticGroovyCustomizer providerWithExtension = new CompileStaticGroovyCustomizer( PrecompiledExtensions.PreventColorUsageExtension.class.getName() + "," + PrecompiledExtensions.PreventCountDownLatchUsageExtension.class.getName()); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(providerWithExtension))) { + 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) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java index 6b18ece..289b2ca 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java @@ -41,9 +41,8 @@ public class GremlinGroovyScriptEngineConfigTest { @Test public void shouldAddBaseScriptClass() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer( - new ConfigurationCustomizerProvider("ScriptBaseClass", BaseScriptForTesting.class.getName())), - new CustomizerProviderCustomizer(new DefaultImportCustomizerProvider())); + final ScriptEngine engine = new GremlinGroovyScriptEngine( + new ConfigurationGroovyCustomizer("ScriptBaseClass", BaseScriptForTesting.class.getName())); assertEquals("hello, stephen", engine.eval("hello('stephen')")); } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/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 65dc56e..eb0a44b 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 @@ -122,7 +122,7 @@ public class GremlinGroovyScriptEngineTest { @Test public void shouldPromoteDefinedVarsInInterpreterModeWithNoBindings() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(new InterpreterModeCustomizerProvider())); + final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeGroovyCustomizer()); engine.eval("def addItUp = { x, y -> x + y }"); assertEquals(3, engine.eval("int xxx = 1 + 2")); assertEquals(4, engine.eval("yyy = xxx + 1")); @@ -168,7 +168,7 @@ public class GremlinGroovyScriptEngineTest { @Test public void shouldPromoteDefinedVarsInInterpreterModeWithBindings() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(new InterpreterModeCustomizerProvider())); + final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeGroovyCustomizer()); final Bindings b = new SimpleBindings(); b.put("x", 2); engine.eval("def addItUp = { x, y -> x + y }", b); @@ -354,7 +354,7 @@ public class GremlinGroovyScriptEngineTest { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference color = new AtomicReference<>(Color.RED); - final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(); + final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(NoImportCustomizerProvider.INSTANCE); try { scriptEngine.eval("Color.BLACK"); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/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 index ea778c6..499373f 100644 --- 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 @@ -55,7 +55,7 @@ public class GremlinGroovyScriptEngineThreadInterruptTest { @Test public void shouldInterruptWhile() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(new ThreadInterruptCustomizerProvider())); + final ScriptEngine engine = new GremlinGroovyScriptEngine(new ThreadInterruptGroovyCustomizer()); final AtomicBoolean asserted = new AtomicBoolean(false); final Thread t = new Thread(() -> { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/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 index fa8d4ef..1745b5d 100644 --- 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 @@ -25,7 +25,6 @@ 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; @@ -49,14 +48,12 @@ public class GremlinGroovyScriptEngineTimedInterruptTest { @Test public void shouldTimeoutScriptOnTimedWhile() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine( - new CustomizerProviderCustomizer(new TimedInterruptCustomizerProvider(1000)), - new CustomizerProviderCustomizer(new DefaultImportCustomizerProvider())); + final ScriptEngine engine = new GremlinGroovyScriptEngine(new TimedInterruptGroovyCustomizer(1000)); try { engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}"); fail("This should have timed out"); } catch (ScriptException se) { - assertEquals(TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); + assertEquals(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); } } @@ -78,15 +75,13 @@ public class GremlinGroovyScriptEngineTimedInterruptTest { @Test public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeout() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine( - new CustomizerProviderCustomizer(new TimedInterruptCustomizerProvider(1000)), - new CustomizerProviderCustomizer(new DefaultImportCustomizerProvider())); + final ScriptEngine engine = new GremlinGroovyScriptEngine(new TimedInterruptGroovyCustomizer(1000)); Thread.sleep(2000); try { engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}"); fail("This should have timed out"); } catch (ScriptException se) { - assertEquals(TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); + assertEquals(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); } assertEquals(2, engine.eval("1+1")); @@ -116,8 +111,7 @@ public class GremlinGroovyScriptEngineTimedInterruptTest { @Test public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception { final ScriptEngine engine = new GremlinGroovyScriptEngine( - new CustomizerProviderCustomizer(new TimedInterruptCustomizerProvider(1000)), - new CustomizerProviderCustomizer(new DefaultImportCustomizerProvider())); + new TimedInterruptGroovyCustomizer(1000)); for (int ix = 0; ix < 5; ix++) { try { @@ -125,7 +119,7 @@ public class GremlinGroovyScriptEngineTimedInterruptTest { engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 2000) {}"); fail("This should have timed out"); } catch (ScriptException se) { - assertEquals(TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); + assertEquals(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); } // this script takes 500 ms less than the interruptionTimeout @@ -148,9 +142,7 @@ public class GremlinGroovyScriptEngineTimedInterruptTest { @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 CustomizerProviderCustomizer(new TimedInterruptCustomizerProvider(1)), - new CustomizerProviderCustomizer(new DefaultImportCustomizerProvider())); + final ScriptEngine engine = new GremlinGroovyScriptEngine(new TimedInterruptGroovyCustomizer(1)); engine.eval("def addItUp(x,y) { x + y }"); assertEquals(3, engine.eval("addItUp(1,2)")); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/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 0ca12d7..6c70e8e 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 @@ -60,8 +60,8 @@ public class GremlinGroovyScriptEngineTypeCheckedTest { assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()")); } - final TypeCheckedCustomizerProvider provider = new TypeCheckedCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(provider))) { + final TypeCheckedGroovyCustomizer provider = new TypeCheckedGroovyCustomizer(); + try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) { scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()"); fail("Should have failed type checking"); } catch (ScriptException se) { @@ -93,14 +93,14 @@ public class GremlinGroovyScriptEngineTypeCheckedTest { @Test public void shouldTypeCheckWithExtension() throws Exception { // with no type checking extension this should pass - final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(providerNoExtension))) { + final TypeCheckedGroovyCustomizer providerNoExtension = new TypeCheckedGroovyCustomizer(); + 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( PrecompiledExtensions.PreventColorUsageExtension.class.getName()); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(providerWithExtension))) { + 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) { @@ -141,16 +141,16 @@ public class GremlinGroovyScriptEngineTypeCheckedTest { @Test public void shouldTypeCheckWithMultipleExtension() throws Exception { // with no type checking extension this should pass - final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(providerNoExtension))) { + final TypeCheckedGroovyCustomizer providerNoExtension = new TypeCheckedGroovyCustomizer(); + 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( + final TypeCheckedGroovyCustomizer providerWithExtension = new TypeCheckedGroovyCustomizer( PrecompiledExtensions.PreventColorUsageExtension.class.getName() + "," + PrecompiledExtensions.PreventCountDownLatchUsageExtension.class.getName()); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(new CustomizerProviderCustomizer(providerWithExtension))) { + 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) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java index 8d2178f..f795fa7 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java @@ -58,7 +58,7 @@ public class GroovyCompilerGremlinPluginTest { final Optional customizers = plugin.getCustomizers("gremlin-groovy"); assertThat(customizers.isPresent(), is(true)); assertEquals(1, customizers.get().length); - assertThat(((CustomizerProviderCustomizer) customizers.get()[0]).getCustomizerProvider(), instanceOf(CompileStaticCustomizerProvider.class)); + assertThat(customizers.get()[0], instanceOf(CompileStaticGroovyCustomizer.class)); } @Test @@ -68,7 +68,7 @@ public class GroovyCompilerGremlinPluginTest { final Optional customizers = plugin.getCustomizers("gremlin-groovy"); assertThat(customizers.isPresent(), is(true)); assertEquals(1, customizers.get().length); - assertThat(((CustomizerProviderCustomizer) customizers.get()[0]).getCustomizerProvider(), instanceOf(TypeCheckedCustomizerProvider.class)); + assertThat(customizers.get()[0], instanceOf(TypeCheckedGroovyCustomizer.class)); } @Test @@ -80,12 +80,12 @@ public class GroovyCompilerGremlinPluginTest { final Optional customizers = plugin.getCustomizers("gremlin-groovy"); assertThat(customizers.isPresent(), is(true)); assertEquals(1, customizers.get().length); - assertThat(((CustomizerProviderCustomizer) customizers.get()[0]).getCustomizerProvider(), instanceOf(ConfigurationCustomizerProvider.class)); + assertThat(customizers.get()[0], instanceOf(ConfigurationGroovyCustomizer.class)); final CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); assertThat(compilerConfiguration.getDebug(), is(false)); - final ConfigurationCustomizerProvider provider = (ConfigurationCustomizerProvider) ((CustomizerProviderCustomizer) customizers.get()[0]).getCustomizerProvider(); + final ConfigurationGroovyCustomizer provider = (ConfigurationGroovyCustomizer) customizers.get()[0]; provider.applyCustomization(compilerConfiguration); assertThat(compilerConfiguration.getDebug(), is(true)); @@ -98,7 +98,7 @@ public class GroovyCompilerGremlinPluginTest { final Optional customizers = plugin.getCustomizers("gremlin-groovy"); assertThat(customizers.isPresent(), is(true)); assertEquals(1, customizers.get().length); - assertThat(((CustomizerProviderCustomizer) customizers.get()[0]).getCustomizerProvider(), instanceOf(InterpreterModeCustomizerProvider.class)); + assertThat(customizers.get()[0], instanceOf(InterpreterModeGroovyCustomizer.class)); } @Test @@ -108,7 +108,7 @@ public class GroovyCompilerGremlinPluginTest { final Optional customizers = plugin.getCustomizers("gremlin-groovy"); assertThat(customizers.isPresent(), is(true)); assertEquals(1, customizers.get().length); - assertThat(((CustomizerProviderCustomizer) customizers.get()[0]).getCustomizerProvider(), instanceOf(ThreadInterruptCustomizerProvider.class)); + assertThat(customizers.get()[0], instanceOf(ThreadInterruptGroovyCustomizer.class)); } @Test @@ -118,7 +118,7 @@ public class GroovyCompilerGremlinPluginTest { final Optional customizers = plugin.getCustomizers("gremlin-groovy"); assertThat(customizers.isPresent(), is(true)); assertEquals(1, customizers.get().length); - assertThat(((CustomizerProviderCustomizer) customizers.get()[0]).getCustomizerProvider(), instanceOf(TimedInterruptCustomizerProvider.class)); + assertThat(customizers.get()[0], instanceOf(TimedInterruptGroovyCustomizer.class)); } @Test(expected = IllegalStateException.class) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b8eb7f9/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java index b931b8c..d5fe62a 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java @@ -279,6 +279,11 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor { final String errorMessage = String.format("A timeout occurred within the script during evaluation of [%s] - consider increasing the limit given to TimedInterruptCustomizerProvider", msg); logger.warn(errorMessage); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider").create()); + } else if (t instanceof org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) { + // occurs when the TimedInterruptCustomizerProvider is in play + final String errorMessage = String.format("A timeout occurred within the script during evaluation of [%s] - consider increasing the limit given to TimedInterruptCustomizerProvider", msg); + logger.warn(errorMessage); + ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider").create()); } else if (t instanceof TimeoutException) { final String errorMessage = String.format("Response evaluation exceeded the configured threshold for request [%s] - %s", msg, t.getMessage()); logger.warn(errorMessage, t);