Build all build.xml (.java) files under a directory

We needed to automate testing that all of the Java samples we ship compile properly. Doing this is pretty easy:

  1. Install the samples on a clean VM (that we revert back to the snapshot for each test run).
  2. Create a build.xml file that calls all the build.xml files installed.
  3. Use ant to run the genrated build.xml

Step 2 requires a means to generate the build.xml file. I wrote a simple program (attached) that does this.

using System; 
using System.IO; 
using System.Text; 
using System.Xml; 
using System.Xml.Linq; 

 

namespace BuildJavaTestScript 
{ 
    public class Program 
    { 
        /// <summary> 
        /// Build build.xml for all build.xml files in sub-directories. 
        /// </summary> 
        /// <param name="args">Optional: build.xml root_folder</param> 
        public static void Main(string[] args) 
        { 
            string projFile = Path.GetFullPath(args.Length > 0 ? args[0] : "build.xml"); 
            string rootDirectory = Path.GetFullPath(args.Length > 1 ? args[1] : Directory.GetCurrentDirectory()); 
            Console.Out.WriteLine(string.Format("Creating build file {0}", projFile)); 
            Console.Out.WriteLine(string.Format("Root directory {0}", rootDirectory)); 

 

            XDocument xdoc = new XDocument(); 
            XElement elementProject = new XElement("project"); 
            xdoc.Add(elementProject); 
            elementProject.Add(new XAttribute("name", "BuildAll")); 
            elementProject.Add(new XAttribute("default", "compile")); 

 

            XElement elementTarget = new XElement("target"); 
            elementProject.Add(elementTarget); 
            elementTarget.Add(new XAttribute("name", "compile")); 

 

            XElement elementEcho = new XElement("echo"); 
            elementTarget.Add(elementEcho); 
            elementEcho.Add(new XAttribute("message", "Build All: jdk = ${java.home}, version = ${java.version}")); 

 

            // add .sln files - recursively 
            AddBuildXmlFiles(elementTarget, rootDirectory, rootDirectory); 

 

            Console.Out.WriteLine("writing build file to disk"); 
            // no BOM 
            using (var writer = new XmlTextWriter(projFile, new UTF8Encoding(false))) 
            { 
                writer.Formatting = Formatting.Indented; 
                xdoc.Save(writer); 
            } 

 

            Console.Out.WriteLine("all done"); 
        } 

 

        private static void AddBuildXmlFiles(XElement elementTarget, string rootDirectory, string folder) 
        { 

 

            // add build.xml files 
            foreach (string fileOn in Directory.GetFiles(folder, "build.xml")) 
            { 
                string filename = Path.GetFileName(fileOn); 
                string workingFolder; 
                if (folder.StartsWith(rootDirectory)) 
                { 
                    workingFolder = folder.Substring(rootDirectory.Length).Trim(); 
                    if ((workingFolder.Length > 0) && (workingFolder[0] == Path.DirectorySeparatorChar || workingFolder[0] == Path.AltDirectorySeparatorChar)) 
                        workingFolder = workingFolder.Substring(1); 
                } 
                else 
                    workingFolder = folder; 
                if (workingFolder.Length == 0) 
                    continue; 

 

                XElement elementExec = new XElement("ant"); 
                elementExec.Add(new XAttribute("dir", workingFolder)); 
                elementExec.Add(new XAttribute("antfile", filename)); 
                elementTarget.Add(elementExec); 
            } 

 

            // look in sub-directories 
            foreach (string subDirectory in Directory.GetDirectories(folder)) 
                AddBuildXmlFiles(elementTarget, rootDirectory, subDirectory); 
        } 
    } 
}
Posted in Uncategorized | Comments Off on Build all build.xml (.java) files under a directory

Build all Solution (.SLN) files under a directory

We needed to automate testing that all of the C#, C++, and VB.NET samples we ship compile properly. Doing this is pretty easy:

  1. Install the samples on a clean VM (that we revert back to the snapshot for each test run).
  2. Create a .proj (MSBuild) file that compiles all the .SLN files installed.
  3. Run the .proj.

Step 2 requires a means to generate the .proj file. I wrote a simple program (attached) that does this.

using System; 
using System.IO; 
using System.Text; 
using System.Xml; 
using System.Xml.Linq; 

 

namespace BuildDotNetTestScript 
{ 
    /// <summary> 
    /// Builds a test script to compile all .sln files under the directory in. 
    /// </summary> 
    public class Program 
    { 
        private static readonly XNamespace xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"; 

 

        private enum VS_VER 
        { 
            VS_2005, 
            VS_2008, 
            VS_2010, 
            NONE 
        } 

 

        private static VS_VER vsVersion = VS_VER.NONE; 

 

