You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/12/12 12:45:09 UTC
[21/47] tinkerpop git commit: TINKERPOP-1562 Change ScriptCustomizer
to an interface.
TINKERPOP-1562 Change ScriptCustomizer to an interface.
This class had been added as part of this branch so recasting it as an interface is non-breaking. Get PluggedIn to process the ScriptCustomizer.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e9e5cfec
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e9e5cfec
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e9e5cfec
Branch: refs/heads/master
Commit: e9e5cfec66bca5f8beb671625f7fe2fff0038907
Parents: 2537d5b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Nov 22 06:49:14 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Dec 2 06:28:51 2016 -0500
----------------------------------------------------------------------
.../gremlin/console/plugin/PluggedIn.groovy | 7 ++-
.../gremlin/jsr223/DefaultScriptCustomizer.java | 57 ++++++++++++++++++++
.../gremlin/jsr223/ScriptCustomizer.java | 36 +++----------
.../gremlin/jsr223/ScriptFileGremlinPlugin.java | 2 +-
4 files changed, 70 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e9e5cfec/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
index 053a072..54659fa 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
@@ -24,7 +24,8 @@ import org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor
import org.apache.tinkerpop.gremlin.groovy.plugin.PluginInitializationException
import org.apache.tinkerpop.gremlin.groovy.plugin.RemoteAcceptor
import org.apache.tinkerpop.gremlin.groovy.plugin.RemoteException
-import org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer
+import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer
+import org.apache.tinkerpop.gremlin.jsr223.ScriptCustomizer
import org.apache.tinkerpop.gremlin.jsr223.console.ConsoleCustomizer
import org.codehaus.groovy.tools.shell.Groovysh
import org.codehaus.groovy.tools.shell.IO
@@ -33,6 +34,7 @@ import org.codehaus.groovy.tools.shell.IO
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
class PluggedIn {
+ private static final String LINE_SEPARATOR = System.getProperty("line.separator")
private final GremlinPlugin plugin
private boolean activated = false
@@ -77,7 +79,6 @@ class PluggedIn {
@Override
void pluginTo(final PluginAcceptor pluginAcceptor) throws IllegalEnvironmentException, PluginInitializationException {
- // TODO: handle script customizer
corePlugin.getCustomizers("gremlin-groovy").each {
if (it instanceof ImportCustomizer) {
def imports = [] as Set
@@ -85,6 +86,8 @@ class PluggedIn {
it.methodImports.each { imports.add("import static " + it.declaringClass.canonicalName + "." + it.name) }
it.enumImports.each { imports.add("import static " + it.declaringClass.canonicalName + "." + it.name()) }
pluginAcceptor.addImports(imports)
+ } else if (it instanceof ScriptCustomizer) {
+ it.getScripts().collect { it.join(LINE_SEPARATOR) }.each { pluginAcceptor.eval(it) }
}
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e9e5cfec/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultScriptCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultScriptCustomizer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultScriptCustomizer.java
new file mode 100644
index 0000000..9640f28
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultScriptCustomizer.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.jsr223;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Default implementation of the {@link ScriptCustomizer} that can create the script list from a list of files or
+ * from lines of script.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class DefaultScriptCustomizer implements ScriptCustomizer {
+
+ private final Collection<List<String>> scripts;
+
+ public DefaultScriptCustomizer(final Set<File> files) {
+ this(files.stream().map(f -> {
+ try {
+ return Files.lines(f.toPath(), StandardCharsets.UTF_8).collect(Collectors.toList());
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ }
+ }).collect(Collectors.toList()));
+ }
+
+ public DefaultScriptCustomizer(final Collection<List<String>> scripts) {
+ this.scripts = scripts;
+ }
+
+ public Collection<List<String>> getScripts() {
+ return scripts;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e9e5cfec/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptCustomizer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptCustomizer.java
index 28603df..eb2f8bc 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptCustomizer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptCustomizer.java
@@ -18,39 +18,17 @@
*/
package org.apache.tinkerpop.gremlin.jsr223;
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
/**
+ * A {@link Customizer} that executes scripts in a {@link GremlinScriptEngine} instance for purpose of initialization.
+ *
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class ScriptCustomizer implements Customizer {
-
- private final Collection<List<String>> scripts;
-
- public ScriptCustomizer(final Set<File> files) {
- this(files.stream().map(f -> {
- try {
- return Files.lines(f.toPath(), StandardCharsets.UTF_8).collect(Collectors.toList());
- } catch (IOException ioe) {
- throw new IllegalStateException(ioe);
- }
- }).collect(Collectors.toList()));
- }
-
- public ScriptCustomizer(final Collection<List<String>> scripts) {
- this.scripts = scripts;
- }
-
- public Collection<List<String>> scripts() {
- return scripts;
- }
+public interface ScriptCustomizer extends Customizer {
+ /**
+ * Gets a collection of scripts where each is represented as a list of script lines.
+ */
+ public Collection<List<String>> getScripts();
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e9e5cfec/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
index 30e66ed..3fd811a 100644
--- 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
@@ -31,7 +31,7 @@ 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));
+ super(MODULE_NAME, builder.appliesTo, new DefaultScriptCustomizer(builder.files));
}
public static Builder build() {