org.arakhne.vmutil
Class VMCommandLine

java.lang.Object
  extended by org.arakhne.vmutil.VMCommandLine

public class VMCommandLine
extends Object

This utility class permits to get the java command line for the current VM.

Version:
7.2 (rev:394) 2013-03-20 23:37:56
Author:
Stéphane GALLAND
Maven Group Id:
org.arakhne.afc
Maven Artifact Id:
arakhneVmutils

Constructor Summary
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
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 by saveVMParameters(Class, String[]).
static void saveVMParameters(Class<?> classToLaunch, String... parameters)
          Save parameters that permit to relaunch a VM with relaunchVM().
static void saveVMParameters(String classToLaunch, String... parameters)
          Save parameters that permit to relaunch a VM with relaunchVM().
static void saveVMParametersIfNotSet(Class<?> classToLaunch, String... parameters)
          Save parameters that permit to relaunch a VM with relaunchVM().
static void saveVMParametersIfNotSet(String classToLaunch, String... parameters)
          Save parameters that permit to relaunch a VM with relaunchVM().
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VMCommandLine

public VMCommandLine(Class<?> classToLaunch,
                     String... parameters)
Create a interface to the command line options.

Parameters:
classToLaunch - is the class which contains a main.
parameters - is the parameters to pass to the main.
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 a main.
parameters - is the parameters to pass to the main.
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 a main.
optionDefinitions - is the list of definitions of the available command line options.
parameters - is the parameters to pass to the main.
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 a main.
optionDefinitions - is the list of definitions of the available command line options.
parameters - is the parameters to pass to the main.
Since:
6.2
See Also:
saveVMParametersIfNotSet(String, String[]), splitOptionsAndParameters(String[])

VMCommandLine

public VMCommandLine()
Create a interface to the command line options.

See Also:
VMCommandLine(Class, String[], String[]), VMCommandLine(Class, String[])
Method Detail

getExecutableFilename

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

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
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
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
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
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
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

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
Since:
6.2

saveVMParameters

public static void saveVMParameters(Class<?> classToLaunch,
                                    String... parameters)
Save parameters that permit to relaunch a VM with relaunchVM().

Parameters:
classToLaunch - is the class which contains a main.
parameters - is the parameters to pass to the main.

saveVMParameters

public static void saveVMParameters(String classToLaunch,
                                    String... parameters)
Save parameters that permit to relaunch a VM with relaunchVM().

Parameters:
classToLaunch - is the class which contains a main.
parameters - is the parameters to pass to the main.
Since:
6.2

saveVMParametersIfNotSet

public static void saveVMParametersIfNotSet(Class<?> classToLaunch,
                                            String... parameters)
Save parameters that permit to relaunch a VM with relaunchVM().

Parameters:
classToLaunch - is the class which contains a main.
parameters - is the parameters to pass to the main.

saveVMParametersIfNotSet

public static void saveVMParametersIfNotSet(String classToLaunch,
                                            String... parameters)
Save parameters that permit to relaunch a VM with relaunchVM().

Parameters:
classToLaunch - is the class which contains a main.
parameters - is the parameters to pass to the main.
Since:
6.2

relaunchVM

public static Process relaunchVM()
                          throws IOException
Launch a VM with the same parameters as ones saved by saveVMParameters(Class, String[]).

Returns:
the process that is running the new virtual machine, neither null
Throws:
IOException

getAllCommandLineParameters

public static String[] getAllCommandLineParameters()
Replies the command line including the options and the standard parameters.

Returns:
the command line.

getCommandLineParameters

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

public static Map<String,List<Object>> getCommandLineOptions()
Replies the command line options.

Returns:
the list of options passed on the command line

getCommandLineOption

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

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, otherwise false.

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 of optionDefinitions describes an option. They must have one of the following formats:

Parameters:
optionDefinitions - is the list of definitions of the available command line options.

hasOption

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, otherwise false

getFirstOptionValue

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

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

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

public int getParameterCount()
Replies the count of parameters on the command line that are not options.

Returns:
the count of parameters

getParameterAt

public String getParameterAt(int index)
Replies the parameter at the specified index.

Parameters:
index -
Returns:
the value of the parameter.
Throws:
IndexOutOfBoundsException

isParameterExists

public boolean isParameterExists(int index)
Replies if the given index corresponds to a command line parameter.

Parameters:
index -
Returns:
true if the given index corresponds to a parameter, otherwise false
Throws:
IndexOutOfBoundsException


Copyright © 2006-2013 Arakhnê.org Consortium. All rights reserved under LGPL license terms.