Describes the installation and usage of the Jalopy Maven 2 plug-in. Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.
Explains the steps involved in getting the Maven 2 plug-in up and running.
The plug-in requires Maven 2.0 or later. See Section 1.1, “System requirements” for the basic requirements to run Jalopy. Please note that a different plug-in is available for older Maven releases (see Chapter 10, Maven 1 Plug-in).
The plug-in comes as an executable Jar Archive (JAR) that contains a graphical setup wizard to let you easily install the software. Wizard installation is highly recommended and explained in detail in Section 1.3, “Wizard Installation”.
If you would rather install the plug-in manually, you have to decompress and copy the appropriate files into the different application and/or settings folders. To decompress the contents of the installer JAR, you can often use the build-in support of your file manager (e.g. Nautilus) or any other software that can handle the ZIP compression format (e.g. 7Zip, WinZip or Stuffit Expander). If you don’t have access to one of the convenience tools, you might resort to the jar command-line application that ships with your Java distribution.
When you’re upgrading from a prior version and want to keep your settings, first
copy or rename the current Jalopy settings directory to match the version number
of the new release. For instance, if your current settings directory is
C:\Users\John Doo\.jalopy\1.9
and you’re about to install Jalopy 1.9.4, either copy the directory
contents or rename it to
C:\Users\John Doo\.jalopy\1.9.4
.
First copy the Jalopy Maven plug-in folder triemax
from the
temporary directory into the Maven 2 repository directory. This might either
be the local repository (e.g.
C:\Documents And Settings\John Doo\.m2\repository\
on a Windows XP
system) or the repository directory of your internal repository in case you’re using
a shared repository for your organization.
Copy the file jalopy-1.9.4.jar
below the
triemax/jalopy/1.9.4/
folder in your Maven
repository, and jalopy-maven-1.9.4.jar
from the
temporary directory into the
triemax/jalopy-maven/1.9.4/
folder of your Maven
2 repository.
After all steps have been performed, you should have a folder structure like
the following:
.m2 repository ... triemax jalopy 1.9.4-108 jalopy-1.9.4-108.jar jalopy-1.9.4-108.pom jalopy-maven 1.9.4-108 jalopy-maven-1.9.4-108.jar jalopy-maven-1.9.4-108.pom maven-metadata-local.xml maven-metadata-central.xml ...
Although Jalopy ships with sensible default settings (mimicking the Sun Java coding convention), you most likely want to configure the formatter to match your needs (adding copyright headers, tune Javadoc handling and the like). For such, Jalopy comes with a graphical configuration tool that lets you interactively customize the settings. See Chapter 2, Configuration for an in-depth discussion of the available options.
To display the configuration tool described in Section 2.1.1, “Preferences GUI”, you can utilize the configure goal from within Maven. Either using the complete notation
% mvn triemax:jalopy-maven:configure
or just the shorthand
% mvn jalopy:configure
If you should have any of the other plug-ins described in this manual installed, you can of course use their corresponding feature, e.g. invoke the preferences dialog directly from within an IDE. When you’re done configuring the settings, you should export the code convention as described in Section 2.1.1.11, “Export code convention”. The exported settings file is typically used as part of the Jalopy plug-in configuration in the build script.
In order to integrate Jalopy into your build process, you need to edit your
pom.xml
and add the Jalopy plug-in below the
<plugins>
section:
<project> ... <plugins> <plugin> <groupId>triemax</groupId> <artifactId>jalopy-maven</artifactId> <version>1.9.4-108</version> <configuration> <compile>true</compile> ... </configuration> <executions> <execution> <phase>process-sources</phase> <goals> <goal>format</goal> </goals> </execution> </executions> </plugin> ... </plugins> ... </project>
This would execute Jalopy during the process-sources phase, which is probably the most appropriate for standard use. Please note that you typically should apply formatting before the compile phase in order to ensure that formatting does not cause discrepancies between the location information in the compiled .class files and the actual source code. Because Jalopy might still need access the binary project information, you should configure Jalopy to compile the project before formatting as shown above. See Appendix A, “Type Resolution” for the list of features that require access to the class path.
For more information about the Maven build lifecycle, please refer to the “Maven Build Lifecycle Guide” on the Maven home page. It contains a reference of the available build phases. If you don’t want to have the format goal execute during the build, you simply don’t bind the goal to a specific phase:
<project> ... <plugins> <plugin> <groupId>triemax</groupId> <artifactId>jalopy-maven</artifactId> <configuration> ... </configuration> </plugin> ... </plugins> </project>
Formatting can be manually triggered from the command-line using either
% mvn triemax:jalopy-maven:format
or the shorthand
% mvn jalopy:format
Configuration
Naturally the plug-in provides a few parameters to configure its behavior.
Table 11.1. Jalopy Maven plug-in parameters
Property | Type | Description | Since | |
---|---|---|---|---|
backup | Boolean | Sets whether backup copies of all processed source files should be kept. When omitted, the corresponding code convention setting will be used (see Section 2.2.2.2, “Backup”) | 1.7 | |
classpathElements | List | Defines the class path to use for type resolution. See Appendix A, “Type Resolution” for the list of features that require access to the class path. By default, the project class path, ${project.compileClasspathElements}, is used. There should seldom be a need to configure it differently | 1.7 | |
compile | Boolean | Sets whether the project should be compiled before formatting. This is useful if you want to utilize any of the features that require type resolution (refer to Appendix A, “Type Resolution” for the complete list), because then Jalopy needs to have access to the binary class files. Formatting after the compile phase is usually a bad idea, as formatting might change the line offsets and render stacktrace information unusable | 1.9.4 | |
convention | String |
Sets the location of the code convention file to use—given either relative to the project’s base directory or as an absolute local path or Internet address (refer to Section 2.1.1.10, “Import code convention” for information how to export your settings). When omitted and not specified otherwise (see profile below), the settings of the current profile are used. Since Jalopy 1.9.3, it’s also possible to load conventions from the class path. This can be achieved with the following syntax: <convention>classpath:[path]<convention> where [path] denotes the relative path to the resource in the artifact, e.g. jalopy.xml if the settings file can be found at the root level, or config/jalopy/sonar.xml when located in a nested folder | 1.7 | |
destDir | File | Sets the destination directory to create/copy all formatting output into. If the given directory does not exist, it will be created. When omitted, all input files will simply be overridden | 1.7 | |
encoding | String | Sets the encoding that controls how Jalopy interprets text files containing characters beyond the ASCII character set. Defaults to the platform default encoding | 1.7 | |
environment | Map | Defines temporary environment variables overrides | 1.7 | |
excludes | List | A list of exclusion filters. Uses the standard Maven pattern syntax. Please note that Jalopy ignores all files it cannot format by default, so exclusions are only necessary if you want to omit formatting for certain files, like e.g. test data files etc. | 1.7 | |
failOnError | Boolean | Sets whether a run should be held if errors occurred. Defaults to “true” | 1.7 | |
fileFormat | String | Sets the file format of the output files. The file format controls what end of line character is used. Either one of “UNIX”, “DOS”, “DEFAULT” or “AUTO” can be used (case insensitive). Defaults to “AUTO” | 1.7 | |
force | Boolean | Sets whether the formatting of files should be forced, even if a file is up-to-date. Defaults to “false” | 1.7 | |
fork | Boolean | Sets whether the processing should be performed in a separate VM. Defaults to “false” | 1.7 | |
history | String | Sets the history policy to use. Either one of “ADLER32”, “CRC32” or “NONE” can be used (case insensitive). If omitted, the corresponding code convention setting will used (see Section 2.2.2.1, “History”) | 1.7 | |
includes | List | A list of inclusion filters for formatting. Uses the standard Maven pattern syntax. Please note that Jalopy ignores all files it cannot format by default, so inclusions are only necessary if you want to omit formatting for certain files, like e.g. test data files etc. | 1.7 | |
inputEncoding | String | Sets the encoding that controls how Jalopy interprets text files containing characters beyond the ASCII character set. Defaults to the platform default encoding. Please note that this setting always overrides encoding | 1.7 | |
javadoc | String | Indicates whether Javadoc related messages should be printed. Defaults to “true” | 1.7 | |
logLevel | String | Specifies the logging level for message output. Either one of “ERROR”, “WARN”, “INFO” or “DEBUG” can be used (case insensitive). When omitted, the current code convention settings will be used (see Section 2.6.1, “Categories”) | 1.7 | |
logFile | File |
Specifies the log file to use for logging output. The format of the logging
output is determined by the extension of the given file. Valid extensions are
“.log” for a custom plain text format,
“.xml” for a plain XML format and
“.html” for a hierarchical HTML
report. When omitted, the current code convention setting will be used
(see Section 2.6.2, “Logging”)
| 1.7 | |
outputEncoding | String | Sets the character encoding Jalopy uses to write files. Defaults to the platform default encoding. Please note that this setting always overrides encoding | 1.7 | |
profile | String | Sets the Jalopy profile that should be used during the formatting run (refer to Section 2.1.1.1, “Main window” for more information about profiles). The currently active profile will be restored after formatting. Please note that if no convention is specified, the profile must exist! | 1.7 | |
repository | Boolean | Indicates whether the disk-based type repository should be used for type resolution. You may want to set this to “false“ if you commonly format a single file or only a small set of files in order to avoid the maintenance overhead of the type repository. Please be aware that the import collapsing feature requires the type repository. Defaults to “true” | 1.7 | |
skip | Boolean | Indicates whether the current project should be skipped, i.e. no formatting applied. Defaults to “false” | 1.9.4 | |
sources | List | The source directories containing the sources to be formatted. When omitted, uses the directories defined for the compiler, ${project.compileSourceRoots}, instead | 1.7 | |
test | Boolean | Sets whether formatting output should actually be written to disk. If set to “true” no output will be written to disk. The default is “false” | 1.7 | |
threads | Integer | Specifies the number of processing threads to use. Integer between
1 - 8 . Defaults to '1'
| 1.7 | |
trackFile | File | Specifies the file path to a file where Jalopy keeps track of those files that would be actually formatted during a run. The file path strings will be separated by the platform line delimiter. Implies test. When omitted, no track file will be written | 1.9.4 |
You can display the parameter descriptions from the command line as follows:
$ mvn help:describe -Dcmd=jalopy:format -Ddetail
To configure the plug-in, you specify elements named after the available parameters where the contents of an element is the value to be assigned to the parameter.
<plugin> <groupId>triemax</groupId> <artifactId>jalopy-maven</artifactId> <configuration> <threads>4</threads> <profile>test</profile> </configuration> ... </plugin>
For parameters of type List you would use multiple element tags to add the different values to the list.
<plugin> <groupId>triemax</groupId> <artifactId>jalopy-maven</artifactId> <configuration> <includes> <include>com/foo/siri/**</include> <include>com/foo/lana/**</include> </includes> <excludes> <exclude>**/*.sqlj</exclude> <exclude>**/*Test/**</exclude> </excludes> ... </configuration> </plugin>
Configuring Maps works similar: elements are named after the keys and the element contents is the value to be assigned to the key.
<plugin> <groupId>triemax</groupId> <artifactId>jalopy-maven</artifactId> <configuration> <environment> <lead>John Doo</lead> <office>Alta Nova</office> </environment> ... </configuration> </plugin>
Parameters might be temporarily overridden from the command-line using system
properties following the “jalopy.parameter” notation.
This works for all parameters besides those that use Java Collection types, e.g.
environment
or
excludes
. Such parameters
can only be configured from the POM.
$ mvn -Djalopy.threads=8 -Djalopy.compile=false ...
For a complete sample POM, please refer to Section 11.4, “Example” below.
Below you find a complete POM that makes sure that the binary project information is accessible before formatting, disables logging of Javadoc related messages, only displays messages with warning severity or higher, activates the profile “test” during formatting and imports the code convention jalopy.xml from the build-config artifact. Formatting is applied to all Java source files of the project that are not located below the “testdata” folder.
Example 11.1. Maven POM
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <packaging>jar</packaging> <version>r05-SNAPSHOT</version> <name>Guava: Google Core Libraries for Java 1.5</name> <url>http://code.google.com/p/guava-libraries</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>triemax</groupId> <artifactId>jalopy-maven</artifactId> <version>1.9.4-108</version> <configuration> <compile>true</compile> <convention>classpath:jalopy.xml</convention> <javadoc>false</javadoc> <logLevel>warn</logLevel> <environment> <lead>John Doo</lead> <office>Alta Nova</office> </environment> <excludes> <exclude>**/testdata/**</exclude> </excludes> <includes> <include>**/*.java</include> </includes> <sources> <source>/work/foo/main/src/java</source> <source>/work/foo/test/src/java</source> </sources> </configuration> <dependencies> <!-- Import the artifact that provides the code convention --> <dependency> <groupId>com.mycompany</groupId> <artifactId>build-config</artifactId> <version>1.0.2</version> </dependency> </dependencies> <executions> <execution> <phase>process-sources</phase> <goals> <goal>format</goal> </goals> </execution> </executions> </plugin> </plugins> <finalName>${project.artifactId}-${project.version}</finalName> <sourceDirectory>src</sourceDirectory> <testSourceDirectory>tests_disabled</testSourceDirectory> </build> </project>