Package adams.flow.source
Class Exec
-
- All Implemented Interfaces:
AdditionalInformationHandler
,ClassCrossReference
,CleanUpHandler
,CrossReference
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,EnvironmentVariablesHandler
,WorkingDirectoryHandler
,OptionHandler
,QuickInfoSupporter
,ShallowCopySupporter<Actor>
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,VariablesInspectionHandler
,VariableChangeListener
,Actor
,ErrorHandler
,OutputProducer
,Serializable
,Comparable
public class Exec extends AbstractSource implements ClassCrossReference, EnvironmentVariablesHandler, WorkingDirectoryHandler
Runs an external system command and broadcasts the generated output (stdout or stderr).
See also:
adams.flow.source.Exec
Input/output:
- generates:
java.lang.String
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-name <java.lang.String> (property: name) The name of the actor. default: Exec
-annotation <adams.core.base.BaseAnnotation> (property: annotations) The annotations to attach to this actor. default:
-skip <boolean> (property: skip) If set to true, transformation is skipped and the input token is just forwarded as it is. default: false
-stop-flow-on-error <boolean> (property: stopFlowOnError) If set to true, the flow execution at this level gets stopped in case this actor encounters an error; the error gets propagated; useful for critical actors. default: false
-silent <boolean> (property: silent) If enabled, then no errors are output in the console; Note: the enclosing actor handler must have this enabled as well. default: false
-cmd <adams.core.base.BaseText> (property: command) The external command to run. default: ls -l .
-working-directory <java.lang.String> (property: workingDirectory) The current working directory for the command. default:
-env-var <adams.core.base.BaseKeyValuePair> [-env-var ...] (property: envVars) The environment variables to overlay on top of the current ones. default:
-placeholder <boolean> (property: commandContainsPlaceholder) Set this to true to enable automatic placeholder expansion for the command string. default: false
-variable <boolean> (property: commandContainsVariable) Set this to true to enable automatic variable expansion for the command string. default: false
-output-type <STDOUT|STDERR|BOTH> (property: outputType) Determines the output type; if BOTH is selected then an array is output with stdout as first element and stderr as second default: STDOUT
-split-output <boolean> (property: splitOutput) If set to true, then the output gets split on newline; does not apply when outputting stdout and stderr together. default: false
-conversion <adams.data.conversion.ConversionFromString> (property: conversion) The conversion scheme to apply to the output; does not apply when outputting stdout and stderr together. default: adams.data.conversion.StringToString
-fail-on-process-error <boolean> (property: failOnProcessError) If enabled, the actor will fail as well if the process failed. default: true
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Exec.OutputType
What to output.
-
Field Summary
Fields Modifier and Type Field Description protected BaseText
m_Command
the command to run.protected boolean
m_CommandContainsPlaceholder
whether the replace string contains a placeholder, which needs to be expanded first.protected boolean
m_CommandContainsVariable
whether the replace string contains a variable, which needs to be expanded first.protected ConversionFromString
m_Conversion
the conversion scheme to process the output with.protected BaseKeyValuePair[]
m_EnvVars
environment variables.protected boolean
m_FailOnProcessError
whether to fail on process error.protected List
m_Output
the tokens to forward.protected Exec.OutputType
m_OutputType
whether to output stderr instead of stdout.protected com.github.fracpete.processoutput4j.output.CollectingProcessOutput
m_ProcessOutput
for executing the command and collecting stdout/err output.protected boolean
m_SplitOutput
whether to split the string output on the new line before converting.protected String
m_WorkingDirectory
the current working directory.-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Constructor Summary
Constructors Constructor Description Exec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
commandContainsPlaceholderTipText()
Returns the tip text for this property.String
commandContainsVariableTipText()
Returns the tip text for this property.String
commandTipText()
Returns the tip text for this property.String
conversionTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.protected String
doExecute()
Executes the flow item.String
envVarsTipText()
Returns the tip text for this property.String
failOnProcessErrorTipText()
Returns the tip text for this property.Class[]
generates()
Returns the class of objects that it generates.Class[]
getClassCrossReferences()
Returns the cross-referenced classes.BaseText
getCommand()
Returns the command to run.boolean
getCommandContainsPlaceholder()
Returns whether the command string contains a placeholder which needs to be expanded first.boolean
getCommandContainsVariable()
Returns whether the command string contains a variable which needs to be expanded first.ConversionFromString
getConversion()
Returns the conversion to apply to the output.BaseKeyValuePair[]
getEnvVars()
Returns the environment variables to overlay on top of the current ones.boolean
getFailOnProcessError()
Returns whether to fail as well if the process failed.Exec.OutputType
getOutputType()
Returns what output from the process to forward.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.boolean
getSplitOutput()
Returns whether to split the output on newline or crlf.String
getWorkingDirectory()
Returns the current working directory for the command.String
globalInfo()
Returns a string describing the object.boolean
hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.protected void
initialize()
Initializes the members.Token
output()
Returns the generated token.String
outputTypeTipText()
Returns the tip text for this property.protected void
reset()
Resets the scheme.void
setCommand(BaseText value)
Sets the command to run.void
setCommandContainsPlaceholder(boolean value)
Sets whether the command string contains a placeholder which needs to be expanded first.void
setCommandContainsVariable(boolean value)
Sets whether the command string contains a variable which needs to be expanded first.void
setConversion(ConversionFromString value)
Sets the conversion to apply to the output.void
setEnvVars(BaseKeyValuePair[] value)
Sets the environment variables to overlay on top of the current ones.void
setFailOnProcessError(boolean value)
Sets whether to fail as well if the process failed.void
setOutputType(Exec.OutputType value)
Sets what output from the process to forward.void
setSplitOutput(boolean value)
Sets whether to split the output on the newline or crlf.void
setWorkingDirectory(String value)
Sets the current working directory for the command.String
splitOutputTipText()
Returns the tip text for this property.void
stopExecution()
Stops the execution.String
workingDirectoryTipText()
Returns the tip text for this property.-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, backupState, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, execute, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, postExecute, preExecute, pruneBackup, pruneBackup, restoreState, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged, wrapUp
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
cleanUp, compareTo, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, toCommandLine, variableChanged, wrapUp
-
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
Methods inherited from interface adams.core.VariablesInspectionHandler
canInspectOptions
-
-
-
-
Field Detail
-
m_Command
protected BaseText m_Command
the command to run.
-
m_WorkingDirectory
protected String m_WorkingDirectory
the current working directory.
-
m_EnvVars
protected BaseKeyValuePair[] m_EnvVars
environment variables.
-
m_CommandContainsPlaceholder
protected boolean m_CommandContainsPlaceholder
whether the replace string contains a placeholder, which needs to be expanded first.
-
m_CommandContainsVariable
protected boolean m_CommandContainsVariable
whether the replace string contains a variable, which needs to be expanded first.
-
m_OutputType
protected Exec.OutputType m_OutputType
whether to output stderr instead of stdout.
-
m_SplitOutput
protected boolean m_SplitOutput
whether to split the string output on the new line before converting.
-
m_Conversion
protected ConversionFromString m_Conversion
the conversion scheme to process the output with.
-
m_Output
protected List m_Output
the tokens to forward.
-
m_FailOnProcessError
protected boolean m_FailOnProcessError
whether to fail on process error.
-
m_ProcessOutput
protected transient com.github.fracpete.processoutput4j.output.CollectingProcessOutput m_ProcessOutput
for executing the command and collecting stdout/err output.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
getClassCrossReferences
public Class[] getClassCrossReferences()
Returns the cross-referenced classes.- Specified by:
getClassCrossReferences
in interfaceClassCrossReference
- Returns:
- the classes
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractActor
-
reset
protected void reset()
Resets the scheme.- Overrides:
reset
in classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractActor
- Returns:
- null if no info available, otherwise short string
-
setCommand
public void setCommand(BaseText value)
Sets the command to run.- Parameters:
value
- the command
-
getCommand
public BaseText getCommand()
Returns the command to run.- Returns:
- the command
-
commandTipText
public String commandTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setWorkingDirectory
public void setWorkingDirectory(String value)
Sets the current working directory for the command.- Specified by:
setWorkingDirectory
in interfaceWorkingDirectoryHandler
- Parameters:
value
- the directory, ignored if empty
-
getWorkingDirectory
public String getWorkingDirectory()
Returns the current working directory for the command.- Specified by:
getWorkingDirectory
in interfaceWorkingDirectoryHandler
- Returns:
- the directory, ignored if empty
-
workingDirectoryTipText
public String workingDirectoryTipText()
Returns the tip text for this property.- Specified by:
workingDirectoryTipText
in interfaceWorkingDirectoryHandler
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setEnvVars
public void setEnvVars(BaseKeyValuePair[] value)
Sets the environment variables to overlay on top of the current ones.- Specified by:
setEnvVars
in interfaceEnvironmentVariablesHandler
- Parameters:
value
- the environment variables
-
getEnvVars
public BaseKeyValuePair[] getEnvVars()
Returns the environment variables to overlay on top of the current ones.- Specified by:
getEnvVars
in interfaceEnvironmentVariablesHandler
- Returns:
- the environment variables
-
envVarsTipText
public String envVarsTipText()
Returns the tip text for this property.- Specified by:
envVarsTipText
in interfaceEnvironmentVariablesHandler
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setCommandContainsPlaceholder
public void setCommandContainsPlaceholder(boolean value)
Sets whether the command string contains a placeholder which needs to be expanded first.- Parameters:
value
- true if command string contains a placeholder
-
getCommandContainsPlaceholder
public boolean getCommandContainsPlaceholder()
Returns whether the command string contains a placeholder which needs to be expanded first.- Returns:
- true if command string contains a placeholder
-
commandContainsPlaceholderTipText
public String commandContainsPlaceholderTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setCommandContainsVariable
public void setCommandContainsVariable(boolean value)
Sets whether the command string contains a variable which needs to be expanded first.- Parameters:
value
- true if command string contains a variable
-
getCommandContainsVariable
public boolean getCommandContainsVariable()
Returns whether the command string contains a variable which needs to be expanded first.- Returns:
- true if command string contains a variable
-
commandContainsVariableTipText
public String commandContainsVariableTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setOutputType
public void setOutputType(Exec.OutputType value)
Sets what output from the process to forward.- Parameters:
value
- the output type
-
getOutputType
public Exec.OutputType getOutputType()
Returns what output from the process to forward.- Returns:
- the output type
-
outputTypeTipText
public String outputTypeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setSplitOutput
public void setSplitOutput(boolean value)
Sets whether to split the output on the newline or crlf.- Parameters:
value
- if true then output is split
-
getSplitOutput
public boolean getSplitOutput()
Returns whether to split the output on newline or crlf.- Returns:
- true if output is split
-
splitOutputTipText
public String splitOutputTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setConversion
public void setConversion(ConversionFromString value)
Sets the conversion to apply to the output.- Parameters:
value
- the conversion
-
getConversion
public ConversionFromString getConversion()
Returns the conversion to apply to the output.- Returns:
- the conversion
-
conversionTipText
public String conversionTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setFailOnProcessError
public void setFailOnProcessError(boolean value)
Sets whether to fail as well if the process failed.- Parameters:
value
- true if to fail as well
-
getFailOnProcessError
public boolean getFailOnProcessError()
Returns whether to fail as well if the process failed.- Returns:
- true if to fail as well
-
failOnProcessErrorTipText
public String failOnProcessErrorTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
generates
public Class[] generates()
Returns the class of objects that it generates.- Specified by:
generates
in interfaceOutputProducer
- Returns:
- java.lang.String.class
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecute
in classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
-
output
public Token output()
Returns the generated token.- Specified by:
output
in interfaceOutputProducer
- Returns:
- the generated token
-
hasPendingOutput
public boolean hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.- Specified by:
hasPendingOutput
in interfaceOutputProducer
- Returns:
- true if there is pending output
-
stopExecution
public void stopExecution()
Stops the execution. No message set.- Specified by:
stopExecution
in interfaceActor
- Specified by:
stopExecution
in interfaceStoppable
- Overrides:
stopExecution
in classAbstractActor
-
-