...
Expand | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
As per https://gerrit.onap.org/r/#/c/79312/1/onap-java-formatter.xml, an ONAP Eclipse Java Formatter XML file has been merged and can be imported into Eclipse. Updates to the settings should be committed and merged back into the repository (e.g.
Maven Plugins to Reformat Java codeUsing the Eclipse Formatter file above and maven plugin configuration in pom.xml as per https://gerrit.onap.org/r/#/c/79312/1/pom.xml (https://code.revelc.net/formatter-maven-plugin/ for Eclipse formatter and https://github.com/diffplug/spotless/tree/master/plugin-maven for import order)
the combination can be used in a maven command to rewrite code and imports, then checkstyle audit like so
|
Modify settings to adapt to ONAP
- Select "Window -> Preferences".
- In the filter text box, type "tab".
- Under "Editors -> Text Editors", set "Displayed tab width:" to 4.
- Under "Editors -> Text Editors", activate "Insert spaces for tabs".
- If you want a visual aid for the print margin, under "Editors -> Text Editors", activate "Show print margin" and set "Print margin column:" to 120.
- Under "XML -> XML Files -> Editor", change to "Indent using spaces".
- Clear the filter text box and type"format".
- Under "Java -> Code Style Formatter", for "Active profile:" select GoogleStyle.
- Press the "Edit..." button.
- Expand the "Indentation" section.
- Select "Spaces only" for "Tab policy", and "4" for "Indentation size".
- Expand the "Line Wrapping" section.
- Set "Maximum line width:" to "120", and press "Apply".
- Expand the "Comments" section.
- Set "Maximum width for comments:" to "120"
- Unset "Count width from comment's starting position"
- Unset "Enable header comment formatting", and press "Apply" and then "OK"
- Clear the filter text box and type "save actions".
- Under "Java -> Editor -> Save Actions", check the "Perform the selected actions on save", and "Additional actions" check boxes.
- Press the "Configure..." button.
- On the "Code Organizing" tab in the "Formatter" box, check the "Remove trailing whitespace" check box.
- Press "OK".
- Select "Java -> Editor -> Content Assist -> Favorites".
- For each of the types below, press "New Type..." and type in the type and press "OK".
org.junit.Assert
org.junit.Assume
org.junit.jupiter.api.Assert
org.junit.jupiter.api.Assumptions
org.junit.jupiter.api.DynamicContainer
org.junit.jupiter.api.DynamicTest
org.mockito.ArgumentMatchers
org.mockito.Mock
org.mockito.Mockito - Select "Java -Code Style -> Organize Imports".
- Remove all items from the list.
- Press "Apply and Close".
To format a file open in an editor after these style preferences, press "Shift + Ctrl + F".
Install useful plugins
Install EclEmma for code coverage, and SonarLint for static code analysis.
...