Working with SVN in Eclipse
by, 02-29-2012 at 12:26 PM (5731 Views)
In a team work environment, using a version control system has been becoming standard approach to foster collaboration among team members, increase productivity, centralize resources management, reduce risks and development time…Subversion (SVN) is a version control system which is very popular and widely used in software development, and Subclipse is an Eclipse plug-in that supports Subversion within the Eclipses IDE. Subclipse has been widely used to develop Java projects in Eclipse IDE for team-oriented working environments.
This article will walk you from installing to using Subclipse for the most common tasks in terms of team collaboration. The version of Eclipse IDE targeted in this article is 3.7 – Indigo for Java EE developers.
A brief overview about Subclipse
Subclipse is an open-source Eclipse plug-in that supports working with Subversion servers within Eclipse IDE. It allows many developers working together on a project at the same time and synchronizing their work through a set of perspectives, views and functionalities. The project is managed by CollabNet, Inc – the firm started to develop Subversion as a replacement for CVS. Its home page can be touch at: http://subclipse.tigris.org/. The latest version is 1.8.5 and it is working with Eclipse versions from 3.2 or higher. Subclipse can be installed from its update site via Eclipse’s Install New Software feature, or can be downloaded separately from its website to be installed locally.
Install Subclipse in Eclipse
The easiest way is to install Subclipse from its update site. Select Help -> Install New Software… from Eclipse’s main menu. In the Install dialog, type the following URL into the text field Work with:
Hit Enter, Eclipse will load features available for the plug-in in the drop-down list, the Subclipse and SVNKit, as shown in the following screenshot:
Figure: Select features of Subclipse to be installed
Click Select All, and click Next. It may take a while for Eclipse to calculate requirements and dependencies before displaying the Install Details dialog:
Figure: Review the items to be installed
Click Next, in the Review Licenses screen, select I accept the terms of the license agreements:
Figure: Accept the terms of the license agreements
Click Finish, Eclipse is installing the software:
Figure: Installation is in progress
During the installation, a security warning pops up:
Figure: Accept a security warning
Click OK. After installation completed, Eclipse asks to restart the IDE or apply changes immediately:
Figure: Restart the IDE after installation completed
It is advisable to click Restart Now.
Perspectives and Views for SVN
Once installed, Subclipse provides two perspectives, one for SVN and one for team collaboration:
- SVN Repositories Exploring
- Team Synchronizing
You can switch to the perspective by select Window -> Open Perspective… -> Other, and select one from the Open Perspective dialog:
Figure: Open perspectives provivded by Subclipse
The views provided by Subclipse can be found by selecting Window -> Show View -> Other… Expand the SVN branch:
Figure: Views provided by Subclipse
Check in a project to a SVN server
Check in is the process of putting a project from a local computer to a SVN server. The project will be shared to other developers so that they can work on the project at the same time.
Right click on to the project in Project Explorer view, and select Team -> Share Project… from the context menu:
Figure: Check in a project
The Share Project dialog appears, select SVN, click Next:
Figure: Select SVN as repository type
In the next screen, Share Project with SVN Repository, select Create a new repository location, click Next:
Figure: Create a new repository location
Type URL of the SVN repository into the Url field:
Figure: Type URL of the repository
Click Next, in the next screen, you can specify the name of the folder in the SVN repository:
Figure: Enter folder name
Click Finish. Note that you may have to enter user name and password to access the SVN repository, depending on the server’s settings.
Check out a project from a SVN server
Check out is the process of getting a project from a SVN server’s repository to local disk. There are two ways to check out a project in Eclipse:
- Check out from menu File.
- Check out from SVN Repositories view.
Check out from menu File
Select File -> New -> Project… In the New Project dialog, expand SVN node and select Check out projects from SVN:
Figure: Create a new project from SVN
Click Next, in the next screen, select Create a new repository location:
Figure: Create a new repository location
Click Next, enter URL of the SVN repository into the Url field, and click Next:
Figure: Specify URL of the repository
Eclipse will load content of the repository on the SVN server and ask you to select a project folder:
Figure: Select folder to be checked out
Click Next, in the Check Out As screen, you can specify how to check out the project as a new project using the New Project Wizard or as a project in the current workspace. You can also select to check out a specific revision. Click Finish when done:
Figure: Check out options
The check out is in progress:
Figure: Eclipse is downloading project from SVN
Note that you may be asked for providing user name and password to access the SVN repository.
Check out from SVN Repositories view
Switch to SVN Repository Exploring perspective, in the view SVN Repositories, click on the Add Repository icon:
Figure: Add SVN repository
In the dialog Add SVN Repository, type URL of the SVN repository into Url field, and click Finish:
Figure: Specify URL of the repository
You may have to provide user name and password to access the SVN repository. Eclipse will load content of the repository in a hierarchical tree. Expand the repository node, and right click on the folder name which you want to check out:
Figure: Check out from context menu
And follow the steps same as described above, for the Check Out As screen.
Team collaboration tasks
Subclipse provides a comprehensive context menu for team collaboration, it is the Team menu which can be found in the context menu:
Figure: Team context menu
Synchronize with Repository
This task allows reviewing your changes with other team members in order to synchronize them. Select Team -> Synchronize with Repository from context menu, Eclipse will switch you to Team Synchronizing perspective:
Figure: The Synchronize view
In the Synchronize view you can take a look at:
- Outgoing changes: changes made by you and ready to be committed. They are denoted by an outgoing arrow in gray.
- Incoming changes: changes made by other team members and ready to be updated. They are denoted by an incoming arrow in blue.
- Conflicts: are the resources that have been changed by someone while you are still working on them. Conflicts are denoted by a two-way arrow in red.
From the changes in the Synchronize view, you can decide to do by some quick commands in the context menu:
Figure: Quick commands in context menu
Push your changes to SVN repository. The dialog Commit appears, you can review what changes to commit and provide a comment, then click OK.
Update the resource with a latest revision from the repository. A conflict will be notified if any.
Override and Update
Always replace the content of the resource with a latest revision from the repository. If there is any conflict, you’re the local version is overridden by the revision from the repository.
Mark as Merged
This command should be called to indicate that the current resource is merged with incoming changes from the repository. This is usually used after resolving conflicts.
Undo the changes made to the resource since the last update.
Review revision history of a resource. Details will be shown up in the History view, and you can switch back to a specific revision via context menu.
Above are the most frequently used tasks. There are many other tasks which are waiting for you to explore.
The Synchronize view comes with a handy toolbar that helps switching to incoming mode, outgoing mode, conflicts mode, update all incoming/outgoing changes…:
Figure: Quick toolbar in Synchronize view
The Team Synchronization perspective also provides a very useful compare editor which lets you to compare the local changes and remote changes visually:
Figure: Code compare editor
The compare editor is automatically loaded when double clicking on a resource, it is very helpful for resolving conflicts and merging changes.
Subclipse is a great plug-in for working with SVN and fostering team collaboration, so it should be one of must-have tools for any Java developers.