|
Jalopy 1.0b10 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--de.hunsicker.jalopy.Jalopy
The bean-like interface to Jalopy.
Sample Usage
// create a new Jalopy instance with the currently active code convention settings Jalopy jalopy = new Jalopy(); File file = ...; // specify input and output target jalopy.setInput(file); jalopy.setOutput(file); // format and overwrite the given input file jalopy.format(); if (jalopy.getState() == Jalopy.State.OK) System.out.println(file + " successfully formatted"); else if (jalopy.getState() == Jalopy.State.WARN) System.out.println(file + " formatted with warnings"); else if (jalopy.getState() == Jalopy.State.ERROR) System.out.println(file + " could not be formatted"); // setup a destination directory File destination = ...; jalopy.setDestination(destination); jalopy.setInput(file); jalopy.setOutput(file); // format the given input file and write the output to the given destination, // the package structure will be retained automatically jalopy.format(); ...
Thread safety
This class is thread-hostile, it is not safe for concurrent use by multiple threads even if all method invocations are surrounded by external synchronisation. You should rather create one instance of this class per thread.
Inner Class Summary | |
static class |
Jalopy.State
Represents a Jalopy run state. |
Constructor Summary | |
Jalopy()
Creates a new Jalopy object. |
Method Summary | |
static void |
checkCompatibility(String packageName)
Checks whether the specification version of the given Plug-in is compatible with the Jalopy Plug-in API spec version. |
void |
cleanupBackupDirectory()
Cleans up the backup directory. |
boolean |
format()
Formats the (via setInput(File) ) specified input source and writes the
formatted result to the specified target. |
File |
getBackupDirectory()
Returns the directory where file backups will be stored. |
String |
getProfileTimes()
Returns a string with the elapsed times for the different profiling categories. |
JavaRecognizer |
getRecognizer()
Returns the used Java recognizer. |
Jalopy.State |
getState()
Returns the current state info. |
static Version |
getVersion()
Returns the version information. |
void |
inspect()
Inspects the (via setInput(File) ) specified input source for code
convention violations and coding weaknesses. |
void |
inspect(JavaNode tree)
Inspects the given Java AST for code convention violations and coding weaknesses. |
boolean |
isInspect()
Determines wether the code inspector is enabled during formatting runs. |
JavaNode |
parse()
Parses the (via setInput(File) ) specified input source. |
void |
reset()
Resets this instance. |
void |
setBackup(boolean backup)
Sets whether to hold a backup copy of an input file. |
void |
setBackupDirectory(File directory)
Sets the directory where backup files will be stored. |
void |
setBackupDirectory(String directory)
Sets the directory where backup files will be stored. |
void |
setBackupLevel(int level)
Sets the number of backups to hold. |
static void |
setConvention(File file)
Sets the code convention to be loaded from the given file (either a qualified file path or single file name). |
static void |
setConvention(String location)
Sets the code convention to be loaded from the given location string. |
static void |
setConvention(URL url)
Sets the code convention to be loaded from the given url. |
void |
setDestination(File destination)
Sets the destination directory to create all formatting output into. |
void |
setEncoding(String encoding)
Sets the encoding that controls how Jalopy interprets text files containing characters beyond the ASCII character set. |
void |
setFileFormat(FileFormat format)
Sets the file format of the output stream. |
void |
setFileFormat(String format)
Sets the file format of the output stream. |
void |
setForce(boolean force)
Specifies whether all files should be formatted no matter what the state of a file is. |
void |
setHistoryMethod(History.Method method)
Sets the history method to use. |
void |
setHistoryPolicy(History.Policy policy)
Sets the history policy to use. |
void |
setInput(File input)
Sets the input source to use. |
void |
setInput(InputStream input,
String path)
Sets the input source to use. |
void |
setInput(Reader input,
String path)
Sets the input source to use. |
void |
setInput(String input,
String path)
Sets the input source to use. |
void |
setInspect(boolean enabled)
Enables or disables the code inspector during formatting runs. |
void |
setOutput(File output)
Sets the output target to use. |
void |
setOutput(StringBuffer output)
Sets the output target to use. |
void |
setOutput(Writer output)
Sets the output target to use. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Jalopy()
Method Detail |
public static void setConvention(File file) throws IOException
file
- the code convention file.IOException
- if no code convention could be loaded from the given file.public static void setConvention(URL url) throws IOException
url
- url.IOException
- if no code convention could be loaded from the given url.public static void setConvention(String location) throws IOException
location
- location. Either a local file pathname or a pointer to a
distributed resource accessible via the HTTP protocol (that is starting
with "http://
" or "www.
").IOException
- if no code convention could be loaded from the given location.public void setEncoding(String encoding)
encoding
- a valid encoding name. For a list of valid encoding names refer to
Supported
Encodings. Note that null
is permitted and indicates the
platform's default encoding.IllegalArgumentException
- if an invalid encoding was specified.public void setFileFormat(FileFormat format)
format
- file format to use.public void setFileFormat(String format)
format
- string representation of the file format to use.FileFormat.valueOf(java.lang.String)
public void setForce(boolean force)
Defaults to false
, which means that a source file will be only
formatted if it hasn't ever been formatted before or if it has been modified
since the last time it was processed.
force
- if true
all files are always formatted.public void setHistoryMethod(History.Method method)
method
- a history method.public void setHistoryPolicy(History.Policy policy)
policy
- a history policy.public void setInspect(boolean enabled)
inspect()
methods.enabled
- if true
the code inspector will be enabled.inspect()
,
inspect(JavaNode)
public boolean isInspect()
true
if the code inspector is enabled.public static Version getVersion()
public void setOutput(Writer output)
output
- writer to use as output target.public String getProfileTimes()
public JavaRecognizer getRecognizer()
public Jalopy.State getState()
public static void checkCompatibility(String packageName) throws VersionMismatchException
packageName
- the package name of a Plug-in as specified in the Jar Manifest,
e.g. "de.hunsicker.jalopy.plugin.ant".VersionMismatchException
- if the Plug-in with the given package name is not
compatible with the Plug-in API version of the Jalopy runtime.public void setBackup(boolean backup)
true
.
This switch only takes action if you specify the same file for both input and output.
Note that you can specify how many backups should be retained, in case you want a
history. See setBackupLevel(int)
for further information.
backup
- if true
the backup of an input file will not be deleted
after the run.setBackupLevel(int)
,
setInput(File)
,
setOutput(File)
public void setBackupDirectory(File directory)
directory
- path to an existing directory.IllegalArgumentException
- if the given file does not denote a valid
directory.setBackup(boolean)
public void setBackupDirectory(String directory)
setBackupDirectory(File)
with newFile(directory)
.directory
- path to an existing directory.setBackup(boolean)
,
setBackupDirectory(java.io.File)
public File getBackupDirectory()
setBackup(boolean)
public void setBackupLevel(int level)
0
means to hold no
backup at all (same as setBackup(false)
). The default is
1
.level
- number of backups to hold.IllegalArgumentException
- if level < 0
setBackup(boolean)
public void setDestination(File destination)
reset()
was
called (which results in deleting the destination, files are overwritten now on).
If the given destination does not exist, it will be created.
Only applies if a file output target was specified.
destination
- destination directory.IllegalArgumentException
- if destination is null
or
does not denote a directory.RuntimeException
- if the destination directory could not be created.setOutput(File)
public void setInput(String input, String path)
input
- string to use as input source.path
- path of the file that is to be processed.NullPointerException
- if input == null
or
path == null
public void setInput(InputStream input, String path)
input
- stream to use as input source.path
- path of file that is to be processed.IllegalArgumentException
- if path == null
or if
path does not denote a valid, i.e. existing file or the system
input stream.public void setInput(Reader input, String path)
input
- reader to use as input source.path
- path of file that is to be processed.IllegalArgumentException
- if path == null
or if
path does not denote a valid, i.e. existing file.public void setInput(File input) throws FileNotFoundException
input
- file to use as input source.FileNotFoundException
- if the specified source file does not exist.setInput(Reader, String)
,
setInput(String, String)
public void setOutput(File output)
output
- file to use as output target.public void setOutput(StringBuffer output)
output
- buffer to use as output target.public void cleanupBackupDirectory()
setBackup(boolean)
public boolean format()
setInput(File)
) specified input source and writes the
formatted result to the specified target.
Formatting a file means that parsing
, inspecting
and printing will be performed in sequence depending on the current state. Thus
the parsing and/or inspection phase may be skipped.
It is safe to call this method multiple times after you've first constructed an instance: just set new input/output targets and go with it. But remember that this class is thread-hostile: accessing the class concurrently from multiple threads will lead to unsuspected results.
true
if any formatting was applied.IllegalStateException
- if no input source has been specified.setInput(File)
,
setOutput(File)
,
parse()
,
inspect()
public void inspect()
setInput(File)
) specified input source for code
convention violations and coding weaknesses. If no parsing was performed yet, the
input source will be first parsed.setInput(File)
,
parse()
public void inspect(JavaNode tree)
tree
- root node of the Java AST that is to be inspected.NullPointerException
- if tree == null
IllegalArgumentException
- if tree is not the root node of a Java
AST.parse()
public JavaNode parse()
setInput(File)
) specified input source. You should always
check the state after parsing, to be sure the input source could be successfully
parsed.null
if the input source could not be successfully parsed
(i.e. always use getState()
to check for success).IllegalStateException
- if no input source has been specified.setInput(File)
,
getState()
public void reset()
Note that this method is not meant to be invoked after every call of format()
, but rather serves as a way to reset this instance to exactly the state
directly after the object creation.
|
Jalopy 1.0b10 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |