JDeveloper SCM API

oracle.ide.scm.util.runner
Class SCMShellRunner

java.lang.Object
  |
  +--oracle.ide.scm.util.runner.SCMShellRunner

public class SCMShellRunner
extends java.lang.Object

Class for the running of shell commands. This, along with the process wrapper and stream monitor adapters, provide convenience utilities for running external processes and accessing output.


Constructor Summary
SCMShellRunner()
          Constructs a new shell runner.
 
Method Summary
 void addErrorMonitor(SCMStreamMonitor monitor)
          Adds a process error stream monitor to the shell runner's list.
 void addOutputMonitor(SCMStreamMonitor monitor)
          Adds a process output stream monitor to the shell runner's list.
 void clearMonitors()
          Clears all process output and error monitors for the shell runner.
protected  java.lang.String[] createCommandSpi(java.lang.String[] cmdarray)
          Implementation for command changes prior to execution.
protected  SCMProcess createProcess(java.lang.String[] cmdarray)
          Runs the given command through Runtime, creating a new process.
protected  SCMProcess doExecSpi(java.lang.String[] cmdarray)
          Implementation for command execution by process creation.
 SCMProcess exec()
          Executes the configured command of this shell runner, spawning a process.
 java.lang.String[] getCmdArray()
          Gets the command parts for this shell runner.
 java.util.List getCmdList()
          Gets the command parts for this shell runner as a list.
 java.lang.String getCommand()
          Gets the command string for this shell runner.
 java.io.File getDirectory()
          Gets the working directory for the process.
 java.net.URL getDirURL()
          Gets the working directory for the process from a URL.
 java.lang.String[] getEnvpArray()
          Gets the environment variables for the process.
 java.util.Map getEnvpMap()
          Gets the environment variables for the process in a map.
protected  java.util.List getErrorMonitors()
          Gets the internal error monitor list.
protected  java.util.List getOutputMonitors()
          Gets the internal output monitor list.
 java.lang.String getReadableCommand()
          Builds a readable string for representing the command invocation.
 long getTimeout()
          Gets the process activity timeout length, in milliseconds.
 boolean getUseNativeShell()
          Asks whether the process will be run by a recognized native shell.
 boolean getUseWin32Console()
          Asks whether a detached console wil be created for the new process.
 boolean isOutputBuffered()
          Asks whether process output will be buffered.
protected  void postExecSpi(SCMProcess process)
          Implementation for actions after the running of a command.
protected  void preExecSpi()
          Implementation for actions prior to the running of a command.
 void removeErrorMonitor(SCMStreamMonitor monitor)
          Removes a process error stream monitor from the shell runner's list.
 void removeOutputMonitor(SCMStreamMonitor monitor)
          Removes a process output stream monitor from the shell runner's list.
 void setCmdArray(java.lang.String[] cmd_array)
          Sets the command parts for this shell runner.
 void setCmdList(java.util.List cmd_list)
          Sets the command parts for this shell runner from a list.
 void setCommand(java.lang.String command)
          Sets the command string for this shell runner.
 void setDirectory(java.io.File dir)
          Sets the working directory for the process.
 void setDirURL(java.net.URL dir)
          Sets the working directory for the process from a URL.
 void setEnvpArray(java.lang.String[] envp_array)
          Sets the environment variables for the process from an array.
 void setEnvpMap(java.util.Map envp_map)
          Sets the environment variables for the process from a map.
 void setOutputBuffered(boolean buffered)
          Sets whether process output will be buffered.
 void setTimeout(long timeout)
          Sets the process activity timeout length, in milliseconds.
 void setUseNativeShell(boolean shell)
          Sets whether the process will be run by a recognized native shell.
 void setUseWin32Console(boolean console)
          Sets whether a detached console wil be created for the new process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SCMShellRunner

public SCMShellRunner()
Constructs a new shell runner.
Method Detail

setCommand

public void setCommand(java.lang.String command)
Sets the command string for this shell runner. By default, there is no command for a shell runner.
Parameters:
command - the shell runner's command.

setCmdArray

public void setCmdArray(java.lang.String[] cmd_array)
Sets the command parts for this shell runner. By default, there is no command for a shell runner.
Parameters:
cmdarray - the shell runner's command array.

setCmdList

public void setCmdList(java.util.List cmd_list)
Sets the command parts for this shell runner from a list. By default, there is no command for a shell runner.
Parameters:
cmdlist - the shell runner's command array.

setEnvpArray

public void setEnvpArray(java.lang.String[] envp_array)
Sets the environment variables for the process from an array. By default, there are no environment parameters defined.
Parameters:
envp - the environment variables, in the form name=value.

setEnvpMap

public void setEnvpMap(java.util.Map envp_map)
Sets the environment variables for the process from a map. By default, there are no environment parameters defined.
Parameters:
envp - the environment variables, in a map of names and values.

setDirectory

public void setDirectory(java.io.File dir)
Sets the working directory for the process. By default, there is no working directory set.
Parameters:
dir - the working directory.

setDirURL

public void setDirURL(java.net.URL dir)
Sets the working directory for the process from a URL. By default, there is no working directory set.
Parameters:
dir - the working directory, as a URL.

addOutputMonitor

public void addOutputMonitor(SCMStreamMonitor monitor)
Adds a process output stream monitor to the shell runner's list.
Parameters:
monitor - the stream monitor.

