TINKERPOP-1421 TINKERPOP-1621 Removed deprecated GremlinPlugin/ControlOps infrastructure
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/da909d1e Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/da909d1e Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/da909d1e Branch: refs/heads/TINKERPOP-1612 Commit: da909d1e25a531c2442c14c8ed747d42fd7e3a85 Parents: 17a845d Author: Stephen Mallette <[email protected]> Authored: Mon Feb 27 17:03:35 2017 -0500 Committer: Stephen Mallette <[email protected]> Committed: Tue Feb 28 06:32:40 2017 -0500 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 2 + docs/src/upgrade/release-3.3.x.asciidoc | 31 +- .../groovy/util/DependencyGrabber.groovy | 14 - .../AbstractImportCustomizerProvider.java | 221 --------- .../groovy/CompilerCustomizerProvider.java | 39 -- .../groovy/DefaultImportCustomizerProvider.java | 80 ---- .../groovy/EmptyImportCustomizerProvider.java | 87 ---- .../groovy/ImportCustomizerProvider.java | 41 -- .../groovy/NoImportCustomizerProvider.java | 64 --- .../gremlin/groovy/engine/GremlinExecutor.java | 247 +--------- .../gremlin/groovy/engine/ScriptEngines.java | 461 ------------------- .../groovy/jsr223/DependencyManager.java | 84 ---- .../jsr223/GremlinGroovyScriptEngine.java | 198 +------- .../jsr223/ScriptEnginePluginAcceptor.java | 96 ---- .../jsr223/TimedInterruptTimeoutException.java | 4 +- .../jsr223/TypeCheckedGroovyCustomizer.java | 1 - .../CompileStaticCustomizerProvider.java | 64 --- .../ConfigurationCustomizerProvider.java | 86 ---- .../InterpreterModeCustomizerProvider.java | 42 -- .../ThreadInterruptCustomizerProvider.java | 39 -- .../TimedInterruptCustomizerProvider.java | 66 --- .../TimedInterruptTimeoutException.java | 38 -- .../TypeCheckedCustomizerProvider.java | 68 --- .../VariableIdentificationCustomizer.java | 93 ---- .../groovy/plugin/AbstractGremlinPlugin.java | 99 ---- .../gremlin/groovy/plugin/Artifact.java | 88 ---- .../gremlin/groovy/plugin/GremlinPlugin.java | 72 --- .../groovy/plugin/GremlinPluginException.java | 43 -- .../plugin/IllegalEnvironmentException.java | 33 -- .../gremlin/groovy/plugin/PluginAcceptor.java | 67 --- .../plugin/PluginInitializationException.java | 41 -- .../gremlin/groovy/plugin/RemoteAcceptor.java | 92 ---- .../gremlin/groovy/plugin/RemoteException.java | 42 -- .../groovy/plugin/SugarGremlinPlugin.java | 53 --- .../plugin/dsl/credential/CredentialGraph.java | 123 ----- .../CredentialGraphGremlinPlugin.java | 57 --- .../dsl/credential/CredentialGraphTokens.java | 33 -- ...aultDefaultImportCustomizerProviderTest.java | 90 ---- .../groovy/engine/GremlinExecutorTest.java | 136 ++---- .../groovy/engine/ScriptEnginesTest.java | 218 --------- .../ConfigurationCustomizerProviderTest.java | 77 ++++ ...mlinGroovyScriptEngineCompileStaticTest.java | 66 --- .../GremlinGroovyScriptEngineConfigTest.java | 10 - ...remlinGroovyScriptEngineFileSandboxTest.java | 16 +- .../GremlinGroovyScriptEngineOverGraphTest.java | 46 +- ...GroovyScriptEngineSandboxedStandardTest.java | 12 +- .../jsr223/GremlinGroovyScriptEngineTest.java | 215 --------- ...inGroovyScriptEngineThreadInterruptTest.java | 21 - ...linGroovyScriptEngineTimedInterruptTest.java | 62 --- ...nGroovyScriptEngineTinkerPopSandboxTest.java | 7 +- ...remlinGroovyScriptEngineTypeCheckedTest.java | 69 +-- .../jsr223/GroovyCompilerGremlinPluginTest.java | 6 - .../ConfigurationCustomizerProviderTest.java | 78 ---- .../gremlin/groovy/plugin/ArtifactTest.java | 85 ---- .../util/DependencyGrabberIntegrateTest.java | 1 - .../dsl/credential/CredentialGraphTest.java | 118 ----- .../tinkerpop/gremlin/server/Settings.java | 9 - .../server/auth/SimpleAuthenticator.java | 4 +- .../handler/HttpBasicAuthenticationHandler.java | 4 +- .../server/op/AbstractEvalOpProcessor.java | 7 +- .../server/op/control/ControlOpProcessor.java | 168 ------- .../gremlin/server/op/control/ControlOps.java | 123 ----- .../gremlin/server/op/session/Session.java | 13 +- .../op/traversal/TraversalOpProcessor.java | 1 - .../server/util/GremlinServerInstall.java | 2 +- .../server/util/ServerGremlinExecutor.java | 12 +- ....apache.tinkerpop.gremlin.server.OpProcessor | 1 - .../gremlin/hadoop/HadoopGremlinSuite.java | 3 +- .../hadoop/jsr223/HadoopGremlinPluginCheck.java | 397 ---------------- .../computer/SparkHadoopGraphProvider.java | 9 - 70 files changed, 194 insertions(+), 4901 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 5faa5ea..361e843 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -33,6 +33,8 @@ TinkerPop 3.3.0 (Release Date: NOT OFFICIALLY RELEASED YET) * Established the GraphSON 3.0 format. * Removed `gremlin-groovy-test`. * Removed previously deprecated "G" functions in `gremlin-groovy` (i.e. `GFunction`). +* Removed references to the old `GremlinPlugin` system that was in `gremlin-groovy` - the revised `GremlinPlugin` system in `gremlin-core` is the only one now in use. +* `GremlinGroovyScriptEngine` no longer implements the now removed `DependencyManager`. * Added `Vertex`, `Edge`, `VertexProperty`, and `Property` serializers to Gremlin-Python and exposed tests that use graph object arguments. * `Bytecode.getSourceInstructions()` and `Bytecode.getStepInstructions()` now returns `List<Instruction>` instead of `Iterable<Instruction>`. * Added various `TraversalStrategy` registrations with `GryoMapper`. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/docs/src/upgrade/release-3.3.x.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc index 72be2aa..4604320 100644 --- a/docs/src/upgrade/release-3.3.x.asciidoc +++ b/docs/src/upgrade/release-3.3.x.asciidoc @@ -182,7 +182,7 @@ The following deprecated classes, methods or fields have been removed in this ve * `gremlin-console` ** `org.apache.tinkerpop.gremlin.console.Console(String)` ** `org.apache.tinkerpop.gremlin.console.ConsoleImportCustomizerProvider` -** `org.apache.tinkerpop.gremlin.console.plugin.* +** `org.apache.tinkerpop.gremlin.console.plugin.*` ** `org.apache.tinkerpop.gremlin.console.groovy.plugin.DriverGremlinPlugin` ** `org.apache.tinkerpop.gremlin.console.groovy.plugin.DriverRemoteAcceptor` ** `org.apache.tinkerpop.gremlin.console.groovy.plugin.GephiGremlinPlugin` @@ -197,12 +197,36 @@ The following deprecated classes, methods or fields have been removed in this ve ** `org.apache.tinkerpop.gremlin.structure.Graph.OptIn#SUITE_GROOVY_ENVIRONMENT` ** `org.apache.tinkerpop.gremlin.structure.Graph.OptIn#SUITE_GROOVY_ENVIRONMENT_INTEGRATE` * `gremlin-groovy` +** `org.apache.tinkerpop.gremlin.groovy.AbstractImportCustomizerProvider` +** `org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider` +** `org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider` +** `org.apache.tinkerpop.gremlin.groovy.EmptyImportCustomizerProvider` +** `org.apache.tinkerpop.gremlin.groovy.ImportCustomizerProvider` +** `org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider` ** `org.apache.tinkerpop.gremlin.groovy.engine.ConcurrentBindings` +** `org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor#build(String,List,List,List,Map)` +** `org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor#getScriptEngines()` +** `org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.Builder#enabledPlugins(Set) +** `org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.Builder#addEngineSettings(String,List,List,List,Map)` +** `org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.Builder#engineSettings(Map)` +** `org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.Builder#use(List)` +** `org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines` ** `org.apache.tinkerpop.gremlin.groovy.function.*` +** `org.apache.tinkerpop.gremlin.groovy.plugin.*` +** `org.apache.tinkerpop.gremlin.groovy.plugin.credential.*` +** `org.apache.tinkerpop.gremlin.groovy.jsr223.DependencyManager` ** `org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine(ImportCustomizerProvider)` +** `org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine(CompilerCustomizerProvider)` ** `org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine#plugins()` ** `org.apache.tinkerpop.gremlin.groovy.jsr223.ScriptExecutor` +** `org.apache.tinkerpop.gremlin.groovy.jsr223.ScriptEnginePluginAcceptor` ** `org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SandboxExtension` +** `org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.*` +** `org.apache.tinkerpop.gremlin.groovy.util.DependencyGrabber#deleteDependenciesFromPath(org.apache.tinkerpop.gremlin.groovy.plugin.Artifact)` +** `org.apache.tinkerpop.gremlin.groovy.util.DependencyGrabber#copyDependenciesToPath(org.apache.tinkerpop.gremlin.groovy.plugin.Artifact)` +* `gremlin-server` +** `org.apache.tinkerpop.gremlin.server.Settings#plugins` +** `org.apache.tinkerpop.gremlin.server.op.control.*` * `spark-gremlin` ** `org.apache.tinkerpop.gremlin.spark.groovy.plugin.SparkGremlinPlugin` * `tinkergraph-gremlin` @@ -212,8 +236,9 @@ Please see the javadoc deprecation notes or upgrade documentation specific to wh understand how to resolve this breaking change. See: link:https://issues.apache.org/jira/browse/TINKERPOP-1283[TINKERPOP-1283], link:https://issues.apache.org/jira/browse/TINKERPOP-1420[TINKERPOP-1420], -link:https://issues.apache.org/jira/browse/TINKERPOP-833[TINKERPOP-833], link:https://issues.apache.org/jira/browse/TINKERPOP-1040[TINKERPOP-1040], -link:https://issues.apache.org/jira/browse/TINKERPOP-1612[TINKERPOP-1612], link:https://issues.apache.org/jira/browse/TINKERPOP-1622[TINKERPOP-1622] +link:https://issues.apache.org/jira/browse/TINKERPOP-1421[TINKERPOP-1421], link:https://issues.apache.org/jira/browse/TINKERPOP-833[TINKERPOP-833], +link:https://issues.apache.org/jira/browse/TINKERPOP-1040[TINKERPOP-1040], link:https://issues.apache.org/jira/browse/TINKERPOP-1612[TINKERPOP-1612], +link:https://issues.apache.org/jira/browse/TINKERPOP-1622[TINKERPOP-1622] Upgrading for Providers ~~~~~~~~~~~~~~~~~~~~~~~ http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabber.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabber.groovy b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabber.groovy index 4f895c8..f2bfe5c 100644 --- a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabber.groovy +++ b/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabber.groovy @@ -50,13 +50,6 @@ class DependencyGrabber { this.extensionDirectory = extensionDirectory } - /** - * @deprecated As of release 3.2.4, replaced by {@link #deleteDependenciesFromPath(Artifact)} - */ - def String deleteDependenciesFromPath(final org.apache.tinkerpop.gremlin.groovy.plugin.Artifact artifact) { - deleteDependenciesFromPath(new Artifact(artifact.group, artifact.artifact, artifact.version)) - } - def String deleteDependenciesFromPath(final Artifact artifact) { final def dep = makeDepsMap(artifact) final String extClassPath = getPathFromDependency(dep) @@ -70,13 +63,6 @@ class DependencyGrabber { } } - /** - * @deprecated As of release 3.2.4, replaced by {@link #copyDependenciesToPath(Artifact)} - */ - def String copyDependenciesToPath(final org.apache.tinkerpop.gremlin.groovy.plugin.Artifact artifact) { - copyDependenciesToPath(new Artifact(artifact.group, artifact.artifact, artifact.version)) - } - def Set<String> copyDependenciesToPath(final Artifact artifact) { final def dep = makeDepsMap(artifact) final String extClassPath = getPathFromDependency(dep) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/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 deleted file mode 100644 index 47709f2..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java +++ /dev/null @@ -1,221 +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 groovy.grape.Grape; -import groovy.json.JsonBuilder; -import org.apache.commons.configuration.Configuration; -import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslator; -import org.apache.tinkerpop.gremlin.process.computer.Computer; -import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; -import org.apache.tinkerpop.gremlin.process.computer.bulkdumping.BulkDumperVertexProgram; -import org.apache.tinkerpop.gremlin.process.computer.bulkloading.BulkLoaderVertexProgram; -import org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.PeerPressureVertexProgram; -import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgram; -import org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram; -import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy; -import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.optimization.GraphFilterStrategy; -import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph; -import org.apache.tinkerpop.gremlin.process.traversal.Operator; -import org.apache.tinkerpop.gremlin.process.traversal.Order; -import org.apache.tinkerpop.gremlin.process.traversal.P; -import org.apache.tinkerpop.gremlin.process.traversal.Pop; -import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions; -import org.apache.tinkerpop.gremlin.process.traversal.Scope; -import org.apache.tinkerpop.gremlin.process.traversal.Traversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; -import org.apache.tinkerpop.gremlin.process.traversal.engine.ComputerTraversalEngine; -import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent; -import org.apache.tinkerpop.gremlin.process.traversal.step.util.event.Event; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategy; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.ProfileStrategy; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.IdentityRemovalStrategy; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy; -import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics; -import org.apache.tinkerpop.gremlin.structure.Column; -import org.apache.tinkerpop.gremlin.structure.Direction; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.T; -import org.apache.tinkerpop.gremlin.structure.VertexProperty; -import org.apache.tinkerpop.gremlin.structure.io.GraphReader; -import org.apache.tinkerpop.gremlin.structure.io.IoCore; -import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLReader; -import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader; -import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader; -import org.apache.tinkerpop.gremlin.structure.util.GraphFactory; -import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedElement; -import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; -import org.apache.tinkerpop.gremlin.util.Gremlin; -import org.apache.tinkerpop.gremlin.util.TimeUtil; -import org.apache.tinkerpop.gremlin.util.function.FunctionUtils; -import org.codehaus.groovy.control.customizers.CompilationCustomizer; -import org.codehaus.groovy.control.customizers.ImportCustomizer; - -import java.util.HashSet; -import java.util.Set; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.5, replaced by {@link ImportCustomizer} - */ -@Deprecated -public abstract class AbstractImportCustomizerProvider implements ImportCustomizerProvider { - protected static final String DOT_STAR = ".*"; - protected static final String EMPTY_STRING = ""; - protected static final String PERIOD = "."; - - protected final Set<String> extraImports = new HashSet<>(); - protected final Set<String> extraStaticImports = new HashSet<>(); - - private static final Set<String> imports = new HashSet<>(); - private static final Set<String> staticImports = new HashSet<>(); - - static { - // graph structure - imports.add(Graph.class.getPackage().getName() + DOT_STAR); - imports.add(GraphFactory.class.getPackage().getName() + DOT_STAR); - imports.add(DetachedElement.class.getPackage().getName() + DOT_STAR); - imports.add(RemoteGraph.class.getPackage().getName() + DOT_STAR); - imports.add(EmptyGraph.class.getPackage().getName() + DOT_STAR); - staticImports.add(T.class.getCanonicalName() + DOT_STAR); - staticImports.add(Direction.class.getCanonicalName() + DOT_STAR); - staticImports.add(VertexProperty.Cardinality.class.getCanonicalName() + DOT_STAR); - - // graph process - imports.add(Traversal.class.getPackage().getName() + DOT_STAR); - imports.add(GraphComputer.class.getPackage().getName() + DOT_STAR); - imports.add(GraphTraversal.class.getPackage().getName() + DOT_STAR); - imports.add(ComputerTraversalEngine.class.getPackage().getName() + DOT_STAR); - imports.add(PartitionStrategy.class.getPackage().getName() + DOT_STAR); // decoration strategies - imports.add(IdentityRemovalStrategy.class.getPackage().getName() + DOT_STAR); // optimization strategies - imports.add(ProfileStrategy.class.getPackage().getName() + DOT_STAR); // finalization strategies - imports.add(ReadOnlyStrategy.class.getPackage().getName() + DOT_STAR); // verification strategies - imports.add(VertexProgramStrategy.class.getPackage().getName() + DOT_STAR); // computer decoration strategies - imports.add(GraphFilterStrategy.class.getPackage().getName() + DOT_STAR); // computer optimization strategies - imports.add(Event.class.getPackage().getName() + DOT_STAR); // eventing - imports.add(GroovyTranslator.class.getPackage().getName() + DOT_STAR); // groovy translator - - staticImports.add(P.class.getCanonicalName() + DOT_STAR); - staticImports.add(Order.class.getCanonicalName() + DOT_STAR); - staticImports.add(Column.class.getCanonicalName() + DOT_STAR); - staticImports.add(Operator.class.getCanonicalName() + DOT_STAR); - staticImports.add(Scope.class.getCanonicalName() + DOT_STAR); - staticImports.add(Pop.class.getCanonicalName() + DOT_STAR); - staticImports.add(__.class.getCanonicalName() + DOT_STAR); - - staticImports.add(SackFunctions.Barrier.class.getCanonicalName() + DOT_STAR); - staticImports.add(TraversalOptionParent.Pick.class.getCanonicalName() + DOT_STAR); - staticImports.add(GraphTraversalSource.class.getCanonicalName() + DOT_STAR); - - // utils - imports.add(Gremlin.class.getPackage().getName() + DOT_STAR); - imports.add(GremlinLoader.class.getPackage().getName() + DOT_STAR); - imports.add(FunctionUtils.class.getPackage().getName() + DOT_STAR); - imports.add(TraversalMetrics.class.getPackage().getName() + DOT_STAR); - staticImports.add(TimeUtil.class.getCanonicalName() + DOT_STAR); - staticImports.add(Computer.class.getCanonicalName() + DOT_STAR); - - // IO packages - imports.add(GraphReader.class.getPackage().getName() + DOT_STAR); - imports.add(GraphMLReader.class.getPackage().getName() + DOT_STAR); - imports.add(GraphSONReader.class.getPackage().getName() + DOT_STAR); - imports.add(GryoReader.class.getPackage().getName() + DOT_STAR); - staticImports.add(IoCore.class.getCanonicalName() + DOT_STAR); - - // algorithms - imports.add(PeerPressureVertexProgram.class.getPackage().getName() + DOT_STAR); - imports.add(PageRankVertexProgram.class.getPackage().getName() + DOT_STAR); - imports.add(TraversalVertexProgram.class.getPackage().getName() + DOT_STAR); - imports.add(BulkLoaderVertexProgram.class.getPackage().getName() + DOT_STAR); - imports.add(BulkDumperVertexProgram.class.getPackage().getName() + DOT_STAR); - - // groovy extras - imports.add(Grape.class.getCanonicalName()); - imports.add(JsonBuilder.class.getPackage().getName() + DOT_STAR); - - // external - imports.add(Configuration.class.getPackage().getName() + DOT_STAR); - } - - @Override - public CompilationCustomizer create() { - final ImportCustomizer ic = new ImportCustomizer(); - - processImports(ic, imports); - processStaticImports(ic, staticImports); - processImports(ic, extraImports); - processStaticImports(ic, extraStaticImports); - - return ic; - } - - @Override - public Set<String> getImports() { - return imports; - } - - @Override - public Set<String> getStaticImports() { - return staticImports; - } - - @Override - public Set<String> getExtraImports() { - return extraImports; - } - - @Override - public Set<String> getExtraStaticImports() { - return extraStaticImports; - } - - public Set<String> getAllImports() { - final Set<String> allImports = new HashSet<>(); - allImports.addAll(imports); - allImports.addAll(staticImports); - allImports.addAll(extraImports); - allImports.addAll(extraStaticImports); - - return allImports; - } - - protected static void processStaticImports(final ImportCustomizer ic, final Set<String> staticImports) { - for (final String staticImport : staticImports) { - if (staticImport.endsWith(DOT_STAR)) { - ic.addStaticStars(staticImport.replace(DOT_STAR, EMPTY_STRING)); - } else { - final int place = staticImport.lastIndexOf(PERIOD); - ic.addStaticImport(staticImport.substring(0, place), staticImport.substring(place + 1)); - } - } - } - - protected static void processImports(final ImportCustomizer ic, final Set<String> imports) { - for (final String imp : imports) { - if (imp.endsWith(DOT_STAR)) { - ic.addStarImports(imp.replace(DOT_STAR, EMPTY_STRING)); - } else { - ic.addImports(imp); - } - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/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 deleted file mode 100644 index 0e8cc38..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/CompilerCustomizerProvider.java +++ /dev/null @@ -1,39 +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.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; -import org.apache.tinkerpop.gremlin.jsr223.Customizer; -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) - * @deprecated As of release 3.2.5, replaced by {@link Customizer}. - */ -@Deprecated -public interface CompilerCustomizerProvider { - - /** - * 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/da909d1e/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/DefaultImportCustomizerProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/DefaultImportCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/DefaultImportCustomizerProvider.java deleted file mode 100644 index 7282e81..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/DefaultImportCustomizerProvider.java +++ /dev/null @@ -1,80 +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.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer; - -import java.util.HashSet; -import java.util.Set; - -/** - * Grabs the standard Gremlin core classes and allows additional imports to be added. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.5, replaced by {@link DefaultImportCustomizer}. - */ -@Deprecated -public class DefaultImportCustomizerProvider extends AbstractImportCustomizerProvider { - private static Set<String> staticExtraImports = new HashSet<>(); - private static Set<String> staticExtraStaticImports = new HashSet<>(); - - /** - * Utilizes imports defined statically by initializeStatically(). - */ - public DefaultImportCustomizerProvider() { - this.extraImports.addAll(staticExtraImports); - this.extraStaticImports.addAll(staticExtraStaticImports); - } - - /** - * Utilizes imports defined by the supplied arguments. Those imports defined statically through - * initializeStatically() are ignored. - */ - public DefaultImportCustomizerProvider(final Set<String> extraImports, final Set<String> extraStaticImports) { - this.extraStaticImports.addAll(extraStaticImports); - this.extraImports.addAll(extraImports); - } - - /** - * Utilizes imports defined by the supplied arguments. Those imports defined statically through - * initializeStatically() are ignored. - * - * @param baseCustomizer Imports from this customizer get added to the new one - */ - public DefaultImportCustomizerProvider(final ImportCustomizerProvider baseCustomizer, - final Set<String> extraImports, final Set<String> extraStaticImports) { - this(extraImports, extraStaticImports); - this.extraImports.addAll(baseCustomizer.getExtraImports()); - this.extraStaticImports.addAll(baseCustomizer.getExtraStaticImports()); - } - - /** - * Allows imports to defined globally and statically. This method must be called prior to initialization of - * a ScriptEngine instance through the ScriptEngineFactory. - */ - public static void initializeStatically(final Set<String> extraImports, final Set<String> extraStaticImports) { - if (extraImports != null) { - staticExtraImports = extraImports; - } - - if (extraStaticImports != null) { - staticExtraStaticImports = extraStaticImports; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/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 deleted file mode 100644 index 01f6995..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/EmptyImportCustomizerProvider.java +++ /dev/null @@ -1,87 +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.codehaus.groovy.control.customizers.ImportCustomizer; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * This {@link ImportCustomizerProvider} is empty and comes with no pre-defined imports at all. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.5, replaced by {@link ImportCustomizer} - */ -@Deprecated -public class EmptyImportCustomizerProvider extends DefaultImportCustomizerProvider { - - /** - * Utilizes imports defined by the supplied arguments. - */ - public EmptyImportCustomizerProvider(final Set<String> extraImports, final Set<String> extraStaticImports) { - this.extraStaticImports.addAll(extraStaticImports); - this.extraImports.addAll(extraImports); - } - - /** - * Utilizes imports defined by the supplied arguments. - * - * @param baseCustomizer Imports from this customizer get added to the new one. - */ - public EmptyImportCustomizerProvider(final ImportCustomizerProvider baseCustomizer, - final Set<String> extraImports, final Set<String> extraStaticImports) { - this(extraImports, extraStaticImports); - this.extraImports.addAll(baseCustomizer.getImports()); - this.extraImports.addAll(baseCustomizer.getExtraImports()); - this.extraStaticImports.addAll(baseCustomizer.getStaticImports()); - this.extraStaticImports.addAll(baseCustomizer.getExtraStaticImports()); - } - - @Override - public CompilationCustomizer create() { - final ImportCustomizer ic = new ImportCustomizer(); - - processImports(ic, extraImports); - processStaticImports(ic, extraStaticImports); - - return ic; - } - - @Override - public Set<String> getImports() { - return Collections.emptySet(); - } - - @Override - public Set<String> getStaticImports() { - return Collections.emptySet(); - } - - @Override - public Set<String> getAllImports() { - final Set<String> allImports = new HashSet<>(); - allImports.addAll(extraImports); - allImports.addAll(extraStaticImports); - - return allImports; - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/ImportCustomizerProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/ImportCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/ImportCustomizerProvider.java deleted file mode 100644 index cb71865..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/ImportCustomizerProvider.java +++ /dev/null @@ -1,41 +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.ImportCustomizer; - -import java.util.Set; - -/** - * Allows customization of the imports used by the GremlinGroovyScriptEngine implementation. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.5, replaced by {@link ImportCustomizer} - */ -@Deprecated -public interface ImportCustomizerProvider extends CompilerCustomizerProvider { - - Set<String> getExtraImports(); - - Set<String> getExtraStaticImports(); - - Set<String> getImports(); - - Set<String> getStaticImports(); -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/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 deleted file mode 100644 index 433a51d..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/NoImportCustomizerProvider.java +++ /dev/null @@ -1,64 +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.codehaus.groovy.control.customizers.ImportCustomizer; - -import java.util.Collections; -import java.util.Set; - -/** - * Provides no imports. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.5, replaced by {@link ImportCustomizer} - */ -@Deprecated -public final class NoImportCustomizerProvider implements ImportCustomizerProvider { - - public static final NoImportCustomizerProvider INSTANCE = new NoImportCustomizerProvider(); - - private NoImportCustomizerProvider() {} - - @Override - public CompilationCustomizer create() { - return new ImportCustomizer(); - } - - @Override - public Set<String> getExtraImports() { - return Collections.emptySet(); - } - - @Override - public Set<String> getExtraStaticImports() { - return Collections.emptySet(); - } - - @Override - public Set<String> getImports() { - return Collections.emptySet(); - } - - @Override - public Set<String> getStaticImports() { - return Collections.emptySet(); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java index 80e72fd..2d04fb2 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java @@ -20,35 +20,27 @@ package org.apache.tinkerpop.gremlin.groovy.engine; import org.apache.commons.lang.ClassUtils; import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin; +import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine; import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; -import org.javatuples.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.script.Bindings; +import javax.script.Compilable; import javax.script.CompiledScript; import javax.script.ScriptException; import javax.script.SimpleBindings; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; 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.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -61,7 +53,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -81,28 +72,19 @@ import java.util.stream.Stream; public class GremlinExecutor implements AutoCloseable { private static final Logger logger = LoggerFactory.getLogger(GremlinExecutor.class); - /** - * {@link ScriptEngines} instance to evaluate Gremlin script requests. - */ - private ScriptEngines scriptEngines; - private GremlinScriptEngineManager gremlinScriptEngineManager; - private final Map<String, EngineSettings> settings; private final Map<String, Map<String, Map<String,Object>>> plugins; private final long scriptEvaluationTimeout; private final Bindings globalBindings; - private final List<List<String>> use; private final ExecutorService executorService; private final ScheduledExecutorService scheduledExecutorService; private final Consumer<Bindings> beforeEval; private final Consumer<Bindings> afterSuccess; private final Consumer<Bindings> afterTimeout; private final BiConsumer<Bindings, Throwable> afterFailure; - private final Set<String> enabledPlugins; private final boolean suppliedExecutor; private final boolean suppliedScheduledExecutor; - private boolean useGremlinScriptEngineManager; private GremlinExecutor(final Builder builder, final boolean suppliedExecutor, final boolean suppliedScheduledExecutor) { @@ -113,24 +95,13 @@ public class GremlinExecutor implements AutoCloseable { this.afterSuccess = builder.afterSuccess; this.afterTimeout = builder.afterTimeout; this.afterFailure = builder.afterFailure; - this.use = builder.use; - this.settings = builder.settings; this.plugins = builder.plugins; this.scriptEvaluationTimeout = builder.scriptEvaluationTimeout; this.globalBindings = builder.globalBindings; - this.enabledPlugins = builder.enabledPlugins; this.gremlinScriptEngineManager = new CachedGremlinScriptEngineManager(); initializeGremlinScriptEngineManager(); - // this is temporary so that we can have backward compatibility to the old plugin system and ScriptEngines - // approach to configuring Gremlin Server and GremlinExecutor. This code/check should be removed with the - // deprecated code around this is removed. - if (!useGremlinScriptEngineManager) - this.scriptEngines = createScriptEngines(); - else - this.scriptEngines = null; - this.suppliedExecutor = suppliedExecutor; this.suppliedScheduledExecutor = suppliedScheduledExecutor; } @@ -147,14 +118,18 @@ public class GremlinExecutor implements AutoCloseable { /** * Attempts to compile a script and cache it in the request {@link javax.script.ScriptEngine}. This is only - * possible if the {@link javax.script.ScriptEngine} implementation implements {@link javax.script.Compilable}. + * possible if the {@link javax.script.ScriptEngine} implementation implements {@link Compilable}. * In the event that the requested {@link javax.script.ScriptEngine} does not implement it, the method will * return empty. */ public Optional<CompiledScript> compile(final String script, final Optional<String> language) throws ScriptException { final String lang = language.orElse("gremlin-groovy"); try { - return Optional.of(scriptEngines.compile(script, lang)); + final GremlinScriptEngine scriptEngine = gremlinScriptEngineManager.getEngineByName(lang); + if (scriptEngine instanceof Compilable) + return Optional.of(((Compilable) scriptEngine).compile(script)); + else + return Optional.empty(); } catch (UnsupportedOperationException uoe) { return Optional.empty(); } @@ -308,8 +283,7 @@ public class GremlinExecutor implements AutoCloseable { logger.debug("Evaluating script - {} - in thread [{}]", script, Thread.currentThread().getName()); // do this weirdo check until the now deprecated ScriptEngines is gutted - final Object o = useGremlinScriptEngineManager ? - gremlinScriptEngineManager.getEngineByName(lang).eval(script, bindings) : scriptEngines.eval(script, bindings, lang); + final Object o = gremlinScriptEngineManager.getEngineByName(lang).eval(script, bindings); // apply a transformation before sending back the result - useful when trying to force serialization // in the same thread that the eval took place given ThreadLocal nature of graphs as well as some @@ -362,16 +336,7 @@ public class GremlinExecutor implements AutoCloseable { bindings.putAll(globalBindings); bindings.putAll(boundVars); - return useGremlinScriptEngineManager ? - gremlinScriptEngineManager.getEngineByName(lang).eval(bytecode, bindings) : scriptEngines.eval(bytecode, bindings, lang); - } - - /** - * @deprecated As of release 3.2.4, replaced by {@link #getScriptEngineManager()}. - */ - @Deprecated - public ScriptEngines getScriptEngines() { - return this.scriptEngines; + return gremlinScriptEngineManager.getEngineByName(lang).eval(bytecode, bindings); } public GremlinScriptEngineManager getScriptEngineManager() { @@ -431,12 +396,6 @@ public class GremlinExecutor implements AutoCloseable { } } - try { - scriptEngines.close(); - } catch (Exception ex) { - logger.warn("Error while shutting down the ScriptEngines in the GremlinExecutor", ex); - } - future.complete(null); }, "gremlin-executor-close").start(); @@ -444,8 +403,6 @@ public class GremlinExecutor implements AutoCloseable { } private void initializeGremlinScriptEngineManager() { - this.useGremlinScriptEngineManager = !plugins.entrySet().isEmpty(); - for (Map.Entry<String, Map<String, Map<String,Object>>> config : plugins.entrySet()) { final String language = config.getKey(); final Map<String, Map<String,Object>> pluginConfigs = config.getValue(); @@ -493,113 +450,23 @@ public class GremlinExecutor implements AutoCloseable { } } - if (this.useGremlinScriptEngineManager) { - gremlinScriptEngineManager.setBindings(globalBindings); - } - } - - private ScriptEngines createScriptEngines() { - // plugins already on the path - ones static to the classpath - final List<org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin> globalPlugins = new ArrayList<>(); - ServiceLoader.load(org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin.class).forEach(globalPlugins::add); - - return new ScriptEngines(se -> { - // this first part initializes the scriptengines Map - for (Map.Entry<String, EngineSettings> config : settings.entrySet()) { - final String language = config.getKey(); - se.reload(language, new HashSet<>(config.getValue().getImports()), - new HashSet<>(config.getValue().getStaticImports()), config.getValue().getConfig()); - } - - // use grabs dependencies and returns plugins to load - final List<org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin> pluginsToLoad = new ArrayList<>(globalPlugins); - use.forEach(u -> { - if (u.size() != 3) - logger.warn("Could not resolve dependencies for [{}]. Each entry for the 'use' configuration must include [groupId, artifactId, version]", u); - else { - logger.info("Getting dependencies for [{}]", u); - pluginsToLoad.addAll(se.use(u.get(0), u.get(1), u.get(2))); - } - }); - - // now that all dependencies are in place, the imports can't get messed up if a plugin tries to execute - // a script (as the script engine appends the import list to the top of all scripts passed to the engine). - // only enable those plugins that are configured to be enabled. - se.loadPlugins(pluginsToLoad.stream().filter(plugin -> enabledPlugins.contains(plugin.getName())).collect(Collectors.toList())); - - // initialization script eval can now be performed now that dependencies are present with "use" - for (Map.Entry<String, EngineSettings> config : settings.entrySet()) { - final String language = config.getKey(); - - // script engine initialization files that fail will only log warnings - not fail server initialization - final AtomicBoolean hasErrors = new AtomicBoolean(false); - config.getValue().getScripts().stream().map(File::new).filter(f -> { - if (!f.exists()) { - logger.warn("Could not initialize {} ScriptEngine with {} as file does not exist", language, f); - hasErrors.set(true); - } - - return f.exists(); - }).map(f -> { - try { - return Pair.with(f, Optional.of(new FileReader(f))); - } catch (IOException ioe) { - logger.warn("Could not initialize {} ScriptEngine with {} as file could not be read - {}", language, f, ioe.getMessage()); - hasErrors.set(true); - return Pair.with(f, Optional.<FileReader>empty()); - } - }).filter(p -> p.getValue1().isPresent()).map(p -> Pair.with(p.getValue0(), p.getValue1().get())).forEachOrdered(p -> { - try { - final Bindings bindings = new SimpleBindings(); - bindings.putAll(globalBindings); - - // evaluate init scripts with hard reference so as to ensure it doesn't get garbage collected - bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_HARD); - - // the returned object should be a Map of initialized global bindings - final Object initializedBindings = se.eval(p.getValue1(), bindings, language); - if (initializedBindings != null && initializedBindings instanceof Map) - globalBindings.putAll((Map) initializedBindings); - else - logger.warn("Initialization script {} did not return a Map - no global bindings specified", p.getValue0()); - - logger.info("Initialized {} ScriptEngine with {}", language, p.getValue0()); - } catch (ScriptException sx) { - hasErrors.set(true); - logger.warn("Could not initialize {} ScriptEngine with {} as script could not be evaluated - {}", language, p.getValue0(), sx.getMessage()); - } - }); - } - }); + gremlinScriptEngineManager.setBindings(globalBindings); } /** * Create a {@code Builder} with the gremlin-groovy ScriptEngine configured. */ public static Builder build() { - return new Builder().addEngineSettings("gremlin-groovy", new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new HashMap<>()); - } - - /** - * Create a {@code Builder} and specify the first ScriptEngine to be included. - * - * @deprecated As of release 3.2.4, replaced by {@link #build()}. - */ - public static Builder build(final String engineName, final List<String> imports, - final List<String> staticImports, final List<String> scripts, - final Map<String, Object> config) { - return new Builder().addEngineSettings(engineName, imports, staticImports, scripts, config); + return new Builder(); } public final static class Builder { private long scriptEvaluationTimeout = 8000; - private Map<String, EngineSettings> settings = new HashMap<>(); private Map<String, Map<String, Map<String,Object>>> plugins = new HashMap<>(); private ExecutorService executorService = null; private ScheduledExecutorService scheduledExecutorService = null; - private Set<String> enabledPlugins = new HashSet<>(); private Consumer<Bindings> beforeEval = (b) -> { }; private Consumer<Bindings> afterSuccess = (b) -> { @@ -608,37 +475,12 @@ public class GremlinExecutor implements AutoCloseable { }; private BiConsumer<Bindings, Throwable> afterFailure = (b, e) -> { }; - private List<List<String>> use = new ArrayList<>(); private Bindings globalBindings = new org.apache.tinkerpop.gremlin.jsr223.ConcurrentBindings(); private Builder() { } /** - * Add a particular script engine for the executor to instantiate. - * - * @param engineName The name of the engine as defined by the engine itself. - * @param imports A list of imports for the engine. - * @param staticImports A list of static imports for the engine. - * @param scripts A list of scripts to execute in the engine to initialize it. - * @param config Custom configuration map for the ScriptEngine - * - * @deprecated As of release 3.2.4, replaced by {@link #addPlugins(String, Map)}. - */ - @Deprecated - public Builder addEngineSettings(final String engineName, final List<String> imports, - final List<String> staticImports, final List<String> scripts, - final Map<String, Object> config) { - if (null == imports) throw new IllegalArgumentException("imports cannot be null"); - if (null == staticImports) throw new IllegalArgumentException("staticImports cannot be null"); - if (null == scripts) throw new IllegalArgumentException("scripts cannot be null"); - final Map<String, Object> m = null == config ? Collections.emptyMap() : config; - - settings.put(engineName, new EngineSettings(imports, staticImports, scripts, m)); - return this; - } - - /** * Add a configuration for a {@link GremlinPlugin} to the executor. The key is the fully qualified class name * of the {@link GremlinPlugin} instance and the value is a map of configuration values. In that map, the key * is the name of a builder method on the {@link GremlinPlugin} and the value is some argument to pass to that @@ -673,17 +515,6 @@ public class GremlinExecutor implements AutoCloseable { } /** - * Replaces any settings provided. - * - * @deprecated As of release 3.2.4, replaced by {@link #addPlugins(String, Map)}. - */ - @Deprecated - public Builder engineSettings(final Map<String, EngineSettings> settings) { - this.settings = settings; - return this; - } - - /** * The thread pool used to evaluate scripts. */ public Builder executorService(final ExecutorService executorService) { @@ -733,29 +564,6 @@ public class GremlinExecutor implements AutoCloseable { return this; } - /** - * A set of maven coordinates for dependencies to be applied for the script engine instances. - * - * @deprecated As of release 3.2.4, not replaced. - */ - @Deprecated - public Builder use(final List<List<String>> use) { - this.use = use; - return this; - } - - /** - * Set of the names of plugins that should be enabled for the engine. - * - * @deprecated As of release 3.2.4, replaced by {@link #addPlugins(String, Map)} though behavior is not quite - * the same. - */ - @Deprecated - public Builder enabledPlugins(final Set<String> enabledPlugins) { - this.enabledPlugins = enabledPlugins; - return this; - } - public GremlinExecutor create() { final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("gremlin-executor-default-%d").build(); @@ -783,37 +591,6 @@ public class GremlinExecutor implements AutoCloseable { } } - private static class EngineSettings { - private List<String> imports; - private List<String> staticImports; - private List<String> scripts; - private Map<String, Object> config; - - public EngineSettings(final List<String> imports, final List<String> staticImports, - final List<String> scripts, final Map<String, Object> config) { - this.imports = imports; - this.staticImports = staticImports; - this.scripts = scripts; - this.config = config; - } - - private List<String> getImports() { - return imports; - } - - private List<String> getStaticImports() { - return staticImports; - } - - private List<String> getScripts() { - return scripts; - } - - public Map<String, Object> getConfig() { - return config; - } - } - /** * The lifecycle of execution within the {@link #eval(String, String, Bindings, LifeCycle)} method. Since scripts * are executed in a thread pool and graph transactions are bound to a thread all actions related to that script http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/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 deleted file mode 100644 index 7dcfc5c..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java +++ /dev/null @@ -1,461 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tinkerpop.gremlin.groovy.engine; - -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider; -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.jsr223.customizer.ConfigurationCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin; -import org.apache.tinkerpop.gremlin.groovy.plugin.IllegalEnvironmentException; -import org.apache.tinkerpop.gremlin.jsr223.DefaultGremlinScriptEngineManager; -import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine; -import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineManager; -import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; -import org.apache.tinkerpop.gremlin.process.traversal.Traversal; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.script.Bindings; -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptException; -import javax.script.SimpleBindings; -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; -import java.util.Optional; -import java.util.Queue; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.locks.LockSupport; -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. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.4, not directly replaced - see {@link GremlinScriptEngineManager}. - */ -@Deprecated -public class ScriptEngines implements AutoCloseable { - private static final Logger logger = LoggerFactory.getLogger(ScriptEngines.class); - - private final static GremlinScriptEngineManager SCRIPT_ENGINE_MANAGER = new DefaultGremlinScriptEngineManager(); - private static final GremlinGroovyScriptEngineFactory gremlinGroovyScriptEngineFactory = new GremlinGroovyScriptEngineFactory(); - - /** - * {@code ScriptEngine} objects configured for the server keyed on the language name. - */ - private final Map<String, GremlinScriptEngine> scriptEngines = new ConcurrentHashMap<>(); - - private final AtomicBoolean controlOperationExecuting = new AtomicBoolean(false); - private final Queue<Thread> controlWaiters = new ConcurrentLinkedQueue<>(); - private final Queue<Thread> evalWaiters = new ConcurrentLinkedQueue<>(); - - private final Consumer<ScriptEngines> initializer; - - /** - * Creates a new object. - * - * @param initializer allows for external initialization of the newly created {@code ScriptEngines} object - */ - public ScriptEngines(final Consumer<ScriptEngines> initializer) { - this.initializer = initializer; - this.initializer.accept(this); - } - - public Traversal.Admin eval(final Bytecode bytecode, final Bindings bindings, final String language) throws ScriptException { - if (!scriptEngines.containsKey(language)) - throw new IllegalArgumentException(String.format("Language [%s] not supported", language)); - - awaitControlOp(); - - final GremlinScriptEngine engine = scriptEngines.get(language); - final Bindings all = mergeBindings(bindings, engine); - - return engine.eval(bytecode, all); - } - - /** - * Evaluate a script with {@code Bindings} for a particular language. - */ - public Object eval(final String script, final Bindings bindings, final String language) throws ScriptException { - checkLanguageIsSupported(language); - - awaitControlOp(); - - final ScriptEngine engine = scriptEngines.get(language); - final Bindings all = mergeBindings(bindings, engine); - - return engine.eval(script, all); - } - - /** - * Evaluate a script with {@code Bindings} for a particular language. - */ - public Object eval(final Reader reader, final Bindings bindings, final String language) - throws ScriptException { - checkLanguageIsSupported(language); - - awaitControlOp(); - - final ScriptEngine engine = scriptEngines.get(language); - final Bindings all = mergeBindings(bindings, engine); - - return engine.eval(reader, all); - } - - /** - * Compiles a script without executing it. - * - * @throws UnsupportedOperationException if the {@link ScriptEngine} implementation does not implement - * the {@link javax.script.Compilable} interface. - */ - public CompiledScript compile(final String script, final String language) throws ScriptException { - if (!scriptEngines.containsKey(language)) - throw new IllegalArgumentException("Language [%s] not supported"); - - awaitControlOp(); - final ScriptEngine scriptEngine = scriptEngines.get(language); - if (!Compilable.class.isAssignableFrom(scriptEngine.getClass())) - throw new UnsupportedOperationException(String.format("ScriptEngine for %s does not implement %s", language, Compilable.class.getName())); - - final Compilable compilable = (Compilable) scriptEngine; - return compilable.compile(script); - } - - /** - * Compiles a script without executing it. - * - * @throws UnsupportedOperationException if the {@link ScriptEngine} implementation does not implement - * the {@link javax.script.Compilable} interface. - */ - public CompiledScript compile(final Reader script, final String language) throws ScriptException { - if (!scriptEngines.containsKey(language)) - throw new IllegalArgumentException("Language [%s] not supported"); - - awaitControlOp(); - final ScriptEngine scriptEngine = scriptEngines.get(language); - if (scriptEngine instanceof Compilable) - throw new UnsupportedOperationException(String.format("ScriptEngine for %s does not implement %s", language, Compilable.class.getName())); - - final Compilable compilable = (Compilable) scriptEngine; - return compilable.compile(script); - } - - /** - * Reload a {@code ScriptEngine} with fresh imports. Waits for any existing script evaluations to complete but - * then blocks other operations until complete. - */ - public void reload(final String language, final Set<String> imports, final Set<String> staticImports, - final Map<String, Object> config) { - try { - signalControlOpStart(); - if (scriptEngines.containsKey(language)) - scriptEngines.remove(language); - - final GremlinScriptEngine scriptEngine = createScriptEngine(language, imports, staticImports, config) - .orElseThrow(() -> new IllegalArgumentException(String.format("Language [%s] not supported", language))); - scriptEngines.put(language, scriptEngine); - - logger.info("Loaded {} ScriptEngine", language); - } finally { - signalControlOpEnd(); - } - } - - /** - * Perform append to the existing import list for all {@code ScriptEngine} instances that implement the - * {@link DependencyManager} interface. Waits for any existing script evaluations to complete but - * then blocks other operations until complete. - */ - public void addImports(final Set<String> imports) { - try { - signalControlOpStart(); - getDependencyManagers().forEach(dm -> dm.addImports(imports)); - } finally { - signalControlOpEnd(); - } - } - - /** - * Pull in dependencies given some Maven coordinates. Cycle through each {@code ScriptEngine} and determine if it - * implements {@link DependencyManager}. For those that do call the @{link DependencyManager#use} method to fire - * it up. Waits for any existing script evaluations to complete but then blocks other operations until complete. - */ - public List<GremlinPlugin> use(final String group, final String artifact, final String version) { - final List<GremlinPlugin> pluginsToLoad = new ArrayList<>(); - try { - signalControlOpStart(); - getDependencyManagers().forEach(dm -> { - try { - pluginsToLoad.addAll(dm.use(group, artifact, version)); - } catch (Exception ex) { - logger.warn("Could not get dependency for [{}, {}, {}] - {}", group, artifact, version, ex.getMessage()); - } - }); - } finally { - signalControlOpEnd(); - } - - return pluginsToLoad; - } - - /** - * For each {@link DependencyManager} try to load the specified plugins. - */ - public void loadPlugins(final List<GremlinPlugin> plugins) { - try { - signalControlOpStart(); - getDependencyManagers().forEach(dm -> { - try { - dm.loadPlugins(plugins); - } catch (IllegalEnvironmentException iee) { - logger.warn("Some plugins may not have been loaded to {} - {}", dm.getClass().getSimpleName(), iee.getMessage()); - } catch (Exception ex) { - logger.error(String.format("Some plugins may not have been loaded to %s", dm.getClass().getSimpleName()), ex); - } - }); - } finally { - signalControlOpEnd(); - } - } - - /** - * Iterate through all the {@link ScriptEngine} implementations and if they implement {@link AutoCloseable} - * then call the {@link AutoCloseable#close()} method. After that is complete, the script engine cache will be - * cleared. - */ - @Override - public void close() throws Exception { - try { - signalControlOpStart(); - scriptEngines.values().stream() - .filter(se -> se instanceof AutoCloseable) - .map(se -> (AutoCloseable) se).forEach(c -> { - try { - c.close(); - } catch (Exception ignored) { - } - }); - scriptEngines.clear(); - } finally { - signalControlOpEnd(); - } - } - - /** - * Resets the ScriptEngines and re-initializes them. Waits for any existing script evaluations to complete but - * then blocks other operations until complete. - */ - public void reset() { - try { - signalControlOpStart(); - getDependencyManagers().forEach(DependencyManager::reset); - } finally { - signalControlOpEnd(); - this.initializer.accept(this); - } - } - - /** - * List dependencies for those {@code ScriptEngine} objects that implement the {@link DependencyManager} interface. - */ - public Map<String, List<Map>> dependencies() { - final Map<String, List<Map>> m = new HashMap<>(); - scriptEngines.entrySet().stream() - .filter(kv -> kv.getValue() instanceof DependencyManager) - .forEach(kv -> m.put(kv.getKey(), Arrays.asList(((DependencyManager) kv.getValue()).dependencies()))); - return m; - } - - /** - * List the imports for those {@code ScriptEngine} objects that implement the {@link DependencyManager} interface. - */ - public Map<String, List<Map>> imports() { - final Map<String, List<Map>> m = new HashMap<>(); - scriptEngines.entrySet().stream() - .filter(kv -> kv.getValue() instanceof DependencyManager) - .forEach(kv -> m.put(kv.getKey(), Arrays.asList(((DependencyManager) kv.getValue()).imports()))); - return m; - } - - /** - * Get the set of {@code ScriptEngine} that implement {@link DependencyManager} interface. - */ - private Set<DependencyManager> getDependencyManagers() { - return scriptEngines.entrySet().stream() - .map(Map.Entry::getValue) - .filter(se -> se instanceof DependencyManager) - .map(se -> (DependencyManager) se) - .collect(Collectors.<DependencyManager>toSet()); - } - - /** - * Called when a control operation starts. Attempts to grab a lock on the "control" process and parks the - * current thread if it cannot. Parked threads are queued until released by {@link #signalControlOpEnd()}. - */ - private void signalControlOpStart() { - boolean wasInterrupted = false; - final Thread current = Thread.currentThread(); - controlWaiters.add(current); - - // Block while not first in queue or cannot acquire lock - while (controlWaiters.peek() != current || !controlOperationExecuting.compareAndSet(false, true)) { - LockSupport.park(this); - if (Thread.interrupted()) - wasInterrupted = true; - } - - controlWaiters.remove(); - if (wasInterrupted) - current.interrupt(); - } - - /** - * Called when a control operation is finished. Releases the lock for the next thread trying to call a - * control operation. If there are no additional threads trying to call control operations then unpark - * any evaluation threads that are waiting. - */ - private void signalControlOpEnd() { - controlOperationExecuting.set(false); - LockSupport.unpark(controlWaiters.peek()); - - // let the eval threads proceed as long as the control functions waiting are all complete - if (controlWaiters.size() == 0) { - Thread t = evalWaiters.poll(); - while (t != null) { - LockSupport.unpark(t); - t = evalWaiters.poll(); - } - } - } - - /** - * If a control operation is executing or there are some in the queue to be executed, then block the current - * thread until that process completes. - */ - private void awaitControlOp() { - if (controlWaiters.size() > 0 || controlOperationExecuting.get()) { - evalWaiters.add(Thread.currentThread()); - LockSupport.park(this); - } - } - - private static synchronized Optional<GremlinScriptEngine> createScriptEngine(final String language, - final Set<String> imports, - final Set<String> staticImports, - final Map<String, Object> config) { - // gremlin-groovy gets special initialization for mapper imports and such. could implement this more - // 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)); - - // 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 Optional<Constructor> constructor = Stream.of(providerClass.getConstructors()) - .filter(c -> c.getParameterCount() == argClasses.length && - allMatch(c.getParameterTypes(), argClasses)) - .findFirst(); - - if (constructor.isPresent()) providers.add((CompilerCustomizerProvider) - constructor.get().newInstance(args)); - else - throw new IllegalStateException(String.format("Could not configure %s with the supplied options %s", - ConfigurationCustomizerProvider.class.getName(), Arrays.asList(args))); - } else { - providers.add((CompilerCustomizerProvider) providerClass.newInstance()); - } - } catch (Exception ex) { - logger.warn(String.format("Could not instantiate CompilerCustomizerProvider implementation [%s]. It will not be applied.", k), ex); - } - }); - - final CompilerCustomizerProvider[] providerArray = new CompilerCustomizerProvider[providers.size()]; - return Optional.of(new GremlinGroovyScriptEngine(providers.toArray(providerArray))); - } else { - return Optional.ofNullable(SCRIPT_ENGINE_MANAGER.getEngineByName(language)); - } - } - - /** - * Determine if the constructor argument types match the arg types that are going to be passed in to that - * constructor. - */ - private static boolean allMatch(final Class<?>[] constructorArgTypes, final Class<?>[] argTypes) { - for (int ix = 0; ix < constructorArgTypes.length; ix++) { - if (!constructorArgTypes[ix].isAssignableFrom(argTypes[ix])) { - return false; - } - } - - return true; - } - - /** - * Takes the bindings from a request for eval and merges them with the {@code ENGINE_SCOPE} bindings. - */ - private static Bindings mergeBindings(final Bindings bindings, final ScriptEngine engine) { - // plugins place "globals" here - see ScriptEnginePluginAcceptor - final Bindings global = engine.getBindings(ScriptContext.GLOBAL_SCOPE); - if (null == global) return bindings; - - // merge the globals with the incoming bindings where local bindings "win" - final Bindings all = new SimpleBindings(global); - all.putAll(bindings); - return all; - } - - private void checkLanguageIsSupported(final String language) { - if (!scriptEngines.containsKey(language)) { - throw new IllegalArgumentException(String.format("Language [%s] not supported", language)); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/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 deleted file mode 100644 index 4f1384d..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/DependencyManager.java +++ /dev/null @@ -1,84 +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.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 org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Provides a way to dynamically consume dependencies into the ScriptEngine classloader. With Groovy this is - * somewhat easily accomplished with Grape, but other ScriptEngine implementations might have ways to do it too, - * so this interface makes that possible to expose. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.4, not replaced - no longer needed under the new {@link GremlinScriptEngine} model. - */ -@Deprecated -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 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 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(PluginAcceptor)}. - */ - List<GremlinPlugin> use(final String group, final String artifact, final String version); - - /** - * Load a list of {@link GremlinPlugin} instances. These plugins are typically returned from calls to - * {@link #use(String, String, String)}. - * - * @throws GremlinPluginException if there is a problem loading the plugin itself. - */ - void loadPlugins(final List<GremlinPlugin> plugins) throws GremlinPluginException; - - /** - * Perform class imports for the ScriptEngine. - */ - void addImports(final Set<String> importStatements); - - /** - * List the dependencies in the ScriptEngine classloader. - */ - Map[] dependencies(); - - /** - * List the imports in the ScriptEngine; - */ - Map<String, Set<String>> imports(); - - /** - * Reset the ScriptEngine. Clear caches and kill the classloader. - */ - void reset(); -}
