Subversion control using the Subversive plug-in
Source control is an essential part of any serious software development effort, especially one that supports development distributed across a geographically distributed team (this tutorial's co-authors, for example, are on opposite sides of a continent). Such a system allows for uncoordinated changes to a code base, without fear of one programmer making changes that will adversely affect another — yet without a central authority governing the entire process or the need of close and careful coordination between the programmers.
Subversion is an open source version-control system, similar to CVS, but widely considered its eventual successor. Subversion support for Eclipse has been available for many years using third-party plug-ins, the most popular of which was called Subversive. The Ganymede project took on development of Subversive and added it as a core library of Eclipse. However, outstanding legal issues prevent it from being distributed with the rest of Ganymede, so, for now at least, you must still separately install the Subversive plug-in from within Ganymede.
Follow along to see how we set up Subversive and used it to manage the source code for the personal-organizer application.
Subversive consists of two parts, each of which must be separately installed. The first is the Subversive plug-in itself, which provides the UI elements to integrate Subversion support into Eclipse. The second part is the connector libraries, and these are separately developed and licensed. To install the Subversive plug-in from within Eclipse, navigate to Help > Software Updates.
Figure 4. Software Updates from the Help menu
Choose the Available Software screen, then click Add Site. For the
http://download.eclipse.org/technology/subversive/0.7/update-site/ and click OK.
Figure 5. Add Site for Subversive
This will add a list of related plug-ins, but before installing those, click Add
Site again, and add the location for the Subversive connectors. Enter
for the location and click OK.
Figure 6. Add site for Subversive connectors
You'll see that both update sites have added a number of different possible plug-ins. You can select them all, but the minimal required for now are the ones labeled SVN Team Provider and the Subversive SVN Connectors. Select it from the list and click Install.
Figure 7. Subversive plug-ins
Eclipse will take you through a standard set of screens for installing the plug-ins, including a screen asking you to review and accept the licensing terms. Work through these screens, and, when promoted, restart your Eclipse workbench. The Subversive plug-ins are now installed.
Subversion, like CVS, is a server-based source-code repository, which makes it an excellent choice for collaborative software development across distributed teams. The server piece is not a part of Eclipse, and installing and setting up a Subversion server is beyond the scope of this tutorial. However, there are a number of ways to run one, including using Apache (see Resources for more information).
Once you have a Subversion server you can use, you can set up your project to store its source and configurations using the Subversive plug-in. Highlight the project name in the Package Explorer and display its context menu. From there, choose Team > Share Projects. Eclipse will display a screen offering you a choice of versioning systems: CVS, which has been available as a core feature of Eclipse for some time; and SVN, which is the short-hand notation for Subversion, which was enabled when you added Subclipse.
Figure 8. Sharing a project via SVN
Select SVN and choose Next. You'll be presented with a screen (shown in Figure 9) where you'll enter the server URL and credentials for your Subversion server. Enter the information for your server. From here, you can accept the defaults for naming the repository that are set on the next screens and click Finish.
Figure 9. Share Project wizard
Eclipse will present you with the commit screen for your project (see Figure 10). All the files that are part of our project will be selected by default, but you can choose to keep some from being checked in at this time if you want. You will also be promoted for an initial check-in comment. It's good practice to enter comments on every check-in. Enter your comment and click OK. For the organizer application code, we have all of the files checked.
Figure 10. Subversion Check-in box
Eclipse has now added all of the files for our organizer to your Subversion repository. If you are using a WebDAV version of Subversion, such as through Apache as we did, you can explore the repository's structure using your Web browser. Simply enter the same URL and credentials you used to set up the repository in Subversive and navigate through the directory tree by way of the hyperlinks on each file or directory.
Figure 11. A view of the Subversion repository through the Web
You can see that our project is now wired to Subversion in the Package Explorer. Each filed under Subversion control has a revision number next to it, and the project itself has the name of the repository next to its name.
Figure 12. The Package Explorer after being shared through Subversion
Like CVS, we can now access the Subversion source-control functions from the Team context menu. To select a file from the Package Explorer that we want to update in the repository, bring up its context menu and select Team. This now shows all the Subversion features in this context menu.
Following is a list of the more common commands we'll use (see Figure 13):
- To save your changes to the repository
- To refresh your local copy with the latest from the repository
- To discard your changes and replace them with the latest in the repository
Add to Version Control
- To mark newly created local files in the repository (you must then Commit the file to add it to the server).
Figure 13. The Subversion context menu
To delete a file from the repository, delete it from the Package Explorer as you
normally would (the Delete item on that file's context menu). Then
commit the parent directory of that file. Prior to executing any
commit on the server, you will have a chance to review all
the changes; for a delete, you will see the name and location of the deleted file.
Subversion is also like CVS in that it uses optimistic locking — that is, rather than checking out a file for editing and locking it from others, code can be edited locally at will and checked in when finished. At the time of check-in, any conflicts are then resolved.