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

Automated Java code formatting and verification #2694

Conversation

groldan
Copy link
Member

@groldan groldan commented Aug 23, 2019

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.

The plugin configuration is inherited from the root pom.
Tell Travis-ci to validate the code formatting during
the install phase, and to ignore the formatter-maven-plugin
during the script phase.

This ensures the build fails if ill-formatted code was
committed at an early stage, and avoids double running
for the plugin.
This is the first commit after configuring the
formatter-maven-plugin, with formatting applied.

From this point on, all commits pushed to github
must have well formatted content, or the build
will fail on travis-ci.

There's nothing special to do though, other than
having compiled/built the project before
committing. The maven plugin will re-format the
code when building, before the compile phase.
@groldan groldan added the java Pull requests that update Java code label Aug 23, 2019
@groldan groldan added this to the 19.06 milestone Aug 23, 2019
@landryb
Copy link
Member

landryb commented Aug 26, 2019

Not a big fan of big PRs reformatting code, as it often invalidates/creates useless conflicts with all pending PRs. Oh well.. has to be done someday, i guess.

Copy link
Contributor

@RemiDesgrange RemiDesgrange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (maybe squash when merge)

@pmauduit
Copy link
Member

(maybe squash when merge)

I think it will be better to keep the reformatting with no changes in a separate commit (for history and understanding purposes).

@fvanderbiest fvanderbiest merged commit 686caf8 into georchestra:master Aug 26, 2019
@fvanderbiest fvanderbiest added this to In progress in Geo2France via automation Aug 26, 2019
@fvanderbiest
Copy link
Member

Thanks Gabriel, awesome.

@groldan groldan deleted the enhancement/GSHDF-209_formatter_maven_plugin branch August 28, 2019 12:07
@fvanderbiest fvanderbiest modified the milestones: 19.09, 19.12 Oct 22, 2019
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
Geo2France
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

5 participants