org.apache.tools.ant.taskdefs.optional.javastyle
Class JavaStyle

java.lang.Object
  extended by MatchingTask
      extended by org.apache.tools.ant.taskdefs.optional.javastyle.JavaStyle

public class JavaStyle
extends MatchingTask

Task for formatting Java source code. This task utilises the PrettyPrinter code in the JRefactory code produced by Chris Sequin . This library can be found at http://users.snip.net/~aseguin/chrissoft.html .

The current implementation is very simple. I am implemented it as quickly as possible to make it available for others to be able to improve upon!

The task takes only a "file" attribute or an embedded fileset. It contains no other attributes at present, as all formatting controls are read from the default pretty printer preferences file which is stored in a ".Refactory" directory in your home directory. If no such file exists the first time this task is run, a default file is generated automatically.

Features that would be well worth implementing include: adding attributes to control all of the formatting features of the PrettyPrinter, and removing any reliance on an external preference file; allowing the formatted source files to be saved into a different location than the originals.

Author:
Stuart Roebuck stuart.roebuck@adolos.com

Field Summary
protected  java.io.File file
          The individual file specified for styling.
protected  java.util.Vector filesets
          A collection of filesets to be styled.
 
Constructor Summary
JavaStyle()
          Constructor for the JavaStyle object
 
Method Summary
 void addFileset(FileSet set)
          Adds a set of files (nested fileset attribute).
 void execute()
          Styles the file(s).
 void init()
          Initialise all the preference files for JRefactory.
 void setFile(java.io.File file)
          Set the name of a single file to be styled.
 void setQuiet(boolean quiet)
          If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error.
 void setVerbose(boolean verbose)
          Used to force listing of all names of styled files.
protected  void styleFile(java.io.File file)
          Style a single file
protected  void styleFiles(java.io.File dir, java.lang.String[] files)
          Style a list of files in a given directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

protected java.io.File file
The individual file specified for styling.


filesets

protected java.util.Vector filesets
A collection of filesets to be styled.

Constructor Detail

JavaStyle

public JavaStyle()
Constructor for the JavaStyle object

Method Detail

setFile

public void setFile(java.io.File file)
Set the name of a single file to be styled.

Parameters:
file - the file to be styled

setVerbose

public void setVerbose(boolean verbose)
Used to force listing of all names of styled files.

Parameters:
verbose - "true" or "on"

setQuiet

public void setQuiet(boolean quiet)
If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error.

Parameters:
quiet - "true" or "on"

addFileset

public void addFileset(FileSet set)
Adds a set of files (nested fileset attribute).

Parameters:
set - the fileset to add.

execute

public void execute()
             throws BuildException
Styles the file(s).

Throws:
BuildException - can be thrown if no files are specified in the task.

init

public void init()
          throws BuildException
Initialise all the preference files for JRefactory. If there are no existing preference files then create some default ones.

Throws:
BuildException - if someting goes wrong with the build

styleFile

protected void styleFile(java.io.File file)
Style a single file

Parameters:
file - The file to be styled.

styleFiles

protected void styleFiles(java.io.File dir,
                          java.lang.String[] files)
Style a list of files in a given directory.

Parameters:
dir - the directory containing the files.
files - an array of filenames within the directory.