org.hackystat.sensor.ant.task
Class HackystatSensorTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.hackystat.sensor.ant.task.HackystatSensorTask
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
CheckstyleSensor, CloverSensor, DependencyFinderSensor, EmmaSensor, FindBugsSensor, JavaNcssSensor, JDependSensor, JUnitSensor, PmdSensor

public abstract class HackystatSensorTask
extends org.apache.tools.ant.Task

An abstract superclass containing instance variables and helper methods used by Hackystat Sensors implemented as Ant tasks. This includes almost all of the sensors except for the Ant Build sensor, which is implemented as a listener.

Author:
Philip Johnson

Field Summary
protected  java.util.List<DataFiles> dataFilesList
          The list of datafile element instances found in the task.
protected  java.lang.String errMsgPrefix
          The string that prefixes all error messages from this sensor.
protected  boolean failOnError
          Whether or not to throw a BuildException if problems occur during sensor execution.
protected  java.lang.String msgPrefix
          The string that prefixes all normal messages from this sensor.
protected  long runtime
          Provides a fixed runtime value for use in sensors that need one.
protected  org.hackystat.sensorshell.SensorShellProperties sensorProps
          Sensor properties to be used with the sensor.
protected  org.hackystat.sensorshell.SensorShell sensorShell
          The sensor shell instance used by this sensor.
protected  java.util.List<SourceFiles> sourceFilesList
          The list of sourcefile element instances found in this task.
protected  java.lang.String tool
          The name of this tool, passed to SensorShell and also looked for in UserMap.
protected  java.lang.String toolAccount
          Tool account in the UserMap to use, or null if not using UserMap.
protected  org.hackystat.utilities.tstamp.TstampSet tstampSet
          Supports generation of unique timestamps.
protected  boolean verbose
          Whether or not to print out additional messages during sensor execution.
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
protected HackystatSensorTask(java.lang.String tool)
          The standard constructor, which will instantiate a SensorShell using the configuration data in sensorshell.properties.
protected HackystatSensorTask(java.lang.String host, java.lang.String email, java.lang.String password, java.lang.String tool)
          A special constructor to be used only for testing purposes, which will use the supplied SensorBase host, email, and password.
 
Method Summary
 DataFiles createDataFiles()
          Creates a returns a new DataFiles instance to Ant.
 SourceFiles createSourceFiles()
          Creates a returns a new SourceFiles instance to Ant.
 void execute()
          The execute() method invoked by Ant.
abstract  void executeInternal()
          This must be implemented by all subclasses to provide the traditional Ant execute() method.
protected  java.util.List<java.io.File> getDataFiles()
          Returns the list of files indicated in the datafiles element.
protected  java.util.List<java.io.File> getFiles(java.util.List<org.apache.tools.ant.types.FileSet> filesets)
          Converts a list of FileSets into a list of their associated files.
protected  java.util.List<java.io.File> getSourceFiles()
          Returns the list of files indicated in the sourcefiles element.
protected  void info(java.lang.String msg)
          Output an informational message from sensor.
protected  boolean isUsingUserMap()
          Returns true if the user has indicated they want to use the UserMap to obtain the SensorBase host, user, and password.
protected  void sendAndQuit()
          Sends any accumulated data in the SensorShell to the server and quits the shell.
 void setFailOnError(java.lang.String mode)
          Set the failOnError attribute to "on", "true", or "yes" to throw a BuildException if problems occur during execution.
 void setRetryAttempts(java.lang.String retryString)
          Set the retryAttempts value to an integer, or set to default if the supplied value was not an integer.
 void setRetryWaitInterval(java.lang.String retryString)
          Set the retryWaitIntervalSeconds value to an integer, or set to default if the supplied value was not an integer.
protected  void setupSensorShell()
          Instantiates the internal sensorshell using either the data in the UserMap or the data in sensorshell.properties.
 void setUserMapTool(java.lang.String tool)
          Allows the user to override the default tool string to be used to retrieve data from the UserMap.
 void setUserMapToolAccount(java.lang.String toolAccount)
          If the user specifies a toolAccount, then the UserMap is consulted to specify the sensorshell host, user, and password data rather than sensorshell.properties.
 void setVerbose(java.lang.String mode)
          Set the verbose attribute to "on", "true", or "yes" to enable trace messages while the sensor is running.
protected  void signalError(java.lang.String msg, java.lang.Exception e)
          Signals an error, which means throwing a BuildException if failOnError is true, or just logging the problem if it's not.
protected  void summaryInfo(java.util.Date startTime, java.lang.String sdt, int numEntries)
          Logs a final summary message regarding the number of entries sent and the elapsed time.
protected  void verboseInfo(java.lang.String msg)
          Output a verbose message if verbose is enabled.
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataFilesList

protected java.util.List<DataFiles> dataFilesList
The list of datafile element instances found in the task.


sourceFilesList

protected java.util.List<SourceFiles> sourceFilesList
The list of sourcefile element instances found in this task.


verbose

protected boolean verbose
Whether or not to print out additional messages during sensor execution.


failOnError

protected boolean failOnError
Whether or not to throw a BuildException if problems occur during sensor execution.


runtime

protected long runtime
Provides a fixed runtime value for use in sensors that need one.


sensorShell

protected org.hackystat.sensorshell.SensorShell sensorShell
The sensor shell instance used by this sensor.


sensorProps

protected org.hackystat.sensorshell.SensorShellProperties sensorProps
Sensor properties to be used with the sensor.


tstampSet

protected org.hackystat.utilities.tstamp.TstampSet tstampSet
Supports generation of unique timestamps.


tool

protected java.lang.String tool
The name of this tool, passed to SensorShell and also looked for in UserMap.


toolAccount

