public abstract class Launcher extends Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
Launcher.AbortException
Exception which shall abort the launcher execution.
|
protected static class |
Launcher.OS |
protected static class |
Launcher.VersionAction |
static class |
Launcher.VMType |
| Modifier and Type | Field and Description |
|---|---|
static int |
LAUNCHER_OPTIONS_INDENT
Default option description indentation.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Launcher() |
| Modifier and Type | Method and Description |
|---|---|
protected Launcher.AbortException |
abort(IOException e)
Exits the launcher, indicating failure because of the provided
IOException. |
protected Launcher.AbortException |
abort(IOException e,
int exitCode)
Exits the launcher with the provided exit code because of the provided
IOException. |
protected Launcher.AbortException |
abort(String message)
Exits the launcher, indicating failure.
|
protected Launcher.AbortException |
abort(String message,
int exitCode)
Exits the launcher, with the provided exit code.
|
protected Launcher.AbortException |
abort(Throwable t)
Exits the launcher, indicating failure because of the provided
Throwable. |
protected Launcher.AbortException |
abort(Throwable t,
int exitCode)
Exits the launcher with the provided exit code because of the provided
Throwable. |
protected Launcher.AbortException |
abortInvalidArgument(String argument,
String message)
Exits the launcher, indicating failure because of an invalid argument.
|
protected Launcher.AbortException |
abortInvalidArgument(String argument,
String message,
int exitCode)
Exits the launcher with the provided exit code because of an invalid argument.
|
protected Launcher.AbortException |
abortUnrecognizedArgument(String argument)
This is called to abort execution when an argument can neither be recognized by the launcher
or as an option for the polyglot engine.
|
protected boolean |
canPolyglot()
Determines if the tool supports polyglot.
|
protected abstract void |
collectArguments(Set<String> options)
Add all known arguments to the
options list. |
protected void |
executeJVM(String classpath,
List<String> jvmArgs,
List<String> remainingArgs)
Called if a JVM has to be started instead of AOT binary.
|
protected void |
executePolyglot(List<String> mainArgs,
boolean forceNative)
Called to execute the bin/polyglot launcher with the supplied options.
|
protected Launcher.AbortException |
exit()
Exits the launcher, indicating success.
|
protected Launcher.AbortException |
exit(int exitCode)
Exits the launcher with the provided exit code.
|
protected abstract org.graalvm.options.OptionDescriptor |
findOptionDescriptor(String group,
String key)
Finds the a descriptor for the option.
|
protected Launcher.VMType |
getDefaultVMType()
The return value specifies the default VM when none of --jvm, --native options is used.
|
protected PrintStream |
getError() |
protected Path |
getGraalVMBinaryPath(String binaryName)
Returns filename of the binary, depending on OS.
|
protected Path |
getGraalVMHome() |
protected Path |
getLogFile()
Provides the name of the log file, if specified on the command line.
|
protected String |
getMainClass()
Returns the name of the main class for this launcher.
|
protected PrintStream |
getOutput() |
protected static String |
getProgramName()
Returns what is an equivalent of
argv[0]}, i.e., the command that executed the
launcher. |
static boolean |
isAOT()
Returns true if the current launcher was compiled ahead-of-time to native code.
|
protected boolean |
isGraalVMAvailable() |
protected boolean |
isStandalone() |
protected void |
launcherOption(String option,
String description)
Prints a line for a launcher option.
|
protected void |
maybeNativeExec(List<String> originalArgs,
List<String> unrecognizedArgs,
boolean isPolyglotLauncher)
Possibly re-executes the launcher when JVM or polyglot mode is requested; call only if
Launcher.isAOT() is true. |
protected void |
maybePrintAdditionalHelp(org.graalvm.options.OptionCategory helpCategory)
Should print tool-specific help.
|
protected static OutputStream |
newLogStream(Path path)
Creates a new log file.
|
protected boolean |
parseCommonOption(String defaultOptionPrefix,
Map<String,String> polyglotOptions,
boolean experimentalOptions,
String arg)
Parses an option, returning success.
|
protected void |
parseUnrecognizedOptions(String defaultOptionPrefix,
Map<String,String> polyglotOptions,
List<String> unrecognizedArgs)
Parses otherwise unrecognized options.
|
protected void |
printDefaultHelp(org.graalvm.options.OptionCategory printCategory)
Prints default help text.
|
protected abstract void |
printHelp(org.graalvm.options.OptionCategory maxCategory)
Prints a help message to stdout.
|
protected void |
println(String... lines)
Prints sequence of lines to the output stream.
|
protected void |
println(String l)
Prints a single line to the output stream, terminated with newline.
|
protected void |
printOtherHelpCategory(String kind,
String option)
Instructs that information about other help categories should be printed.
|
protected abstract void |
printVersion()
Prints version information on stdout.
|
protected boolean |
runLauncherAction()
Runs launcher's action as version print or help.
|
protected void |
setError(PrintStream ps)
Uses the defined output to print error messages.
|
protected void |
setOptionIndent(int indent)
Sets the indentation for option descriptions.
|
protected void |
setOutput(PrintStream ps)
Uses the defined output to print messages.
|
protected void |
warn(String message) |
protected void |
warn(String message,
Object... args) |
public static final int LAUNCHER_OPTIONS_INDENT
protected final Path getLogFile()
null if unspecified.protected final void setOutput(PrintStream ps)
ps - printStream to use as outprotected final void setError(PrintStream ps)
ps - printStream to use as errprotected final PrintStream getOutput()
System.outprotected final PrintStream getError()
System.errprotected final Launcher.AbortException exit()
Launcher.AbortException.protected final Launcher.AbortException exit(int exitCode)
Launcher.AbortException.exitCode - the exit code of the launcher process.protected final Launcher.AbortException abort(String message)
Launcher.AbortException.message - an error message that will be printed to stderr. If
null, nothing will be printed.protected final Launcher.AbortException abort(String message, int exitCode)
Launcher.AbortException.message - an error message that will be printed to stderr. If
null, nothing will be printed.exitCode - the exit code of the launcher process.protected final Launcher.AbortException abort(Throwable t)
Throwable.
This aborts by throwing an Launcher.AbortException.t - the exception that causes the launcher to abort.protected final Launcher.AbortException abort(Throwable t, int exitCode)
Throwable.
This aborts by throwing an Launcher.AbortException.t - the exception that causes the launcher to abort.exitCode - the exit code of the launcher process.protected final Launcher.AbortException abort(IOException e)
IOException.
This tries to build a helpful error message based on exception.
This aborts by throwing an Launcher.AbortException.e - the exception that causes the launcher to abort.protected final Launcher.AbortException abort(IOException e, int exitCode)
IOException.
This tries to build a helpful error message based on exception.
This aborts by throwing an Launcher.AbortException.e - the exception that causes the launcher to abort.exitCode - the exit code of the launcher processprotected Launcher.AbortException abortUnrecognizedArgument(String argument)
argument - the argument that was not recognized.protected final Launcher.AbortException abortInvalidArgument(String argument, String message)
Launcher.AbortException.argument - the problematic argument.message - an error message that is printed to stderr.protected final Launcher.AbortException abortInvalidArgument(String argument, String message, int exitCode)
Launcher.AbortException.argument - the problematic argument.message - an error message that is printed to stderr.exitCode - the exit code of the launcher process.protected void warn(String message)
protected final void setOptionIndent(int indent)
Launcher.LAUNCHER_OPTIONS_INDENT.indent - the new indent.protected abstract void printHelp(org.graalvm.options.OptionCategory maxCategory)
maxCategory or less.maxCategory - the maximum category of options that should be printed.protected abstract void printVersion()
protected abstract void collectArguments(Set<String> options)
options list.options - list to which valid arguments must be added.protected abstract org.graalvm.options.OptionDescriptor findOptionDescriptor(String group, String key)
group - option groupkey - the option name (including the group)null.protected boolean canPolyglot()
--polyglot option is valid
for this tool and polyglot launcher works for it. The default implementation returns false
only when Launcher.isStandalone() is true.true, if polyglot is relevant in this launcher.protected void maybePrintAdditionalHelp(org.graalvm.options.OptionCategory helpCategory)
helpCategory - category of options to printprotected String getMainClass()
return MyLauncher.class.getName();
protected Launcher.VMType getDefaultVMType()
public static boolean isAOT()
protected boolean isGraalVMAvailable()
protected boolean isStandalone()
protected Path getGraalVMHome()
protected final Path getGraalVMBinaryPath(String binaryName)
bin
directory.binaryName - binary name, without path.protected boolean runLauncherAction()
true, if the execution
should terminate, e.g. after printing help. Launcher.parseCommonOption(java.lang.String, java.util.Map<java.lang.String, java.lang.String>, boolean, java.lang.String) should be called for
commandline argument(s) prior to this method to set up flags to display help etc.true when execution should be terminated.protected void printDefaultHelp(org.graalvm.options.OptionCategory printCategory)
printCategory - options category to print.protected void printOtherHelpCategory(String kind, String option)
kind - category kind nameoption - the option to print the categoryprotected final void parseUnrecognizedOptions(String defaultOptionPrefix, Map<String,String> polyglotOptions, List<String> unrecognizedArgs)
defaultOptionPrefix - (language) prefix for the optionspolyglotOptions - options being built for the polyglot launcherunrecognizedArgs - arguments (options) to evaluateprotected boolean parseCommonOption(String defaultOptionPrefix, Map<String,String> polyglotOptions, boolean experimentalOptions, String arg)
true.defaultOptionPrefix - default prefix for the option names, derived from the launching
application.polyglotOptions - options for polyglot engineexperimentalOptions - true, if experimental options are explicitly allowedarg - argument to parseprotected void launcherOption(String option, String description)
Launcher.setOptionIndent(int) to
align option's description. If option name is too long, description is printed on the next
line, indented.option - option name, including dash(es)description - descriptionprotected final void println(String l)
l - line text.protected final void println(String... lines)
lines - linesprotected static String getProgramName()
argv[0]}, i.e., the command that executed the
launcher. If the launcher was executed via a symlink, this returns the symlink. If the
launcher was executed via a command resolved via the user's PATH environment variable, this
returns that command.null if not available.protected final void maybeNativeExec(List<String> originalArgs, List<String> unrecognizedArgs, boolean isPolyglotLauncher)
Launcher.isAOT() is true. If the result is to run native, then it applies VM options on the
current process.
The method parses the unrecognizedArgs for --jvm/--native/--polyglot flags and --vm.*
options. If JVM mode is requested, it execs a Java process configured with supported JVM
parameters and system properties over this process - in this case, the method does not return
(except errors).originalArgs - the original arguments from main(), unmodified.unrecognizedArgs - a subset of originalArgs that was not recognized by
AbstractLanguageLauncher.preprocessArguments(List, Map). All arguments
recognized by maybeExec are removed from the list.isPolyglotLauncher - whether this is the PolyglotLauncher (bin/polyglot)protected void executeJVM(String classpath, List<String> jvmArgs, List<String> remainingArgs)
classpath - class path to be used with the JVMjvmArgs - arguments for the VMremainingArgs - main argumentsprotected void executePolyglot(List<String> mainArgs, boolean forceNative)
mainArgs - program argumentsprotected static OutputStream newLogStream(Path path) throws IOException
path - the desired output for logIOException - in case of I/O error opening the file