Use SVN version control under Eclipse

Source: Internet
Author: User
Tags svn

Zhu Xianzhong compiled from celestial pole [Url]http://dev.yesky.com/356/2578856.shtml[/url]

SummaryCVS is cool, but subversion is even cooler. However, if you are using Eclipse for development, you may not be able to take advantage of the subversion benefits until recently. With the release of Subclipse, subversion may eventually overwhelm CVs in the full power of your Eclipse IDE environment.

I. Introduction to SCM and Subversion

Software configuration Management (SCM) is a good art of managing source code and keeping it safe, and it enables the sharing of source code with other team members and the ability to protect it. With a good use of SCM, you can easily track software releases and new development branches, making it easier to identify and remediate errors in product releases.

In fact, there are a large number of SCM tools available, both open source and commercial, such as Starteam,perforce,bitkeeper and ClearCase. In the open source world, the de facto SCM standard is the concurrent version management System (CVS), which is widely used in hundreds of thousands of open source and commercial projects worldwide. However, CVS also has many of the following inherent flaws that make it impossible to be perfectly suited for modern engineering development:

· Essentially, the design of a text file makes CVS less capable of processing binary files. At each commit, the binaries are transferred and stored as a whole, which creates a waste of bandwidth and disk space.

· In CVS, you cannot move files and directories. Your only choice is basically to delete and re-add them, losing all of the file history information throughout the process.

· The concept of atomic commits is not implemented in CVS. For example, you have to submit 10 files to the server, and the commit is often stopped halfway through the process. (This is likely to happen if someone submits a file at the same time, or even if your network fails or your PC restarts.) In this case, the server will only record half of your corrections, which could put the code base part in a potentially unstable state.

Subversion is a relatively new open source SCM tool designed to fundamentally overcome the limitations of the original CVS. It is a well-designed tool with many new features suitable for modern development:

· Commits are atomized. The submitted files can be correctly added to a new revision, or the repository will not be updated, and each new revision is made up of only the changes in one commit.

· Subversion uses a clever binary technique for both text and binary files, which optimizes network traffic and optimizes storage disk space.

· In subversion, each revision represents a complete copy of the tree in a specific time period. Files and directories can be moved without restrictions.

· Subversion only stores changes between two versions, which saves disk space and means that identifying a new version or creating a new child content is almost immediately possible.

· You can access a Subversion repository in a variety of ways, depending on your needs: using HTTP or HTTPS (for use with WebDAV), using fast, patented SVN: protocols, or directly via local files, and so on.

ii. Integration of Subclipse plug-ins with eclipse

A good SCM should be tightly integrated with your work environment. No one really likes to go to the command line to add files to the warehouse. The implementation of the CVS integration was early in eclipse, but until recently subversion users had not been taken seriously. Now, the new Subclipse plugin provides a smooth subversion integration in eclipse.

(i) Install the Subclipse plug-in

Below, you install Subclipse from the update site in the usual way:

1. Open the "Find and install" window ("Help>software updates>find and Install").

2. Select the "Search for new features to install" option and click Next.

3. Click on "New remote site" and create one, using the name subclipse and the URL [Url]http://subclipse.tigris.org/update_1.0.x[/url] (see Figure 1).

4. In the Results installation window, select "Subeclipse in the Features" to the installation list and start installing the plugin via the wizard.

5. After completing this, restart Eclipse. Now, you can go on!


Figure 1: Installing the Subclipse plugin


(ii) Establishment of a repository definition

Now that you have installed the plugin, then you need to tell it where your project warehouse is located. You implemented it in the SVN repository view. Open this view ("Windows>show view>other>svn Repository") and select "New>repository location" in the context menu to display a 2 dialog box. Enter the appropriate URL and click "Finish".


Figure 2. Adding a warehouse definition

(c) Checkout (check out) a project

Once you have a repository, you can browse through all the content in the SVN repository view (see Figure 3). As we'll see later, this view is a very handy way to interact with subversion.


Figure 3. SVN repository view.

Now, let's check out a project in your Eclipse workspace. This simply selects the Subversion repository you need, opens the context menu, and selects "Checkout". This will open a wizard with two options:

· Check out as a project configured using the new project wizard-this option to open the Fresh Engineering Wizard, which allows you to use the built-in Eclipse project type configuration project. This option is often best used because it allows you to use the same project template and configuration screens, and you often use them when you create a regular project.

