Jump to: navigation, search

Developer/Intellij

Installation

  • Make sure you have JAVA_HOME set correctly.
  • Install IntelliJ (there is a community edition) http://www.jetbrains.com/idea/free_java_ide.html
  • If you're on Mac OS X with JDK 1.7 only, change the value of the JVMVersion key from "1.6*" to "1.7*" in the /Applications/IntelliJ IDEA 13 CE.app/Contents/Info.plist file.
  • Run IntelliJ (make sure you have set JAVA_HOME variable first)

/yourIntelliJInstallLocation/bin/idea.sh

Settings

File->Settings->Editor->Code Style->Java->Tabs and Indents</code>

</br>

  • deselect "Use Tab Character"

- set "Tab size:" and "Indent:" to 4

Open Project

The instructions below assume you have cloned a project such as netvirt into ~/git/netvirt.

  • To open a project
 File-->Open Project

Select the pom.xml located in the root of the project

/git/netvirt/pom.xml


It should then open the project structure on the left pane. (there is a package-based view as well similar to Eclipse. In order to switch to it, select in left upper corner of the left pane: "view as: Packages")

Configuring Maven

  • First, verify Intellij is using the correct version and installation of Maven in case you have several versions installed. In order to check it, there are 2 options to reach Maven menu:

1. on right side of Intellij, there is a button named "Maven projects". After the maven menu opens, on its top there's option "maven settings".
2. the same "maven settings" option can be reached via Project Settings --> Maven. The "Settings" button is available under the top menu.

  • Configure convenient shortcuts for running the compilation/build:
Run --> Edit configurations --> Add new configuration (select Maven)

Give it a meaningful name (such as "build including distribution/build with tests")
Fill the working directory (where the parent/root pom.xml is located)
Fill goals in the command line field (for example : clean install)
Fill profiles if exist
If you need to set any -D flags , it is available in the Runner tab

Now you can always select this configuration from the combo box in the main Intellij pane, and press "run" (the green triangle) - it is equivalent to running "mvn clean install ... " from the command line.

Please note you can create and use several different configurations with different names. For example create a "quick" profile with mvn clean install -Pq.

  • Refreshing configuration:

Sometimes after fetching changes that involve pom changes, Intellij will detect that a refresh/reimport is needed. It will popup "Import changes/enable auto import" options. Enabling auto import is a good choice. If for some reason there's a need to reimport all maven configurations without any external changes detected, it is possible by right click menu --> Maven --> Reimport

Keymap/keyboard shortcuts

There are several different mappings for the keyboard shortcuts.
For example, Eclipse users can select to use same keys as in Eclipse.
In order to change the default keymap, go to:

 Settings --> IDE settings --> Keymap.

Select the relevant keymap from the combo box.

Git

1. Intellij detects automatically the project is working with Git and its settings, and the right click menu adjusts to the Git integration. If you see in right bottom corner "git:master" (or whatever branch you're currently working on) - then it's all set. If it didn't detect, select "enable version control" in the VCS top menu option.

2. Git blame - the equivalent of that in IntelliJ is called "annotate". In any class, stand on a grey column on left side of class (where breakpoints/bookmarks are), right click-->Annotate. Or - right click in any class, select Git --> Annotate (see attached snapshot)
Bonus #1: stand on the annotated pane with names, left click any change --> a dialog with all files changed in that commit will open. You can right click all of them, compare different revisions, etc.
Bonus #2: right click a change in same annotated pane -> you'll see "copy revision number" - handy for searching the patch in gerrit... Bonus #3: the annotate option is also available in the diff windows

3. Git log -p <file> (seeing commit history of a specific file) The equivalent in IntelliJ: right click any class/file, select Git-->show history. It will be opened in a separate pane under the class. You can select with mouse+ctrl several revisions and compare them.

4. Checkout branch Right click --> Git -->Checkout branch (note the drop down list with all branches ...) or "as new branch" to create a new one

5. See all changed files (git status) On most bottom pane of Intellij, you'll see "find,run,debug,todo,version control,changes" Select Changes --> local changes tab. You will see all files that were changed on your file system since last commit. Of course you can right click them--> show diff to see what was changed, etc.

6. Reverting a file ("forgetting" all changes since last commit) or what git calls : "git checkout filename" Stand on class/file -right click --> Git --> Revert.

Copyright headers

Idea can add automatically copyright headers if its configured to do so: Open Settings (File/Settings), search for Copyright Profiles. Using + sign add ODL profile with following text:

Copyright (c) $today.year Cisco Systems, Inc. and others.  All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html

Then go up one level to Copyright, select odl as default profile.

See Developer_Best_Practices for details on what should go into the copyright headers.

Import ordering

Do not allow imports to be wildcarded with *: File->Settings->Editor->Code Style->Java->Imports. Select "Use single class import" and set the Class and Names count to 999.

Configure import ordering: File->Settings->Editor->Code Style->Java->Imports. In the table at the bottom remove all rules with - sign, then add following:

  1. import static all other imports
  2. <blank line>
  3. import all other imports

You should have settings as shown on this screenshot:

Imports.png

CheckStyle

How to set Checkstyle up in IntelliJ