What is
maven-properties-checker is a plugin for Apache Maven that i have done to have some validation checks at properties file (java.util.Properties) to prevent problems when you deploy the artifact.
(For more info about writing a new Apache Maven plugin see my guide on slideshare website or in the dedicated post of this blog) .
Consider this possible scenario: you have a properties file with the connection parameters to access at a database and the “password” value have a blank space at the end (eg coming from a quick "copy and paste").
From
java code the value is fetched but is not executed a “trim”; result: you can't access at the database and you must re-deploy the application.
Or, what's happen in someone forgot a value in a property value?
I know that the above errors can be avoided with a precise test-case, but using a dedicated plugin we can have some benefits, like prevent to write more code and use different checks for each properties file.
The plugin contains built-in checks or allow at the user to specify a custom one based on regular expression.
Until Google code is active, you can download it from:
http://code.google.com/p/maven-properties-checker/downloads/list
After, download from:
https://github.com/fulvio999/maven-properties-checker/releases)
How use it
To use it declare his dependency in
pom.xml of your project :
<plugin>
<groupId>properties.maven.plugin</groupId>
<artifactId>maven-properties-checker</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<verificationFile>src/test/verifier/property-check-input.xml</verificationFile>
</configuration>
</plugin>
NOTE: It is not included in the default Maven repository, so that before use it is necessary install manually on your enterprise repository (eg
Artifactory) or in the local repository (/.m2/repository).
To install in your local repository copy the jar file and his .pom (contained in the zip file that you have downloaded) file to folder:
.m2/repository/properties/maven/plugin/maven-properties-checker/1.0/
The input parameter “
verificationFile” is an xml file (placed in the source tree of your project) containinig the checks to apply at each properties file that you provide.
To get information about theplugin usage execute:
mvn properties.maven.plugin:maven-properties-checker:1.0:help -Ddetail=true
The checks names to apply have a fixed name, that can be:
BLANK_VALUES: check the presence of property key without associated value, if found the build fails
EMPTY_SPACES_END: check the presence of blank space(s) at the end of a property key, if found stop the build
CUSTOM_REGEXP: apply a check based on a user defined regular expression: if the regular expression matches the build fails.
Example of input configuration file:
<propertyChecker>
<checkBlock>
<fileLocation>src/main/resources/file1.properties</fileLocation>
<checks>
<check>
<checkName>BLANK_VALUES</checkName>
</check>
<check>
<checkName>EMPTY_SPACES_END</checkName>
</check>
</checks>
</checkBlock>
<checkBlock>
<fileLocation>src/main/resources/file2.properties</fileLocation>
<checks>
<check>
<checkName>EMPTY_SPACES_END</checkName>
</check>
<check>
<checkName>CUSTOM_REGEXP</checkName>
<checkValue><![CDATA[
<("[^"]*"|'[^']*'|[^'">])*>
]]></checkValue>
</check>
</checks>
</checkBlock>
</propertyChecker>
The example input file above checks two java.util.Properties files.
At “file1.properties” are applyed two checks: BLANK_VALUES and EMPTY_SPACES_END.
While at “file2.properties” is applied only a custom check based on a custom regular expression.
Note that to use the custom check is necessary add a new node named
<checkValue>
not necessary for the others two.
In more details the above regexp verify the presence of
html tags in the “value” part of a key-value pair
(eg if we have:
myKey=testValue<div> using the above regexp the build fails).
Look my presentation on slideshare .net/
http://www.slideshare.net/slideshow/embed_code/19905023