<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>uk-dave.com &#187; Development</title>
	<atom:link href="http://www.uk-dave.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.uk-dave.com</link>
	<description>// todo: insert witty tagline here</description>
	<lastBuildDate>Sun, 31 May 2009 12:03:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Integrating Subversion, Mantis and Eclipse</title>
		<link>http://www.uk-dave.com/2009/05/integrating-subversion-mantis-and-eclipse/</link>
		<comments>http://www.uk-dave.com/2009/05/integrating-subversion-mantis-and-eclipse/#comments</comments>
		<pubDate>Fri, 29 May 2009 22:18:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.uk-dave.com/?p=300</guid>
		<description><![CDATA[I recently installed Subversion and Mantis on my Linux server for handling version control and issue tracking of my software projects. I also use the excellent Eclipse IDE for all my development whether it be Java, C++ or PHP. This post details how I managed to integrate all these tools together so that I could [...]]]></description>
			<content:encoded><![CDATA[<p>
I recently installed <a href="http://subversion.tigris.org/">Subversion</a> and <a href="http://www.mantisbt.org">Mantis</a> on my Linux server for handling version control and issue tracking of my software projects. I also use the excellent <a href="http://www.eclipse.org">Eclipse</a> IDE for all my development whether it be Java, C++ or PHP. This post details how I managed to integrate all these tools together so that I could commit my code changes straight from Eclipse into my Subversion repository and also automatically update an associated issue report in Mantis.
</p>
<p>The basic steps are as follows:</p>
<ol>
<li><a href="#install-svn">Installing Subversion and WebSVN</a></li>
<li><a href="#install-mantis">Installing and Tweaking Mantis</a></li>
<li><a href="#add-hook">Add a Subversion Post-Commit Hook</a></li>
<li><a href="#install-subclipse">Installing Subclipse</a></li>
<li><a href="#add-bugtraqprops">Adding BugTraq Properties</a></li>
</ol>
<p>The information on this page came from multiple sources, but most of the credit goes to <a href="http://www.mantisbt.org/bugs/view.php?id=8070">Marc on the Mantis forums</a> for providing the necessary code modifications to mantis.</p>
<p>&#160;</p>


<a name="install-svn">&#160;</a>
<h3>1. Installing Subversion and WebSVN</h3>
<p>
First off I installed <a href="http://subversion.tigris.org/">Subversion</a> and <a href="http://websvn.tigris.org/">WebSVN</a> (a web interface onto your Subversion repository) on my Ubuntu Linux server.
</p><p>
To install Subversion I simply ran <br/>
<tt>&#160;&#160;&#160;sudo apt-get install subversion</tt><br/>
and configured a single repository in <tt>/var/lib/svn</tt>.
</p><p>
I then installed the latest version of WebSVN by doing:<br/>
<tt>
&#160;&#160;&#160;wget http://websvn.tigris.org/files/documents/1380/45918/websvn-2.2.1.tar.gz<br/>
&#160;&#160;&#160;sudo apt-get install enscript<br/>
&#160;&#160;&#160;cd /var/www<br/>
&#160;&#160;&#160;sudo tar xzf ~/home/david/websvn-2.2.1.tar.gz<br/>
&#160;&#160;&#160;sudo cp websvn-2.2.1/include/distconfig.php websvn-2.2.1/include/config.php
</tt>
</p><p>
I then edited <tt>websvn-2.2.1/include/config.php</tt> and changed the following settings:
</p>
<blockquote><pre>
$config->addRepository('Default', 'file:///var/lib/svn');
$config->useEnscript();
$config->useBugtraqProperties();
</pre></blockquote>
<p>
This has told WebSVN where my repository is and that I want to use Enscript for syntax highlighting. The last line tells WebSVN to lookout for some special properties on the repository that will link it with the Mantis issue tracker &#8211; more on this in a bit.
</p>
<div style="text-align: center;">
<img src="/wp-content/images/blog/websvn.png" width="728" height="485" alt="WebSVN screenshot"/>
</div>
<p>&#160;</p>


<a name="install-mantis">&#160;</a>
<h3>2. Installing and Tweaking Mantis</h3>
<p>
Mantis is is a free web-based bug tracking system. It is written in the PHP scripting language and works with MySQL. I&#8217;m using version 1.2.0a3 here. Simply download the .tar.gz file, unpack it and follow the setup wizard at http://yourserver/mantis/ to configure it. 
</p><p>
To get Mantis to integrate with Subversion and WebSVN I had to make a few tweaks to some of it&#8217;s PHP files. The instructions I followed were based on the ones I found here: <a href="http://www.mantisbt.org/bugs/view.php?id=8070">http://www.mantisbt.org/bugs/view.php?id=8070</a>.
</p><p>
Note that you will need to add a new user to Mantis that Subversion will use to add notes to issues. I have created a user called &quot;<tt>svn</tt>&quot; and given it Developer access to my projects.
</p><p>
Edit <tt>plugins/MantisCoreFormatting/MantisCoreFormatting.php</tt> and after every line that says:
</p>
<blockquote><pre>$t_string = string_process_cvs_link( $t_string );</pre></blockquote>
<p>add another line that looks like this:</p>
<blockquote><pre>$t_string = string_process_svn_link( $t_string );</pre></blockquote>
<p>There should be 3 in all.</p>
<p>&#160;</p>
<p>
Next, edit <tt>mantis/core/string_api.php</tt> and add this code:
</p>
<blockquote><pre>
# process the $p_string and convert filenames in the formats
#  SVN:rev:U   full/path/filename.ext
#  SVN:rev:
# into URLs pointing to the WebSVN server.
# 'rev' is the revision number.
# 'U   full/path/filename.ext' is the output format
# of 'svnlook changed'.
# 
# if $p_include_anchor is true, include an &lt;a href="..."&gt; tag,
#  otherwise, just insert the URL as text
function string_process_svn_link( $p_string, $p_include_anchor=true ) {
	$t_string = $p_string;
	$t_svn_web = config_get( 'svn_web' );
	$t_svn_web_repname = config_get( 'svn_web_repname' );
	$t_svn_web_showdiff = config_get( 'svn_web_showdiff' );
	$t_svn_web_file_page = $t_svn_web_showdiff ? "diff.php" : "filedetails.php";
	
	$t_status['A '] = 'added:    ';
	$t_status['D '] = 'deleted:  ';
	$t_status['U '] = 'modified: ';
	$t_status['_U'] = 'props:    ';
	$t_status['UU'] = 'mod+prop: ';
      
	if ( $p_include_anchor ) {
		$t_file_replace_with = "\$t_status['\\2'].'&lt;a href=\"'.\$t_svn_web.\$t_svn_web_file_page.'?repname='.\$t_svn_web_repname.'&#038;sc=1&#038;path='.urlencode('/\\3').'&#038;rev=\\1\" target=\"_blank\"&gt;\\3&lt;/a&gt;'";
		$t_rev_replace_with  = 'Revision: &lt;a href="'.$t_svn_web.'listing.php?repname='.$t_svn_web_repname.'&#038;sc=1&#038;path=%2F&#038;rev=\\1" target="_blank"&gt;\\1&lt;/a&gt;';
	} else {
		$t_file_replace_with = "\$t_status['\\2'].': \\3 - '.\$t_svn_web.\$t_svn_web_file_page.'?repname='.\$t_svn_web_repname.'&#038;sc=1&#038;path='.urlencode('/\\3').'&#038;rev=\\1'";
		$t_rev_replace_with  = 'Revision: \\1 - '.$t_svn_web.'listing.php?repname='.$t_svn_web_repname.'&#038;sc=1&#038;path=%2F&#038;rev=\\1';
	}
	
	# files
	$t_string = preg_replace( '/SVN:(\d+):([\w\s]{2})\s{2}([\/\w\.\s]+)/e', $t_file_replace_with, $t_string );
	
	# revisions
	$t_string = preg_replace( '/^SVN:Revision:\s*(\d+)/m', $t_rev_replace_with, $t_string );
	
	return $t_string;
}
# --------------------
</pre></blockquote>
<p>&#160;</p>
<p>
Now edit <tt>mantis/config_inc.php</tt> and add the following:
</p>
<blockquote><pre>
# --- Source Control --------------
# Account to be used by the source control script.
$g_source_control_account = 'svn';

#
$g_source_control_notes_view_status = VS_PUBLIC;

# Regular expression used to detect issue ids within checkin comments.
$g_source_control_regexp  = '/\bMantis ID #(\d+)\b/i';


# --- SVN linking ---------------
# Converts SVN filenames into URLs pointing to your WebSVN server
# (e.g.: 'SVN:513:trunk/myproject/readme.txt')
# 
# insert the URL to your WebSVN server
# eg: http://www.mydomain.org/WebSVN/
# (include trailing slash, no php filename)
$g_svn_web		= 'http://yourserver/websvn/';

# the WebSVN name of the repository
# (WebSVNs $config->addRepository())
$g_svn_web_repname      = 'Default';

# when showing a file, WebSVN can either display
# a diff with the previous version (ON) or
# the whole file contents (OFF).
$g_svn_web_showdiff      = ON;
</pre></blockquote>
<p>&#160;</p>
<p>
Phew, that was quite a lot of work, but we&#8217;re all most done! What we have just done is modify Mantis to parse commit messages from Subversion and if the message contains &quot;<tt>[Mantis ID: #n]</tt>&quot; it will automatically add a new note to the corresponding issue containing the commit message and add hyperlinks to WebSVN to view diffs for all the modified files.
</p>
<p>&#160;</p>


<a name="add-hook">&#160;</a>
<h3>3. Add a Subversion Post-Commit Hooks</h3>
<p>
Before Mantis can parse our Subversion commit messages we actually need to tell Subversion to pass them to Mantis which we do using a Subversion post-commit hook. The post commit-hook is simply a shell script that Subversion executes after a commit has been made to the repository. The commit-hook is based on the one found here: <a href="http://www.mantisbt.org/bugs/view.php?id=8070">http://www.mantisbt.org/bugs/view.php?id=8070</a>. It takes the repository location and revision ID and then uses the &quot;<tt>svnlook</tt>&quot; command to lookup the commit message and list of modified files. It then constructs a message that is passed to Mantis by calling it&#8217;s &quot;<tt>checkip.php</tt>&quot; script. 
</p><p>
Create the file <tt>/var/lib/svn/hooks/post-commit</tt> and add the following:
</p>
<blockquote><pre>
#!/bin/sh
REPOS="$1"
REV="$2"

SVNLOOK=/usr/bin/svnlook
PHP=/usr/bin/php
MANTIS=/var/www/mantis/scripts/checkin.php

COMMIT_MSG=`$SVNLOOK log -r $REV "$REPOS"`
CHANGED_FILES=`$SVNLOOK changed -r $REV "$REPOS" | sed s/^/SVN:$REV:/`

$PHP -f $MANTIS &lt;&lt;zzzMantiszzz
$COMMIT_MSG

--- Changed Files ---
SVN:Revision: $REV
$CHANGED_FILES
zzzMantiszzz
</pre></blockquote>
<p>
Be sure to make the script executable with<br/>
<tt>&#160;&#160;&#160;chmod a+x /var/lib/svn/hooks/post-commit</tt>
</p>
<p>&#160;</p>
<p>Now when we make a commit that contains &quot;<tt>[Mantis ID: #n]</tt>&quot; a new note will automatically be added to the Mantis issue:</p>
<div style="text-align:center;">
<img src="/wp-content/images/blog/mantis-note.png" width="940" height="127" alt="Mantis note."/>
</div>
<p>&#160;</p>


<a name="install-subclipse">&#160;</a>
<h3>4. Installing Subclipse</h3>
<p>
Eclipse already has support for CVS under the Team menu. <a href="http://subclipse.tigris.org/">Subclipse</a> is plug-in that adds a Team Provider for Subversion. This allows checking in and out straight from Eclipse!
</p>
<div style="text-align: center;">
<img src="/wp-content/images/blog/subclipse.png" width="741" height="582" alt="Subclipse screenshot"/>
</div>
<p>
The easiest way to install Subclipse is to go to the &quot;Software Updates and Add-ons&quot; and add a new site: <a href="http://subclipse.tigris.org/update_1.6.x">http://subclipse.tigris.org/update_1.6.x</a>. More detailed <a href="http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA">installation instructions</a> are available on the Subclipse website.
</p>
<p>
To set a project up to use Subversion do the following:</p>
<ul>
<li>Create a new project in Eclipse, or open an existing one.</li>
<li>Right-click on it and select &quot;<tt>Team-&gt;Share Project...</tt>&quot; from the pop-up menu.</li>
<li>Select &quot;<tt>SVN</tt>&quot; as the repository type.</li>
<li>Set the repository location as &quot;<tt>svn+ssh://yourserver/var/lib/svn</tt>&quot;.</li>
<li>Finally select a name for the project and perform the initial commit.</li>
</ul>
<p>&#160;</p>


<a name="add-bugtraqprops">&#160;</a>
<h3>5. Adding BugTraq Properties</h3>
<p>
Currently to link a commit to a Mantis issue we have to include &quot;<tt>[Mantis ID: #n]</tt>&quot; somewhere in our commit message. Using BugTraq properties we can get Subclipse to automatically provide a extra input field for the Mantis issue ID which is separate from the commit message. Additionally Subclipse can even provide a warning message if we forget to enter a Mantis issue ID.
</p><p>
Subversion properties are &quot;metadata&quot; that can be attached to files and directories. This metadata is primarily intended to be used as processing directives by client applications (e.g. Subclipse). BugTraq is a set of properties for a standardized way of integrating Subversion clients and third party bug tracking software. The original spec can be found at: <a href="http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/doc/issuetrackers.txt">http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/doc/issuetrackers.txt</a> (You’ll be prompted for user id and password, use &quot;guest&quot; with no password).
</p><p>
The main properties that I am using are:</p>
<ul>
<li><tt>bugtraq:url</tt> &#8211; <i>This is the URL to the Mantis issue page.</i></li>
<li><tt>bugtraq:label</tt> &#8211; <i>This is the text that Subclipse will show when asking for the issue ID.</i></li>
<li><tt>bugtraq:message</tt> &#8211; <i>This is the text that will be appended to the commit message.</i></li>
<li><tt>bugtraq:warnifnoissue</tt> &#8211; <i>This can be set to display a warning if no issue ID is entered.</i></li>
</ul>
<p>
These properties must be set on the top level directory of each project in the Subversion repository. These properties can be added to a project using Subclipse by right-clicking on the project and selecting &quot;<tt>Team-&gt;Set Property...</tt>&quot;. This action needs to be performed several times to add the following properties:
</p>
<blockquote><pre>
bugtraq:url             http://yourserver/mantis/view.php?id=%BUGID%
bugtraq:label           Mantis ID:
bugtraq:message         [Mantis ID #%BUGID%]
bugtraq:warnifnoissue   true
</pre></blockquote>
<p>
Now when you perform a commit from Eclipse the commit dialog will have a text field for you to type in the Mantis issue ID. Eclipse will then take care of adding the magic &quot;<tt>[Mantis ID #n]</tt>&quot; tag to your commit message.
</p>
<div style="text-align: center;">
<img src="/wp-content/images/blog/subclipse-commit.png" width="552" height="546" alt="Subclipse screenshot"/>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.uk-dave.com/2009/05/integrating-subversion-mantis-and-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
