Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: ColdFusion, Adobe Flex

ColdFusion: Article

Version Control Using Subversion

This article describes the differences between CVS and Subversion and explains how to install Subversion

Using JavaSVN
The JavaSVN Open Source library is used in several projects for interaction with Subversion. Projects that use JavaSVN include Subclipse, SmartSVN, and Atlassian JIRA. JavaSVN is a pure Java Subversion client library.

In the following example I use JavaSVN to access the Subversion repository from a ColdFusion application. It achieves a very simple task: It reads the latest revision from a file in the repository called "test.htm."

The JavaSVN library must be accessible to ColdFusion so I copied javasvn.jar to the Directory "C:\CFusionMX7\wwwroot\WEB-INF\lib\."

Example: getLatestRevision
First we have to initialize the library:

<!--- initialize the library to work with a repository for DAV (over http and https) --->
<cfset CreateObject
("java", "org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory").setup()>

The configuration part is easy; we define the URL to the repository, the user credentials, and the file path:

<!--- configuration --->
<cfset sRepUrl = "http://rocket/svn/projects/trunk">
<cfset sUser = "">
<cfset sPasswd = "">
<cfset sFilePath = "test.htm">
<cfset oSVNURL = CreateObject("java", "org.tmatesoft.svn.core.SVNURL").parseURIEncoded(sRepUrl)>

Next we create a repository driver object and authenticate the user:

<!--- create an SVNRepository driver object --->
<cfset oSVNRepository = CreateObject("java",
"org.tmatesoft.svn.core.io.SVNRepositoryFactory").create(oSVNURL.parseURIEncoded(sRepUrl))>
<cfset oAuthManager = CreateObject("java",
"org.tmatesoft.svn.core.wc.SVNWCUtil").createDefaultAuthenticationManager(sUser, sPasswd)>
<cfset oSVNRepository.setAuthenticationManager(oAuthManager)>

Finally we get the file using the method getFile() and dump the latest revision number for this file:

<cfset oSvnFileprops = CreateObject("java", "java.util.HashMap")>
<cfset oBaos = CreateObject("java", "java.io.ByteArrayOutputStream")>
<cfset oSVNRepository.getFile(sFilePath, JavaCast('long', -1), oSvnFileprops, oBaos)>

<cfset latestRevision = oSVNRepository.getLatestRevision()>
<cfdump var="#latestRevision#">

Please consult the JavaSVN documentation, it contains several other excellent Java samples.

Conclusion
The switch from CVS to Subversion was quite easy because of the excellent tools and documentation available. I hope that this article contains some useful information for developers wanting to switch from CVS or some other version control system to Subversion. Maybe it will help to convince your boss that Subversion is the right choice for your team.

Resources

Books

More Stories By Harry Klein

Harry Klein is cofounder and CTO at CONTENS Software GmbH, a leading supplier of enterprise content management software. He is a Certified Advanced ColdFusion developer and Microsoft MSCE.

Comments (3) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Mark Bickford 07/20/06 09:00:52 AM EDT

In the section on IDE integration, I would have been interested in knowing about any experiences with integrating Subversion with the Source Control functionality in CF Studio (IIRC, Homesite didn't do Source Control directly.)

CFDJ News Desk 07/19/06 07:32:56 PM EDT

This article describes the differences between CVS and Subversion and explains how to install Subversion and migrate an existing CVS repository. It also describes how to configure Subversion in a Windows environment, explains a basic Subversion project structure, and introduces the main Subversion clients. Finally, it shows ways to use Subversion with Ant and how to get connected to the repository via JavaSVN and ColdFusion.

CFDJ News Desk 06/07/06 05:08:37 PM EDT

This article describes the differences between CVS and Subversion and explains how to install Subversion and migrate an existing CVS repository. It also describes how to configure Subversion in a Windows environment, explains a basic Subversion project structure, and introduces the main Subversion clients. Finally, it shows ways to use Subversion with Ant and how to get connected to the repository via JavaSVN and ColdFusion.