TINKERPOP-1562 Renamed GremlinModule to GremlinPlugin in gremlin-core
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/68487c2b Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/68487c2b Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/68487c2b Branch: refs/heads/master Commit: 68487c2b89fd589256925af2750907ef8da3c07a Parents: d7d6d5b Author: Stephen Mallette <sp...@genoprime.com> Authored: Mon Nov 21 13:15:02 2016 -0500 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Fri Dec 2 06:28:50 2016 -0500 ---------------------------------------------------------------------- .../groovy/plugin/GiraphGremlinPlugin.java | 3 +- .../giraph/jsr223/GiraphGremlinModule.java | 58 ------- .../giraph/jsr223/GiraphGremlinPlugin.java | 58 +++++++ .../gremlin/jsr223/AbstractGremlinModule.java | 58 ------- .../gremlin/jsr223/AbstractGremlinPlugin.java | 58 +++++++ .../gremlin/jsr223/CoreGremlinModule.java | 62 ------- .../gremlin/jsr223/CoreGremlinPlugin.java | 62 +++++++ .../DefaultGremlinScriptEngineManager.java | 6 +- .../tinkerpop/gremlin/jsr223/GremlinModule.java | 70 -------- .../tinkerpop/gremlin/jsr223/GremlinPlugin.java | 70 ++++++++ .../jsr223/GremlinScriptEngineManager.java | 4 +- .../gremlin/jsr223/ImportGremlinModule.java | 173 ------------------- .../gremlin/jsr223/ImportGremlinPlugin.java | 173 +++++++++++++++++++ .../gremlin/jsr223/RemoteAcceptor.java | 2 +- .../gremlin/jsr223/ScriptFileGremlinPlugin.java | 71 ++++++++ .../gremlin/jsr223/ScriptFileModule.java | 71 -------- .../gremlin/jsr223/ImportGremlinModuleTest.java | 149 ---------------- .../gremlin/jsr223/ImportGremlinPluginTest.java | 149 ++++++++++++++++ .../gremlin/groovy/engine/GremlinExecutor.java | 19 +- .../tinkerpop/gremlin/server/Settings.java | 4 +- .../jsr223/GremlinServerGremlinModule.java | 42 ----- .../jsr223/GremlinServerGremlinPlugin.java | 42 +++++ .../server/util/ServerGremlinExecutor.java | 3 - 23 files changed, 701 insertions(+), 706 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/groovy/plugin/GiraphGremlinPlugin.java ---------------------------------------------------------------------- diff --git a/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/groovy/plugin/GiraphGremlinPlugin.java b/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/groovy/plugin/GiraphGremlinPlugin.java index 29f2455..80d98f9 100644 --- a/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/groovy/plugin/GiraphGremlinPlugin.java +++ b/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/groovy/plugin/GiraphGremlinPlugin.java @@ -19,7 +19,6 @@ package org.apache.tinkerpop.gremlin.giraph.groovy.plugin; -import org.apache.tinkerpop.gremlin.giraph.jsr223.GiraphGremlinModule; import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphGraphComputer; import org.apache.tinkerpop.gremlin.groovy.plugin.AbstractGremlinPlugin; import org.apache.tinkerpop.gremlin.groovy.plugin.IllegalEnvironmentException; @@ -33,7 +32,7 @@ import java.util.Set; /** * @author Marko A. Rodriguez (http://markorodriguez.com) - * @deprecated As of release 3.2.4, replaced by {@link GiraphGremlinModule}. + * @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.giraph.jsr223.GiraphGremlinPlugin}. */ @Deprecated public final class GiraphGremlinPlugin extends AbstractGremlinPlugin { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/jsr223/GiraphGremlinModule.java ---------------------------------------------------------------------- diff --git a/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/jsr223/GiraphGremlinModule.java b/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/jsr223/GiraphGremlinModule.java deleted file mode 100644 index 69f3586..0000000 --- a/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/jsr223/GiraphGremlinModule.java +++ /dev/null @@ -1,58 +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.giraph.jsr223; - -import org.apache.tinkerpop.gremlin.giraph.process.computer.EmptyOutEdges; -import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphComputation; -import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphGraphComputer; -import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphMemory; -import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphMessageCombiner; -import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphMessenger; -import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphVertex; -import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphWorkerContext; -import org.apache.tinkerpop.gremlin.giraph.process.computer.MemoryAggregator; -import org.apache.tinkerpop.gremlin.giraph.process.computer.PassThroughMemory; -import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinModule; -import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public final class GiraphGremlinModule extends AbstractGremlinModule { - private static final String MODULE_NAME = "tinkerpop.giraph"; - private static final GiraphGremlinModule instance = new GiraphGremlinModule(); - - private GiraphGremlinModule() { - super(MODULE_NAME, ImportCustomizer.build().addClassImports( - EmptyOutEdges.class, - GiraphComputation.class, - GiraphGraphComputer.class, - GiraphMemory.class, - GiraphMessageCombiner.class, - GiraphMessenger.class, - GiraphVertex.class, - GiraphWorkerContext.class, - MemoryAggregator.class, - PassThroughMemory.class).create()); - } - - public static GiraphGremlinModule instance() { - return instance; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/jsr223/GiraphGremlinPlugin.java ---------------------------------------------------------------------- diff --git a/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/jsr223/GiraphGremlinPlugin.java b/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/jsr223/GiraphGremlinPlugin.java new file mode 100644 index 0000000..a96ac86 --- /dev/null +++ b/giraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/giraph/jsr223/GiraphGremlinPlugin.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.giraph.jsr223; + +import org.apache.tinkerpop.gremlin.giraph.process.computer.EmptyOutEdges; +import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphComputation; +import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphGraphComputer; +import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphMemory; +import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphMessageCombiner; +import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphMessenger; +import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphVertex; +import org.apache.tinkerpop.gremlin.giraph.process.computer.GiraphWorkerContext; +import org.apache.tinkerpop.gremlin.giraph.process.computer.MemoryAggregator; +import org.apache.tinkerpop.gremlin.giraph.process.computer.PassThroughMemory; +import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin; +import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public final class GiraphGremlinPlugin extends AbstractGremlinPlugin { + private static final String MODULE_NAME = "tinkerpop.giraph"; + private static final GiraphGremlinPlugin instance = new GiraphGremlinPlugin(); + + private GiraphGremlinPlugin() { + super(MODULE_NAME, ImportCustomizer.build().addClassImports( + EmptyOutEdges.class, + GiraphComputation.class, + GiraphGraphComputer.class, + GiraphMemory.class, + GiraphMessageCombiner.class, + GiraphMessenger.class, + GiraphVertex.class, + GiraphWorkerContext.class, + MemoryAggregator.class, + PassThroughMemory.class).create()); + } + + public static GiraphGremlinPlugin instance() { + return instance; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/AbstractGremlinModule.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/AbstractGremlinModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/AbstractGremlinModule.java deleted file mode 100644 index 4b9cd2c..0000000 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/AbstractGremlinModule.java +++ /dev/null @@ -1,58 +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.jsr223; - -import java.util.Collections; -import java.util.Optional; -import java.util.Set; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public abstract class AbstractGremlinModule implements GremlinModule { - protected final String moduleName; - protected final Customizer[] customizers; - protected final Set<String> appliesTo; - - /** - * Creates a base {@link GremlinModule} that will apply to all {@link GremlinScriptEngine} instances. - */ - public AbstractGremlinModule(final String moduleName, final Customizer... customizers) { - this(moduleName, Collections.emptySet(), customizers); - } - /** - * Creates a base {@link GremlinModule} that will apply to specific {@link GremlinScriptEngine} instances. - */ - public AbstractGremlinModule(final String moduleName, final Set<String> appliesTo, final Customizer... customizers) { - this.moduleName = moduleName; - this.appliesTo = appliesTo; - this.customizers = customizers; - } - - @Override - public String getName() { - return moduleName; - } - - @Override - public Optional<Customizer[]> getCustomizers(final String scriptEngineName) { - return null == scriptEngineName || appliesTo.isEmpty() || appliesTo.contains(scriptEngineName) ? - Optional.of(customizers) : Optional.empty(); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/AbstractGremlinPlugin.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/AbstractGremlinPlugin.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/AbstractGremlinPlugin.java new file mode 100644 index 0000000..f25c611 --- /dev/null +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/AbstractGremlinPlugin.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.jsr223; + +import java.util.Collections; +import java.util.Optional; +import java.util.Set; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public abstract class AbstractGremlinPlugin implements GremlinPlugin { + protected final String moduleName; + protected final Customizer[] customizers; + protected final Set<String> appliesTo; + + /** + * Creates a base {@link GremlinPlugin} that will apply to all {@link GremlinScriptEngine} instances. + */ + public AbstractGremlinPlugin(final String moduleName, final Customizer... customizers) { + this(moduleName, Collections.emptySet(), customizers); + } + /** + * Creates a base {@link GremlinPlugin} that will apply to specific {@link GremlinScriptEngine} instances. + */ + public AbstractGremlinPlugin(final String moduleName, final Set<String> appliesTo, final Customizer... customizers) { + this.moduleName = moduleName; + this.appliesTo = appliesTo; + this.customizers = customizers; + } + + @Override + public String getName() { + return moduleName; + } + + @Override + public Optional<Customizer[]> getCustomizers(final String scriptEngineName) { + return null == scriptEngineName || appliesTo.isEmpty() || appliesTo.contains(scriptEngineName) ? + Optional.of(customizers) : Optional.empty(); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CoreGremlinModule.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CoreGremlinModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CoreGremlinModule.java deleted file mode 100644 index ff47767..0000000 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CoreGremlinModule.java +++ /dev/null @@ -1,62 +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.jsr223; - -import org.apache.tinkerpop.gremlin.util.CoreImports; - -import java.util.Optional; - -/** - * This module is required for a {@code ScriptEngine} to be Gremlin-enabled. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public final class CoreGremlinModule implements GremlinModule { - - private static final String MODULE_NAME = "tinkerpop.core"; - - private static final ImportCustomizer gremlinCore = ImportCustomizer.build() - .addClassImports(CoreImports.getClassImports()) - .addEnumImports(CoreImports.getEnumImports()) - .addMethodImports(CoreImports.getMethodImports()).create(); - - private static final Customizer[] customizers = new Customizer[] {gremlinCore}; - - /** - * @deprecated As of 3.2.4, replaced by {@link #instance()} as this field will later become private. - */ - @Deprecated - public static final CoreGremlinModule INSTANCE = new CoreGremlinModule(); - - private CoreGremlinModule() {} - - public static CoreGremlinModule instance() { - return INSTANCE; - } - - @Override - public Optional<Customizer[]> getCustomizers(final String scriptEngineName) { - return Optional.of(customizers); - } - - @Override - public String getName() { - return MODULE_NAME; - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CoreGremlinPlugin.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CoreGremlinPlugin.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CoreGremlinPlugin.java new file mode 100644 index 0000000..3f5ac2c --- /dev/null +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CoreGremlinPlugin.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.jsr223; + +import org.apache.tinkerpop.gremlin.util.CoreImports; + +import java.util.Optional; + +/** + * This module is required for a {@code ScriptEngine} to be Gremlin-enabled. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public final class CoreGremlinPlugin implements GremlinPlugin { + + private static final String MODULE_NAME = "tinkerpop.core"; + + private static final ImportCustomizer gremlinCore = ImportCustomizer.build() + .addClassImports(CoreImports.getClassImports()) + .addEnumImports(CoreImports.getEnumImports()) + .addMethodImports(CoreImports.getMethodImports()).create(); + + private static final Customizer[] customizers = new Customizer[] {gremlinCore}; + + /** + * @deprecated As of 3.2.4, replaced by {@link #instance()} as this field will later become private. + */ + @Deprecated + public static final CoreGremlinPlugin INSTANCE = new CoreGremlinPlugin(); + + private CoreGremlinPlugin() {} + + public static CoreGremlinPlugin instance() { + return INSTANCE; + } + + @Override + public Optional<Customizer[]> getCustomizers(final String scriptEngineName) { + return Optional.of(customizers); + } + + @Override + public String getName() { + return MODULE_NAME; + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java index 25a0612..10bdfa3 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java @@ -95,7 +95,7 @@ public class DefaultGremlinScriptEngineManager implements GremlinScriptEngineMan * List of extensions for the {@link GremlinScriptEngineManager} which will be used to supply * {@link Customizer} instances to {@link GremlinScriptEngineFactory} that are instantiated. */ - private List<GremlinModule> modules = new ArrayList<>(); + private List<GremlinPlugin> modules = new ArrayList<>(); /** * The effect of calling this constructor is the same as calling @@ -125,7 +125,7 @@ public class DefaultGremlinScriptEngineManager implements GremlinScriptEngineMan } @Override - public void addModule(final GremlinModule module) { + public void addModule(final GremlinPlugin module) { // TODO: should modules be a set based on "name" to ensure uniqueness? not sure what bad stuff can happen with dupes if (module != null) modules.add(module); } @@ -378,7 +378,7 @@ public class DefaultGremlinScriptEngineManager implements GremlinScriptEngineMan private void initEngines(final ClassLoader loader) { // always need this module for a scriptengine to be "Gremlin-enabled" - modules.add(CoreGremlinModule.INSTANCE); + modules.add(CoreGremlinPlugin.INSTANCE); Iterator<GremlinScriptEngineFactory> itty; try { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinModule.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinModule.java deleted file mode 100644 index 1077cf3..0000000 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinModule.java +++ /dev/null @@ -1,70 +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.jsr223; - -import java.util.Optional; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public interface GremlinModule { - /** - * The name of the module. This name should be unique (use a namespaced approach) as naming clashes will - * prevent proper module operations. Modules developed by TinkerPop will be prefixed with "tinkerpop." - * For example, TinkerPop's implementation of Giraph would be named "tinkerpop.giraph". If Facebook were - * to do their own implementation the implementation might be called "facebook.giraph". - */ - public String getName(); - - /** - * Some modules may require a restart of the plugin host for the classloader to pick up the features. This is - * typically true of modules that rely on {@code Class.forName()} to dynamically instantiate classes from the - * root classloader (e.g. JDBC drivers that instantiate via @{code DriverManager}). - */ - public default boolean requireRestart() { - return false; - } - - /** - * Gets the list of all {@link Customizer} implementations to assign to a new {@link GremlinScriptEngine}. This is - * the same as doing {@code getCustomizers(null)}. - */ - public default Optional<Customizer[]> getCustomizers(){ - return getCustomizers(null); - } - - /** - * Gets the list of {@link Customizer} implementations to assign to a new {@link GremlinScriptEngine}. The - * implementation should filter the returned {@code Customizers} according to the supplied name of the - * Gremlin-enabled {@code ScriptEngine}. By providing a filter, {@code GremlinModule} developers can have the - * ability to target specific {@code ScriptEngines}. - * - * @param scriptEngineName The name of the {@code ScriptEngine} or null to get all the available {@code Customizers} - */ - public Optional<Customizer[]> getCustomizers(final String scriptEngineName); - - /** - * Allows a plugin to utilize features of the {@code :remote} and {@code :submit} commands of the Gremlin Console. - * This method does not need to be implemented if the plugin is not meant for the Console for some reason or - * if it does not intend to take advantage of those commands. - */ - public default Optional<RemoteAcceptor> remoteAcceptor() { - return Optional.empty(); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinPlugin.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinPlugin.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinPlugin.java new file mode 100644 index 0000000..390c027 --- /dev/null +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinPlugin.java @@ -0,0 +1,70 @@ +/* + * 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.jsr223; + +import java.util.Optional; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public interface GremlinPlugin { + /** + * The name of the module. This name should be unique (use a namespaced approach) as naming clashes will + * prevent proper module operations. Modules developed by TinkerPop will be prefixed with "tinkerpop." + * For example, TinkerPop's implementation of Giraph would be named "tinkerpop.giraph". If Facebook were + * to do their own implementation the implementation might be called "facebook.giraph". + */ + public String getName(); + + /** + * Some modules may require a restart of the plugin host for the classloader to pick up the features. This is + * typically true of modules that rely on {@code Class.forName()} to dynamically instantiate classes from the + * root classloader (e.g. JDBC drivers that instantiate via @{code DriverManager}). + */ + public default boolean requireRestart() { + return false; + } + + /** + * Gets the list of all {@link Customizer} implementations to assign to a new {@link GremlinScriptEngine}. This is + * the same as doing {@code getCustomizers(null)}. + */ + public default Optional<Customizer[]> getCustomizers(){ + return getCustomizers(null); + } + + /** + * Gets the list of {@link Customizer} implementations to assign to a new {@link GremlinScriptEngine}. The + * implementation should filter the returned {@code Customizers} according to the supplied name of the + * Gremlin-enabled {@code ScriptEngine}. By providing a filter, {@code GremlinModule} developers can have the + * ability to target specific {@code ScriptEngines}. + * + * @param scriptEngineName The name of the {@code ScriptEngine} or null to get all the available {@code Customizers} + */ + public Optional<Customizer[]> getCustomizers(final String scriptEngineName); + + /** + * Allows a plugin to utilize features of the {@code :remote} and {@code :submit} commands of the Gremlin Console. + * This method does not need to be implemented if the plugin is not meant for the Console for some reason or + * if it does not intend to take advantage of those commands. + */ + public default Optional<RemoteAcceptor> remoteAcceptor() { + return Optional.empty(); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinScriptEngineManager.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinScriptEngineManager.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinScriptEngineManager.java index 270d136..b2966c5 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinScriptEngineManager.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinScriptEngineManager.java @@ -118,9 +118,9 @@ public interface GremlinScriptEngineManager { public List<GremlinScriptEngineFactory> getEngineFactories(); /** - * Add {@link GremlinModule} instances to customize newly created {@link GremlinScriptEngine} instances. + * Add {@link GremlinPlugin} instances to customize newly created {@link GremlinScriptEngine} instances. */ - public void addModule(final GremlinModule module); + public void addModule(final GremlinPlugin module); /** * Registers a {@link GremlinScriptEngineFactory} to handle a language name. Overrides any such association found http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinModule.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinModule.java deleted file mode 100644 index e9ca477..0000000 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinModule.java +++ /dev/null @@ -1,173 +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.jsr223; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * A module that allows custom class, static method and enum imports (i.e. those that are statically defined by a - * module within itself). A user might utilize this class to supply their own imports. This module is not specific - * to any {@link GremlinScriptEngine} - the imports are supplied to all engines. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public final class ImportGremlinModule extends AbstractGremlinModule { - private static final String MODULE_NAME = "tinkerpop.import"; - - private ImportGremlinModule(final Builder builder) { - super(MODULE_NAME, builder.appliesTo, ImportCustomizer.build() - .addClassImports(builder.classImports) - .addEnumImports(builder.enumImports) - .addMethodImports(builder.methodImports).create()); - } - - public static Builder build() { - return new Builder(); - } - - public static final class Builder { - private static final Pattern METHOD_PATTERN = Pattern.compile("(.*)#(.*)\\((.*)\\)"); - private static final Pattern ENUM_PATTERN = Pattern.compile("(.*)#(.*)"); - private Set<Class> classImports = new HashSet<>(); - private Set<Method> methodImports = new HashSet<>(); - private Set<Enum> enumImports = new HashSet<>(); - private final Set<String> appliesTo = new HashSet<>(); - - private Builder() {} - - /** - * The name of the {@link GremlinScriptEngine} that this module will apply to. Setting no values here will - * make the module available to all the engines. - */ - public Builder appliesTo(final Collection<String> scriptEngineName) { - this.appliesTo.addAll(scriptEngineName); - return this; - } - - public Builder classImports(final Collection<String> classes) { - for (String clazz : classes) { - try { - classImports.add(Class.forName(clazz)); - } catch (Exception ex) { - throw new IllegalStateException(ex); - } - } - return this; - } - - public Builder methodImports(final Collection<String> methods) { - for (String method : methods) { - try { - if (method.endsWith("#*")) { - final String classString = method.substring(0, method.length() - 2); - final Class<?> clazz = Class.forName(classString); - methodImports.addAll(allStaticMethods(clazz)); - } else { - final Matcher matcher = METHOD_PATTERN.matcher(method); - - if (!matcher.matches()) - throw new IllegalArgumentException(String.format("Could not read method descriptor - check format of: %s", method)); - - final String classString = matcher.group(1); - final String methodString = matcher.group(2); - final String argString = matcher.group(3); - final Class<?> clazz = Class.forName(classString); - methodImports.add(clazz.getMethod(methodString, parse(argString))); - } - } catch (IllegalArgumentException iae) { - throw iae; - } catch (Exception ex) { - throw new IllegalStateException(ex); - } - } - return this; - } - - public Builder enumImports(final Collection<String> enums) { - for (String enumItem : enums) { - try { - if (enumItem.endsWith("#*")) { - final String classString = enumItem.substring(0, enumItem.length() - 2); - final Class<?> clazz = Class.forName(classString); - enumImports.addAll(allEnums(clazz)); - } else { - final Matcher matcher = ENUM_PATTERN.matcher(enumItem); - - if (!matcher.matches()) - throw new IllegalArgumentException(String.format("Could not read enum descriptor - check format of: %s", enumItem)); - - final String classString = matcher.group(1); - final String enumValString = matcher.group(2); - final Class<?> clazz = Class.forName(classString); - - Stream.of(clazz.getEnumConstants()) - .filter(e -> ((Enum) e).name().equals(enumValString)) - .findFirst().ifPresent(e -> enumImports.add((Enum) e)); - } - } catch (IllegalArgumentException iae) { - throw iae; - } catch (Exception ex) { - throw new IllegalStateException(ex); - } - } - return this; - } - - public ImportGremlinModule create() { - if (enumImports.isEmpty() && classImports.isEmpty() && methodImports.isEmpty()) - throw new IllegalStateException("At least one import must be specified"); - - return new ImportGremlinModule(this); - } - - private static List<Enum> allEnums(final Class<?> clazz) { - return Stream.of(clazz.getEnumConstants()).map(e -> (Enum) e).collect(Collectors.toList()); - } - - private static List<Method> allStaticMethods(final Class<?> clazz) { - return Stream.of(clazz.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).collect(Collectors.toList()); - } - - private static Class<?>[] parse(final String argString) { - if (null == argString || argString.isEmpty()) - return new Class<?>[0]; - - final List<String> args = Stream.of(argString.split(",")).map(String::trim).collect(Collectors.toList()); - final Class<?>[] classes = new Class<?>[args.size()]; - for (int ix = 0; ix < args.size(); ix++) { - try { - classes[ix] = Class.forName(args.get(ix)); - } catch (Exception ex) { - throw new IllegalStateException(ex); - } - } - - return classes; - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinPlugin.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinPlugin.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinPlugin.java new file mode 100644 index 0000000..f99ee68 --- /dev/null +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinPlugin.java @@ -0,0 +1,173 @@ +/* + * 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.jsr223; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * A module that allows custom class, static method and enum imports (i.e. those that are statically defined by a + * module within itself). A user might utilize this class to supply their own imports. This module is not specific + * to any {@link GremlinScriptEngine} - the imports are supplied to all engines. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public final class ImportGremlinPlugin extends AbstractGremlinPlugin { + private static final String MODULE_NAME = "tinkerpop.import"; + + private ImportGremlinPlugin(final Builder builder) { + super(MODULE_NAME, builder.appliesTo, ImportCustomizer.build() + .addClassImports(builder.classImports) + .addEnumImports(builder.enumImports) + .addMethodImports(builder.methodImports).create()); + } + + public static Builder build() { + return new Builder(); + } + + public static final class Builder { + private static final Pattern METHOD_PATTERN = Pattern.compile("(.*)#(.*)\\((.*)\\)"); + private static final Pattern ENUM_PATTERN = Pattern.compile("(.*)#(.*)"); + private Set<Class> classImports = new HashSet<>(); + private Set<Method> methodImports = new HashSet<>(); + private Set<Enum> enumImports = new HashSet<>(); + private final Set<String> appliesTo = new HashSet<>(); + + private Builder() {} + + /** + * The name of the {@link GremlinScriptEngine} that this module will apply to. Setting no values here will + * make the module available to all the engines. + */ + public Builder appliesTo(final Collection<String> scriptEngineName) { + this.appliesTo.addAll(scriptEngineName); + return this; + } + + public Builder classImports(final Collection<String> classes) { + for (String clazz : classes) { + try { + classImports.add(Class.forName(clazz)); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + return this; + } + + public Builder methodImports(final Collection<String> methods) { + for (String method : methods) { + try { + if (method.endsWith("#*")) { + final String classString = method.substring(0, method.length() - 2); + final Class<?> clazz = Class.forName(classString); + methodImports.addAll(allStaticMethods(clazz)); + } else { + final Matcher matcher = METHOD_PATTERN.matcher(method); + + if (!matcher.matches()) + throw new IllegalArgumentException(String.format("Could not read method descriptor - check format of: %s", method)); + + final String classString = matcher.group(1); + final String methodString = matcher.group(2); + final String argString = matcher.group(3); + final Class<?> clazz = Class.forName(classString); + methodImports.add(clazz.getMethod(methodString, parse(argString))); + } + } catch (IllegalArgumentException iae) { + throw iae; + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + return this; + } + + public Builder enumImports(final Collection<String> enums) { + for (String enumItem : enums) { + try { + if (enumItem.endsWith("#*")) { + final String classString = enumItem.substring(0, enumItem.length() - 2); + final Class<?> clazz = Class.forName(classString); + enumImports.addAll(allEnums(clazz)); + } else { + final Matcher matcher = ENUM_PATTERN.matcher(enumItem); + + if (!matcher.matches()) + throw new IllegalArgumentException(String.format("Could not read enum descriptor - check format of: %s", enumItem)); + + final String classString = matcher.group(1); + final String enumValString = matcher.group(2); + final Class<?> clazz = Class.forName(classString); + + Stream.of(clazz.getEnumConstants()) + .filter(e -> ((Enum) e).name().equals(enumValString)) + .findFirst().ifPresent(e -> enumImports.add((Enum) e)); + } + } catch (IllegalArgumentException iae) { + throw iae; + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + return this; + } + + public ImportGremlinPlugin create() { + if (enumImports.isEmpty() && classImports.isEmpty() && methodImports.isEmpty()) + throw new IllegalStateException("At least one import must be specified"); + + return new ImportGremlinPlugin(this); + } + + private static List<Enum> allEnums(final Class<?> clazz) { + return Stream.of(clazz.getEnumConstants()).map(e -> (Enum) e).collect(Collectors.toList()); + } + + private static List<Method> allStaticMethods(final Class<?> clazz) { + return Stream.of(clazz.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).collect(Collectors.toList()); + } + + private static Class<?>[] parse(final String argString) { + if (null == argString || argString.isEmpty()) + return new Class<?>[0]; + + final List<String> args = Stream.of(argString.split(",")).map(String::trim).collect(Collectors.toList()); + final Class<?>[] classes = new Class<?>[args.size()]; + for (int ix = 0; ix < args.size(); ix++) { + try { + classes[ix] = Class.forName(args.get(ix)); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + + return classes; + } + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/RemoteAcceptor.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/RemoteAcceptor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/RemoteAcceptor.java index f917c09..9c96892 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/RemoteAcceptor.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/RemoteAcceptor.java @@ -27,7 +27,7 @@ import java.util.List; * A "remote connection" does not necessarily have to be a remote server. It simply refers to a resource that is * external to the console. * <p/> - * By implementing this interface and returning an instance of it through {@link GremlinModule#remoteAcceptor()} a + * By implementing this interface and returning an instance of it through {@link GremlinPlugin#remoteAcceptor()} a * plugin can hook into those commands and provide remoting features. * * @author Stephen Mallette (http://stephen.genoprime.com) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptFileGremlinPlugin.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptFileGremlinPlugin.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptFileGremlinPlugin.java new file mode 100644 index 0000000..30e66ed --- /dev/null +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptFileGremlinPlugin.java @@ -0,0 +1,71 @@ +/* + * 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.jsr223; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public final class ScriptFileGremlinPlugin extends AbstractGremlinPlugin { + private static final String MODULE_NAME = "tinkerpop.script"; + + public ScriptFileGremlinPlugin(final Builder builder) { + super(MODULE_NAME, builder.appliesTo, new ScriptCustomizer(builder.files)); + } + + public static Builder build() { + return new Builder(); + } + + public static final class Builder { + + private final Set<String> appliesTo = new HashSet<>(); + private Set<File> files = new HashSet<>(); + + private Builder() {} + + /** + * The name of the {@link GremlinScriptEngine} that this module will apply to. Setting no values here will + * make the module available to all the engines. + */ + public Builder appliesTo(final Collection<String> scriptEngineName) { + this.appliesTo.addAll(scriptEngineName); + return this; + } + + public Builder files(final Set<String> files) { + for (String f : files) { + final File file = new File(f); + if (!file.exists()) throw new IllegalArgumentException(new FileNotFoundException(f)); + this.files.add(file); + } + + return this; + } + + public ScriptFileGremlinPlugin create() { + return new ScriptFileGremlinPlugin(this); + } + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptFileModule.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptFileModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptFileModule.java deleted file mode 100644 index b5c0d0c..0000000 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptFileModule.java +++ /dev/null @@ -1,71 +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.jsr223; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public final class ScriptFileModule extends AbstractGremlinModule { - private static final String MODULE_NAME = "tinkerpop.script"; - - public ScriptFileModule(final Builder builder) { - super(MODULE_NAME, builder.appliesTo, new ScriptCustomizer(builder.files)); - } - - public static Builder build() { - return new Builder(); - } - - public static final class Builder { - - private final Set<String> appliesTo = new HashSet<>(); - private Set<File> files = new HashSet<>(); - - private Builder() {} - - /** - * The name of the {@link GremlinScriptEngine} that this module will apply to. Setting no values here will - * make the module available to all the engines. - */ - public Builder appliesTo(final Collection<String> scriptEngineName) { - this.appliesTo.addAll(scriptEngineName); - return this; - } - - public Builder files(final Set<String> files) { - for (String f : files) { - final File file = new File(f); - if (!file.exists()) throw new IllegalArgumentException(new FileNotFoundException(f)); - this.files.add(file); - } - - return this; - } - - public ScriptFileModule create() { - return new ScriptFileModule(this); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinModuleTest.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinModuleTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinModuleTest.java deleted file mode 100644 index ce62357..0000000 --- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinModuleTest.java +++ /dev/null @@ -1,149 +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.jsr223; - -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.T; -import org.apache.tinkerpop.gremlin.structure.io.IoCore; -import org.apache.tinkerpop.gremlin.util.Gremlin; -import org.junit.Test; - -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsCollectionContaining.hasItems; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class ImportGremlinModuleTest { - - @Test(expected = IllegalStateException.class) - public void shouldImportSomething() { - ImportGremlinModule.build().create(); - } - - @Test - public void shouldImportClass() { - final ImportGremlinModule module = ImportGremlinModule.build() - .classImports(Collections.singletonList(Graph.class.getCanonicalName())).create(); - - final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; - assertEquals(1, module.getCustomizers().get().length); - assertThat(customizer.getClassImports(), hasItems(Graph.class)); - assertEquals(1, customizer.getClassImports().size()); - } - - @Test - public void shouldImportWildcardMethod() throws Exception { - final Method zeroArgs = Gremlin.class.getMethod("version"); - final ImportGremlinModule module = ImportGremlinModule.build() - .methodImports(Collections.singletonList(Gremlin.class.getCanonicalName() + "#*")).create(); - - final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; - assertEquals(1, module.getCustomizers().get().length); - assertThat(customizer.getMethodImports(), hasItems(zeroArgs)); - - // will also have the static main() method - assertEquals(2, customizer.getMethodImports().size()); - } - - @Test - public void shouldImportZeroArgMethod() throws Exception { - final Method zeroArgs = Gremlin.class.getMethod("version"); - final ImportGremlinModule module = ImportGremlinModule.build() - .methodImports(Collections.singletonList(toMethodDescriptor(zeroArgs))).create(); - - final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; - assertEquals(1, module.getCustomizers().get().length); - assertThat(customizer.getMethodImports(), hasItems(zeroArgs)); - assertEquals(1, customizer.getMethodImports().size()); - } - - @Test - public void shouldImportSingleArgMethod() throws Exception { - final Method singleArg = IoCore.class.getMethod("createIoBuilder", String.class); - final ImportGremlinModule module = ImportGremlinModule.build() - .methodImports(Collections.singletonList(toMethodDescriptor(singleArg))).create(); - - final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; - assertEquals(1, module.getCustomizers().get().length); - assertThat(customizer.getMethodImports(), hasItems(singleArg)); - assertEquals(1, customizer.getMethodImports().size()); - } - - @Test - public void shouldThrowExceptionIfInvalidMethodDescriptor() throws Exception { - final String badDescriptor = "Gremlin*version"; - try { - ImportGremlinModule.build() - .methodImports(Collections.singletonList(badDescriptor)).create(); - fail("Should have failed parsing the method descriptor"); - } catch (IllegalArgumentException iae) { - assertEquals(iae.getMessage(), "Could not read method descriptor - check format of: " + badDescriptor); - } - } - - @Test - public void shouldImportWildcardEnum() throws Exception { - final ImportGremlinModule module = ImportGremlinModule.build() - .enumImports(Collections.singletonList(T.class.getCanonicalName() + "#*")).create(); - - final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; - assertEquals(1, module.getCustomizers().get().length); - assertThat(customizer.getEnumImports(), hasItems(T.id, T.key, T.label, T.value)); - assertEquals(4, customizer.getEnumImports().size()); - } - - @Test - public void shouldImportEnum() throws Exception { - final ImportGremlinModule module = ImportGremlinModule.build() - .enumImports(Collections.singletonList(T.class.getCanonicalName() + "#" + T.id.name())).create(); - - final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; - assertEquals(1, module.getCustomizers().get().length); - assertThat(customizer.getEnumImports(), hasItems(T.id)); - } - - @Test - public void shouldThrowExceptionIfInvalidEnumDescriptor() throws Exception { - final String badDescriptor = "T*id"; - try { - ImportGremlinModule.build() - .enumImports(Collections.singletonList(badDescriptor)).create(); - fail("Should have failed parsing the enum descriptor"); - } catch (IllegalArgumentException iae) { - assertEquals("Could not read enum descriptor - check format of: " + badDescriptor, iae.getMessage()); - } - } - - private static String toMethodDescriptor(final Method method) { - return method.getDeclaringClass().getCanonicalName() + - "#" + - method.getName() + - '(' + - String.join(",", Stream.of(method.getParameters()).map(p -> p.getType().getCanonicalName()).collect(Collectors.toList())) + - ')'; - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinPluginTest.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinPluginTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinPluginTest.java new file mode 100644 index 0000000..428fc57 --- /dev/null +++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ImportGremlinPluginTest.java @@ -0,0 +1,149 @@ +/* + * 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.jsr223; + +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.io.IoCore; +import org.apache.tinkerpop.gremlin.util.Gremlin; +import org.junit.Test; + +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsCollectionContaining.hasItems; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public class ImportGremlinPluginTest { + + @Test(expected = IllegalStateException.class) + public void shouldImportSomething() { + ImportGremlinPlugin.build().create(); + } + + @Test + public void shouldImportClass() { + final ImportGremlinPlugin module = ImportGremlinPlugin.build() + .classImports(Collections.singletonList(Graph.class.getCanonicalName())).create(); + + final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; + assertEquals(1, module.getCustomizers().get().length); + assertThat(customizer.getClassImports(), hasItems(Graph.class)); + assertEquals(1, customizer.getClassImports().size()); + } + + @Test + public void shouldImportWildcardMethod() throws Exception { + final Method zeroArgs = Gremlin.class.getMethod("version"); + final ImportGremlinPlugin module = ImportGremlinPlugin.build() + .methodImports(Collections.singletonList(Gremlin.class.getCanonicalName() + "#*")).create(); + + final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; + assertEquals(1, module.getCustomizers().get().length); + assertThat(customizer.getMethodImports(), hasItems(zeroArgs)); + + // will also have the static main() method + assertEquals(2, customizer.getMethodImports().size()); + } + + @Test + public void shouldImportZeroArgMethod() throws Exception { + final Method zeroArgs = Gremlin.class.getMethod("version"); + final ImportGremlinPlugin module = ImportGremlinPlugin.build() + .methodImports(Collections.singletonList(toMethodDescriptor(zeroArgs))).create(); + + final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; + assertEquals(1, module.getCustomizers().get().length); + assertThat(customizer.getMethodImports(), hasItems(zeroArgs)); + assertEquals(1, customizer.getMethodImports().size()); + } + + @Test + public void shouldImportSingleArgMethod() throws Exception { + final Method singleArg = IoCore.class.getMethod("createIoBuilder", String.class); + final ImportGremlinPlugin module = ImportGremlinPlugin.build() + .methodImports(Collections.singletonList(toMethodDescriptor(singleArg))).create(); + + final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; + assertEquals(1, module.getCustomizers().get().length); + assertThat(customizer.getMethodImports(), hasItems(singleArg)); + assertEquals(1, customizer.getMethodImports().size()); + } + + @Test + public void shouldThrowExceptionIfInvalidMethodDescriptor() throws Exception { + final String badDescriptor = "Gremlin*version"; + try { + ImportGremlinPlugin.build() + .methodImports(Collections.singletonList(badDescriptor)).create(); + fail("Should have failed parsing the method descriptor"); + } catch (IllegalArgumentException iae) { + assertEquals(iae.getMessage(), "Could not read method descriptor - check format of: " + badDescriptor); + } + } + + @Test + public void shouldImportWildcardEnum() throws Exception { + final ImportGremlinPlugin module = ImportGremlinPlugin.build() + .enumImports(Collections.singletonList(T.class.getCanonicalName() + "#*")).create(); + + final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; + assertEquals(1, module.getCustomizers().get().length); + assertThat(customizer.getEnumImports(), hasItems(T.id, T.key, T.label, T.value)); + assertEquals(4, customizer.getEnumImports().size()); + } + + @Test + public void shouldImportEnum() throws Exception { + final ImportGremlinPlugin module = ImportGremlinPlugin.build() + .enumImports(Collections.singletonList(T.class.getCanonicalName() + "#" + T.id.name())).create(); + + final ImportCustomizer customizer = (ImportCustomizer) module.getCustomizers().get()[0]; + assertEquals(1, module.getCustomizers().get().length); + assertThat(customizer.getEnumImports(), hasItems(T.id)); + } + + @Test + public void shouldThrowExceptionIfInvalidEnumDescriptor() throws Exception { + final String badDescriptor = "T*id"; + try { + ImportGremlinPlugin.build() + .enumImports(Collections.singletonList(badDescriptor)).create(); + fail("Should have failed parsing the enum descriptor"); + } catch (IllegalArgumentException iae) { + assertEquals("Could not read enum descriptor - check format of: " + badDescriptor, iae.getMessage()); + } + } + + private static String toMethodDescriptor(final Method method) { + return method.getDeclaringClass().getCanonicalName() + + "#" + + method.getName() + + '(' + + String.join(",", Stream.of(method.getParameters()).map(p -> p.getType().getCanonicalName()).collect(Collectors.toList())) + + ')'; + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/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 1ad41c7..8659e24 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,10 +20,9 @@ package org.apache.tinkerpop.gremlin.groovy.engine; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; -import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager; -import org.apache.tinkerpop.gremlin.jsr223.GremlinModule; +import org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin; import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineManager; import org.javatuples.Pair; import org.slf4j.Logger; @@ -439,7 +438,7 @@ public class GremlinExecutor implements AutoCloseable { // first try instance() and if that fails try to use build() try { final Method instanceMethod = clazz.getMethod("instance"); - gremlinScriptEngineManager.addModule((GremlinModule) instanceMethod.invoke(null)); + gremlinScriptEngineManager.addModule((GremlinPlugin) instanceMethod.invoke(null)); } catch (Exception ex) { final Method builderMethod = clazz.getMethod("build"); Object moduleBuilder = builderMethod.invoke(null); @@ -464,7 +463,7 @@ public class GremlinExecutor implements AutoCloseable { } final Method create = builderClazz.getMethod("create"); - gremlinScriptEngineManager.addModule((GremlinModule) create.invoke(moduleBuilder)); + gremlinScriptEngineManager.addModule((GremlinPlugin) create.invoke(moduleBuilder)); } } catch (Exception ex) { throw new IllegalStateException(ex); @@ -475,8 +474,8 @@ public class GremlinExecutor implements AutoCloseable { private ScriptEngines createScriptEngines() { // plugins already on the path - ones static to the classpath - final List<GremlinPlugin> globalPlugins = new ArrayList<>(); - ServiceLoader.load(GremlinPlugin.class).forEach(globalPlugins::add); + 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 @@ -487,7 +486,7 @@ public class GremlinExecutor implements AutoCloseable { } // use grabs dependencies and returns plugins to load - final List<GremlinPlugin> pluginsToLoad = new ArrayList<>(globalPlugins); + 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); @@ -614,9 +613,9 @@ public class GremlinExecutor implements AutoCloseable { } /** - * Add a configuration for a {@link GremlinModule} to the executor. The key is the fully qualified class name - * of the {@link GremlinModule} 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 GremlinModule} and the value is some argument to pass to that + * 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 * method. */ public Builder addModules(final String engineName, final Map<String, Map<String,Object>> modules) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java index a8395bb..75cff3b 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java @@ -20,7 +20,7 @@ package org.apache.tinkerpop.gremlin.server; import io.netty.handler.ssl.SslContext; import org.apache.tinkerpop.gremlin.driver.MessageSerializer; -import org.apache.tinkerpop.gremlin.jsr223.GremlinModule; +import org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin; import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; @@ -341,7 +341,7 @@ public class Settings { public Map<String, Object> config = null; /** - * A set of configurations for {@link GremlinModule} instances to apply to this {@link GremlinScriptEngine}. + * A set of configurations for {@link GremlinPlugin} instances to apply to this {@link GremlinScriptEngine}. */ public Map<String,Map<String,Object>> modules = new HashMap<>(); } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/jsr223/GremlinServerGremlinModule.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/jsr223/GremlinServerGremlinModule.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/jsr223/GremlinServerGremlinModule.java deleted file mode 100644 index b161f69..0000000 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/jsr223/GremlinServerGremlinModule.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tinkerpop.gremlin.server.jsr223; - -import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinModule; -import org.apache.tinkerpop.gremlin.jsr223.GremlinModule; -import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer; -import org.apache.tinkerpop.gremlin.server.util.LifeCycleHook; - -/** - * A {@link GremlinModule} implementation that adds Gremlin Server specific classes to the imports. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public final class GremlinServerGremlinModule extends AbstractGremlinModule { - private static final String MODULE_NAME = "tinkerpop.server"; - private static final GremlinServerGremlinModule instance = new GremlinServerGremlinModule(); - - private GremlinServerGremlinModule() { - super(MODULE_NAME, ImportCustomizer.build().addClassImports(LifeCycleHook.class, LifeCycleHook.Context.class).create()); - } - - public static GremlinServerGremlinModule instance() { - return instance; - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/jsr223/GremlinServerGremlinPlugin.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/jsr223/GremlinServerGremlinPlugin.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/jsr223/GremlinServerGremlinPlugin.java new file mode 100644 index 0000000..e8826ae --- /dev/null +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/jsr223/GremlinServerGremlinPlugin.java @@ -0,0 +1,42 @@ +/* + * 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.server.jsr223; + +import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin; +import org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin; +import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer; +import org.apache.tinkerpop.gremlin.server.util.LifeCycleHook; + +/** + * A {@link GremlinPlugin} implementation that adds Gremlin Server specific classes to the imports. + * + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public final class GremlinServerGremlinPlugin extends AbstractGremlinPlugin { + private static final String MODULE_NAME = "tinkerpop.server"; + private static final GremlinServerGremlinPlugin instance = new GremlinServerGremlinPlugin(); + + private GremlinServerGremlinPlugin() { + super(MODULE_NAME, ImportCustomizer.build().addClassImports(LifeCycleHook.class, LifeCycleHook.Context.class).create()); + } + + public static GremlinServerGremlinPlugin instance() { + return instance; + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/68487c2b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java index bb6c9ce..1204bee 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java @@ -19,7 +19,6 @@ package org.apache.tinkerpop.gremlin.server.util; import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor; -import org.apache.tinkerpop.gremlin.jsr223.ImportGremlinModule; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; import org.apache.tinkerpop.gremlin.server.Channelizer; import org.apache.tinkerpop.gremlin.server.GraphManager; @@ -29,9 +28,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map;