Thursday, 15 January 2009

Hands on Code: Modify Copy Directory Tree 1.1

Introduction
The first part of the title states Hands on Code and will prefix every post in which you can find a little tutorial on hacking open source projects.
Preface
At the moment of writing this post, cptree, a little utility I wrote for replicate directory tree structures, is marked 1.1 stable. This little command line tool consumes Command Line Parser Library 1.4 stable (from now libcmdline-{VERSION}).
Tutorial Purpose
In this tutorial we will upgrade cptree-1.1 to use libcmdline-1.5. Anyway this time we will remove the binary dependency of CommandLine.dll, merging its code with the source of cptree.exe.
Practice
Point your browser to cptree release 1.1 page and download cptree-1.1-stable-src.zip. Download also libcmdline-1.5-stable-src.zip from release 1.5 page of libcmdline.
Unzip cptree source in your project folder. Open the ThisAssembly.cs file located in {cptree-root}/src/Properties.
static class ThisAssembly
{
internal const string Name = "cptree";
internal const string Title = "cptree.exe";
internal const string Copyright = "Copyright (C) 2008 Giacomo Stelluti Scala";
internal const string Version = "1.1.0.0"; //stable
internal const string InformationalVersion = "1.1.0.0";
internal const string MajorMinorVersion = "1.1";
}

The last four fields should be modified as follows.

internal const string Copyright = "Copyright (C) 2008 - 2009 Giacomo Stelluti Scala, {Your-Name}";
internal const string Version = "1.1.0.5"; //stable (gsscoder.blogspot.com tutorial)
internal const string InformationalVersion = "1.1.0.5";

Open the CPTreeTool.cs file, located in the project root. Locate the Options nested type and search the following line inside the string GetUsage(void) method.
info.AddPreOptionsLine("  - Uses CommandLine.dll, Version 1.4 (http://www.codeplex.com/commandline).");

Replace this line of code with this other one.
info.AddPreOptionsLine("  - Includes Command Line Library Version 1.5 (http://www.codeplex.com/commandline).");

Now remove the dependency from CommandLine.dll. If you use some version of MS Visual Studio 2008 you're just one click away from the result.



















If you use NAnt Build Script you should remove the include tag with the CommandLine.dll string inside the name attribute. This tag is located inside the target tag marked build (attribute name="build").
Now create a CommandLine directory with a Tests subdirectory in the root of cptree. Decompress the libcmdline-1.5-stable-src.zip/CommandLine/src/libcmdline in a temporary folder. Move all the *Fixture.cs files to {cptree-root}/src/CommandLine/Tests and the remaining *.cs file to {cptree-root}/src/CommandLine (excluding AssemblyInfo.cs and ThisAssembly.cs).
If you use MS Visual Studio just press the Show All Files button in the project tree, select the CommandLine folder (should be white with dashed border) with the right mouse button and choose Include In Project menu item.
NAnt users have to modify the build scrirpt located in {cptree-root}/nant named default.build. If you are familiar with this tool you will not find difficulties including al *.cs file of the new .../CommandLine directory. If you want use the same condition to add .../CommandLine/Tests only if this kind of build is required. (I think it's take more time to explain than modify the script...)
Conclusion
With this little tutorial we have started learning to manage, modify and work with code written by other persons. I think this is one of the basis of open source.

The instructions published here are valid also for different project versions. If you want exercise, you could repeat this tutorial with older versions; for example you could merge cptree-1.0-alfa with libcmdline-1.3-stable. This is valid also for future versions: you'll be able to experiment how the next version of libcmdline will operate (and/or merge) with current (1.1-stable) or older versions of cptree.




For any problem don't esitate to contact me.
Good Job!

No comments:

Post a Comment