public class NGContext
extends java.lang.Object
Provides quite a bit of potentially useful information to classes specifically written for NailGun. The NailGun server itself, its AliasManager, the remote client's environment variables, and other information is available via this class. For all intents and purposes, the NGContext represents a single connection from a NailGun client.
If a class is written with a
public static void nailMain(NGContext context)
method, that method will be called by NailGun instead of the traditional
main(String[])
method normally used for programs. A fully populated NGContext
object will then be provided to nailMain()
.Modifier and Type | Field and Description |
---|---|
private java.lang.String[] |
args
Command line arguments for the nail
|
private java.lang.String |
command
The command that was issued for this connection
|
java.io.PrintStream |
err
The client's stderr
|
private java.io.PrintStream |
exitStream
A stream to which a client exit code can be printed
|
java.io.InputStream |
in
The client's stdin
|
java.io.PrintStream |
out
The client's stdout
|
private java.util.Properties |
remoteEnvironment
The remote host's environment variables
|
private java.net.InetAddress |
remoteHost
The remote host's address
|
private int |
remotePort
The port on the remote host that is communicating with NailGun
|
private NGServer |
server
The NGServer that accepted this connection
|
private java.lang.String |
workingDirectory |
Constructor and Description |
---|
NGContext()
Creates a new, empty NGContext
|
Modifier and Type | Method and Description |
---|---|
void |
assertLocalClient()
Throws a
java.lang.SecurityException if the client is not
connected from the local machine. |
void |
assertLoopbackClient()
Throws a
java.lang.SecurityException if the client is not
connected via the loopback address. |
void |
exit(int exitCode)
Sends an exit command with the specified exit code to
the client.
|
java.lang.String[] |
getArgs()
Returns the command line arguments for the command
implementation (nail) on the server.
|
java.lang.String |
getCommand()
Returns the command that was issued by the client (either an alias or the name of a class).
|
java.util.Properties |
getEnv()
Returns a
java.util.Properties object containing a copy
of the client's environment variables |
java.lang.String |
getFileSeparator()
Returns the file separator ('/' or '\\') used by the client's os.
|
java.net.InetAddress |
getInetAddress()
Returns the address of the client at the other side of this connection.
|
NGServer |
getNGServer()
Returns the NGServer that accepted this connection
|
java.lang.String |
getPathSeparator()
Returns the path separator (':' or ';') used by the client's os.
|
int |
getPort()
Returns the port on the client connected to the NailGun
server.
|
java.lang.String |
getWorkingDirectory()
Returns the current working directory of the client, as reported by the client.
|
(package private) void |
setArgs(java.lang.String[] args) |
(package private) void |
setCommand(java.lang.String command) |
(package private) void |
setEnv(java.util.Properties remoteEnvironment) |
(package private) void |
setExitStream(java.io.PrintStream exitStream) |
(package private) void |
setInetAddress(java.net.InetAddress remoteHost) |
(package private) void |
setNGServer(NGServer server) |
(package private) void |
setPort(int remotePort) |
(package private) void |
setWorkingDirectory(java.lang.String workingDirectory) |
private java.util.Properties remoteEnvironment
private java.net.InetAddress remoteHost
private int remotePort
private java.lang.String[] args
private java.io.PrintStream exitStream
private NGServer server
private java.lang.String command
private java.lang.String workingDirectory
public java.io.InputStream in
public java.io.PrintStream out
public java.io.PrintStream err
void setExitStream(java.io.PrintStream exitStream)
void setPort(int remotePort)
void setCommand(java.lang.String command)
public java.lang.String getCommand()
void setWorkingDirectory(java.lang.String workingDirectory)
public java.lang.String getWorkingDirectory()
File.separator
('/' or '\'),
which may differ from the separator on the server.void setEnv(java.util.Properties remoteEnvironment)
void setInetAddress(java.net.InetAddress remoteHost)
void setArgs(java.lang.String[] args)
void setNGServer(NGServer server)
public java.util.Properties getEnv()
java.util.Properties
object containing a copy
of the client's environment variablesjava.util.Properties
object containing a copy
of the client's environment variablesProperties
public java.lang.String getFileSeparator()
public java.lang.String getPathSeparator()
public java.net.InetAddress getInetAddress()
public java.lang.String[] getArgs()
public NGServer getNGServer()
public void exit(int exitCode)
exitCode
- the exit code with which the client
should exitpublic int getPort()
public void assertLoopbackClient()
java.lang.SecurityException
if the client is not
connected via the loopback address.public void assertLocalClient()
java.lang.SecurityException
if the client is not
connected from the local machine.