SVNBookCode

HomePage | RecentChanges | Preferences

Book Sample Code and Subversion

Most tech books include source code for the included examples, and to get the full benefit of the book, you should download it and work with it as you read the book. Often this code is arranged by chapter and includes packaged web applications in addition to build files and a source tree.

While simply unzipping the example code on your local disk is an option, it is far better to have the code under source control so that you can try new things while retaining the ability to easily revert to a known good state. Just like your production code.

In this article I will explain how to set up a local Subversion repository and import the example code for "Pro JSF and Ajax" from Apress.

Note: This article assumes you have Subversion installed and are familiar with its use. The instructions assume Subversion under Cygwin, and should be the same on Linux or Unix. Subversion is also available for Windows, and the advice here should still apply if you substitute directory paths that make sense.

Acquire the book and source code

First, [buy the book]! Then download the [source code] and unzip it to a temporary location. I'll assume it's in ~/temp/ProJSFandAjax for the rest of the article.

Create a Subversion repository

  cd ~/svn_data/repos
  svnadmin create projsf

Configure repository auth

  cd ~/svn_data/repos/projsf/conf

Consult [this page] for minimal authorization configuration.

Start svnserve

   svnserve -d -r ~/svn_data

This will start the svnserve daemon listening on port 3690. Configure your firewall as desired to restrict access. For example, you may want to only allow connections from localhost.

Why svnserve? I use Subversion for Cygwin, but I also use TortoiseSVN?. It turns out that if you create a repository with Cygwin svnadmin and then try to access it using a file:/// url, TortoiseSVN? is unable to deal with it. Using svnserve and a svn:// URL avoids the problem entirely. If this is not your situation, you can skip starting svnserve, and access the repository with file:///path/to/repos/projsf

Add the initial repository structure

This is optional, but the convention in a Subversion repository is to have separate directories for tags, branches and trunk.

   cd ~/temp
   svn co svn://localhost/repos/projsf
   cd projsf
   svn mkdir tags
   svn mkdir branches
   svn mkdir trunk
   svn commit -m "Added initial repository structure"

Import the book source code

Change to the directory above where you unzipped the book source code, and import it into your new repository.

   cd ~/temp/
   svn import ProJSFandAjax? svn://localhost/repos/projsf/trunk

Note that this will import the content *underneath* the 'ProJSFandAjax?' directory, so you will end up with a repository structure such as:

   projsf/trunk/chapter01
   projsf/trunk/chapter02
   ...

Now that you've imported the source code, you can delete your unzipped copy:

   rm -rf ProJSFandAjax?

Tag the initial checkin

To make it easier to revert to the initial code, tag the initial checkin:

   svn cp svn://localhost/repos/projsf/trunk svn://localhost/repos/projsf/tags/INITIAL_IMPORT -m "Tagged initial import."

Check out a working copy

   cd ~/projects/
   svn co svn://localhost/repos/projsf/trunk projsf

Enjoy!


The [author] may be reached at wsmoak @ apache.org


HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited June 23, 2007 9:41 am by WendySmoak (diff)
Search: