- java.lang.Object
-
- org.arakhne.afc.vmutil.VMCommandLine
-
public class VMCommandLine extends Object
This utility class permits to get the java command line for the current VM.- Version:
- 17.0 2020-01-04 14:41:35
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- vmutils
-
-
Constructor Summary
Constructors Constructor Description VMCommandLine()
Create a interface to the command line options.VMCommandLine(Class<?> classToLaunch, String... parameters)
Create a interface to the command line options.VMCommandLine(Class<?> classToLaunch, String[] optionDefinitions, String... parameters)
Create a interface to the command line options.VMCommandLine(String classToLaunch, String... parameters)
Create a interface to the command line options.VMCommandLine(String classToLaunch, String[] optionDefinitions, String... parameters)
Create a interface to the command line options.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String[]
getAllCommandLineParameters()
Replies the command line including the options and the standard parameters.static List<Object>
getCommandLineOption(String name)
Replies one command option.static Map<String,List<Object>>
getCommandLineOptions()
Replies the command line options.static String[]
getCommandLineParameters()
Replies the command line parameters.static String
getExecutableFilename(String name)
Replies a binary executable filename depending of the current platform.Object
getFirstOptionValue(String optionLabel)
Replies the first value of the option.List<Object>
getOptionValues(String optionLabel)
Replies the values of the option.String
getParameterAt(int index)
Replies the parameter at the specified index.int
getParameterCount()
Replies the count of parameters on the command line that are not options.String[]
getParameters()
Replies the parameters on the command line that are not options.static String
getVMBinary()
Replies the current java VM binary.static boolean
hasCommandLineOption(String name)
Replies if an option was specified on the command line.boolean
hasOption(String optionLabel)
Replies if the given option is present on the command line.boolean
isParameterExists(int index)
Replies if the given index corresponds to a command line parameter.static Process
launchVM(Class<?> classToLaunch, String... additionalParams)
Run a new VM with the class path of the current VM.static Process
launchVM(String classToLaunch, String... additionalParams)
Run a new VM with the class path of the current VM.static Process
launchVMWithClassPath(Class<?> classToLaunch, File[] classpath, String... additionalParams)
Run a new VM with the given class path.static Process
launchVMWithClassPath(Class<?> classToLaunch, String classpath, String... additionalParams)
Run a new VM with the given class path.static Process
launchVMWithClassPath(String classToLaunch, File[] classpath, String... additionalParams)
Run a new VM with the given class path.static Process
launchVMWithClassPath(String classToLaunch, String classpath, String... additionalParams)
Run a new VM with the given class path.static Process
launchVMWithJar(File jarFile, String... additionalParams)
Run a jar file inside a new VM.static Process
relaunchVM()
Launch a VM with the same parameters as ones saved bysaveVMParameters(Class, String[])
.static void
saveVMParameters(Class<?> classToLaunch, String... parameters)
Save parameters that permit to relaunch a VM withrelaunchVM()
.static void
saveVMParameters(String classToLaunch, String... parameters)
Save parameters that permit to relaunch a VM withrelaunchVM()
.static void
saveVMParametersIfNotSet(Class<?> classToLaunch, String... parameters)
Save parameters that permit to relaunch a VM withrelaunchVM()
.static void
saveVMParametersIfNotSet(String classToLaunch, String... parameters)
Save parameters that permit to relaunch a VM withrelaunchVM()
.static String
shiftCommandLineParameters()
Shift the command line parameters by one on the left.String
shiftParameters()
Shift the command line parameters by one on the left.static void
splitOptionsAndParameters(String... optionDefinitions)
Analyse the command line to extract the options.
-
-
-
Constructor Detail
-
VMCommandLine
public VMCommandLine(Class<?> classToLaunch, String... parameters)
Create a interface to the command line options.- Parameters:
classToLaunch
- is the class which contains amain
.parameters
- is the parameters to pass to themain
.- See Also:
saveVMParametersIfNotSet(Class, String[])
-
VMCommandLine
public VMCommandLine(String classToLaunch, String... parameters)
Create a interface to the command line options.- Parameters:
classToLaunch
- is the class which contains amain
.parameters
- is the parameters to pass to themain
.- Since:
- 6.2
- See Also:
saveVMParametersIfNotSet(String, String[])
-
VMCommandLine
public VMCommandLine(Class<?> classToLaunch, String[] optionDefinitions, String... parameters)
Create a interface to the command line options.- Parameters:
classToLaunch
- is the class which contains amain
.optionDefinitions
- is the list of definitions of the available command line options.parameters
- is the parameters to pass to themain
.- See Also:
saveVMParametersIfNotSet(Class, String[])
,splitOptionsAndParameters(String[])
-
VMCommandLine
public VMCommandLine(String classToLaunch, String[] optionDefinitions, String... parameters)
Create a interface to the command line options.- Parameters:
classToLaunch
- is the class which contains amain
.optionDefinitions
- is the list of definitions of the available command line options.parameters
- is the parameters to pass to themain
.- Since:
- 6.2
- See Also:
saveVMParametersIfNotSet(String, String[])
,splitOptionsAndParameters(String[])
-
VMCommandLine
public VMCommandLine()
Create a interface to the command line options.
-
-
Method Detail
-
getExecutableFilename
@Pure public static String getExecutableFilename(String name)
Replies a binary executable filename depending of the current platform.- Parameters:
name
- is the name which must be converted into a binary executable filename.- Returns:
- the binary executable filename.
-
getVMBinary
@Pure public static String getVMBinary()
Replies the current java VM binary.- Returns:
- the binary executable filename that was used to launch the virtual machine.
-
launchVMWithClassPath
public static Process launchVMWithClassPath(Class<?> classToLaunch, String classpath, String... additionalParams) throws IOException
Run a new VM with the given class path.- Parameters:
classToLaunch
- is the class to launch.classpath
- is the class path to use.additionalParams
- is the list of additional parameters- Returns:
- the process that is running the new virtual machine, neither
null
- Throws:
IOException
- when a IO error occurs.- Since:
- 6.2
-
launchVMWithClassPath
public static Process launchVMWithClassPath(String classToLaunch, String classpath, String... additionalParams) throws IOException
Run a new VM with the given class path.- Parameters:
classToLaunch
- is the class to launch.classpath
- is the class path to use.additionalParams
- is the list of additional parameters- Returns:
- the process that is running the new virtual machine, neither
null
- Throws:
IOException
- when a IO error occurs.- Since:
- 6.2
-
launchVMWithClassPath
public static Process launchVMWithClassPath(Class<?> classToLaunch, File[] classpath, String... additionalParams) throws IOException
Run a new VM with the given class path.- Parameters:
classToLaunch
- is the class to launch.classpath
- is the class path to use.additionalParams
- is the list of additional parameters- Returns:
- the process that is running the new virtual machine, neither
null
- Throws:
IOException
- when a IO error occurs.- Since:
- 6.2
-
launchVMWithClassPath
public static Process launchVMWithClassPath(String classToLaunch, File[] classpath, String... additionalParams) throws IOException
Run a new VM with the given class path.- Parameters:
classToLaunch
- is the class to launch.classpath
- is the class path to use.additionalParams
- is the list of additional parameters- Returns:
- the process that is running the new virtual machine, neither
null
- Throws:
IOException
- when a IO error occurs.- Since:
- 6.2
-
launchVMWithJar
public static Process launchVMWithJar(File jarFile, String... additionalParams) throws IOException
Run a jar file inside a new VM.- Parameters:
jarFile
- is the jar file to launch.additionalParams
- is the list of additional parameters- Returns:
- the process that is running the new virtual machine, neither
null
- Throws:
IOException
- when a IO error occurs.- Since:
- 6.2
-
launchVM
public static Process launchVM(Class<?> classToLaunch, String... additionalParams) throws IOException
Run a new VM with the class path of the current VM.- Parameters:
classToLaunch
- is the class to launch.additionalParams
- is the list of additional parameters- Returns:
- the process that is running the new virtual machine, neither
null
- Throws:
IOException
- when a IO error occurs.
-
launchVM
public static Process launchVM(String classToLaunch, String... additionalParams) throws IOException
Run a new VM with the class path of the current VM.- Parameters:
classToLaunch
- is the class to launch.additionalParams
- is the list of additional parameters- Returns:
- the process that is running the new virtual machine, neither
null
- Throws:
IOException
- when a IO error occurs.- Since:
- 6.2
-
saveVMParameters
public static void saveVMParameters(Class<?> classToLaunch, String... parameters)
Save parameters that permit to relaunch a VM withrelaunchVM()
.- Parameters:
classToLaunch
- is the class which contains amain
.parameters
- is the parameters to pass to themain
.
-
saveVMParameters
public static void saveVMParameters(String classToLaunch, String... parameters)
Save parameters that permit to relaunch a VM withrelaunchVM()
.- Parameters:
classToLaunch
- is the class which contains amain
.parameters
- is the parameters to pass to themain
.- Since:
- 6.2
-
saveVMParametersIfNotSet
public static void saveVMParametersIfNotSet(Class<?> classToLaunch, String... parameters)
Save parameters that permit to relaunch a VM withrelaunchVM()
.- Parameters:
classToLaunch
- is the class which contains amain
.parameters
- is the parameters to pass to themain
.
-
saveVMParametersIfNotSet
public static void saveVMParametersIfNotSet(String classToLaunch, String... parameters)
Save parameters that permit to relaunch a VM withrelaunchVM()
.- Parameters:
classToLaunch
- is the class which contains amain
.parameters
- is the parameters to pass to themain
.- Since:
- 6.2
-
relaunchVM
public static Process relaunchVM() throws IOException
Launch a VM with the same parameters as ones saved bysaveVMParameters(Class, String[])
.- Returns:
- the process that is running the new virtual machine, neither
null
- Throws:
IOException
- when a IO error occurs.
-
getAllCommandLineParameters
@Pure public static String[] getAllCommandLineParameters()
Replies the command line including the options and the standard parameters.- Returns:
- the command line.
-
getCommandLineParameters
@Pure public static String[] getCommandLineParameters()
Replies the command line parameters.- Returns:
- the list of the parameters on the command line
-
shiftCommandLineParameters
public static String shiftCommandLineParameters()
Shift the command line parameters by one on the left. The first parameter is removed from the list.- Returns:
- the removed element or
null
-
getCommandLineOptions
@Pure public static Map<String,List<Object>> getCommandLineOptions()
Replies the command line options.- Returns:
- the list of options passed on the command line
-
getCommandLineOption
@Pure public static List<Object> getCommandLineOption(String name)
Replies one command option.- Parameters:
name
- is the name of the option- Returns:
- the option value or
null
if the option is not on the command line.
-
hasCommandLineOption
@Pure public static boolean hasCommandLineOption(String name)
Replies if an option was specified on the command line.- Parameters:
name
- is the name of the option- Returns:
true
if the option was found on the command line, otherwisefalse
.
-
splitOptionsAndParameters
public static void splitOptionsAndParameters(String... optionDefinitions)
Analyse the command line to extract the options.The options will be recognized thanks to the
optionDefinitions
. Each entry ofoptionDefinitions
describes an option. They must have one of the following formats:name
: a simple option without value or flag,name=s
: an option with a mandatory string value,name:s
: an option with an optional string value,name=i
: an option with a mandatory integer value,name:i
: an option with an optional integer value,name=f
: an option with a mandatory floating-point value,name:f
: an option with an optional floating-point value,name=b
: an option with a mandatory boolean value,name:b
: an option with an optional boolean value,name+
: an option with an autoincremented integer value,name!
: an option which could be flaged or not:--name
or--noname
.
- Parameters:
optionDefinitions
- is the list of definitions of the available command line options.
-
hasOption
@Pure public boolean hasOption(String optionLabel)
Replies if the given option is present on the command line.- Parameters:
optionLabel
- is the name of the option- Returns:
true
if the option is present, otherwisefalse
-
getFirstOptionValue
@Pure public Object getFirstOptionValue(String optionLabel)
Replies the first value of the option.- Parameters:
optionLabel
- is the name of the option- Returns:
- the option value or
null
if the option is not present or has no value.
-
getOptionValues
@Pure public List<Object> getOptionValues(String optionLabel)
Replies the values of the option.- Parameters:
optionLabel
- is the name of the option- Returns:
- the option values or
null
if the option is not present.
-
getParameters
@Pure public String[] getParameters()
Replies the parameters on the command line that are not options.- Returns:
- the parameters.
-
shiftParameters
public String shiftParameters()
Shift the command line parameters by one on the left. The first parameter is removed from the list.- Returns:
- the removed element or
null
-
getParameterCount
@Pure public int getParameterCount()
Replies the count of parameters on the command line that are not options.- Returns:
- the count of parameters
-
getParameterAt
@Pure public String getParameterAt(int index)
Replies the parameter at the specified index.- Parameters:
index
- position of the parameter to reply.- Returns:
- the value of the parameter.
- Throws:
IndexOutOfBoundsException
- if the given index is out of bounds.
-
isParameterExists
@Pure public boolean isParameterExists(int index)
Replies if the given index corresponds to a command line parameter.- Parameters:
index
- position of the parameter to test.- Returns:
true
if the given index corresponds to a parameter, otherwisefalse
- Throws:
IndexOutOfBoundsException
- if the given index is out of bounds.
-
-