User: jbirch
Date: 2009/12/22 05:36 AM

Modified:
 /SolutionTransform/trunk/
 /SolutionTransform/trunk/Scripts/
  CastleSilverlight.boo
 /SolutionTransform/trunk/SolutionTransform.Tests/
  SolutionTransform.Tests.csproj
 /SolutionTransform/trunk/SolutionTransform/
  Program.cs, SolutionFile.cs
 /SolutionTransform/trunk/SolutionTransform/ProjectFile/
  RebaseAssemblies.cs

Log:
 Fixed Rebase Assemblies functionality.

Directory Changes:

Directory: /svn:ignore/
=======================

   + SolutionTransform.4.1.resharper.user
SolutionTransform.suo
_ReSharper.SolutionTransform


--- SolutionTransform/trunk/Scripts/CastleSilverlight.boo       2009-12-21 
11:32:19 UTC (rev 700)
+++ SolutionTransform/trunk/Scripts/CastleSilverlight.boo       2009-12-22 
12:36:51 UTC (rev 701)
@@ -1,10 +1,12 @@
 import SolutionTransform
 import System.Text.RegularExpressions
+import SolutionTransform.ProjectFile
 
 solution.Transform(
        RegexRename("-vs2008", "-Silverlight"),
        RegexFilter(["Castle.Core", "Castle.DynamicProxy", 
"Castle.MicroKernel", "Castle.Windsor"]), 
-       StandardTransforms.SilverlightTransform()
+       StandardTransforms.SilverlightTransform(),
+       RebaseAssemblies(solution, """..\lib\silverlight-3.0""")
        # ,StandardTransforms.CastleStandardsTransform()
 )
Directory: /SolutionTransform/trunk/
====================================

Property changes on: SolutionTransform/trunk
___________________________________________________________________

File Changes:

Directory: /SolutionTransform/trunk/SolutionTransform/ProjectFile/
==================================================================

File [modified]: RebaseAssemblies.cs
Delta lines: +8 -3
===================================================================

--- SolutionTransform/trunk/SolutionTransform/SolutionFile.cs   2009-12-21 
11:32:19 UTC (rev 700)
+++ SolutionTransform/trunk/SolutionTransform/SolutionFile.cs   2009-12-22 
12:36:51 UTC (rev 701)
@@ -37,9 +37,13 @@
                        projects = GetProjects().ToList();
                }
 
-               
+           public string FullPath
+           {
+               get { return path; }
+           }
 