        /// <summary> 
        /// Build TestAll.proj for all .sln files in this directory and sub-directories. 
        /// </summary> 
        /// <param name="args">Optional: [-VS2005 | -VS2008 | -VS2010] TestAll.proj root_folder</param> 
        public static void Main(string[] args) 
        { 

 

            int indexArgs = 0; 
            if (args.Length >= 1 && args[0][0] == '-') 
            { 
                indexArgs = 1; 
                switch (args[0].ToUpper().Trim()) 
                { 
                    case "-VS2005": 
                        vsVersion = VS_VER.VS_2005; 
                        break; 
                    case "-VS2008": 
                        vsVersion = VS_VER.VS_2008; 
                        break; 
                    case "-VS2010": 
                        vsVersion = VS_VER.VS_2010; 
                        break; 
                    default: 
                        Console.Error.WriteLine("Only options are -VS2005, -VS2008, or -VS2010"); 
                        Environment.Exit(1); 
                        return; 
                } 
            } 

 

            string projFile = Path.GetFullPath(args.Length > indexArgs ? args[indexArgs] : "TestAll.proj"); 
            string rootDirectory = 
                Path.GetFullPath(args.Length > indexArgs + 1 ? args[indexArgs + 1] : Directory.GetCurrentDirectory()); 
            Console.Out.WriteLine(string.Format("Creating project file {0}", projFile)); 
            Console.Out.WriteLine(string.Format("Root directory {0}", rootDirectory)); 

 

            XDocument xdoc = new XDocument(); 
            XElement elementProject = new XElement(xmlns + "Project"); 
            xdoc.Add(elementProject); 
            elementProject.Add(new XAttribute("DefaultTargets", "compile")); 
            elementProject.Add(new XAttribute("ToolsVersion", "3.5")); 

 

            XElement elementPropertyGroup = new XElement(xmlns + "PropertyGroup"); 
            elementProject.Add(elementPropertyGroup); 
            XElement elementDevEnv = new XElement(xmlns + "devenv"); 
            elementPropertyGroup.Add(elementDevEnv); 
            elementDevEnv.Value = "devenv.exe"; 

 

            XElement elementTarget = new XElement(xmlns + "Target"); 
            elementProject.Add(elementTarget); 
            elementTarget.Add(new XAttribute("Name", "compile")); 

 

            // add .sln files - recursively 
            AddSlnFiles(elementTarget, rootDirectory, rootDirectory); 

 

            Console.Out.WriteLine("writing project file to disk"); 
            // no BOM 
            using (var writer = new XmlTextWriter(projFile, new UTF8Encoding(false))) 
            { 
                writer.Formatting = Formatting.Indented; 
                xdoc.Save(writer); 
            } 

 

            Console.Out.WriteLine("all done"); 
        } 

 

        private static void AddSlnFiles(XElement elementTarget, string rootDirectory, string folder) 
        { 

 

            // add .sln files 
            foreach (string fileOn in Directory.GetFiles(folder, "*.sln")) 
            { 
                // .../JS/... is VS2005 
                bool isJSharp = fileOn.ToUpper().Replace('\\', '/').Contains("/JS/"); 
                bool versionMatch = true; 
                switch (vsVersion) 
                { 
                    case VS_VER.VS_2005: 
                        if ((!fileOn.ToUpper().Contains("VS2005")) && (! isJSharp)) 
                            versionMatch = false; 
                        break; 
                    case VS_VER.VS_2008: 
                        if (isJSharp || !fileOn.ToUpper().Contains("VS2008")) 
                            versionMatch = false; 
                        break; 
                    case VS_VER.VS_2010: 
                        if (isJSharp || !fileOn.ToUpper().Contains("VS2010")) 
                            versionMatch = false; 
                        break; 
                    default: 
                        if (isJSharp || fileOn.ToUpper().Contains("VS2005") || fileOn.ToUpper().Contains("VS2008") || fileOn.ToUpper().Contains("VS2010")) 
                            versionMatch = false; 
                        break; 
                } 
                if (!versionMatch) 
                    continue; 

 

                string command = string.Format("\"$(devenv)\" \"{0}\" /Rebuild", Path.GetFileName(fileOn)); 
                XElement elementExec = new XElement(xmlns + "Exec"); 
                elementExec.Add(new XAttribute("Command", command)); 

 

                string workingFolder; 
                if (folder.StartsWith(rootDirectory)) 
                { 
                    workingFolder = folder.Substring(rootDirectory.Length).Trim(); 
                    if ((workingFolder.Length > 0) && (workingFolder[0] == Path.DirectorySeparatorChar || workingFolder[0] == Path.AltDirectorySeparatorChar)) 
                        workingFolder = workingFolder.Substring(1); 
                } 
                else 
                    workingFolder = folder; 
                if (workingFolder.Length > 0) 
                    elementExec.Add(new XAttribute("WorkingDirectory", workingFolder)); 
                elementTarget.Add(elementExec); 
            } 

 

            // look in sub-directories 
            foreach (string subDirectory in Directory.GetDirectories(folder)) 
                AddSlnFiles(elementTarget, rootDirectory, subDirectory); 
        } 
    } 
}
Posted in Uncategorized | Comments Off on Build all Solution (.SLN) files under a directory