protected java.lang.String toolAccount
Tool account in the UserMap to use, or null if not using UserMap.


errMsgPrefix

protected java.lang.String errMsgPrefix
The string that prefixes all error messages from this sensor.


msgPrefix

protected java.lang.String msgPrefix
The string that prefixes all normal messages from this sensor.

Constructor Detail

HackystatSensorTask

protected HackystatSensorTask(java.lang.String tool)
The standard constructor, which will instantiate a SensorShell using the configuration data in sensorshell.properties.

Parameters:
tool - The tool associated with this sensor.

HackystatSensorTask

protected HackystatSensorTask(java.lang.String host,
                              java.lang.String email,
                              java.lang.String password,
                              java.lang.String tool)
A special constructor to be used only for testing purposes, which will use the supplied SensorBase host, email, and password. Automatically sets verbose mode to true.

Parameters:
host - The host.
email - The email.
password - The password.
tool - The tool associated with this sensor.
Method Detail

setupSensorShell

protected void setupSensorShell()
Instantiates the internal sensorshell using either the data in the UserMap or the data in sensorshell.properties. Does not instantiate the sensorshell if it already has been done in the testing constructor. DO NOT call this method in your constructor. Instead, call it at the beginning of your execute() method. The reason is that the toolAccount property which controls where the SensorShell data is obtained is not set until Ant finishes constructor setup.


setVerbose

public void setVerbose(java.lang.String mode)
Set the verbose attribute to "on", "true", or "yes" to enable trace messages while the sensor is running. Default is false.

Parameters:
mode - The new verbose value: should be "on", "true", or "yes" to enable.

setRetryWaitInterval

public void setRetryWaitInterval(java.lang.String retryString)
Set the retryWaitIntervalSeconds value to an integer, or set to default if the supplied value was not an integer.

Parameters:
retryString - The new retryWaitIntervalSeconds value, an integer, as a string.

setRetryAttempts

public void setRetryAttempts(java.lang.String retryString)
Set the retryAttempts value to an integer, or set to default if the supplied value was not an integer.

Parameters:
retryString - The new retryAttempts value, an integer, as a string.

execute

public void execute()
             throws org.apache.tools.ant.BuildException
The execute() method invoked by Ant. This method invokes the subclass executeInternal() method, and if that method throws an exception, it will retry according to the values of retryAttempts and retryWaitInterval.

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - If there is an error after all the retries are done.

executeInternal

public abstract void executeInternal()
This must be implemented by all subclasses to provide the traditional Ant execute() method. The executeInternal may be invoked multiple times, depending upon the retryAttempts value.


setFailOnError

public void setFailOnError(java.lang.String mode)
Set the failOnError attribute to "on", "true", or "yes" to throw a BuildException if problems occur during execution. Default is true.

Parameters:
mode - The new verbose value: should be "on", "true", or "yes" to enable.

setUserMapTool

public void setUserMapTool(java.lang.String tool)
Allows the user to override the default tool string to be used to retrieve data from the UserMap. Note that UserMap processing is only enabled when the toolAccount value is provided.

Parameters:
tool - The tool containing the tool account to be used when sending data.

setUserMapToolAccount

public void setUserMapToolAccount(java.lang.String toolAccount)
If the user specifies a toolAccount, then the UserMap is consulted to specify the sensorshell host, user, and password data rather than sensorshell.properties. Note that the user does not need to specify the tool explicitly, it will be provided with a default value by the sensor, although specifying it explicitly might be good for documentation purposes.

Parameters:
toolAccount - The tool account in the UserMap to use when sending data.

createSourceFiles

public SourceFiles createSourceFiles()
Creates a returns a new SourceFiles instance to Ant. Ant will then populate this guy with its internal file set.

Returns:
The SourceFiles instance.

createDataFiles

public DataFiles createDataFiles()
Creates a returns a new DataFiles instance to Ant. Ant will then populate this guy with its internal file set.

Returns:
The DataFiles instance.

getSourceFiles

protected java.util.List<java.io.File> getSourceFiles()
Returns the list of files indicated in the sourcefiles element.

Returns:
The list of files in the sourcefiles element.

getDataFiles

protected java.util.List<java.io.File> getDataFiles()
Returns the list of files indicated in the datafiles element.

Returns:
The list of files in the datafiles element.

getFiles

protected java.util.List<java.io.File> getFiles(java.util.List<org.apache.tools.ant.types.FileSet> filesets)
Converts a list of FileSets into a list of their associated files.

Parameters:
filesets - The filesets of interest.
Returns:
The files of interest.

isUsingUserMap

protected boolean isUsingUserMap()
Returns true if the user has indicated they want to use the UserMap to obtain the SensorBase host, user, and password. If false, then the sensorshell.properties file should be consulted.

Returns:
Returns true if UserMap processing is enabled, false otherwise.

verboseInfo

protected final void verboseInfo(java.lang.String msg)
Output a verbose message if verbose is enabled.

Parameters:
msg - The message to print if verbose mode is enabled.

info

protected final void info(java.lang.String msg)
Output an informational message from sensor.

Parameters:
msg - The message.

summaryInfo

protected void summaryInfo(java.util.Date startTime,
                           java.lang.String sdt,
                           int numEntries)
Logs a final summary message regarding the number of entries sent and the elapsed time.

Parameters:
startTime - The start time of the sensor.
sdt - The type of data sent.
numEntries - The number of entries sent.

sendAndQuit

protected void sendAndQuit()
Sends any accumulated data in the SensorShell to the server and quits the shell.


signalError

protected void signalError(java.lang.String msg,
                           java.lang.Exception e)
Signals an error, which means throwing a BuildException if failOnError is true, or just logging the problem if it's not.

Parameters:
msg - The informative error message from the client.
e - The exception.