Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport 19.04] Automated Java code formatting and verification #2695

Conversation

groldan
Copy link
Member

@groldan groldan commented Aug 23, 2019

Backport of #2694 to 19.04.

Apply formatter-maven-plugin formatting to all projects.

Add the net.revelc.code.formatter:formatter-maven-plugin and configure it to be inherited by georchestra projects (no geoserver/geonetwork submodules).

The plugin is configured to format only java source code files using the .mvn/formatter.xml eclipse format definition.
This file can be directly imported from eclipse IDE and from IntelliJ IDEA's Eclipse Code Formatter plugin.

When compiling a project that includes the formatter-maven-plugin, the default action is to format the source code to adhere to the defined code style.

The other option is to instruct the plugin to check for correct formatting and fail the build.

This behavior is controlled by the fmt.action property, like in mvn compile -Dfmt.action=format or -Dfmt.action=validate. By default a project build will run the format action, so nothing special needs to be done in order to ensure the proper format of the code other than making sure to run the build before committing/pushing to github.

On a CI build server (Jenkins/Travis-CI), the -Dfmt.action=validate should be used, to ensure a committer did his/her due diligence before pushing to the upstream git repository, which is already the case for Travis-CI.

Finally, the plugin can be disabled with the -Dfmt.skip=true maven property.

Define a common format for all georchestra modules
using an eclipse formatter definition file, which
will be passed as an argument to the
net.revelc.code.formatter:formatter-maven-plugin.

The format follows standard Java formatting conventions
with 120 characters line wrap limit and 4 spaces
for indentation.
Add the net.revelc.code.formatter:formatter-maven-plugin
maven plugin to the root pom's pluginManagement
section and configure it with to be inherited
by child projects that add it to their <plugins> section.

The plugin is configured to format only java source
code files using the .mvn/formatter.xml eclipse
formatter definition.

This formatter can be directly imported from eclipse IDE
and from IntelliJ IDEA's "Eclipse Code Formatter" plugin
(https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter).

When compiling a project that includes the formatter-maven-plugin,
the default action is to format the source code to adhere to the
defined code style.

The other option is to instruct the plugin to check for correct
formatting and fail the build.

This behavior is controlled by the fmt.action property, like in:
mvn compile -Dfmt.action=format or -Dfmt.action=validate.

On a CI build server (Jenkins/Travis-CI), the -Dfmt.action=validate
should be used, to ensure a committer did his/her due diligence
before pushing to the upstream git repository.

Finally, the plugin can be disabled with the -Dfmt.skip=true
maven property.
Add the formatter-maven-plugin to the build/plugins
section on the following projects:
analytics, atlas, commons, console, extractorapp, header,
mapfishapp, ogc-server-statistics, security-proxy, epsg_extension.

The plugin configuration is inherited from the root pom.
This is the first commit after configuring the
formatter-maven-plugin, with formatting applied,
so that further commits that need to be backported
can be easily applied.
@groldan groldan added the java Pull requests that update Java code label Aug 23, 2019
@fvanderbiest fvanderbiest merged commit d1f6bbc into georchestra:19.04 Aug 26, 2019
@groldan groldan deleted the enhancement/GSHDF-209_formatter_maven_plugin_19.04 branch August 28, 2019 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java Pull requests that update Java code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants