terp - the Codemesh Modular
Template Interpreter v1.3.337

com.codemesh.terp.eval.executors
Class ProcessExecutor

java.lang.Object
  extended by com.codemesh.terp.api.Executor.AbstractExecutor<ProcessExecutor.Result>
      extended by com.codemesh.terp.eval.executors.ProcessExecutor
All Implemented Interfaces:
Executor<ProcessExecutor.Result>
Direct Known Subclasses:
Ar.ArExecutor, Bc.BcExecutor, DPAnalysis.DPAnalysisExecutor, Gprof.GprofExecutor, ShellExecutor

public class ProcessExecutor
extends Executor.AbstractExecutor<ProcessExecutor.Result>

An executor that runs a process on behalf of the terp runtime. The ProcessExecutor executor is registered with the terp runtime under the ^exec name. You need to configure at least the executable property, the other two properties are optional. Retrieve the process execution's result as a ProcessExecutor.Result instance directly from the invoked execute() method.


Nested Class Summary
static class ProcessExecutor.Result
          The result of any ProcessExecutor invocation.
 
Nested classes/interfaces inherited from interface com.codemesh.terp.api.Executor
Executor.AbstractExecutor<T>, Executor.ForMethod
 
Field Summary
static java.util.regex.Pattern EOL
          The EOL pattern used to split process output into lines.
protected static boolean IS_WINDOWS
          True if the host's OS is Windows.
protected static java.util.logging.Logger logger
          The logger.
protected  java.lang.String[] theEnvironment
          The environment strings for the newly launched process.
protected  java.io.File theExecutable
          The executable that will be launched as a process.
protected  java.lang.String theTerpCmdVar
          The value of the TERP_CMD variable that should be added to the environment (if not null).
protected  java.io.File theWorkingDir
          The working directory of the newly launched process.
protected static Converter<java.io.File> TO_FILE
          A to file converter instance.
protected static Converter<java.util.List> TO_LIST
          A to list converter instance.
 
Constructor Summary
ProcessExecutor()
           
 
Method Summary
 void appendToEnvironment(java.lang.String key, java.lang.String value)
           
 ProcessExecutor.Result execute(java.util.List<java.lang.Object> args, TerpEvaluator eval, TerpContext ctx)
          Performs the executor's action on the given arguments in the given context.
 ProcessExecutor.Result execute(java.lang.String... args)
           
static ProcessExecutor fromFile(java.io.File executable)
           
static ProcessExecutor fromMap(java.util.Map<java.lang.String,java.lang.Object> map)
           
static ProcessExecutor fromMap(ProcessExecutor exec, java.util.Map<java.lang.String,java.lang.Object> map)
           
static ProcessExecutor fromString(java.lang.String executable)
           
 java.util.SortedSet<java.lang.String> getEnvironment()
          Returns the configured environment as a sorted set.
 java.io.File getExecutable()
          Returns the executable.
 java.io.File getWorkingDir()
          Returns the wroking directory for the process.
 java.lang.String[] marshallArguments(java.util.List<java.lang.Object> args)
           
 boolean matches(java.util.List<java.lang.Object> args)
          Returns true if the executor applies to the given arguments.
 void setEnvironment(java.util.Set<java.lang.String> env)
          Sets the process' environment.
 void setExecutable(java.io.File exec)
          Sets the file to execute.
 void setWorkingDir(java.io.File workingDir)
          Sets the working directory for the launched process.
 
Methods inherited from class com.codemesh.terp.api.Executor.AbstractExecutor
execute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theExecutable

protected java.io.File theExecutable
The executable that will be launched as a process.


theWorkingDir

protected java.io.File theWorkingDir
The working directory of the newly launched process.


theEnvironment

protected java.lang.String[] theEnvironment
The environment strings for the newly launched process.


theTerpCmdVar

protected java.lang.String theTerpCmdVar
The value of the TERP_CMD variable that should be added to the environment (if not null).


EOL

public static final java.util.regex.Pattern EOL
The EOL pattern used to split process output into lines.


IS_WINDOWS

protected static final boolean IS_WINDOWS
True if the host's OS is Windows.


TO_FILE

protected static final Converter<java.io.File> TO_FILE
A to file converter instance.


TO_LIST

protected static final Converter<java.util.List> TO_LIST
A to list converter instance.


logger

protected static final java.util.logging.Logger logger
The logger.

Constructor Detail

ProcessExecutor

public ProcessExecutor()
Method Detail

setExecutable

public void setExecutable(java.io.File exec)
Sets the file to execute. The executable needs to be specified for the execution to succeed.

Parameters:
exec - the executable.

getExecutable

public java.io.File getExecutable()
Returns the executable.

Returns:
the executable.

setWorkingDir

public void setWorkingDir(java.io.File workingDir)
Sets the working directory for the launched process. The working directory is optional. If no working directory is specified, the process is invoked with a working directory of null, meaning that the invoking process' working directory is inherited.

Parameters:
workingDir - the working directory for the process.

getWorkingDir

public java.io.File getWorkingDir()
Returns the wroking directory for the process.

Returns:
the configured working directory or null if none is specified.

setEnvironment

public void setEnvironment(java.util.Set<java.lang.String> env)
Sets the process' environment. The argument is a set of environment strings. Environment strings may be just a name or a name=value setting. If you specify an environment, be it an empty one, it completely supercedes the inherited environment. To run a process without an inherited environment, confgure an empty set.

Parameters:
env - a set of environment strings.

getEnvironment

public java.util.SortedSet<java.lang.String> getEnvironment()
Returns the configured environment as a sorted set.

Returns:
the configured environment or null if none is configured.

appendToEnvironment

public void appendToEnvironment(java.lang.String key,
                                java.lang.String value)

fromString

public static ProcessExecutor fromString(java.lang.String executable)

fromFile

public static ProcessExecutor fromFile(java.io.File executable)

fromMap

public static ProcessExecutor fromMap(java.util.Map<java.lang.String,java.lang.Object> map)

fromMap

public static ProcessExecutor fromMap(ProcessExecutor exec,
                                      java.util.Map<java.lang.String,java.lang.Object> map)

matches

public boolean matches(java.util.List<java.lang.Object> args)
Description copied from interface: Executor
Returns true if the executor applies to the given arguments. Typically, your custom executor will implement this method to check for the proper number of arguments and the proper argument types.

Parameters:
args - the arguments passed to the executor.
Returns:
true if the executor knows how to handle the given arguments, false otherwise.

marshallArguments

public java.lang.String[] marshallArguments(java.util.List<java.lang.Object> args)

execute

public ProcessExecutor.Result execute(java.lang.String... args)

execute

public ProcessExecutor.Result execute(java.util.List<java.lang.Object> args,
                                      TerpEvaluator eval,
                                      TerpContext ctx)
Description copied from interface: Executor
Performs the executor's action on the given arguments in the given context. Typically, your custom executor will implement this method to provide its core functionality.

Parameters:
args - the arguments.
eval - the evaluator to use. Can frequently be null.
ctx - the context in which the execution occurs. Can frequently be null.
Returns:
the execution result.

terp - the Codemesh Modular
Template Interpreter v1.3.337

Copyright © 2008-2016 by Codemesh, Inc. All Rights Reserved.