JindentTask

Installation and use

In this section and for the remaining of the page, it assumed that you are familiar with the open-source Jakarta's Ant tool.
In order to use this task, it is required to have downloaded the Jindent product, especially its byte-code archive file (jindent.jar, usually), to place it in the $ANT_HOME/lib directory, where $ANT_HOME stands for the Ant distribution folder. It is also required to place the provided Jindent Ant task JindentTask.jar byte-code archive file in that same directory.
In the Ant build file script which makes use of this task, first "dynamically load" the task definition before using it.

Description

Make use of the Jindent formatting tool. Jindent aims at enabling Java source code totally open re-indentation.

This task acts on Java source code files and yields re-formated source code, according to an indentation grammar.

This task is especially usefull when processing recursively Java source files and when it is needed to yield the result in another folder, while respecting the original source hierarchy tree. This task can only be used inside open-source Jakarta's Ant tool.
One thing is missing: this task does not implement the Jindent -copy argument option.

Parameters

Note that if a parameter is not used or omitted, Jindent default behaviour is applied for the corresponding traditional argument option. Moreover, the types of the attributes are given so as to notify what expected value should be used.

Attribute Description Jindent equivalent Type Required
respect Whether or not the original folder hierarchy should be respected when yielding the result. Defaults to "false".
Does not correspond to anything in Jindent.
No equivalent boolean No
d Where to yield the formated source files. If the folder does not exist, all the necessary folders are created of possible. Corresponds to -d some/path/(...)/somewhere Jindent argument option. path No
p The Jindent formatting property file. Corresponds to -p some/sort/(...)/of/jindent.jin Jindent argument option. file No
format The format used (UNIX, DOS, auto). Authorised values are:
  • unix
  • dos
  • auto
Corresponds to -unix, -dos, -auto Jindent argument option. string No
itab The tab size of input files. It is checked that the given value (an integer) is positive or null. Corresponds to -itab tab_size Jindent argument option. integer No
buf The buffer size (in KB) for the input stream. It is checked that the given value (an integer) is positive or null. Corresponds to -buf buffer_size Jindent argument option. integer No
mutem The mutem attribute. If set to "true", it supresses output of normal messages to console, but shows errors. Corresponds to -mutem Jindent argument option. boolean No
mute The mute attribute. If set to "true", it supresses output of normal messages and errors to console. Corresponds to -mute Jindent argument option. boolean No
bak The bak attribute. If set to "true", if no destination path is set, then backups of all original java files will be stored. If set to "false", no backups of old java files will be stored. Corresponds to -bak and -nobak Jindent argument options. boolean No
w The w attribute. If set to "true", shows all Jindent warnings. Corresponds to -w Jindent argument option. boolean No
wdoc The wdoc attribute. If set to "true", only shows java doc relevant warnings. Corresponds to -wdoc Jindent argument option. boolean No
log Method that sets the Jindent yielded log file. If the directory of the log file does not exist, all intermediate directories are created. Corresponds to -log my_log_file Jindent argument option. file No
time The time attribute. If set to "true", it shows needed formatting time. Corresponds to -time Jindent argument option. boolean No
anim The anim attribute. If set, turns ascii animation on and use mode defined by its value. Authorised values are:
  • 0: -noanim is used in that case
  • 1: -anim 1 is used in that case
  • 2: -anim 2 is used in that case
Corresponds to -anim and -noanim Jindent argument options. integer No
debug The debug attribute. If set to "true", it shows some internal debug informations. Corresponds to -debug Jindent argument option. boolean No

Parameters specified as nested elements

env

Jindent's global environment variable. This nested element enables to define new Jindent global environment variables, just like the -env name="value" Jindent argument option.
The env element is composed by two attributes:

  1. name which can take any value and which stands for the name of the environment variable
  2. value which can take any value and which stands for the value of the environment variable
As many env nested elements may be used.
Example
<JindentTask>
	<env
		name="my_variable1"
		value="value1"
	/>
	<env
		name="my_variable2"
		value="value2"
	/>
	<fileset dir="source">
		<include name="my_package/*.java"/>
	</fileset>
</JindentTask>
formats all Java source files present in my_package folder, and defines Jindent environment variables my_variable1 and my_variable2.

envf

Jindent's global environment variable file. This nested element is an Ant FileSet which enables to provide all the Jindent environment variable files. It corresponds to the -envf filename Jindent argument option. Each file reachable thanks to this Ant FileSet will be considered as a Jindent global environment variable file.
As many envf nested elements may be used.

Example
<JindentTask>
	<env
		name="my_variable1"
		value="value1"
	/>
	<envf dir=".">
		<include name="*jindent.txt"/>
	</envf>
	<fileset dir="source">
		<include name="my_package/*.java"/>
	</fileset>
</JindentTask>
formats all Java source files present in my_package folder, defines Jindent environment variables my_variable1 and loads all Jindent global environment variable files in current directory and whose name ends with jindent.txt.

fileset

The Java source files. This nested element is an Ant FileSet, which enables to define all the Java source files which are bound to be formated. It corresponds to the <inputfiles> Jindent last argument. Each file reachable through this Ant FileSet will be considered as a Java source file that should be formated by Jindent.
As many fileset nested elements may be used. Note that no checking is performed to determine if the files specified are actually Java files.

Example
<JindentTask>
	<env
		name="my_variable1"
		value="value1"
	/>
	<fileset dir="source">
		<include name="package1/*.java"/>
	</fileset>
	<fileset dir="other_source">
		<include name="package2/**.java"/>
		<exclude name="package2/sub/**/*.java"/>
	</fileset>
</JindentTask>
formats all Java source files present in package1 folder, as well as all the ones (recursively) present in other_source/package2 directory, but excluding recursively all those in other_source/package2/sub directory.

Global example

A last example that should be self-explanatory:

<taskdef
	name="JindentTask"
	classname="org.ed.pack.ant.JindentTask"
/>
<JindentTask
	respect="true"
	d="new_source"
	p="jin/XPS-Style.jin"
	format="dos"
	itab="2"
	buf="2000"
	mutem="true"
	mute="false"
	bak="true"
	w="true"
	wdoc="true"
	log="log/jindent.log"
	time="true"
	anim="1"
	debug="true"
>
	<env
		name="my_variable1"
		value="value1"
	/>
	<env
		name="my_variable2"
		value="value2"
	/>
	<envf dir=".">
		<include name="jindent_env.txt"/>
	</envf>
	<fileset dir="source">
		<include name="my_package1/*.java"/>
		<exclude name="my_package2/sub/*.java"/>
	</fileset>
</JindentTask>
This example shows that the optional JindentTask should be "loaded dynamically" within the Ant build file script. Copy and paste this example into your Ant build file so as to start with something you just have to customize very basically.


Edouard Mercier