/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This is the main class for Java script shell.
*/
public class Main {
/**
* main entry point to the command line tool
* @param args command line argument array
*/
// parse command line options
// process each script command
}
}
// Each -e or -f or interactive mode is represented
// by an instance of Command.
private static interface Command {
}
/**
* Parses and processes command line options.
* @param args command line argument array
*/
// current scripting language selected
// current script file encoding selected
// check for -classpath or -cp first
// have we seen -e or -f ?
boolean seenScript = false;
// have we seen -f - already?
boolean seenStdin = false;
// handled already, just continue
i++;
continue;
}
// collect non-option arguments and pass these as script arguments
int numScriptArgs;
int startScriptArg;
if (seenScript) {
// if we have seen -e or -f already all non-option arguments
// are passed as script arguments
startScriptArg = i;
} else {
// if we have not seen -e or -f, first non-option argument
// is treated as script file name and rest of the non-option
// arguments are passed to script as script arguments
startScriptArg = i + 1;
}
// collect script arguments and return to main
return result;
}
if (eq != -1) {
} else {
} else {
// do not allow empty property name
}
}
continue;
seenScript = true;
continue;
currentEncoding = args[i];
continue;
seenScript = true;
if (seenStdin) {
} else {
seenStdin = true;
}
} else {
}
continue;
currentLanguage = args[i];
continue;
}
// some unknown option...
}
if (! seenScript) {
}
return new String[0];
}
/**
* Adds interactive mode Command
* @param se ScriptEngine to use in interactive mode.
*/
}
});
}
/**
* Adds script source file Command
* @param se ScriptEngine used to evaluate the script file
* @param fileName script file name
* @param encoding script file encoding
*/
}
});
}
/**
* Adds script string source Command
* @param se ScriptEngine to be used to evaluate the script string
* @param source Script source string
*/
try {
} finally {
}
}
});
}
/**
* Prints list of script engines available and exits.
*/
private static void listScriptEngines() {
}));
}
}
/**
* Processes a given source file or standard input.
* @param se ScriptEngine to be used to evaluate
* @param filename file name, can be null
* @param encoding script file encoding, can be null
*/
(new InputStreamReader(getIn()));
boolean hitEOF = false;
while (!hitEOF) {
try {
} catch (IOException ioe) {
}
hitEOF = true;
break;
}
res = "null";
}
}
}
} else {
try {
} catch (FileNotFoundException fnfe) {
}
}
}
/**
* Evaluates given script source
* @param se ScriptEngine to evaluate the string
* @param script Script source string
* @param exitOnError whether to exit the process on script error
*/
try {
} catch (ScriptException sexp) {
if (exitOnError)
if (exitOnError)
}
return null;
}
/**
* Evaluate script string source and exit on script error
* @param se ScriptEngine to evaluate the string
* @param script Script source string
*/
}
/**
* Evaluates script from given reader
* @param se ScriptEngine to evaluate the string
* @param reader Reader from which is script is read
* @param name file name to report in error.
*/
try {
} catch (ScriptException sexp) {
} finally {
}
return null;
}
/**
* Evaluates given input stream
* @param se ScriptEngine to evaluate the string
* @param is InputStream from which script is read
* @param name file name to report in error
*/
try {
encoding));
} catch (UnsupportedEncodingException uee) {
}
} else {
}
}
/**
* Prints usage message and exits
* @param exitCode process exit code
*/
new Object[] { PROGRAM_NAME }));
}
/**
* Gets prompt for interactive mode
* @return prompt string to use
*/
}
/**
* Get formatted, localized error message
*/
}
// input stream from where we will read
}
// stream to print error messages
}
// get current script engine
}
// initialize the engine
// to avoid re-initialization of engine, store it in a map
}
return se;
}
// initialize a given script engine
// put engine global variable
// load init.<ext> file from resource
ext);
}
}
}
/**
* Checks for -classpath, -cp in command line args. Creates a ClassLoader
* and sets it as Thread context loader for current thread.
*
* @param args command line argument array
*/
// just -classpath or -cp with no value
} else {
}
}
}
/* We create a class loader, configure it with specified
* classpath values and set the same as context loader.
* Note that ScriptEngineManager uses context loader to
* load script engines. So, this ensures that user defined
* script engines will be loaded. For classes referred
* from scripts, Rhino engine uses thread context loader
* but this is script engine dependent. We don't have
* script engine independent solution anyway. Unless we
* know the class loader used by a specific engine, we
* can't configure correct loader.
*/
}
// now initialize script engine manager. Note that this has to
// be done after setting the context loader so that manager
// will see script engines from user specified classpath
engineManager = new ScriptEngineManager();
}
/**
* Utility method for converting a search path string to an array
* of directory and JAR file URLs.
*
* @param path the search path string
* @return the resulting array of directory and JAR file URLs
*/
int count = 0;
}
}
}
return urls;
}
/**
* Returns the directory or JAR file URL corresponding to the specified
* local file name.
*
* @param file the File object
* @return the resulting directory or JAR file URL, or null if unknown
*/
try {
} catch (IOException e) {
}
}
// If the file does not exist, then assume that it's a directory
}
try {
} catch (MalformedURLException e) {
throw new IllegalArgumentException("file");
}
}
}
return oldName;
}
// exit codes
// default scripting language
// list of scripts to process
// the script engine manager
// map of engines we loaded
// error messages resource
static {
}
}