1. Introduction to SCM and subversion
Software Configuration Management (SCM) is a good art for managing source code and maintaining its security. It can share source code with other team members and protect it. By making good use of SCM, you can easily track software releases and new development branches; in this way, you can more easily identify and correct errors in the release product.
In fact, there are a lot of SCM tools available, both open source and commercial, such as starteam, perforce, bitkeeper and clearcase. In the open-source world, the actual SCM standard is the Concurrent Version Management System (CVS), which is widely used in hundreds of open-source and commercial projects around the world. However, CVS also has many of the following inherent defects, which makes it not perfectly suited to modern engineering development:
· Essentially, the design of text files makes CVS less capable of processing binary files. During each submission, binary files are transmitted and stored as a whole, which wastes bandwidth and disk space.
· In CVs, you cannot move files and directories. Your only choice is to delete and re-add them, thus losing all the file history information throughout the process.
· There is no concept of atomic commit in CVS. For example, if you want to submit 10 files to the server, the submission usually stops halfway through the process. (This may 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 corrected information, which may causeCodeThe base part is 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:
· Submission is atomic. All submitted documents can be correctly added to a new revision; otherwise, the repository will not be updated; and each new revision consists of only one submitted change.
· Subversion uses a clever binary Technology for text and binary files, which optimizes network traffic and warehouse disk space.
· In subversion, each revision represents a complete copy of the directory tree at a specific time. Files and directories can be moved without restrictions.
· Subversion only stores the modified content between two versions, which not only saves disk space, but also means that you can identify a new version or create a new sub-content almost immediately.
· You can access a subversion repository in multiple ways, depending on your needs: using HTTP or HTTPS (used together with WebDAV), using quick patent SVN: protocol, or directly through local files.
Ii. Integration of subclipse plug-in with eclipse
A good SCM should be closely integrated with your work environment. No one really likes to go to the command line to add files to the repository. Eclipse has implemented CVS integration for a long time, but it has not been noticed by subversion users until recently. Now, the new subclipse plug-in provides a smooth subversion integration in eclipse.
(1) 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 "new remote site" and create a remote site using the name subclipse and URL http://subclipse.tigris.org/update_1.0.x (see figure 1 ).
4. In the result installation window, select "subeclipse In the features" to the installation list and start installing the plug-in through the wizard.
5. After completing these steps, restart eclipse. Now, you can proceed!
Figure 1. Install the subclipse plug-in |
(2) create a repository Definition
Now that you have installed the plug-in, you need to tell it where your project repository 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 dialog box shown in figure 2. Enter the appropriate URL and click "finish ".
Figure 2. Add a repository Definition |
(3) Check out a project
Once a repository is created, you can view all the content in the svn repository view (see figure 3 ). We will see later that this view is a very convenient way to interact with subversion.
Figure 3.svn repository view.
Now, let's check out a project to your eclipse workspace. Select the desired subversion repository, open the context menu, and select "checkout. This will open a wizard with two options:
· Check out as a project configured using the new project wizard-this option opens the New Project Wizard, which allows you to use the built-in Eclipse project type configuration project. This option is usually best used because it allows you to use the same project template and configuration screen, and you often use it 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 checked source code.
In the above two cases, you still need to update the build path of the project, because eclipse cannot determine the location of the Java source code before detecting the source code of the project.
(4) import a new project to the warehouse
If you only start a new project, you need to import it to the Subversion repository. Subclipse provides a convenient way to implement this directly from within your ide. To do this, select your project from the package explorer view and select "Team> share project" from the context menu ". You can use one of the existing repositories or create a new repository definition. After you specify the repository and project name, you can specify the files and directories you want to put in the repository and provide an initial comment (see figure 4 ). This method is particularly useful because it allows you to selectively import files managed only by subversion, even if the project also contains other files (such as the generated class, temporary files or other non-essential content ).
Figure 4. Import a project to a subversion Repository |
<Object codebase = http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 Height = 200 width = 240 classid = CLSID: D27CDB6E-AE6D-11cf-96B8-444553540000>
</Object>
3. Use Subversion in eclipse
Now that your project that supports subversion has been started and runs, most of the necessary subversion commands can be accessed through the "team" context menu (see figure 5 ). You can view the status of your local file in package Explorer (see figure 6). Any modified file is marked with an asterisk. The files stored in the warehouse all display a small yellow bucket icon (representing a database); files not added to the warehouse are displayed with a question mark.
Figure 5. Most subversion commands can be accessed through the team menu
Figure 6. You can view the local file status in package Explorer |
(1) synchronization with Repository
It is quite straightforward to update your files from the repository and submit your changes to the repository. This can be done using the "Team> Update and team> commit" menu options. Before submitting your changes, you may want to check whether any files on the server have been modified since your last update. Therefore, you can use "Team> synchronize with repository ". This command allows you to see what has been locally modified, what has been modified on the server, and any conflicts between the two changes (see figure 7 ). You can also visually view conflicting versions and correct any prominent conflicts before submitting your changes.
Figure 7. Synchronization with warehouse |
(2) Use 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 attributes you like, but subversion also provides some useful built-in attributes, such as the Attributes provided in figure 8 below:
· SVN: executable attribute, which allows you to set an executable flag for a file on an operating system that supports this capability.
· SVN: the need-lock attribute, which can be used to forcibly apply the exclusion lock on files (such as binary files. A file defining the svn: Need-lock attribute can only be modified by one person at a time. When the file is detected, it is read-only. If you want to modify the file, you must first use the "Team> lock" menu option. Then, use "Team> unlock" to release the file, or submit your changes only. This row will release the lock and allow other users to also obtain a lock on the file.
Figure 8. Add a subversion attribute to a file |
(3) Tag and branch
In subversion, it is easy to create new tags and branch. You can use tags to identify a specific version (such as "Release 1.0 ").; While a branch is used for new development without affecting the primary source code base (called trunk ). Development on a branch will continue until the developer is ready to integrate the changes back to the master trunk.
In subversion, branch and tag are created by creating a virtual copy (with another name and/or another directory) for the given revision. In general, branch is stored in the branches directory and the tag is located in the tags directory, although in practice you can use any of your own customization to meet your project requirements.
From eclipse, the "Team> branch/Tag" menu enables you to create branch and tag (see figure 9 ). Among them, the Browse button provides a convenient way to view which branch and tag 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), the subversion will only update the file (it needs to keep the synchronization between your current working copy and the destination branch ).
Figure 9. Create a new branch or tag |
(4) revision history
Like most SCM Systems, subversion allows you to track changes in your source code. The "Team> show in resource history" menu option allows you to query the list of these changes (including changes to a file, directory, or even the entire project) (see figure 10 ).
Remember, in subversion, commit is atomic-A commit consists of a group of file changes and a global annotation. 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 flexible SCM tool and a successful successor of CVS. Combined with subclipse, subversion can be fully used in your Eclipse IDE environment.