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
*
* https://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.accumulo.shell.commands;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleScriptContext;
import org.apache.accumulo.core.client.AccumuloClient;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.shell.Shell;
import org.apache.accumulo.shell.Shell.Command;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* @deprecated since 2.0; this command shouldn't be used; The script command is deprecated; use
* jshell for scripting instead
*/
@Deprecated(since = "2.1.0")
public class ScriptCommand extends Command {
// Command to allow user to run scripts, see JSR-223
// https://www.oracle.com/technetwork/articles/javase/scripting-140262.html
protected Option list, engine, script, file, args, out, function, object;
private static final String DEFAULT_ENGINE = "rhino";
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
justification = "app is run in same security context as user providing the filename")
@Override
public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
boolean invoke = false;
Shell.log.warn("The script command is deprecated; use jshell for scripting instead");
ScriptEngineManager mgr = new ScriptEngineManager();
if (cl.hasOption(list.getOpt())) {
listJSREngineInfo(mgr, shellState);
} else if (cl.hasOption(file.getOpt()) || cl.hasOption(script.getOpt())) {
String engineName = DEFAULT_ENGINE;
if (cl.hasOption(engine.getOpt())) {
engineName = cl.getOptionValue(engine.getOpt());
}
ScriptEngine engine = mgr.getEngineByName(engineName);
if (engine == null) {
shellState.printException(new Exception(engineName + " not found"));
return 1;
}
if (cl.hasOption(object.getOpt()) || cl.hasOption(function.getOpt())) {
if (!(engine instanceof Invocable)) {
shellState.printException(
new Exception(engineName + " does not support invoking functions or methods"));
return 1;
}
invoke = true;
}
ScriptContext ctx = new SimpleScriptContext();
// Put the following objects into the context so that they
// are available to the scripts
// TODO: What else should go in here?
Bindings b = engine.getBindings(ScriptContext.ENGINE_SCOPE);
putConnector(b, shellState.getAccumuloClient());
b.put("client", shellState.getAccumuloClient());
List