-               IEnumerable<SolutionProject> GetProjects() {
+
+           IEnumerable<SolutionProject> GetProjects() {
                        int index = 0;
                        foreach (var line in lines)
                        {
@@ -95,7 +99,8 @@
             // NB Solution files will not load unless you save them as 
Unicode.  In particular, UTF8 doesn't work.
                        using (var writer = new StreamWriter(destination, 
false, Encoding.Unicode))
                        {
-                               foreach (var line in lines)
+                writer.WriteLine();  // Guarantee a blank line
+                               foreach (var line in 
lines.SkipWhile(string.IsNullOrEmpty)) // Skip any others
                                {
                                        writer.WriteLine(line);

Directory: /SolutionTransform/trunk/Scripts/
============================================

File [modified]: CastleSilverlight.boo
Delta lines: +42 -9
===================================================================

--- SolutionTransform/trunk/SolutionTransform/Program.cs        2009-12-21 
11:32:19 UTC (rev 700)
+++ SolutionTransform/trunk/SolutionTransform/Program.cs        2009-12-22 
12:36:51 UTC (rev 701)
@@ -15,6 +15,7 @@
 using System.IO;
 using System.Reflection;
 using System.Runtime.CompilerServices;
+using System.Text.RegularExpressions;
 
 [assembly:InternalsVisibleTo("SolutionTransform.Tests")]
 
@@ -71,21 +72,53 @@
             return result.Substring(6);
         }
 
-               public static void Main(string[] args)
+               public static int Main(string[] args)
                {
                        if (args.Length < 2) {
                                Console.WriteLine("Usage:  SolutionTransform 
<scriptPath> <solutionPath>");
                        } else
                        {
-                               var interpreter = new 
Boo.Lang.Interpreter.InteractiveInterpreter2();
-                               interpreter.SetValue("solution", 
GetSolutionFile(args[1]));
-                var script = FullPath(args[0]).FileContent();
-                               var context = interpreter.Eval(script);
-                               foreach (var e in context.Errors)
-                               {
-                                       Console.WriteLine(e.ToString());
-                               }
+                try
+                {
+
+                    var interpreter = new 
Boo.Lang.Interpreter.InteractiveInterpreter2();
+                    interpreter.SetValue("solution", GetSolutionFile(args[1]));
+                    string scriptFile = args[0];
+                    if (!scriptFile.Contains("."))
+                    {
+                        scriptFile += ".boo";
+                    }
+                    var script = FullPath(scriptFile).FileContent();
+
+                    var context = interpreter.Eval(script);
+                    foreach (var e in context.Errors)
+                    {
+                        Console.WriteLine(e.ToString());
+                    }
+                    if (context.Errors.Count != 0)
+                    {
+                        return 2;
+                    }
+               } catch (Exception ex) {
+                    WriteException(Console.Out, ex);
+                    return 1;
+                }
                        }
+            return 0;
                }
+
+        static void WriteException(TextWriter writer, Exception ex)
+        {
+            writer.WriteLine(ex.Message);
+            writer.WriteLine();
+            writer.WriteLine(ex.StackTrace);
+            var inner = ex.InnerException;
+            if (inner != null)
+            {
+                writer.WriteLine("======");
+                WriteException(writer, inner);
+            }
+            
+        }
        }

Directory: /SolutionTransform/trunk/SolutionTransform/
======================================================

File [modified]: Program.cs
Delta lines: +42 -17
===================================================================

--- SolutionTransform/trunk/SolutionTransform/ProjectFile/RebaseAssemblies.cs   
2009-12-21 11:32:19 UTC (rev 700)
+++ SolutionTransform/trunk/SolutionTransform/ProjectFile/RebaseAssemblies.cs   
2009-12-22 12:36:51 UTC (rev 701)
@@ -2,45 +2,70 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
 using System.Xml;
 
 namespace SolutionTransform.ProjectFile
 {
     public class RebaseAssemblies : MSBuild2003Transform
     {
-        private readonly IEnumerable<string> relativePaths;
+        private readonly IEnumerable<string> absolutePaths;
 
-        public RebaseAssemblies(IEnumerable<string> relativePaths)
+        public RebaseAssemblies(SolutionFile root, params string[] 
relativePaths) : this(root.FullPath, (IEnumerable<string>) relativePaths)
         {
-            this.relativePaths = relativePaths;
+            
         }
 
-        public override void DoApplyTransform(string path, XmlDocument 
document) {
+        public RebaseAssemblies(string solutionPath, IEnumerable<string> 
relativePaths)
+        {
+            var solutionDirectory = Path.GetDirectoryName(solutionPath);
+            this.absolutePaths = relativePaths.Select(p => p.Contains(":") ? p 
: Path.Combine(solutionDirectory, p)).ToList();
+        }
+
+        public override void DoApplyTransform(string path, XmlDocument 
document)
+        {
             // TODO: Centralize path hacking logic
-            var projectDirectory = Path.GetDirectoryName(path);
-            var paths = relativePaths.Select(
-                p => new
-                         {
-                             relative = p,
-                             absolute = p.Contains(":") ? p : 
Path.Combine(projectDirectory, p)
-                         }
-                ).ToList();
             foreach (XmlElement hintPath in 
document.SelectNodes("//x:HintPath", namespaces))
             {
                 var fileName = Path.GetFileName(hintPath.InnerText);
-                var directory = paths.FirstOrDefault(p => 
File.Exists(Path.Combine(p.absolute, fileName)));
+                var directory = absolutePaths.FirstOrDefault(p => 
File.Exists(Path.Combine(p, fileName)));
                 if (directory == null)
                 {
-                    hintPath.InnerText = Path.Combine(directory.relative, 
fileName);
+                    var error = string.Format("Couldn't rebase {0}.", 
hintPath.InnerText);
+                    var comment = hintPath.OwnerDocument.CreateComment(error);
+                    Console.WriteLine(error);
+                    hintPath.ParentNode.AppendChild(comment);
+                    
                 } else
                 {
-                    var comment = hintPath.OwnerDocument.CreateComment(
-                        string.Format("Couldn't rebase {0}.", 
hintPath.InnerText));
-                    hintPath.ParentNode.AppendChild(comment);
+                    var relative = RelativePath(Path.GetDirectoryName(path), 
Path.Combine(directory, fileName));
+                    hintPath.InnerText = relative;
                 }
             }
         }
 
+        static string RelativePath(string from, string to)
+        {
+            return RelativePath(from, to, 0);
+        }
+
+        static string RelativePath(string from, string to, int directoriesUp)
+        {
+            var match = Regex.Match(to, Regex.Escape(from));
+            if (match == Match.Empty)
+            {
+                return RelativePath(Path.GetDirectoryName(from), to, 
directoriesUp+1);
+            }
+            var result = new string[directoriesUp+1];
+            for (int index = 0; index < directoriesUp; index++)
+            {
+                result[index] = "..";
+            }
+            result[directoriesUp] = to.Substring(match.Length+1);
+            return string.Join("\\", result);
+        }
+
         public override void DoApplyTransform(XmlDocument document)
         {

File [modified]: SolutionFile.cs
Delta lines: +1 -1
===================================================================

--- 
SolutionTransform/trunk/SolutionTransform.Tests/SolutionTransform.Tests.csproj  
    2009-12-21 11:32:19 UTC (rev 700)
+++ 
SolutionTransform/trunk/SolutionTransform.Tests/SolutionTransform.Tests.csproj  
    2009-12-22 12:36:51 UTC (rev 701)
@@ -49,7 +49,7 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference 
Include="..\..\SolutionTransform\SolutionTransform.csproj">
+    <ProjectReference Include="..\SolutionTransform\SolutionTransform.csproj">
       <Project>{F37F9843-2A33-48A4-8D90-81277E0FBAC8}</Project>
       <Name>SolutionTransform</Name>

Directory: /SolutionTransform/trunk/SolutionTransform.Tests/
============================================================

File [modified]: SolutionTransform.Tests.csproj
Delta lines: +0 -0
===================================================================

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-commits?hl=en.


Reply via email to