· Check out as a project in the workspace-this option simply creates an Eclipse project in your workspace that contains the checkout source.

In both cases, you still need to update the construction path of the project, because before the source code is checked out, eclipse cannot determineJavaWhere the source code is located.

(iv) Import a new project into the warehouse

If you just started a new project, then you need to import it into the Subversion repository. Subclipse provides a convenient way to implement this directly from within your IDE. To do this, simply select your project from the Package Explorer view and select "Team>share Project" from the context menu. You can use one of the existing warehouses or create a new warehouse definition. After you specify the warehouse and project name, you can specify the files and directories you want to put in the warehouse and provide an initial comment (see Figure 4). This method is particularly useful because it allows you to selectively import files that are managed only by subversion, even if the project contains other files (such as generated classes, temporary files, or other content that is not required).

Figure 4. Import a project into a subversion repository


Iii. using Subversion in eclipse

Now that your subversion-enabled project is up and running, most of the necessary subversion commands can be accessed via the "Team" context menu (see Figure 5). You can see the status of your local files in the package explorer (see Figure 6), where any modified files are marked with an asterisk. Files stored in the warehouse display a small yellow bucket icon (representing a database), and files that have not been added to the warehouse are displayed with a question mark.


Figure 5. Most subversion commands can be accessed via the Team menu

Figure 6. You can see the status of the local files in the package explorer


(i) Keep in sync with repository

Updating your files from the repository and submitting your changes to the warehouse is a straightforward process, which can be accomplished using the Team>update and team>commit menu option. Before submitting your changes, you may want to see if any of the files on the server have been modified since your last update. To do this, you can use "Team >synchronize with Repository". This command lets you see what has been partially modified, what has been modified on the server, and any conflicts between the two changes (see Figure 7). You can also visually see conflicting versions and correct any more prominent conflicts before committing your changes.


Figure 7: Keeping in sync with the warehouse


(ii) Use of attributes

attribute is one of the innovative features of subversion. In subversion, you can associate metadata ("Properties") to any file or directory. You can define any property you like, but subversion also provides some useful built-in properties, such as those provided in Figure 8 below:

· The Svn:executable property allows you to set an executable flag for a file on an operating system that supports this capability.

· The Svn:need-lock property, which can be used to impose an exclusion lock on a file (for example, useful for binary files). A file that defines the Svn:need-lock attribute can only be modified by one person at a time. When the file is checked out, it is read-only. If you want to modify the file, you need to first use the "Team>lock" menu option. After that, use "team> Unlock" to release the file, or submit only your changes. This behavior will release the lock and allow other users to get a lock on the file as well.


Figure 8. Add a Subversion attribute to a file


III) TAG and branch

In subversion, it's easy to create new tags and branch. You can use tag to identify a specific version (using a readable name, such as "Release 1.0"). , while a branch is used for new development work without affecting the main source base (called trunk). Development on a branch will continue until the developer is ready to integrate the changes back into the main trunk.

In subversion, branch and tag are created by making a virtual copy of a given revision (in another name and/or another directory). Under normal circumstances, branch stored in the branches directory, tag is located in the tags directory, although in practice in order to meet your project you can use your own any custom.

From Eclipse, the "Team>branch/tag" menu allows you to create Branch and tags (see Figure 9). The browse button provides a convenient way to see which branch and tags exist in the repository.

When you use "Team>switch" to create a new branch or tag, you can easily switch between branches. Whenever you switch to a different branch (or return to trunk), subversion will only update the file (it needs to keep the copy of your current work synchronized with the destination branch).


Figure 9. Create a new branch or tag


(iv) Revision history

Like most SCM systems, Subversion lets you track changes in your source code. The "Team>show in Resource" menu option allows you to query the list of changes (including changes to a file, directory, or even the entire project) (see Figure 10).

Remember, in subversion, commits are atomic-one commit consists of a set of file changes and a global comment. The SVN Resource history view shows you a concise view of each submission, including modified files and related comments.


Figure 10: Historical Resources


Iv. Conclusion

Subversion is a powerful and very flexible SCM tool and a successful successor to CVS. Combined with subclipse,subversion can ultimately be fully played in your Eclipse IDE environment.

Use SVN version control under Eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.