Goodbye Cody, We’ll Always Love You

Cody passed away Monday night due to cancer. He was an absolutely wonderful dog and we all miss him so much.

It’s amazing how close we get to our dogs and how much they mean to us. There are times I just lose it and start crying I miss him so much. The first couple of mornings after when I would go to open our bedroom door I found myself wishing so hard that when I opened it, he would still be there, tail wagging, so happy to see me wake up. He would run in the room to get a pet from my wife. Then back to me for me to pet him, then to the top of the stares looking at me to remind me it’s time to feed him.

Cody was a rescue dog. We got him when he was about 2 years old and he clearly had had a hard life up till then. He was scared of everything, would not bark, and wanted to stay in a crate most of the time. So we were very slow and quiet around him and treated him gently. My youngest daughter slept on the kitchen floor next to his crate the first couple of nights.

And he started to relax. After 2 months he barked for the first time (a very quiet bark) and we all congratulated him. After a couple more times telling him it was ok he started to bark regularly and he started to feel safe at home. He always remained somewhat nervous and I was the only adult male he was fully relaxed around, but he did get to the point where most of the time he was fine.

He was the most loving dog ever. When we were watching TV he would climb up on the couch and put his head in my wife’s lap. Both of them were so happy like that. Or I would be reading and he would come over, rest his head on my leg so I could pet him, and then lie down next to me happy to sleep there as I read. All he wanted was to be with us.

He wasn’t much of a retriever. We would take our 3 dogs to the park and the others would happily chase a ball for 30 minutes until they dropped. Cody would do it 2 or 3 times but then we would throw it again and we would get this look like “are you kidding me?” And he would then wander around looking for interesting things to smell.

He was super-friendly. Anytime we met others he wanted to say hi to them – the people and other dogs. At the dog park he would go around saying hi to all the other dogs. When a new dog showed up he would run over to introduce himself. That was the essence of Cody, wanting to be everyone’s friend.

We also got a 2nd rescue dog a couple of months after we got Cody so he wouldn’t be lonely during the day. Zoe was the opposite of Cody, not friendly toward other dogs and always going a million miles an hour. But the two of them became buddies and spent the day together. Mostly sleeping but they had each other for company and had lots of fun barking at the squirrels and bunnies in the yard.

One of my daughters got a puppy and at first he was a lot more energy than Cody wanted to handle. But he was a trooper putting up with Cooper, including one time Cooper launched through the error to land on Cody’s back and slide over him. But over time Cooper’s energy decreased a little and Cody got used to him and they would wrestle and play throughout the day. For the last couple of months Cody was no longer able to play and Cooper didn’t understand.

Two months ago we found out he had cancer. One that was very fast. So we had 2 months to say goodbye to him. I’m glad we had the time but it was way too short. We spoiled him rotten during that time and gave him even more hugs and attention. And he tried so hard to keep to his routine, but stairs became harder and harder for him and so he couldn’t follow us every time we went up or down the stairs. But he did manage to climb them every morning except that last 2 days to be at my door when I opened it in the morning.

And he was always there at the door barking like crazy when we got home so happy to see us. Moving a little slower but still there. Because that was the best part of the day to him, getting to see us.

Monday evening he couldn’t get up and was struggling to breathe. He was suffering really badly and stopping that was more important than our wanting a couple more days with him. We all got in the car with him riding in my wife’s lap. It was the hardest drive of my life to the vet. All I wanted to do was pull a U-turn and drive home with him. And he’s in the seat very happy because he’s going for a drive, he’s in my wife’s lap, and my daughters are petting him.

At the vet they have a nice room to say goodbye and we just hugged him and told him how much we loved him. I know we did this for quite a while but it seemed all too short. I then had to ask the vet to come in. God that was hard. When he went to give him the final shot I wanted to yell “give it to me instead.” So we held him and cried and said goodbye. And afterwards we held him some more and cried more. And then I couldn’t handle it anymore and had to leave the room.

The last 5 days have been rough. Opening the bedroom door each morning has me in tears. Anytime I would normally see him was really rough. But even at work, in the middle of programming, he would jump into my memories and I would have to stop work for a bit.

Dogs give us their hearts and their love completely and unreservedly. And in return we give them ours. And yet their lifespan is shorter than ours so we are the ones that have to say goodbye. And that hurts so bad. It’s not so much that we rescued Cody, it’s that he rescued us.

Cody, we’ll always remember you and always love you.

Posted in Uncategorized | Comments Off on Goodbye Cody, We’ll Always Love You