Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tinkerpop.gremlin.groovy.jsr223;
import groovy.grape.Grape;
import groovy.lang.Binding;
import groovy.lang.Closure;
import groovy.lang.DelegatingMetaClass;
import groovy.lang.MetaClass;
import groovy.lang.MissingMethodException;
import groovy.lang.MissingPropertyException;
import groovy.lang.Script;
import groovy.lang.Tuple;
import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.EmptyImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.ImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ConfigurationCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.InterpreterModeCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader;
import org.apache.tinkerpop.gremlin.groovy.plugin.Artifact;
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin;
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPluginException;
import org.apache.tinkerpop.gremlin.jsr223.Customizer;
import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory;
import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.jsr223.GroovyCompiledScript;
import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.MetaClassHelper;
import org.codehaus.groovy.runtime.MethodClosure;
import org.codehaus.groovy.syntax.SyntaxException;
import org.codehaus.groovy.util.ReferenceBundle;
import javax.script.Bindings;
import javax.script.CompiledScript;
import javax.script.ScriptContext;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Provides methods to compile and evaluate Gremlin scripts. Compiled scripts are stored in a managed cache to cut
* down on compilation times of future evaluations of the same script. This {@code ScriptEngine} implementation is
* heavily adapted from the {@code GroovyScriptEngineImpl} to include some additional functionality.
*
* @author Marko A. Rodriguez (http://markorodriguez.com)
* @author Stephen Mallette (http://stephen.genoprime.com)
* @see org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor
*/
public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
implements DependencyManager, AutoCloseable, GremlinScriptEngine {
/**
* An "internal" key for sandboxing the script engine - technically not for public use.
*/
public static final String COMPILE_OPTIONS_VAR_TYPES = "sandbox.bindings";
/**
* The attribute key (passed as a binding on the context) for how to cache scripts. The value must be one of
* the following:
*
*
{@link #REFERENCE_TYPE_HARD}
*
{@link #REFERENCE_TYPE_SOFT}
*
{@link #REFERENCE_TYPE_WEAK}
*
{@link #REFERENCE_TYPE_PHANTOM}
*
*/
public static final String KEY_REFERENCE_TYPE = "#jsr223.groovy.engine.keep.globals";
/**
* A value to the {@link #KEY_REFERENCE_TYPE} that immediately garbage collects the script after evaluation.
*/
public static final String REFERENCE_TYPE_PHANTOM = "phantom";
/**
* A value to the {@link #KEY_REFERENCE_TYPE} that marks the script as one that can be garbage collected
* even when memory is abundant.
*/
public static final String REFERENCE_TYPE_WEAK = "weak";
/**
* A value to the {@link #KEY_REFERENCE_TYPE} that retains the script until memory is "low" and therefore
* should be reclaimed before an {@link OutOfMemoryError} occurs.
*/
public static final String REFERENCE_TYPE_SOFT = "soft";
/**
* A value to the {@link #KEY_REFERENCE_TYPE} that makes the evaluated script available in the cache for the life
* of the JVM.
*/
public static final String REFERENCE_TYPE_HARD = "hard";
/**
* Name of variable that holds local variables to be globally bound if "interpreter mode" is enabled with
* {@link InterpreterModeCustomizerProvider}.
*/
public static final String COLLECTED_BOUND_VARS_MAP_VARNAME = "gremlin_script_engine_collected_boundvars";
private static final Pattern patternImportStatic = Pattern.compile("\\Aimport\\sstatic.*");
public static final ThreadLocal