2.3. Environment

Lets you specify/view/adjust environment variables.

Environment variables can be used in header, footer and Javadoc templates to form expressions that will be resolved during printing. Embedded strings of the form $variable$ are replaced with their corresponding value. This process is called variable interpolation.

Environment variables are simple key/value pairs. Valid keys take the form [a-zA-Z_][a-zA-Z0-9_.\\-]* and are case-sensitive. Values can be freely chosen.

Example 2.1. Header template with environment variables expressions

//==============================================================
// file :       $file.name$
// project:     $project$
//
// create:      date:       $date$
//              by:         $author$
//
//--------------------------------------------------------------
// copyright:   BSJT Software License (see class documentation)
//==============================================================

Example 2.2. Sample environment variables

author = John Doo
project.description = Nukes: The OpenSource CMS

Jalopy lets you define custom variables, but also provides access to the Java environment variables as well as some Jalopy-specific variables that are generally useful for common source formatting needs.

2.3.1. Custom environment variables

Lets you view and/or modify the custom environment variables.

Figure 2.19. Custom Environment settings page

Custom Environment settings page

Use the Add... and Remove buttons to add or remove items to and from the list.

Figure 2.20. Add Custom Environment Variable

Add Custom Environment Variable

Select a variable and press the Change... button if you want to adjust an existing environment variable.

Figure 2.21. Change Custom Environment Variable

Change Custom Environment Variable
Local Overrides

Custom user variables are stored as part of your code convention and are therefore shared across a whole team. If you need to define user-specific information, e.g. to automatically add the name of the developer who creates a class, this is possible via the local overrides file ".user.properties".

When found in the Jalopy settings directory, the variables defined here will override any other custom or system variables. The overrides file uses the common java.util.Properties format.

On a typical Windows XP installation, the local overrides file for user John Doo would be

C:\Documents and Settings\John Doo\.jalopy\.user.properties

On Linux it might be

/home/John Doo/.jalopy/.user.properties

Further information about the Jalopy settings directory can be found in Chapter 2, Configuration.

To define/override the variables "author" and "division", the local overrides file might look like this:

Example 2.3. Local Overrides File

author=John Doo
division=IT_DEV_AR

Since 1.6

Please note that the environment may be overwritten manually using the Console and Ant Plug-ins as well. Please refer to the Plug-in documentation.

2.3.2. System environment variables

Lets you view your Java system environment variables.

All system environment variables are automatically available as well, but cannot be changed from within Jalopy.

Figure 2.22. System environment variables

System environment variables

2.3.3. Local environment variables

Additionally, Jalopy provides some local variables that are automatically set depending on the execution context.

The current list of valid local variables reads as follows:

Table 2.2. Local environment variables

NameDescriptionScopeSince
fileThe absolute path of the currently processed source file (e.g. /usr/projects/test/MyFile.java)global1.0
file.nameThe name of the currently processed source file (e.g. MyFile.java)global1.0
file.formatA string represent ion of the file format that will be used to write a file (UNIX, DOS or MAC)global1.0
conventionThe name of the currently active code convention (as specified in the settings)global1.0
convention.descThe description of the currently active code convention (as specified in the settings)global1.0
projectThe name of the currently active project/profile. For IDE Plug-ins this resolves to the current IDE project, otherwise the active Jalopy profile name is usedglobal1.0.1
project.descThe description of the currently active Jalopy profileglobal1.0.1
tab.sizeThe current indentation setting (as specified in the settings)global1.0
dateThe current date, formatted in the style specified in the Date/Time settings (see Section 2.3.5, "Date/Time" below) global1.0
date.yearThe current yearglobal1.0
date.longThe current date, formatted as java.text.DateFormat LONG styleglobal1.0
date.fullThe current date, formatted as java.text.DateFormat FULL styleglobal1.0
timeThe current time, formatted in the style specified in the Date/Time settings (see Section 2.3.5, "Date/Time" below)global1.0
time.longThe current time, formatted as java.text.DateFormat LONG styleglobal1.0
time.fullThe current time, formatted as java.text.DateFormat FULL styleglobal1.0
package.nameThe package name of the currently processed source file (e.g. com.foo.mypackage)global1.0
class.nameHolds the name of the currently processed class, interface or enumJavadoc class, interface, field, constructor, method, getter, setter 1.0
field.nameHolds the name of the currently processed fieldJavadoc field1.0
field.typeHolds the type name of the currently processed fieldJavadoc field1.0
method.nameHolds the name of the currently processed methodJavadoc method1.0
param.nameHolds the name of the currently processed Javadoc parameter tagJavadoc constructor, method1.0
param.typeHolds the type of the currently processed Javadoc parameter tagJavadoc constructor, method1.0
exception.typeHolds the type of the currently processed throws clause memberJavadoc constructor, method1.0
return.typeHolds the return type of the currently processed methodJavadoc method1.0
property.nameHolds the property name of the currently processed getter/setter method. You can control the behavior during variable interpolation with the "Format bean property" option Javadoc getter/getter method1.1

2.3.4. Usage

Once defined, variables can then be enclosed with dollar signs to form variable expressions. Variable expressions thus take the form $[a-zA-Z_][a-zA-Z0-9_.\\-]*$.

Example 2.4. Sample variable expressions

$author$
$projectr$

During printing these expressions will be interpolated and the value of the variable inserted into the output file.

Example 2.5. Header template with environment variable expressions

//===============================================================
// file :       $file.name$
// project:     $project$
//
// last change: date:       $Date$
//              by:         $author$
//              revision:   $Revision$
//---------------------------------------------------------------
// copyright:   BSJT Software License (see class documentation)
//===============================================================

Example 2.6. Header after interpolation

//===============================================================
// file :       Byte.java
// project:     bsjt-rt
//
// last change: date:       $Date$
//              by:         John Doo
//              revision:   $Revision$
//---------------------------------------------------------------
// copyright:   BSJT Software License (see class documentation)
//===============================================================

As you can see in the above example, if a variable is not defined, Jalopy won't touch the expression and simply preserves the original content. This way, the formatter works nicely with other source code tools and SCM products.

The available user and local environment variables are provided from within the context menu of the text component when customizing the different templates.

Figure 2.23. Insert variables via context menu

Insert variables via context menu

Please see Section 2.3.1, "Custom variables", Section 2.3.2, "System variables" and Section 2.3.3, "Local variables" for a description of the different available variable types.

2.3.5. Date & Time settings

Lets you define the patterns that should be used for the $date$ and $time$ expressions (see Section 2.3.3, "Local variables").

Figure 2.24. Environment Date & Time settings page

Environment Date & Time settings page

For a detailed description, the list of available patterns and further examples, please refer to the Javadoc for the java.text.SimpleDateFormat class.

Date pattern

Lets you define the pattern that is used for the $date$ variable expression (see Local variables).

The default pattern is M/d/yy which translates to something like 12/24/98.

Since 1.2

Time pattern

Lets you define the pattern that is used for the $time$ variable expression (see Local variables).

The default pattern is h:mm a which translates to something like 02:56 PM.

Since 1.2