[Skip to content]

2.4. Environment

Lets you specify, view and adjust environment variables. Environment variables are simple key/value pairs and can be used in header, footer and Javadoc templates to form expressions that will be resolved during formatting. Embedded strings of the form $variable$ are replaced with their corresponding value. This process is called variable interpolation.

Valid keys take the form [a-zA-Z_][a-zA-Z0-9_.-]* and are case-sensitive. Values can be freely chosen.

Example 2.3. 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.4. 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.4.1. Custom environment variables

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

Figure 2.22. 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.23. Add Custom Environment Variable

Add Custom Environment Variable

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

Figure 2.24. 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 specified variables will override any other custom or system variables. The overrides file uses the common java.util.Properties format.

Table 2.3. Typical .overrides locations for user “John Doo”

Operating SystemJalopy .overrides Location
Linux/home/John Doo/.jalopy/.user.properties
Mac OS X/Users/John Doo/.jalopy/.user.properties
Solaris/export/home/John Doo/.jalopy/.user.properties
Windows VistaC:\Users\John Doo\AppData\Roaming\.jalopy\.user.properties
Windows XPC:\Documents and Settings\John Doo\.jalopy\.user.properties

Please consult your operating system documentation if your system uses different paths for the user directories. Detailed information about the Jalopy settings directory can be found in Chapter 2, Configuration.

Since 1.6

Example 2.5. Local Overrides File

author=John Doo
division=IT_DEV_AR

The above example would define/override the variables “author” and “division”. Please note that the environment may be overwritten manually using the Console and Ant plug-ins as well. Please refer to the corresponding plug-in documentation.

2.4.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.25. System environment variables

System environment variables

2.4.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.4. 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 representation of the line ending character(s) 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.4.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.4.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/setter1.1
Property.Name Holds the capitalized property name of the currently processed getter/setter method Javadoc getter/setter1.9.3

2.4.4. Usage

Once defined, variables can be enclosed with dollar signs to form variable expressions and embedded in comment templates. Variable expressions take the form $[a-zA-Z_][a-zA-Z0-9_.-]*$.

Example 2.6. Sample variable expressions

$author$
$project$

During emitting, these expressions will be interpolated and the value of the variable inserted into the source file.

Example 2.7. 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.8. 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.26. Insert variables via context menu

Insert variables via context menu

Please see Section 2.4.1, “Custom variables”, Section 2.4.2, “System variables” and Section 2.4.3, “Local variables” for descriptions of the different available variable types.

2.4.5. Date & Time settings

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

Figure 2.27. 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. The default pattern is M/d/yy, which translates to something like 07/23/09.

Since 1.2

Time pattern

Lets you define the pattern that is used for the $time$ variable expression. The default pattern is h:mm a, which translates to something like 02:56 PM.

Since 1.2