removeOutputMonitor

public void removeOutputMonitor(SCMStreamMonitor monitor)
Removes a process output stream monitor from the shell runner's list.
Parameters:
monitor - the stream monitor.

addErrorMonitor

public void addErrorMonitor(SCMStreamMonitor monitor)
Adds a process error stream monitor to the shell runner's list.
Parameters:
monitor - the stream monitor.

removeErrorMonitor

public void removeErrorMonitor(SCMStreamMonitor monitor)
Removes a process error stream monitor from the shell runner's list.
Parameters:
monitor - the stream monitor.

clearMonitors

public void clearMonitors()
Clears all process output and error monitors for the shell runner.

setTimeout

public void setTimeout(long timeout)
Sets the process activity timeout length, in milliseconds. A process is thought to be idle when it has not written to its output streams. By default, there is no timeout on process activity.
Parameters:
timeout - the length of the timeout, or a value <= 0 to indicate no timeout.

setOutputBuffered

public void setOutputBuffered(boolean buffered)
Sets whether process output will be buffered. By default, output is buffered in the process wrapper.
Parameters:
buffered - a decision on the buffering of output.

setUseNativeShell

public void setUseNativeShell(boolean shell)
Sets whether the process will be run by a recognized native shell. By default, the command is delegated (when appropriate) to the most suitable shell for the OS.
Parameters:
shell - a decision on whether a recognized shell for the OS will be used.

setUseWin32Console

public void setUseWin32Console(boolean console)
Sets whether a detached console wil be created for the new process. Note that this will prevent output from the process from being monitored, and that a timeout will not be effective.
Parameters:
console - a decision on whether a console should be spawned (Win32).

getCommand

public java.lang.String getCommand()
Gets the command string for this shell runner.
Returns:
the shell runner's command.

getCmdArray

public java.lang.String[] getCmdArray()
Gets the command parts for this shell runner.
Returns:
the shell runner's command array.

getCmdList

public java.util.List getCmdList()
Gets the command parts for this shell runner as a list.
Returns:
the shell runner's command list.

getEnvpArray

public java.lang.String[] getEnvpArray()
Gets the environment variables for the process.
Returns:
the environment variables, in the form name=value.

getEnvpMap

public java.util.Map getEnvpMap()
Gets the environment variables for the process in a map.
Returns:
the environment variables, in a map of names and values.

getDirectory

public java.io.File getDirectory()
Gets the working directory for the process.
Returns:
the working directory.

getDirURL

public java.net.URL getDirURL()
Gets the working directory for the process from a URL.
Returns:
the working directory, as a URL

getTimeout

public long getTimeout()
Gets the process activity timeout length, in milliseconds.
Returns:
the length of the timeout.

isOutputBuffered

public boolean isOutputBuffered()
Asks whether process output will be buffered.
Returns:
a verdict on the buffering of output.

getUseNativeShell

public boolean getUseNativeShell()
Asks whether the process will be run by a recognized native shell.
Returns:
a verdict on whether a recognized shell for the OS will be used.

getUseWin32Console

public boolean getUseWin32Console()
Asks whether a detached console wil be created for the new process.
Returns:
a decision on whether a console should be spawned (Win32).

getReadableCommand

public java.lang.String getReadableCommand()
Builds a readable string for representing the command invocation.
Returns:
a readable command-line like string represention of the full command specification.

exec

public SCMProcess exec()
                throws SCMException
Executes the configured command of this shell runner, spawning a process.
Returns:
the resulting process, or null if the command is invalid.
Throws:
SCMException - if an error occurred when running the command.

createCommandSpi

protected java.lang.String[] createCommandSpi(java.lang.String[] cmdarray)
Implementation for command changes prior to execution. Override this method to manipulate the command or any aspect of state before the process is created.
Parameters:
cmdarray - the command, before modification.
Returns:
the well-formed command.

preExecSpi

protected void preExecSpi()
                   throws SCMException
Implementation for actions prior to the running of a command. Override this method to set up the shell runner or environment as necessary before process creation.

doExecSpi

protected SCMProcess doExecSpi(java.lang.String[] cmdarray)
                        throws SCMException
Implementation for command execution by process creation. Override this method to use an alternative means of creating the command process. A null may safely be returned by this method.
Parameters:
cmdarray - the command to run.
Returns:
a wrapper for the new process.
Throws:
SCMException - if an error occurred when running the command.

postExecSpi

protected void postExecSpi(SCMProcess process)
                    throws SCMException
Implementation for actions after the running of a command. Override this method to perform any default actions with the created process, handle errors, and write log messages.
Parameters:
process - the newly created process.

createProcess

protected final SCMProcess createProcess(java.lang.String[] cmdarray)
                                  throws SCMException
Runs the given command through Runtime, creating a new process.
Parameters:
cmdarray - the command to run.
Returns:
a wrapper for the new process.
Throws:
SCMException - if an error occurred when running the command.

getOutputMonitors

protected final java.util.List getOutputMonitors()
Gets the internal output monitor list.
Returns:
the list of stream monitors.

getErrorMonitors

protected final java.util.List getErrorMonitors()
Gets the internal error monitor list.
Returns:
the list of stream monitors.

Copyright © 2002 Oracle Corporation