Versions Compared

Key

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

Table of Contents

IDE Setup

The project does not enforce the use of a specific IDE, but rather suggest the use of IntelliJ IDEA community edition which is free.

The following examples and documentation focus on IntelliJ IDEA. For other IDEs, developers should consult the documentation for the IDE of choice for specific configuration steps. 

To get the best development experience for ONOS, the team suggests to use IntelliJ 2018.1 with the Bazel plugin installed.

You can find and download 2018.1 version here: https://www.jetbrains.com/idea/download/previous.html

IMPORTANT: Latest 2018.2 IntelliJ version currently has no support for Bazel plugin. 

If you have no idea where to start, here are some instructions on how to install IntelliJ.

Bazel plugin Installation

After having dowloaded and installed Intellij IDEA 2018.1 ONOS requires the Bazel plugin to be installed. 

  1. Go into Intellij IDEA > Preferences > Plugins > Browse Repositories and search for Bazel 
  2. Click on Install
  3. Wait for download and installation
  4. Click on restart IntelliJ 

More information on how to install the Bazel plugin can be found here: https://ij.bazel.build/docs/bazel-plugin.html

Importing the ONOS Source

Assuming you have obtained the source code already and Installed the Bazel plugin form the previous section, the following steps can be followed to import ONOS into IntelliJ: 

  1. To import the ONOS project, simply open IntelliJ IDEA and select: Import Bazel Project from the welcome screen if it's your first time using Intellij. Otherwise do File > Import Bazel Project.
  2. The next window asks you for the Bazel Workspace, click on the three dots (...) on the right, navigate to the ONOS folder and select it, the path should appear in the widows' box. Press Next.
  3.  The next window asks you to Select a project view, since ONOS does not have a common .bazelproject file we select Create from scratch and then press Next.
  4. Select Finish to accept the following window in order to import all ONOS project.

More information on how to import a Bazel project can be found here: https://ij.bazel.build/docs/import-project.html

Import Troubleshooting

If your import fails with the error Error:Cannot run program "bazel" (in directory ): error=2, No such file or directory IntelliJ did not properly pick-up the location of the Bazel binary and we need to change it. 

  1. Go into Intellij IDEA > Preferences > Bazel Settings
  2. Under Bazel Binary Location click on click on the three dots (...) on the right and select the location you installed Bazel in ( e.g. /usr/local/bin/bazel ). You can also type the Bazel path. 
  3. Repeat "Importing the ONOS source" steps

More information on this error can be found here: https://github.com/bazelbuild/intellij/issues/230

Importing the settings

While the project is being processed, we can go ahead and import the recommended IDEA settings. We do this by selecting File… Import Settings… and then navigating to the ONOStools/dev directory and selecting the idea-settings.jar file. We can complete the process by pressing the OK button.

These settings have the JDK home setup for OS X (/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home). For Linux, select  File... Project Structure... SDKs... then edit the JDK home path for 1.8 to be /usr/lib/jvm/java-8-oracle. If IntelliJ is throwing errors such as "cannot resolve symbol string", the JDK home is likely incorrect.

If IntelliJ is throwing errors like "The package 'org.onosproject.cluster' is not exported by the bundle dependencies," go to IntelliJ IDEA->Preferences. On the sidebar, under the Editor dropdown section, select Inspections. From there, search OSGi and under the OSGi dropdown, uncheck Package accessibility inspections and press OK.

Importing the Copyright header

Since ONOS is licensed under Apache 2 license, we need to make sure that all source files are properly decorated with the Apache 2 license header file.

To configure IntelliJ appropriately, we will locate the header.txt file under ONOS tools/dev directory and copy its contents. Then, from IntelliJ preferences, we will select Copyright section and add a new new copyright profile. We will call this profile ONOS and paste in the previously copied header text.

Then we will make sure that the newly created ONOS copyright profile is the default and we are done.

Next Steps

The ONOS Screencasts page provides helpful videos on importing, debugging, and developing ONOS with IntelliJ.