-- Expanding Properties within Checkstyle configuration files --
Checkstyle contains a feature that lets you define module properties in a way that they can expanded
dynamically when the configuration is loaded. Such a property is defined using the
well known ${property_name} notation.
Normally these properties are resolved from command line or ant properties. Of
course this does not work within the plug-in so using a checkstyle configuration
containing such expandable properties will probably fail.
But as you might have thought there are some features in place to help you out in this
case.
When a Check Configuration is set up the plugin will check the Checkstyle configuration
file for unresolved properties. When found the plugin will warn you that this
configuration cannot be used until those properties can be resolved. To resolve
such properties you have a variety of options.
Built-in properties
First there are some properties that are automatically expanded by the plug-in:
-
${basedir} - gets mapped to the current project
directory
-
${project_loc} - same as ${basedir}
-
${workspace_loc} - gets mapped to the current
Eclipse workspace directory
-
${config_loc} & ${samedir} - get mapped to the directory the configuration file lies
in
Resolving from .properties file
If you have more properties that need to be expanded there is another feature for you.
Using External, Remote or Project Relative Configuration you can write the properties you
need to be expanded into a .properties file that lies in
the same directory as the configuration file and has the same name. For instance:
D:/path/to/my/config/myCheckConfiguration.xml
can resolve properties defined in
D:/path/to/my/config/myCheckConfiguration.properties
Expandable properties within your configuration file will then be resolved from the
corresponding .properties file.
Resolving from Classpath Variables and Environment properties
New in 4.1.0 is that you can resolve properties from Classpath Variables (set up in
workspace preferences) and from Environment Properties. Note that these need to be
passed into the VM Eclipse runs on using the famous -D parameter.
Additional properties configured with the Check Configuration
If all this stuff doesn't suit your needs there is another option for
you. Reintroduced in 4.1.0 is support for storing properties with the Check
Configuration setup. You might have already noted the new Additional
properties... button located in the lower left of a Check Configuration setup
dialog. Pressing this button will lead you to another dialog where you can input
properties and their values To aid in this task the plugin offers to find unresolved
properties for you. Properties set up here will be stored with the Check
Configuration data, for Global Configurations within the plugins workspace state
location, for Local Configurations within the .checkstyle file.
Note that the plug-in supports 'property chaining' to let you use
'properties within properties'. With this feature you can write
something like this in your .properties file:
property1=abc property2=${property1}def
Using ${property2} in your checkstyle configuration
will then be resolved to: abcdef
|