Policy Developer Environment: Setting up Eclipse
Download google’s java formatter plugin:
https://github.com/google/google-java-format#eclipse
Git clone google’s java style guide:
https://github.com/google/styleguide
From a fresh install of Oxygen 2, do not launch it yet. Instead open a terminal sessions and cd to the dropins directory:
cd {oxygen-dir}/Eclipse.app/Contents/Eclipse/dropins/
Now copy the formatter plugin into the dropins subdirectory:
cp ~/Downloads/google-java-format-eclipse-plugin_1.6.0.jar .
Launch Eclipse and go into the Eclipse Preferences.
Java -> Code Style -> Formatter
you should now see a box displayed that allows you to select a formatter.
First, load the profile for ONAP by clicking the import button and browsing to the cloned directory of Google’s style guide.
The file to import is eclipse-java-google-style.xml.
Second, select the Formatter implementation “google-style-format”.
There are 2 items that ONAP is modifying (see wiki)
So Edit the active profile (which now should be GoogleStyle).
Install the Eclipse Checkstyle Plugin configuration into Eclipse.
Ensure organize imports is alphabetical
Go into XML and set to spaces and 120 width, 4 indentation
Character Configuration
Go to Preferences->General->Editors→Text Editors
Set tab width to "4"
Check "Insert spaces for tabs"
Go to Preferences->General→Workspace
Under "Text file encoding", select the "other" radio button, and choose "UTF-8" from the drop-down
Under "New text file line delimiter", select the "other" radio button and choose "Unix" from the drop-down
Removing White Space
Go to Preferences->java->Editor->Save Actions
Check "Perform selected actions on save"
Check "Additional Actions"
Click "Configure"
Check "Remove trailing whitespace"
Check "all Lines"
Click OK
Uncheck everything else in the other tabs
Click "Apply and Close"
Organize Imports Alphabetically
Go to Preferences->Java→Code Style→Organize Imports
Select all of the items and click "Remove"
Configuring Content Assist (so that Eclipse will provide suggestions for "import" statements)
Go to Preferences->Java->Editor→Content Assist→Favorites
Click "New type" and add "org.assertj.core.api.Assertions"
Click "New type" and add "org.mockito.Matchers"
Click "New type" and add "org.mockito.Mockito"
Disabling Validation (which slows local builds and generates numerous irrelevant warnings)
Go to Preferences→Validation
Uncheck "Allow projects to override these preference settings"
Deselect ALL
Setting up the ONAP Checkstyle in Eclipse
(There may well be an easier way but this works)
The first issue is that the current ONAP master tagged versino of the checkstyle does not work with Eclipse Oxygen/Photon (and maybe other versions) because of the "curly bracket" issue. There is a fix on the way but it's not here yet. The current tagged version of oparent we are using in Policy is 1.2.1.
Hack oparent to fix "curly bracket" issue
To get around this issue, check out oparent, checked out the 1.2.1 tag, fixed the "curly bracket" bug and built it on my local machine.
Check out oparent
git tag -l
git co tags/1.2.1 -b 1.2.1
edit checkstyle/src/main/resources/onap-checkstyle/onap-java-style.xml, fix module name
- <module name="LineLength">
+ <module name="LineLengthCheck">The versions in the POMs in oparent are snapshot, so we need to change those to 1.2.1
mvn versions:set -DnewVersion=1.2.1Now build locally:
mvn clean install
Set "ONAP" configuration in Eclipse
To set the newly built checkstyle files in Eclipse:
Preferences->Checkstyle
Click "New"
Select "External Configuration File"
Give it a name eg ONAP
Point at the file eg: /home/liam/git/onap/oparent/checkstyle/src/main/resources/onap-checkstyle/onap-java-style.xml
Click OK
Select "ONAP" configuration and click "Set as Default"
Select "Apply and Close"
Apply "ONAP" configuration to a project in Eclipse
Now we need to activate the checkstyle on one project and set it as the blueprint for all of them:
Select a project in eclipse and right click->Properties->Checkstyle
check "Checkstyle active for this project"
Select the "ONAP" checkstyle profile
Click "Apply and Close"
Spread blueprint to other projects in Eclipse
Now spread the profile to all other projects:
Select all the projects you want to apply the profile to in the Eclipse project explorer (not the one that you set up above)
Right click->Checkstyle->Configure projects from blueprint
Select the project you set up above
Now all the projects have the correct checkstyle setup.
Sorry this was so long, how can something so simple be so complex!
Install lombok plugin
Policy components use lombok for defining models & pojos. The maven dependency is already added to projects. But for development, it is required to install it in the IDE.
Download the lombok executable jar from https://projectlombok.org/download
And then follow the steps mentioned here https://projectlombok.org/setup/eclipse
Enabling Sonar plugin
Install SonarLint via the Eclipse Market Place (Help→Eclipse Market Place)
Right click on one of the projects and select SonarLint→Bind to SonarQube or SonarCloud
Click the SonarQube radio button and then "Next"
Enter the URL, "https://sonar.onap.org"
Click the "Username + password" radio button and click "Next"
Enter your LF user name and password and click "Next"
Click "Next" and "Finish"
On the page, "Select projects to bind", click "Add"
Select all projects and click "Next"
In the "Select SonarQube/SonarCloud project" type "policy" and then pick the relevant policy repo from the drop-down list
Click "Finish"
Note: this process will take several minutes to run. It may also generate the following warning in the console window, which can be ignored:
The following plugins do not meet the required minimum versions, please upgrade them on your SonarQube server