Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

SSH Connection (Recommended)

HTTPS Connection

Working with a Proxy

IDEs

Eclipse

IntelliJ

Optional additional 

git-review

...

Log in to the Gerrit host https://gerrit.onap.org/, pull down the menu under your user name (at the extreme top right of the browser window), click on "Settings":

Click your account name on the top right corner of the website and click on Settings.

Add the public ssh key that you created in the previous step.

HTTPS Connection

Expand

If you choose to use HTTP/HTTPS, you'll need to generate an access password. Log in to the Gerrit host https://gerrit.onap.org/, pull down the menu under your user name (at the extreme top right of the browser window), click on "Settings", and select "HTTP Password"

This password may have a limited time to live, so you might get errors like this one:

Problem running 'git remote update gerrit'
Fetching gerrit
fatal: unable to access 'https://USERNAME@gerrit.onap.org/r/a/mso/ ': Unknown SSL protocol error in connection to gerrit.onap.org:443 error: Could not fetch gerrit

Regenerating a password will most likely solve the connectivity issue. Sometimes, the Gerrit interface on HTTPS might be temporarily faulty, so retries might be needed.


Working with a Proxy

Expand

For developers working with a proxy, you might have proxy issues connecting to Linux Foundation website. To avoid the connection issue, you must define the proxy setting for both IntelliJ and Git.

To configure the proxy settings in IntelliJ;

click File -> Settings -> Appearance & Behavior -> System Settings -> HTTP Proxy

 enter the correct proxy settings and click Apply.

In case of Manual proxy configuration, while entering the Host name, there is no need to write http:// in front of the URL. For example, if the proxy value is http://one.proxy.com, you would put one.proxy.com as the Host name


To configure the proxy settings for Git, play the following command:

git config --global https.proxy https://<proxy username>:<proxy password>@<proxy url> 
git config --global http.proxy http://<proxy username>:<proxy password>@<proxy url>

Note: while entering the proxy username, sometimes it may require to add the domain name in front.


IDEs

Eclipse

Install Eclipse

Download and run the installer from: Install Eclipse. Select "Eclipse IDE for Java Developers" to install.

Import Google style preferences

Follow instructions on: Installing the coding style settings in eclipse.

See also Java code style

ONAP Eclipse Java Formatter (Optional)

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.

Jira
serverONAP JIRA
serverId425b2b0a-557c-3c0c-b515-579789cceedb
keyAAI-2198
) . TBC: This should probably be in oparent for all to share.

Maven Plugins to Reformat Java code

Using 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)

Code Block
languagexml
titleExample pom.xml configuration
collapsetrue
            <plugins>
                <!--
                Using https://code.revelc.net/formatter-maven-plugin/ for Eclipse formatter
                Using https://github.com/diffplug/spotless/tree/master/plugin-maven for import order
                Use in combination to rewrite code and imports, then checkstyle
                
                mvn formatter:format spotless:apply process-sources
                -->
                <plugin>
                     <groupId>net.revelc.code.formatter</groupId>
                     <artifactId>formatter-maven-plugin</artifactId>
                     <version>2.8.1</version>
                     <configuration>
                        <configFile>${project.parent.basedir}/onap-java-formatter.xml</configFile>
                     </configuration>
                     <!-- https://code.revelc.net/formatter-maven-plugin/
                          use mvn formatter:format to rewrite source files
                          use mvn formatter:validate to validate source files -->
                 </plugin>
                <plugin>
                  <groupId>com.diffplug.spotless</groupId>
                  <artifactId>spotless-maven-plugin</artifactId>
                  <version>1.18.0</version>
                  <configuration>
                    <java>
                     <importOrder>
                       <order>com,java,javax,org</order>
                     </importOrder>
                    </java>
                  </configuration>
                <!-- https://github.com/diffplug/spotless/tree/master/plugin-maven
                     use mvn spotless:apply to rewrite source files
                     use mvn spotless:check to validate source files -->
                </plugin>
            </plugins>


the combination can be used in a maven command to rewrite code and imports, then checkstyle audit like so

Code Block
titleExample maven command
mvn formatter:format spotless:apply process-sources


