You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

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

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

Click "Apply and Close"

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.

  1. Check out oparent
  2. git tag -l
  3. git co tags/1.2.1 -b 1.2.1
  4.  edit checkstyle/src/main/resources/onap-checkstyle/onap-java-style.xml, fix bug
    -            <property name="maxLineLength" value="120"/>
    +            <!--property name="maxLineLength" value="120"/-->
  5. 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.1
  6. Now build locally:
    mvn clean install

Set "ONAP" configuration in Eclipse

To set the newly built checkstyle files in Eclipse:

  1. Preferences->Checkstyle
  2. Click "New"
  3. Select "External Configuration File"
  4. Give it a name eg ONAP
  5. Point at the file eg: /home/liam/git/onap/oparent/checkstyle/src/main/resources/onap-checkstyle/onap-java-style.xml
  6. Click OK
  7. Select "ONAP" configuration and click "Set as Default"
  8. 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:

  1. Select all the projects you want to apply the profile to in the Eclipse project explorer (not the one that you set up above)
  2. Right click->Checkstyle->Configure projects from blueprint
  3. Select the project you set up above
  4. Now all the projects have the correct checkstyle setup.

Sorry this was so long, how can something so simple be so complex!

  • No labels