Monday, April 20, 2009

First experience with blog’s …

Since the blog community is such a big help in daily work, I wanted to see if I can give something back and also start a blog. I created one blogspot almost 3 years ago, but never followed up on it.

So – since I though I have something interesting to post, I gave it a try. I like good tools so I went on a mission to get my tools together. First step was to pick a place to host the blog. I have a web hosted environment on 1and1.com, so I tried their blog … don’t do it, that was the first disappointment. Wordpress.com was the next stop. For the heck of it, I couldn’t find a template that was NOT fixed wide. I hate those. What is the point of a wide screen monitor if only 750 pixels are used ? Especially since I would be posting code fragments.

Going back to blogspot – the templates are not any better, but after a lot of searching, try and error the one I used is at least not fixed width. I know it is ugly – but it serves the purpose.

Next stop – I like to see how it looks when I write. I read a lot of good things about Windows LiveWriter. The annoying part is that Microsoft REALLY want'’s you. If you not careful saying No to most of the components on the installer, it takes over your system …

It is actually a pretty good tool. Next stop was to find a way to pretty-print the source code fragments. What a odyssey – After trying numerous Plugin’s I settled for SyntaxHighlighter from Alex Gorbatchev along with SyntaxHighlighter for Windows Live Writer Plugin.

The post that really got me going was How to display code (nicely) in Blogger posts | techqi

And the most important information in there

Additionally, the code might include break tags before lines. In Blogger, go to Settings>Formatting and set 'Convert line breaks?' to No. (Note- this will remove line breaks throughout your previous posts as well, and you'll have to resort to pasting lots of double-break tags.) Unfortunately, this seems like the only solution at this point.

 

Sunday, April 19, 2009

Creating a Subversion Changelog via MSBuild …

The other day, I thought it would be a good idea to provide a generated ChangeLog for our integration builds. We are using TeamCity and MSBuild projects.
After searching for a while, I found only one solutions – svn2cl by Arthur de Jong. It is pretty straight forward, using the xml output of the svn log command and applying a XSL Stylesheet. It supports the standard GNU Changelog text format and a basic html formated one. The tool comes standard as a korn-shell script for Unix only, but luckily there is a windows port by Iwasa Kazmi using csript.
I could have just called the script via a <Exec> task, but this would have been no fun. The script uses the MSBuild Community Extensions.
In addition to just the Changelog I wanted to include
  1. Creation time
  2. The Subversion Repository root and revision
  3. HTML format with revision links back to our trac – changeset browser
  4. Embed the style sheet, so the generated html file is self sufficient
So – let’s get on with it. In your MSBuild project, import the “svn2cl.targets” project, set some properties and call the target or set a dependency.

How to use it

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

 <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
 <Import Project="./Build/svn2cl/svn2cl.targets"/>

 <PropertyGroup>
   <!-- pick up the workspace repository root or overwrite here -->
   <!--<Svn2clRepositoryPath> ... </Svn2clRepositoryPath>-->
   <!-- the marker ## will be replaced with the revision number -->
   <Svn2clRevisionLink>https://trac-location/trac/project/changeset/##/</Svn2clRevisionLink>
   <Svn2clLimit>100</Svn2clLimit>
   <Svn2clChangelogFile>./Changelog.html</Svn2clChangelogFile>
   <!-- by default take the current workspace revision -->
   <!--<Svn2clTopRevision>HEAD</Svn2clTopRevision>-->
 </PropertyGroup>

 <Target Name="BuildChangeLog" DependsOnTargets="SvnChangeLog"/>
</Project>

Repository information

I am using the SvnInfo task from the Community Extensions to determine information about the workspace.
    <!-- If Svn2clRepositoryPath is not set, get the information from the current working directory -->
   <SvnInfo LocalPath="$(MSBuildProjectDirectory)" Condition="$(Svn2clRepositoryPath) == ''">
     <Output TaskParameter="RepositoryPath" PropertyName="Svn2clRepositoryPath"/>
     <Output TaskParameter="Revision" PropertyName="Svn2clTopRevision"/>
   </SvnInfo>

   <Error Condition="$(Svn2clRepositoryPath) == ''" Text="Could not determine the Svn2clRepositoryPath"/>

Embed the CSS Style Sheet

I didn’t like the fact that the CSS Style sheet was just referenced, so I changed the XSLT to include it.
<!DOCTYPE xsl:stylesheet [
<!ENTITY newl "&#38;#xA;">
<!ENTITY space "&#32;">
<!ENTITY css SYSTEM "svn2html.css">
]>
...
<xsl:template match="log">
 <html>
  <head>
   <title><xsl:value-of select="string($title)" /></title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
       &css;
    </style>      
  </head>
  <body>

Subversion UID’s to real user names with email

The XSL can also read author information from a xml file and include them in the Changelog.
<?xml version="1.0" encoding="utf-8"?>
  <authors xmlns:html="http://www.w3.org/1999/xhtml">
   <author uid="bscholze">
     Bernd Scholze &lt;<html:a href="mailto:bscholze@gmail.com">bscholze@gmail.com</html:a>&gt;
  </author>
  <author uid="nobody">
     Who's this &lt;nobody@example.com&gt;
  </author>
</authors>
Download the MSBuild task.