Package org.graalvm.launcher
Class Launcher
java.lang.Object
org.graalvm.launcher.Launcher
- Direct Known Subclasses:
LanguageLauncherBase
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classException which shall abort the launcher execution.protected static enumprotected static enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault option description indentation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final Launcher.AbortExceptionabort(IOException e) Exits the launcher, indicating failure because of the providedIOException.protected final Launcher.AbortExceptionabort(IOException e, int exitCode) Exits the launcher with the provided exit code because of the providedIOException.protected final Launcher.AbortExceptionExits the launcher, indicating failure.protected final Launcher.AbortExceptionExits the launcher, with the provided exit code.protected final Launcher.AbortExceptionExits the launcher, indicating failure because of the providedThrowable.protected final Launcher.AbortExceptionExits the launcher with the provided exit code because of the providedThrowable.protected final Launcher.AbortExceptionabortInvalidArgument(String argument, String message) Exits the launcher, indicating failure because of an invalid argument.protected final Launcher.AbortExceptionabortInvalidArgument(String argument, String message, int exitCode) Exits the launcher with the provided exit code because of an invalid argument.protected Launcher.AbortExceptionabortUnrecognizedArgument(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 booleanDetermines if the tool supports polyglot.protected abstract voidcollectArguments(Set<String> options) Add all known arguments to theoptionslist.protected voidCalled if a JVM has to be started instead of AOT binary.protected voidexecuteJVM(String classpath, List<String> jvmArgs, List<String> remainingArgs, Map<String, String> polyglotOptions) Deprecated.protected voidexecutePolyglot(List<String> mainArgs, boolean forceNative) Called to execute the bin/polyglot launcher with the supplied options.protected voidDeprecated.protected final Launcher.AbortExceptionexit()Exits the launcher, indicating success.protected final Launcher.AbortExceptionexit(int exitCode) Exits the launcher with the provided exit code.protected abstract org.graalvm.options.OptionDescriptorfindOptionDescriptor(String group, String key) Finds the a descriptor for the option.protected Launcher.VMTypeThe return value specifies the default VM when none of --jvm, --native options is used.protected final PrintStreamgetError()protected final PathgetGraalVMBinaryPath(String binaryName) Returns filename of the binary, depending on OS.protected Pathprotected final PathProvides the name of the log file, if specified on the command line.protected StringReturns the name of the main class for this launcher.protected final PrintStreamprotected static StringReturns what is an equivalent ofargv[0]}, i.e., the command that executed the launcher.static booleanisAOT()Returns true if the current launcher was compiled ahead-of-time to native code.protected booleanprotected booleanprotected static booleanisTTY()Returns true if stdin and stdout are both TTY, false otherwise.protected voidlauncherOption(String option, String description) Prints a line for a launcher option.protected final voidDeprecated.protected final voidmaybeNativeExec(List<String> originalArgs, List<String> unrecognizedArgs, boolean isPolyglotLauncher) Possibly re-executes the launcher when JVM or polyglot mode is requested; call only ifisAOT()is true.protected voidmaybePrintAdditionalHelp(org.graalvm.options.OptionCategory helpCategory) Should print tool-specific help.static OutputStreamnewLogStream(Path path) Creates a new log file.protected booleanparseCommonOption(String defaultOptionPrefix, Map<String, String> polyglotOptions, boolean experimentalOptions, String arg) Parses an option, returning success.protected final voidparseUnrecognizedOptions(String defaultOptionPrefix, Map<String, String> polyglotOptions, List<String> unrecognizedArgs) Parses otherwise unrecognized options.protected voidprintDefaultHelp(org.graalvm.options.OptionCategory printCategory) Prints default help text.protected abstract voidprintHelp(org.graalvm.options.OptionCategory maxCategory) Prints a help message to stdout.protected final voidPrints a single line to the output stream, terminated with newline.protected final voidPrints sequence of lines to the output stream.protected voidprintOtherHelpCategory(String kind, String option) Instructs that information about other help categories should be printed.protected abstract voidPrints version information on stdout.protected booleanRuns launcher's action as version print or help.protected final voidsetError(PrintStream ps) Uses the defined output to print error messages.protected final voidsetOptionIndent(int indent) Sets the indentation for option descriptions.protected final voidsetOutput(PrintStream ps) Uses the defined output to print messages.protected voidprotected void
-
Field Details
-
LAUNCHER_OPTIONS_INDENT
public static final int LAUNCHER_OPTIONS_INDENTDefault option description indentation.- See Also:
-
-
Constructor Details
-
Launcher
protected Launcher()
-
-
Method Details
-
getLogFile
Provides the name of the log file, if specified on the command line.- Returns:
- log file Path.
nullif unspecified. - Since:
- 20.0
-
setOutput
Uses the defined output to print messages.- Parameters:
ps- printStream to use as out- Since:
- 20.0
-
setError
Uses the defined output to print error messages.- Parameters:
ps- printStream to use as err- Since:
- 20.0
-
getOutput
- Returns:
- the stream for regular output. Defaults to
System.out - Since:
- 20.0
-
getError
- Returns:
- the stream for errors. Defaults to
System.err - Since:
- 20.0
-
exit
Exits the launcher, indicating success. This exits by throwing anLauncher.AbortException. -
exit
Exits the launcher with the provided exit code. This exits by throwing anLauncher.AbortException.- Parameters:
exitCode- the exit code of the launcher process.
-
abort
Exits the launcher, indicating failure. This aborts by throwing anLauncher.AbortException.- Parameters:
message- an error message that will be printed to stderr. If null, nothing will be printed.
-
abort
Exits the launcher, with the provided exit code. This aborts by throwing anLauncher.AbortException.- Parameters:
message- an error message that will be printed to stderr. If null, nothing will be printed.exitCode- the exit code of the launcher process.
-
abort
Exits the launcher, indicating failure because of the providedThrowable. This aborts by throwing anLauncher.AbortException.- Parameters:
t- the exception that causes the launcher to abort.
-
abort
Exits the launcher with the provided exit code because of the providedThrowable. This aborts by throwing anLauncher.AbortException.- Parameters:
t- the exception that causes the launcher to abort.exitCode- the exit code of the launcher process.
-
abort
Exits the launcher, indicating failure because of the providedIOException. This tries to build a helpful error message based on exception. This aborts by throwing anLauncher.AbortException.- Parameters:
e- the exception that causes the launcher to abort.
-
abort
Exits the launcher with the provided exit code because of the providedIOException. This tries to build a helpful error message based on exception. This aborts by throwing anLauncher.AbortException.- Parameters:
e- the exception that causes the launcher to abort.exitCode- the exit code of the launcher process
-
abortUnrecognizedArgument
This is called to abort execution when an argument can neither be recognized by the launcher or as an option for the polyglot engine.- Parameters:
argument- the argument that was not recognized.
-
abortInvalidArgument
Exits the launcher, indicating failure because of an invalid argument. This aborts by throwing anLauncher.AbortException.- Parameters:
argument- the problematic argument.message- an error message that is printed to stderr.
-
abortInvalidArgument
protected final Launcher.AbortException abortInvalidArgument(String argument, String message, int exitCode) Exits the launcher with the provided exit code because of an invalid argument. This aborts by throwing anLauncher.AbortException.- Parameters:
argument- the problematic argument.message- an error message that is printed to stderr.exitCode- the exit code of the launcher process.
-
warn
-
warn
-
setOptionIndent
protected final void setOptionIndent(int indent) Sets the indentation for option descriptions. Sets number of spaces in the first column reserved for option names. Defaults toLAUNCHER_OPTIONS_INDENT.- Parameters:
indent- the new indent.- Since:
- 20.0
-
printHelp
protected abstract void printHelp(org.graalvm.options.OptionCategory maxCategory) Prints a help message to stdout. This only prints options that belong to categoriesmaxCategory or less.- Parameters:
maxCategory- the maximum category of options that should be printed.
-
printVersion
protected abstract void printVersion()Prints version information on stdout. -
collectArguments
Add all known arguments to theoptionslist.- Parameters:
options- list to which valid arguments must be added.
-
findOptionDescriptor
protected abstract org.graalvm.options.OptionDescriptor findOptionDescriptor(String group, String key) Finds the a descriptor for the option.- Parameters:
group- option groupkey- the option name (including the group)- Returns:
- descriptor or
null. - Since:
- 20.0
-
canPolyglot
protected boolean canPolyglot()Determines if the tool supports polyglot. Returns true, if--polyglotoption is valid for this tool and polyglot launcher works for it. The default implementation returns false only whenisStandalone()is true.- Returns:
true, if polyglot is relevant in this launcher.- Since:
- 20.0
-
maybePrintAdditionalHelp
protected void maybePrintAdditionalHelp(org.graalvm.options.OptionCategory helpCategory) Should print tool-specific help. Regular languages print info on the installed tools and languages. The default implementation prints nothing.- Parameters:
helpCategory- category of options to print- Since:
- 20.0
-
getMainClass
Returns the name of the main class for this launcher. Typically:return MyLauncher.class.getName();
-
getDefaultVMType
The return value specifies the default VM when none of --jvm, --native options is used.- Returns:
- the default VMType
-
isAOT
public static boolean isAOT()Returns true if the current launcher was compiled ahead-of-time to native code. -
isGraalVMAvailable
protected boolean isGraalVMAvailable() -
isStandalone
protected boolean isStandalone() -
getGraalVMHome
-
getGraalVMBinaryPath
Returns filename of the binary, depending on OS. Binary will be searched inbindirectory.- Parameters:
binaryName- binary name, without path.- Returns:
- OS-dependent binary filename.
-
runLauncherAction
protected boolean runLauncherAction()Runs launcher's action as version print or help. Returnstrue, if the execution should terminate, e.g. after printing help.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.- Returns:
truewhen execution should be terminated.- Since:
- 20.0
-
printDefaultHelp
protected void printDefaultHelp(org.graalvm.options.OptionCategory printCategory) Prints default help text. Prints options, starting with tool specific options. Launcher implementations can override to provide launcher-specific intro / summary.- Parameters:
printCategory- options category to print.- Since:
- 20.0
-
printOtherHelpCategory
Instructs that information about other help categories should be printed.- Parameters:
kind- category kind nameoption- the option to print the category- Since:
- 20.0
-
parseUnrecognizedOptions
protected final void parseUnrecognizedOptions(String defaultOptionPrefix, Map<String, String> polyglotOptions, List<String> unrecognizedArgs) Parses otherwise unrecognized options. Terminates the application if an option is not among the generic launcher / VM ones.- Parameters:
defaultOptionPrefix- (language) prefix for the optionspolyglotOptions- options being built for the polyglot launcherunrecognizedArgs- arguments (options) to evaluate- Since:
- 20.0
-
parseCommonOption
protected boolean parseCommonOption(String defaultOptionPrefix, Map<String, String> polyglotOptions, boolean experimentalOptions, String arg) Parses an option, returning success. The method is called to parse `arg` option from the commandline, not recognized by the application. The method may contribute to the `polyglotOptions` (in/out parameter, modifiable) to alter polyglot behaviour. If the option is recognized, the method must returntrue.- Parameters:
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 parse- Returns:
- true, if the option was recognized.
- Since:
- 20.0
-
launcherOption
Prints a line for a launcher option. Uses indentation set bysetOptionIndent(int)to align option's description. If option name is too long, description is printed on the next line, indented.- Parameters:
option- option name, including dash(es)description- description- Since:
- 20.0
-
isTTY
protected static boolean isTTY()Returns true if stdin and stdout are both TTY, false otherwise.- Since:
- 24.0
-
println
Prints a single line to the output stream, terminated with newline.- Parameters:
l- line text.- Since:
- 20.0
-
println
Prints sequence of lines to the output stream. Each argument will be printed as a whole line, terminated by a newline.- Parameters:
lines- lines- Since:
- 20.0
-
getProgramName
Returns what is an equivalent ofargv[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.- Returns:
- The program name or
nullif not available.
-
maybeNativeExec
@Deprecated(since="20.3") protected final void maybeNativeExec(List<String> args, boolean isPolyglotLauncher, Map<String, String> polyglotOptions) Deprecated. -
maybeNativeExec
protected final void maybeNativeExec(List<String> originalArgs, List<String> unrecognizedArgs, boolean isPolyglotLauncher) Possibly re-executes the launcher when JVM or polyglot mode is requested; call only ifisAOT()is true. If the result is to run native, then it applies VM options on the current process. The method parses theunrecognizedArgsfor --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).- Parameters:
originalArgs- the original arguments from main(), unmodified.unrecognizedArgs- a subset oforiginalArgsthat was not recognized byAbstractLanguageLauncher.preprocessArguments(List, Map). All arguments recognized by maybeExec are removed from the list.isPolyglotLauncher- whether this is thePolyglotLauncher(bin/polyglot)- Since:
- 20.0
-
executeJVM
@Deprecated(since="20.3") protected void executeJVM(String classpath, List<String> jvmArgs, List<String> remainingArgs, Map<String, String> polyglotOptions) Deprecated. -
executeJVM
Called if a JVM has to be started instead of AOT binary. The method is only called in AOT mode. Subclasses may override to apply different options or launch mechanism- Parameters:
classpath- class path to be used with the JVMjvmArgs- arguments for the VMremainingArgs- main arguments
-
executePolyglot
@Deprecated(since="20.3") protected void executePolyglot(List<String> mainArgs, Map<String, String> polyglotOptions, boolean forceNative) Deprecated. -
executePolyglot
Called to execute the bin/polyglot launcher with the supplied options. Subclasses may eventually override and implement in a different way.- Parameters:
mainArgs- program arguments
-
newLogStream
Creates a new log file. The method uses a supplemental lock file to determine the file is still opened for output; in that case, it creates a different file, named `path'1, `path`2, ... until it finds a free name. Files not locked (actively written to) are overwritten.- Parameters:
path- the desired output for log- Returns:
- the OutputStream for logging
- Throws:
IOException- in case of I/O error opening the file- Since:
- 20.0
-