Skip to content

Contribute using Eclipse IDE

marcusk24 edited this page Jul 21, 2013 · 6 revisions

Install Eclipse

The Restlet Framework project has been mainly developed using the popular Eclipse IDE. It doesn't prevent you from using another IDE like NetBeans or IDEA IntelliJ, but keep in mind that the project was structured to take advantage of Eclipse flat projects organization. In Eclipse, each Restlet module and library is a Java project that has dependencies with other project, so you need to properly import them at the same time in your workspace.

If you don't have a recent version of Eclipse SDK (4.2 was the best choice at the time of writing), then consider installing a fresh copy from the Eclipse site.

Note also that it is recommended to have Java 5 and Java 6 installed as they are required for respectively Restlet Framework 2.1 and 2.2. You should configure Eclipse to declare your Java installations. For this, go into "Window/Preferences/Java/Installed JREs".

Select a workspace

As the Restlet source code is composed of many Eclipse projects, it is recommended to dedicate a complete workspace to each version of it that you want to work on.

Launch Eclipse and it should ask you to select the location of the workspace. Note that, if you already have installed and used Eclipse SDK, you can create a switch to a new workspace by using the "File / Switch workspace..." menu command.

Check out code from GitHub

In Eclipse, open the 'Git Repository Exploring' perspective by selecting its entry via the "Window / Open Perspective / Others..." menu.

If you have already checked out Git repositories, for example using TortoiseGit on Windows, you can now add your existing repositories using the dedicated wizard.

Otherwise, In the "Git Repositories" tab, click on the Git button with a blue arrow for the "Clone Git Repository" wizard, enter the GitHub URI and credentials.

Import the Restlet projects

Go into the "Java" perspective. Select "File / Import..." in the main menu. In the "Import" wizard, select the "General / Existing Projects into Workspace" tree node and press "Next >". Make sure the option "Search for nested projects" is selected. Now you can press "Browse..." to select the root directory. Point the file dialog to the root directory of your Restlet Git working copy (%RESTLET_HOME% in our case) and press "Ok".

Eclipse will recursively inspect the folder and propose to import all the Restlet projects (modules, libraries and build). You can now press "Finish" to complete the import. Let Eclipse refresh the workspace until all imported project show an Git overlay icon. As you can see the list of projects is quite long!

Group projects into working sets [optional]

In order to better manage these project, we will create Eclipse working sets to group them. In the Project Explorer view, select the shallow triangle icon on the upper right and click on "Select Working Set".

Click on "New..." then "Java". Enter "Extensions" as the Working set name, select all the projects stating with "org.restlet.ext" and then "Finish"
Click on "New..." then "Java". Enter "Core" as the Working set name, select all the projects starting with "org.restlet" that are not extensions and then "Finish"
Click on "New..." then "Java". Enter "Libraries" as the Working set name, click on "Select All", deselect all the projects starting with "org.restlet" and then "Finish"

Back in the "Select Working Set", press the "Select All" button then "Ok". Now, in the "Project Explorer", click again on the triangle and select "Top Level Elements/Working Sets". See how your projects are now nicely grouped!

Follow the code style

When collaborating on an open source project, you generally want to use a common code style to facilitate comparison between multiple revisions of a source file and speed-up SVN commits. Go into the "Window / Preferences..." menu.

First, we want to make sure that all developers use the same code clean ups. Select the "Java / Code Style / Clean Up" tree node, click on the "Import..." button and finally select the "%RESTLET_HOME%/build/tmpl/eclipse/cleanUp.xml" file.

Now, we want to make sure that all developers use the same code templates for new artifacts. Select the "Java / Code Style / Code Templates" tree node, click on the "Import..." button and finally select the "%RESTLET_HOME%/build/tmpl/eclipse/codeTemplates.xml" file.

Then, we need to ensure a consistent formatting of the source code. For this, select the "Java / Code Style / Formatter" tree node, click on the "Import..." button and finally select the "%RESTLET_HOME%/build/tmpl/eclipse/formatter.xml" file.

Press "OK" to close the preferences dialog.

While developing new code for Restlet, you should also ensure that your class members are always sorted. Eclipse is of great help here with its code sorting feature. You can access this feature via the menu "Source / Sort Members". In the dialog, make sure that the "Sort all members" option is selected.

Finally, you should go to the "General / Editors / Text Editors" preference panel and check the "Insert spaces for tabs".

Setting-up Ant [optional]

As you may have seen in the guide "How-To Build", we rely on Ant to build the whole project. Eclipse has a nice support for Ant that you can leverage. Select "Window / Show View / Ant". Press the "Add Buildfiles" button in the Ant view (button with an ant and a plus sign) and select "org.restlet.build/build.xml". Now you can expand the "Restlet" node in the Ant view and select the targets that you want to execute.

That's it, you are now all set to help us develop the Restlet project!