class ForkedJvm
extends java.lang.Object
main()
method of some tool in a forked JVM.Modifier and Type | Field and Description |
---|---|
private java.util.Set |
classPathEntries
The class path entries for the forked JVM, given as strings.
|
private java.util.List |
cmdLineArgs
The command line arguments to pass to the
main() method, given as strings. |
private java.lang.String |
executable
The executable used to fork the JVM.
|
private java.lang.String |
mainClass
The qualified name of the class on which to invoke the
main() method. |
private org.codehaus.plexus.util.cli.StreamConsumer |
systemErr
The consumer for
System.err messages. |
private org.codehaus.plexus.util.cli.StreamConsumer |
systemOut
The consumer for
System.out messages. |
private java.io.File |
workingDirectory
The working directory for the forked JVM.
|
Constructor and Description |
---|
ForkedJvm()
Creates a new configuration to fork a JVM.
|
Modifier and Type | Method and Description |
---|---|
void |
addArgument(java.io.File argument)
Adds the specified file path to the command line for the
main() method. |
void |
addArgument(java.lang.String argument)
Adds the specified argument to the command line for the
main() method. |
void |
addArguments(java.lang.String[] arguments)
Adds the specified arguments to the command line for the
main() method. |
void |
addClassPathEntry(java.lang.Class type)
Adds the source JAR of the specified class/interface to the class path of the forked JVM.
|
void |
addClassPathEntry(java.io.File path)
Adds the specified path to the class path of the forked JVM.
|
void |
addClassPathEntry(java.lang.String path)
Adds the specified path to the class path of the forked JVM.
|
private org.codehaus.plexus.util.cli.Commandline |
createCommandLine()
Creates the command line for the new JVM based on the current configuration.
|
private java.lang.String[] |
getArguments()
Gets the command line arguments for the
main() method. |
private java.lang.String |
getClassPath()
Gets the class path for the forked JVM.
|
private static java.io.File |
getClassSource(java.lang.Class type)
Gets the JAR file or directory that contains the specified class.
|
private static java.io.File |
getClassSource(java.lang.String className)
Gets the JAR file or directory that contains the specified class.
|
private static java.lang.String |
getDefaultExecutable()
Gets the absolute path to the JVM executable.
|
private static java.io.File |
getResourceSource(java.lang.String resource,
java.lang.ClassLoader loader)
Gets the JAR file or directory that contains the specified resource.
|
int |
run()
Forks a JVM using the previously set parameters.
|
void |
setMainClass(java.lang.Class type)
Sets the class on which to invoke the
main() method. |
void |
setMainClass(java.lang.String name)
Sets the qualified name of the class on which to invoke the
main() method. |
void |
setSystemErr(org.codehaus.plexus.util.cli.StreamConsumer consumer)
Sets the stream consumer used to handle messages from
System.err . |
void |
setSystemOut(org.codehaus.plexus.util.cli.StreamConsumer consumer)
Sets the stream consumer used to handle messages from
System.out . |
void |
setWorkingDirectory(java.io.File directory)
Sets the working directory for the forked JVM.
|
java.lang.String |
toString()
Gets a string representation of the command line arguments.
|
private org.codehaus.plexus.util.cli.StreamConsumer systemOut
System.out
messages.private org.codehaus.plexus.util.cli.StreamConsumer systemErr
System.err
messages.private java.lang.String executable
private java.io.File workingDirectory
private java.util.Set classPathEntries
private java.lang.String mainClass
main()
method.private java.util.List cmdLineArgs
main()
method, given as strings.private static java.lang.String getDefaultExecutable()
public void setWorkingDirectory(java.io.File directory)
directory
- The working directory for the forked JVM, may be null
to inherit the working
directory of the current JVM.public void setSystemOut(org.codehaus.plexus.util.cli.StreamConsumer consumer)
System.out
.consumer
- The stream consumer, may be null
to discard the output.public void setSystemErr(org.codehaus.plexus.util.cli.StreamConsumer consumer)
System.err
.consumer
- The stream consumer, may be null
to discard the output.private java.lang.String getClassPath()
public void addClassPathEntry(java.lang.String path)
path
- The path to add, may be null
.public void addClassPathEntry(java.io.File path)
path
- The path to add, may be null
.public void addClassPathEntry(java.lang.Class type)
type
- The class/interface to add, may be null
.private static java.io.File getClassSource(java.lang.Class type)
type
- The class/interface to find, may be null
.null
if unknown.private static java.io.File getClassSource(java.lang.String className)
className
- The qualified name of the class/interface to find, may be null
.null
if unknown.private static java.io.File getResourceSource(java.lang.String resource, java.lang.ClassLoader loader)
resource
- The absolute name of the resource to find, may be null
.loader
- The class loader to use for searching the resource, may be null
.null
if unknown.public void setMainClass(java.lang.String name)
main()
method. The source of the
specified class will automatically be added to the class path of the forked JVM.name
- The qualified name of the class on which to invoke the main()
method.public void setMainClass(java.lang.Class type)
main()
method. The source of the specified class will
automatically be added to the class path of the forked JVM.type
- The class on which to invoke the main()
method, may be null
.private java.lang.String[] getArguments()
main()
method.main()
method.public void addArgument(java.lang.String argument)
main()
method.argument
- The argument to add, may be null
.public void addArgument(java.io.File argument)
main()
method.argument
- The argument to add, may be null
.public void addArguments(java.lang.String[] arguments)
main()
method.arguments
- The arguments to add, may be null
.private org.codehaus.plexus.util.cli.Commandline createCommandLine()
null
.public int run() throws java.lang.Exception
java.lang.Exception
- If the JVM could not be forked.public java.lang.String toString()
toString
in class java.lang.Object