Modify settings to adapt to ONAP

  1. Select "Window -> Preferences".
  2. In the filter text box, type "tab".
  3. Under "Editors -> Text Editors", set "Displayed tab width:" to 4.
  4. Under "Editors -> Text Editors", activate "Insert spaces for tabs".
  5. 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.
  6. Under "XML -> XML Files -> Editor", change to "Indent using spaces".
  7. Clear the filter text box and type"format".
  8. Under "Java -> Code Style Formatter", for "Active profile:" select GoogleStyle.
  9. Press the "Edit..." button.
  10. Expand the "Indentation" section.
  11. Select "Spaces only" for "Tab policy", and "4" for "Indentation size".
  12. Expand the "Line Wrapping" section.
  13. Set "Maximum line width:" to "120", and press "Apply".
  14. Expand the "Comments" section.
  15. Set "Maximum width for comments:" to "120"
  16. Unset "Count width from comment's starting position"
  17. Unset "Enable header comment formatting", and press "Apply" and then "OK"
  18. Clear the filter text box and type "save actions".
  19. Under "Java -> Editor -> Save Actions", check the "Perform the selected actions on save", and "Additional actions" check boxes.
  20. Press the "Configure..." button.
  21. On the "Code Organizing" tab in the "Formatter" box, check the "Remove trailing whitespace" check box.
  22. Press "OK".
  23. Select "Java -> Editor -> Content Assist -> Favorites".
  24. 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
  25. Select "Java -Code Style -> Organize Imports".
  26. Remove all items from the list.
  27. 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.

Set up Sonar towards ONAP

To bind your projects to the ONAP Sonar server, follow the instructions below. Your projects should be imported in to Eclipse before this.

  1. Right click on the project and select "SonarLint -> Bind to SonarQube or SonarCloud...".
  2. Select "sonarcloud" and press "Next".
  3. Click "Generate Token"
  4. A browser opens and you are taken to a Sonarcloud login page
  5. Login with an appropriate account from the list presented, most likely your GitHub account
  6. You are now directed to a sonarcloud token generation page
  7. Enter a name for your token and click "Generate"
  8. Copy the token hex string that is generated from the browser and paste it into the "Token" field in Eclipse and click "Next"
  9. In the "Organization" field, enter the string "onap" and press "Next"
  10. The Connection name "SonarCloud/onap" should be found by the system, click "Next"
  11. The connection should be successfully created, click "Finish"
  12. Press "Add...".
  13. Select the projects you want to add and press "OK".
  14. Press "Next".
  15. Start typing the name of your project, and it should appear in a list box where it should be selected.
  16. Press "Finish".

To see messages from Sonar introduced by edits made in the projects, select "Window -> Show Wiew -> Other...". Expand "SonarLint" and select "SonarLint -> On-The-Fly".

Setting up the ONAP Checkstyle in Eclipse


Expand

(There may well be an easier way but this works)

The first issue is that the current ONAP master tagged version 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.3 -b 1.2.3
  4. If you want CheckStyle to ignore generated files, do the following:
    1. Add the following tag to the above file:
      <module name="SuppressionFilter">
        <property name="file" value="<absolute path to the directory of the file>/suppressions.xml"/>
      </module>
    2. Create a file called "suppressions.xml" in the folder given above, and put the following content in it:
      <?xml version="1.0"?>
      <!DOCTYPE suppressions PUBLIC
        "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
        "https://checkstyle.org/dtds/suppressions_1_2.dtd">
      <suppressions>
        <suppress files="[\\/]generated-sources[\\/]" checks="[a-zA-Z0-9]*"/>
      </suppressions>
  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 <your_git_folder>/oparent/checkstyle/src/main/resources/onap-checkstyle/onap-java-style.xml  
    (assuming you have downloaded the oparent repo)
  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!

Install useful plugins

IntelliJ

Optional additional 

git-review

Run Git Bash as Administrator (for example, in Windows 10, use the Windows menu, scroll to the Git directory, right-click on Git-bash, and select "Run as administrator"

Within Git Bash, type the following command: assumes you already installed python above

$ pip install git-review

To use git review, you have to be in a Git clone directory that already contains a (possibly hidden) .gitreview configuration file (see Gerrit/Advanced usage#Setting up a repository for git-remote), otherwise you will get the error message UnboundLocalError: local variable 'no_git_dir' referenced before assignment.

Info

The Git and git-review installation steps above are derived from the description at: https://www.mediawiki.org/wiki/Gerrit/git-review#Windows 

Configure Git to remember your Linux Foundation user name and email address (the user name and email address associated with your Linux Foundation login):

git config --global user.email <your_LF_account_email>

git config --global --add gitreview.username <your_LF_user_name>

Configure git review

Code Block
themeMidnight
git config --global gitreview.remote origin


If you are using VPN, you might encounter a proxy problem while connecting to the Linux Foundation website. To avoid the problem, you should add the proxy setting in git config, using the following command:

git config --global https.proxy https://<proxy username>:<proxy password>@<proxy url> 

git config --global http.proxy http://<proxy username>:<proxy password>@<proxy url>

NOTE: When entering the proxy username, you might be required to add the domain name in front of the username.

Python

Download Python version 2.7.10:

Execute the install file that you just downloaded. (You must have administrative privileges.) During installation, select "Add python.exe to Path", overriding the default setting. Also, be sure to install "pip" (this is the default).

Node-JS

The dcae build will install npm in most cases.

...