User: jbirch
Date: 2010/01/10 10:47 AM
Added:
/SolutionTransform/trunk/SolutionTransform.Tests/
RenameTests.cs
/SolutionTransform/trunk/SolutionTransform/
FilePath.cs
/SolutionTransform/trunk/SolutionTransform/ProjectFile/
ChangeOutputPaths.cs, LocalizeGACedReferences.cs
/SolutionTransform/trunk/SolutionTransform/Solutions/
ExternalSolutionApi.cs
Modified:
/SolutionTransform/trunk/
SolutionTransform.sln
/SolutionTransform/trunk/Scripts/
CastleSilverlight.boo
/SolutionTransform/trunk/SolutionTransform.Tests/
SolutionRoundTrip.cs, SolutionTransform.Tests.csproj, StandardizationTest.cs,
TargetTests.cs
/SolutionTransform/trunk/SolutionTransform/
Program.cs, RegexRename.cs, SolutionTransform.csproj, StandardTransforms.cs,
TextReaderHelper.cs, XmlFile.cs
/SolutionTransform/trunk/SolutionTransform/CodingStandards/
IStandardizer.cs, StandardizeTransform.cs, Standardizer.cs
/SolutionTransform/trunk/SolutionTransform/ProjectFile/
MainSilverlightTransform.cs, RebaseAssemblies.cs
/SolutionTransform/trunk/SolutionTransform/Solutions/
CompositeCommand.cs, ExcludeCommand.cs, ISolutionCommand.cs, SolutionFile.cs,
SolutionFile2.cs, SolutionFileParser.cs, SolutionProject.cs, TransformCommand.cs
Log:
Fixed NUnit test. Also restructured FilePath handling and added NUnit tests.
Also, renames are slightly improved now.
External API still isn't stable, however...
File Changes:
Directory: /SolutionTransform/trunk/SolutionTransform/CodingStandards/
======================================================================
File [modified]: IStandardizer.cs
Delta lines: +4 -4
===================================================================
---
SolutionTransform/trunk/SolutionTransform/CodingStandards/StandardizeTransform.cs
2010-01-06 18:49:16 UTC (rev 707)
+++
SolutionTransform/trunk/SolutionTransform/CodingStandards/StandardizeTransform.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -35,14 +35,14 @@
public override void DoApplyTransform(XmlFile xmlFile)
{
- string root = Path.GetDirectoryName(xmlFile.Path);
+ FilePath root = xmlFile.Path.Parent;
foreach (XmlElement compile in
xmlFile.Document.SelectNodes("//x:compi...@include]", namespaces))
{
string include =
compile.GetAttribute("Include");
if (CSharp.IsMatch(include) &&
!AssemblyInfo.IsMatch(include))
{
- var filePath = Path.Combine(root,
include);
- if (File.Exists(filePath))
+ var filePath = root.File(include);
+ if (File.Exists(filePath.Path))
{
var content =
filePath.FileContent();
var transformed =
standardizer.Standardize(filePath, content);
@@ -50,7 +50,7 @@
{
continue;
}
- using (var writer = new
StreamWriter(filePath, false))
+ using (var writer = new
StreamWriter(filePath.Path, false))
{
writer.Write(transformed);
File [modified]: StandardizeTransform.cs
Delta lines: +2 -2
===================================================================
--- SolutionTransform/trunk/SolutionTransform/CodingStandards/Standardizer.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/CodingStandards/Standardizer.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -17,7 +17,7 @@
using System.Collections.Generic;
using System.IO;
- class Standardizer : IStandardizer {
+ class Standardizer : IStandardizer {
private readonly string licenseHeader;
private readonly int tabSize;
@@ -27,7 +27,7 @@
this.tabSize = tabSize;
}
- public string Standardize(string path, string code) {
+ public string Standardize(FilePath path, string code) {
var result = InternalStandardize(code);
if (result != InternalStandardize(result)) {
File [modified]: Standardizer.cs
Delta lines: +105 -0
===================================================================
--- SolutionTransform/trunk/SolutionTransform/FilePath.cs
(rev 0)
+++ SolutionTransform/trunk/SolutionTransform/FilePath.cs 2010-01-10
17:47:31 UTC (rev 708)
@@ -0,0 +1,106 @@
+using System.Diagnostics;
+using System.Text.RegularExpressions;
+
+namespace SolutionTransform
+{
+ [DebuggerDisplay("{path}")]
+ public class FilePath
+ {
+ private readonly string path;
+ private readonly bool isDirectory;
+ private readonly bool isAbsolute;
+
+ public FilePath(string path, bool isDirectory) : this(path,
isDirectory, path.Contains(":") || path.StartsWith("\\"))
+ {
+
+ }
+ public FilePath(string path, bool isDirectory, bool isAbsolute)
+ {
+ this.path = path;
+ this.isDirectory = isDirectory;
+ this.isAbsolute = isAbsolute;
+ if (path.EndsWith(".sln") && isDirectory)
+ {
+ int x = 0;
+ }
+ }
+
+
+ public bool IsDirectory
+ {
+ get { return isDirectory; }
+ }
+
+ public string Path {
+ get {
+ return path;
+ }
+ }
+
+ public FilePath File(string fileName)
+ {
+ if (!isDirectory)
+ {
+ return Parent.File(fileName);
+ }
+ return new FilePath(System.IO.Path.Combine(path, fileName), false,
isAbsolute);
+ }
+
+ public FilePath Directory(string directoryName) {
+ if (!isDirectory) {
+ return Parent.Directory(directoryName);
+ }
+ return new FilePath(System.IO.Path.Combine(path, directoryName),
true, isAbsolute);
+ }
+
+ public FilePath ToAbsolutePath(FilePath from) {
+ if (isAbsolute)
+ {
+ return this;
+ }
+ if (!from.isDirectory)
+ {
+ return ToAbsolutePath(from.Parent);
+ }
+ return new FilePath(System.IO.Path.Combine(from.Path, this.Path),
this.IsDirectory, true);
+ }
+
+ public FilePath PathFrom(FilePath from) {
+ if (!from.isDirectory)
+ {
+ return PathFrom(from.Parent);
+ }
+ if (isAbsolute)
+ {
+ return new FilePath(WorkOutRelativePath(from.Path, this.Path,
0), this.IsDirectory, false);
+ }
+ return this;
+ }
+
+ public FilePath Parent
+ {
+ get
+ {
+ var parentPath = System.IO.Path.GetDirectoryName(Path);
+ if (parentPath == null)
+ {
+ return null;
+ }
+ return new FilePath(parentPath, true, isAbsolute);
+ }
+ }
+
+ static string WorkOutRelativePath(string from, string to, int
directoriesUp) {
+ var match = Regex.Match(to, Regex.Escape(from));
+ if (match == Match.Empty) {
+ return
WorkOutRelativePath(System.IO.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);
+ }
+ }
Directory: /SolutionTransform/trunk/SolutionTransform/ProjectFile/
==================================================================
File [added]: ChangeOutputPaths.cs
Delta lines: +32 -0
===================================================================
---
SolutionTransform/trunk/SolutionTransform/ProjectFile/LocalizeGACedReferences.cs
(rev 0)
+++
SolutionTransform/trunk/SolutionTransform/ProjectFile/LocalizeGACedReferences.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -0,0 +1,33 @@
+using System.Xml;
+
+namespace SolutionTransform.ProjectFile
+{
+// ReSharper disable InconsistentNaming
+ public class LocalizeGACedReferences : MSBuild2003Transform
+// ReSharper restore InconsistentNaming
+ {
+ public override void DoApplyTransform(XmlDocument document)
+ {
+ var references =
document.SelectNodes("/*/x:ItemGroup/x:Reference", namespaces);
+ foreach (XmlElement reference in references)
+ {
+ if (reference.GetAttribute("Include") == "mscorlib")
+ {
+ continue; // We need to process everything except mscorlib
+ }
+ var copyLocal = GetCopyLocal(reference);
+ copyLocal.InnerText = "True";
+ }
+ }
+
+ private XmlElement GetCopyLocal(XmlNode reference)
+ {
+ var result = reference.SelectSingleNode("x:Private", namespaces);
+ if (result == null)
+ {
+ return AddElement(reference, "Private");
+ }
+ return (XmlElement) result;
+ }
+ }
File [added]: LocalizeGACedReferences.cs
Delta lines: +2 -0
===================================================================
---
SolutionTransform/trunk/SolutionTransform/ProjectFile/MainSilverlightTransform.cs
2010-01-06 18:49:16 UTC (rev 707)
+++
SolutionTransform/trunk/SolutionTransform/ProjectFile/MainSilverlightTransform.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -39,6 +39,8 @@
var flavour = AddElement(vs, "FlavorProperties");
flavour.SetAttribute("GUID",
"{A1591282-1198-4647-A2B1-27E5FF5F6F3B}");
var spp = AddElement(flavour,
"SilverlightProjectProperties");
+
+ Delete(document.DocumentElement, "//x:RequiredTargetFramework");
}
}
File [modified]: MainSilverlightTransform.cs
Delta lines: +6 -26
===================================================================
--- SolutionTransform/trunk/SolutionTransform/ProjectFile/RebaseAssemblies.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/ProjectFile/RebaseAssemblies.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -3,15 +3,15 @@
using System.IO;
using System.Linq;
using System.Text;
-using System.Text.RegularExpressions;
using System.Xml;
using SolutionTransform.Solutions;
namespace SolutionTransform.ProjectFile
{
+
public class RebaseAssemblies : MSBuild2003Transform
{
- private readonly IEnumerable<string> absolutePaths;
+ private readonly IEnumerable<FilePath> absolutePaths;
public RebaseAssemblies(string basePath, params string[] relativePaths)
: this(basePath, (IEnumerable<string>)relativePaths)
@@ -21,8 +21,8 @@
public RebaseAssemblies(string basePath, IEnumerable<string>
relativePaths)
{
- var solutionDirectory = basePath;
- this.absolutePaths = relativePaths.Select(p => p.Contains(":") ? p
: Path.Combine(solutionDirectory, p)).ToList();
+ var solutionDirectory = new FilePath(basePath, true);
+ this.absolutePaths = relativePaths.Select(p => (new FilePath(p,
true)).ToAbsolutePath(solutionDirectory)).ToList();
}
public override void DoApplyTransform(XmlFile xmlFile)
@@ -31,7 +31,7 @@
foreach (XmlElement hintPath in
xmlFile.Document.SelectNodes("//x:HintPath", namespaces))
{
var fileName = Path.GetFileName(hintPath.InnerText);
- var directory = absolutePaths.FirstOrDefault(p =>
File.Exists(Path.Combine(p, fileName)));
+ var directory = absolutePaths.FirstOrDefault(p =>
File.Exists(p.File(fileName).Path));
if (directory == null)
{
var error = string.Format("Couldn't rebase {0}.",
hintPath.InnerText);
@@ -41,33 +41,13 @@
} else
{
- var relative =
RelativePath(Path.GetDirectoryName(xmlFile.Path), Path.Combine(directory,
fileName));
+ var relative =
directory.File(fileName).PathFrom(xmlFile.Path).Path;
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]: RebaseAssemblies.cs
Delta lines: +22 -10
===================================================================
--- SolutionTransform/trunk/SolutionTransform/RegexRename.cs 2010-01-06
18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/RegexRename.cs 2010-01-10
17:47:31 UTC (rev 708)
@@ -1,25 +1,33 @@
+using System.IO;
using System.Text.RegularExpressions;
namespace SolutionTransform {
- public class RegexRename : IRename {
- private readonly Regex pattern;
+ public class StandardRename : IRename {
+ private readonly string delimiter;
private readonly string replacement;
- public RegexRename(string pattern, string replacement)
- : this (new Regex(pattern, RegexOptions.IgnoreCase), replacement)
+ public StandardRename(string replacement, string delimiter)
+
{
-
+ this.replacement = replacement;
+ this.delimiter = delimiter;
}
- public RegexRename(Regex pattern, string replacement)
+
+ public StandardRename(string replacement)
+ : this(replacement.Substring(1), replacement.Substring(0, 1))
{
- this.pattern = pattern;
- this.replacement = replacement;
+
}
public string RenameCsproj(string csproj)
{
- return pattern.Replace(csproj, replacement);
+ string name = Path.GetFileNameWithoutExtension(csproj);
+ string newFileName = string.Concat(
+ RenameProjectName(name)
+ ,Path.GetExtension(csproj))
+ ;
+ return Path.Combine(Path.GetDirectoryName(csproj), newFileName);
}
public string RenameSln(string solutionPath)
@@ -33,7 +41,11 @@
public string RenameProjectName(string name)
{
- return name + replacement;
+ int index = name.IndexOf(delimiter);
+ return string.Concat(
+ index < 0 ? name : name.Substring(0, index)
+ , string.IsNullOrEmpty(replacement) ? "" : delimiter
+ , replacement);
}
}
Directory: /SolutionTransform/trunk/Scripts/
============================================
File [modified]: CastleSilverlight.boo
Delta lines: +1 -1
===================================================================
--- SolutionTransform/trunk/SolutionTransform/CodingStandards/IStandardizer.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/CodingStandards/IStandardizer.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -16,6 +16,6 @@
{
public interface IStandardizer
{
- string Standardize(string path, string code);
+ string Standardize(FilePath path, string code);
}
Directory: /SolutionTransform/trunk/SolutionTransform/
======================================================
File [added]: FilePath.cs
Delta lines: +16 -15
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Program.cs 2010-01-06
18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Program.cs 2010-01-10
17:47:31 UTC (rev 708)
@@ -26,34 +26,35 @@
public static ExternalSolutionApi GetSolutionFile(string path)
{
var parser = new SolutionFileParser();
- return new ExternalSolutionApi(parser.Parse(path,
path.FileContent().AsLines()));
+ var filePath = new FilePath(path, false);
+ return new ExternalSolutionApi(parser.Parse(filePath,
filePath.FileContent().AsLines()));
}
- public static string FullPath(string file)
+ public static FilePath FullPath(string file)
{
if (file.Contains("\\"))
{
if (file.Contains(":"))
{
- return file;
+ return new FilePath(file, false);
}
- return Path.Combine(GetCurrentPath(), file);
+ return GetCurrentPath().File(file);
}
return FindScript(GetCurrentPath(), file);
}
- private static string FindScript(string path, string file)
+ private static FilePath FindScript(FilePath path, string file)
{
- string fullPath = Path.Combine(path, file);
- if (File.Exists(fullPath))
+ var searchPath = path.File(file);
+ if (File.Exists(searchPath.Path))
{
- return fullPath;
+ return searchPath;
}
- fullPath = Path.Combine(Path.Combine(path, "Scripts"), file);
- if (File.Exists(fullPath)) {
- return fullPath;
+ searchPath = path.Directory("Scripts").File(file);
+ if (File.Exists(searchPath.Path)) {
+ return searchPath;
}
- string parent = Path.GetDirectoryName(path);
+ var parent = path.Parent;
if (parent == null)
{
return null;
@@ -61,16 +62,16 @@
return FindScript(parent, file);
}
- public static string GetCurrentPath()
+ public static FilePath GetCurrentPath()
{
var executablePath = Assembly.GetExecutingAssembly().CodeBase;
return ToLocal(Path.GetDirectoryName(executablePath));
}
- static string ToLocal(string uriStyle)
+ static FilePath ToLocal(string uriStyle)
{
string result = uriStyle.Replace("/", "\\");
- return result.Substring(6);
+ return new FilePath(result.Substring(6), true);
}
File [modified]: Program.cs
Delta lines: +45 -0
===================================================================
--- SolutionTransform/trunk/SolutionTransform/ProjectFile/ChangeOutputPaths.cs
(rev 0)
+++ SolutionTransform/trunk/SolutionTransform/ProjectFile/ChangeOutputPaths.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -0,0 +1,46 @@
+using System;
+using System.Xml;
+
+namespace SolutionTransform.ProjectFile
+{
+ public class ChangeOutputPaths : MSBuild2003Transform
+ {
+ private readonly FilePath path;
+
+ public ChangeOutputPaths(string path) : this(new FilePath(path, true,
false))
+ {
+
+ }
+
+ public ChangeOutputPaths(FilePath path)
+ {
+ this.path = path;
+ }
+
+ public override void DoApplyTransform(XmlDocument document)
+ {
+ foreach (XmlElement outputPath in
document.SelectNodes("/*/x:PropertyGroup/x:OutputPath", namespaces))
+ {
+ var condition = ((XmlElement)
outputPath.ParentNode).GetAttribute("Condition");
+ var config = ExtractConfiguration(condition);
+ var newOutputPath = path.Directory(config).Path;
+ outputPath.InnerText = newOutputPath;
+ }
+ }
+
+ internal string ExtractConfiguration(string condition)
+ {
+ var pipeIndex = condition.LastIndexOf('|');
+ if (pipeIndex < 0)
+ {
+ throw new Exception(string.Format("Couldn't find a pipe symbol
in {0}", condition));
+ }
+ var prePipe = condition.Substring(0, pipeIndex);
+ var quoteIndex = prePipe.LastIndexOf('\'');
+ if (quoteIndex < 0) {
+ throw new Exception(string.Format("Couldn't find a quote
symbol before a pipe in {0}", condition));
+ }
+ return prePipe.Substring(quoteIndex + 1);
+ }
+ }
File [modified]: RegexRename.cs
Delta lines: +8 -5
===================================================================
--- SolutionTransform/trunk/SolutionTransform/SolutionTransform.csproj
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/SolutionTransform.csproj
2010-01-10 17:47:31 UTC (rev 708)
@@ -78,20 +78,23 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="CodingStandards\CastleStandardizer.cs" />
+ <Compile Include="CodingStandards\IStandardizer.cs" />
+ <Compile Include="CodingStandards\Standardizer.cs" />
+ <Compile Include="CodingStandards\StandardizeTransform.cs" />
<Compile Include="DontRename.cs" />
<Compile Include="IProjectFilter.cs" />
<Compile Include="IRename.cs" />
<Compile Include="ProjectFile\AddDefineConstant.cs" />
<Compile Include="ProjectFile\AddTarget.cs" />
<Compile Include="ProjectFile\AltDotNetTransform.cs" />
- <Compile Include="ProjectFile\CodingStandards\CastleStandardizer.cs" />
- <Compile Include="ProjectFile\CodingStandards\IStandardizer.cs" />
- <Compile Include="ProjectFile\CodingStandards\Standardizer.cs" />
- <Compile Include="ProjectFile\CodingStandards\StandardizeTransform.cs" />
+ <Compile Include="ProjectFile\ChangeOutputPaths.cs" />
<Compile Include="ProjectFile\DefineConstantTransform.cs" />
<Compile Include="Program.cs" />
<Compile Include="ProjectFile\CompositeTransform.cs" />
<Compile Include="ITransform.cs" />
+ <Compile Include="FilePath.cs" />
+ <Compile Include="ProjectFile\LocalizeGACedReferences.cs" />
<Compile Include="ProjectFile\MainSilverlightTransform.cs" />
<Compile Include="ProjectFile\MSBuild2003Transform.cs" />
<Compile Include="ProjectFile\NameTransform.cs" />
@@ -104,11 +107,11 @@
<Compile Include="RegexFilter.cs" />
<Compile Include="Solutions\CompositeCommand.cs" />
<Compile Include="Solutions\ExcludeCommand.cs" />
+ <Compile Include="Solutions\ExternalSolutionApi.cs" />
<Compile Include="Solutions\GlobalSection.cs" />
<Compile Include="Solutions\ISolutionCommand.cs" />
<Compile Include="Solutions\SolutionChapter.cs" />
<Compile Include="Solutions\SolutionFile.cs" />
- <Compile Include="Solutions\SolutionFile2.cs" />
<Compile Include="Solutions\SolutionFileParser.cs" />
<Compile Include="Solutions\SolutionProject.cs" />
File [modified]: SolutionTransform.csproj
Delta lines: +1 -1
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/CompositeCommand.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/CompositeCommand.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -11,7 +11,7 @@
this.underlying = underlying;
}
- public void Process(SolutionFile2 solutionFile)
+ public void Process(SolutionFile solutionFile)
{
foreach (var command in underlying)
File [modified]: StandardTransforms.cs
Delta lines: +2 -2
===================================================================
--- SolutionTransform/trunk/SolutionTransform/TextReaderHelper.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/TextReaderHelper.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -33,9 +33,9 @@
}
}
- public static string FileContent(this string path)
+ public static string FileContent(this FilePath path)
{
- using (var stream = new StreamReader(path)) {
+ using (var stream = new StreamReader(path.Path)) {
return stream.ReadToEnd();
}
File [modified]: TextReaderHelper.cs
Delta lines: +4 -4
===================================================================
--- SolutionTransform/trunk/SolutionTransform/XmlFile.cs 2010-01-06
18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/XmlFile.cs 2010-01-10
17:47:31 UTC (rev 708)
@@ -4,10 +4,10 @@
{
public class XmlFile
{
- private readonly string filePath;
+ private readonly FilePath filePath;
XmlDocument document;
- public XmlFile(string filePath)
+ public XmlFile(FilePath filePath)
{
this.filePath = filePath;
}
@@ -21,13 +21,13 @@
get {
if (document == null) {
document = new XmlDocument();
- document.Load(filePath);
+ document.Load(filePath.Path);
}
return document;
}
}
- public string Path
+ public FilePath Path
{
get { return filePath; }
File [modified]: XmlFile.cs
Delta lines: +17 -0
===================================================================
--- SolutionTransform/trunk/SolutionTransform.Tests/RenameTests.cs
(rev 0)
+++ SolutionTransform/trunk/SolutionTransform.Tests/RenameTests.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace SolutionTransform.Tests {
+ [TestFixture]
+ public class RenameTests {
+ [Test]
+ public void StandardRenameChangesDashExtension()
+ {
+ var rename = new StandardRename("-Silverlight");
+ var renamed = rename.RenameCsproj(@"Folder\Test-vs2008.csproj");
+ Assert.That(renamed,
Is.EqualTo(@"Folder\Test-Silverlight.csproj"));
+ }
+ }
Directory: /SolutionTransform/trunk/SolutionTransform.Tests/
============================================================
File [added]: RenameTests.cs
Delta lines: +6 -6
===================================================================
--- SolutionTransform/trunk/SolutionTransform.Tests/SolutionRoundTrip.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform.Tests/SolutionRoundTrip.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -3,9 +3,11 @@
using System.Linq;
using System.Text;
using SolutionTransform.Solutions;
+using NUnit.Framework;
namespace SolutionTransform.Tests {
- class SolutionRoundTrip {
+ [TestFixture]
+ public class SolutionRoundTrip {
string iocSolutionJan2010 = @"
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
@@ -59,15 +61,13 @@
EndGlobal
";
+ [Test]
public void CanRoundTripSolutionFile()
{
var parser = new SolutionFileParser();
- var solutionFile = parser.Parse("c:\\x.sln",
iocSolutionJan2010.AsLines());
+ var solutionFile = parser.Parse(new FilePath ("c:\\x.sln", false),
iocSolutionJan2010.AsLines());
var roundTripped = string.Join(Environment.NewLine,
solutionFile.Lines().ToArray()) + Environment.NewLine;
- if (roundTripped != iocSolutionJan2010)
- {
- throw new Exception("We have a problem");
- }
+ Assert.That(roundTripped, Is.EqualTo(iocSolutionJan2010),
"Roundtripping loading the solution should not have changed it at all.");
}
}
File [modified]: SolutionRoundTrip.cs
Delta lines: +5 -0
===================================================================
---
SolutionTransform/trunk/SolutionTransform.Tests/SolutionTransform.Tests.csproj
2010-01-06 18:49:16 UTC (rev 707)
+++
SolutionTransform/trunk/SolutionTransform.Tests/SolutionTransform.Tests.csproj
2010-01-10 17:47:31 UTC (rev 708)
@@ -31,6 +31,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="nunit.framework, Version=2.5.3.9345, Culture=neutral,
PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Lib\nunit.framework.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -45,6 +49,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="RenameTests.cs" />
<Compile Include="SolutionRoundTrip.cs" />
<Compile Include="StandardizationTest.cs" />
File [modified]: SolutionTransform.Tests.csproj
Delta lines: +4 -5
===================================================================
--- SolutionTransform/trunk/SolutionTransform.Tests/StandardizationTest.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform.Tests/StandardizationTest.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -2,11 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using NUnit.Framework;
using SolutionTransform.CodingStandards;
namespace SolutionTransform.Tests {
+ [TestFixture]
public class StandardizationTest {
-
+ [Test]
public void CompilerDirectivesOutsideOfNamespaceShouldBePreserved()
{
string file =
@@ -61,10 +63,7 @@
";
var standardizer = new CastleStandardizer();
var result = standardizer.Standardize(null, file);
- if (!result.Contains("#if"))
- {
- throw new Exception();
- }
+ Assert.IsTrue(result.Contains("#if"), "Preprocessor directive was
stripped. This is bad...");
}
}
File [modified]: StandardizationTest.cs
Delta lines: +4 -5
===================================================================
--- SolutionTransform/trunk/SolutionTransform.Tests/TargetTests.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform.Tests/TargetTests.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -3,9 +3,11 @@
using System.Linq;
using System.Text;
using System.Xml;
+using NUnit.Framework;
namespace SolutionTransform.Tests {
- class TargetTests {
+ [TestFixture]
+ public class TargetTests {
string iocTests = @"
<Project DefaultTargets=""Build""
xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""
ToolsVersion=""3.5"">
<PropertyGroup>
@@ -512,10 +514,7 @@
document.LoadXml(this.iocTests);
var remove = StandardTransforms.RemoveFlavourTargetsAndDefines();
remove.ApplyTransform(new XmlFile(document));
- if (document.OuterXml.Contains(".targets"))
- {
- throw new Exception();
- }
+ Assert.IsFalse(document.OuterXml.Contains(".targets"), "Targets
were not removed.");
}
}
}
File [modified]: TargetTests.cs
Delta lines: +1 -0
===================================================================
--- SolutionTransform/trunk/SolutionTransform.sln 2010-01-06 18:49:16 UTC
(rev 707)
+++ SolutionTransform/trunk/SolutionTransform.sln 2010-01-10 17:47:31 UTC
(rev 708)
@@ -12,6 +12,7 @@
Lib\Boo.Lang.Parser.dll = Lib\Boo.Lang.Parser.dll
Lib\Boo.Lang.PatternMatching.dll =
Lib\Boo.Lang.PatternMatching.dll
Lib\Boo.Lang.Useful.dll = Lib\Boo.Lang.Useful.dll
+ Lib\nunit.framework.dll = Lib\nunit.framework.dll
EndProjectSection
EndProject
Directory: /SolutionTransform/trunk/SolutionTransform/Solutions/
================================================================
File [modified]: CompositeCommand.cs
Delta lines: +1 -1
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/ExcludeCommand.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/ExcludeCommand.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -9,7 +9,7 @@
this.filter = filter;
}
- public void Process(SolutionFile2 solutionFile) {
+ public void Process(SolutionFile solutionFile) {
foreach (var project in solutionFile.Projects.ToList()) {
if (!filter.ShouldApply(project)) {
File [modified]: ExcludeCommand.cs
Delta lines: +44 -0
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/ExternalSolutionApi.cs
(rev 0)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/ExternalSolutionApi.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -0,0 +1,45 @@
+using System.Linq;
+using SolutionTransform.ProjectFile;
+
+namespace SolutionTransform.Solutions
+{
+ public class ExternalSolutionApi
+ {
+ private readonly SolutionFile solutionFile;
+
+ public ExternalSolutionApi(SolutionFile solutionFile)
+ {
+ this.solutionFile = solutionFile;
+ }
+
+ public void Transform(IRename rename, ISolutionCommand
solutionCommand) {
+ solutionCommand.Process(solutionFile);
+ var renameCommand = new TransformCommand(new DontFilter(), new
NameTransform(rename));
+ renameCommand.Process(solutionFile);
+
+ foreach (var project in solutionFile.Projects.Where(p =>
!p.IsFolder)) {
+ project.Name = rename.RenameSolutionProjectName(project.Name);
+ project.Path = new FilePath
(rename.RenameCsproj(project.Path.Path), false);
+
project.XmlFile.Document.Save(rename.RenameCsproj(project.XmlFile.Path.Path));
+ // Note that project.Path and project.XmlFile.Path have
different values....
+ }
+ solutionFile.Save(rename.RenameSln(solutionFile.FullPath.Path));
+ }
+
+ public void Transform(IRename rename, IProjectFilter filter,
ITransform transform) {
+ Transform(rename, new TransformCommand(filter, transform));
+ }
+
+ public void Transform(IRename rename, IProjectFilter filter, params
ITransform[] transforms) {
+ Transform(rename, filter, new CompositeTransform(transforms));
+ }
+
+ public string BasePath
+ {
+ get
+ {
+ return solutionFile.FullPath.Parent.Path;
+ }
+ }
+ }
File [added]: ExternalSolutionApi.cs
Delta lines: +1 -1
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/ISolutionCommand.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/ISolutionCommand.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -2,6 +2,6 @@
{
public interface ISolutionCommand
{
- void Process(SolutionFile2 solutionFile);
+ void Process(SolutionFile solutionFile);
}
File [modified]: ISolutionCommand.cs
Delta lines: +45 -113
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/SolutionFile.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/SolutionFile.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -1,129 +1,61 @@
-// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
using System.Text;
-namespace SolutionTransform.Solutions
-{
- /*
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Xml;
- using SolutionTransform.ProjectFile;
-
+namespace SolutionTransform.Solutions {
public class SolutionFile {
- private readonly string path;
- internal List<string> lines = new List<string>();
- internal List<SolutionProject> projects;
+ private readonly FilePath solutionPath;
+ List<string> preamble;
+ List<SolutionChapter> chapters;
- public SolutionFile(string path, string content) {
- this.path = path;
- lines.AddRange(content.AsLines());
- // .SkipWhile(l => l.TrimEnd().Length == 0)
- // The whole skipwhile thing is to deal with the blank
lines at the start of the Castle solution file
- projects = GetProjects().ToList();
- }
+ public SolutionFile(FilePath solutionPath, IEnumerable<string>
preamble, IEnumerable<SolutionChapter> chapters) {
+ this.solutionPath = solutionPath;
+ this.preamble = preamble.ToList();
+ this.chapters = chapters.ToList();
+ }
- public string FullPath
- {
- get { return path; }
- }
+ public IEnumerable<SolutionProject> Projects {
+ get { return chapters.OfType<SolutionProject>(); }
+ }
+ public IEnumerable<string> Lines() {
+ var result = new List<string>();
+ result.AddRange(preamble);
+ result.AddRange(chapters.SelectMany(c => c.Lines()));
+ return result;
+ }
- IEnumerable<SolutionProject> GetProjects() {
- int index = 0;
- foreach (var line in lines)
- {
- if (line.StartsWith("Project"))
- {
- yield return new SolutionProject(line,
index, this);
- }
- index++;
- }
- }
-
- public void Remove(SolutionProject solutionProject) {
- lines.RemoveRange(solutionProject.lineIndex, 2); //
Take out the end project as well
- foreach (var project in projects.Where(p => p.lineIndex
> solutionProject.lineIndex)) {
- project.lineIndex -= 2;
- }
- var regex = new Regex(solutionProject.Id.ToString(),
RegexOptions.IgnoreCase);
- lines.RemoveAll(regex.IsMatch);
- projects.Remove(solutionProject);
- }
-
- public void Add(SolutionProject solutionProject) {
- var insertLine = lines.FindLastIndex(l => l == "Global");
- lines.InsertRange(insertLine, solutionProject.Lines()); // Slap it
on the end where it won't do any damage
-
- lines.RemoveRange(solutionProject.lineIndex, 2); // Take out the
end project as well
- foreach (var project in projects.Where(p => p.lineIndex >
solutionProject.lineIndex)) {
- project.lineIndex -= 2;
+ internal GlobalChapter Globals {
+ get {
+ return chapters.OfType<GlobalChapter>().Single();
}
- var regex = new Regex(solutionProject.Id.ToString(),
RegexOptions.IgnoreCase);
- lines.RemoveAll(regex.IsMatch);
- projects.Remove(solutionProject);
}
- public void Transform(IRename rename, ISolutionCommand solutionCommand)
- {
- solutionCommand.Process(this);
- var renameCommand = new TransformCommand(new DontFilter(), new
NameTransform(rename));
- renameCommand.Process(this);
+ public FilePath FullPath {
+ get { return solutionPath; }
+ }
- foreach (var project in projects.Where(p => !p.IsFolder)) {
- project.Name = rename.RenameSolutionProjectName(project.Name);
- project.Path = rename.RenameCsproj(project.Path);
-
project.XmlFile.Document.Save(rename.RenameCsproj(project.XmlFile.Path));
- // Note that project.Path and project.XmlFile.Path have
different values....
- }
- Save(rename.RenameSln(path));
+ public void Remove(SolutionProject project) {
+ chapters.Remove(project);
+ Globals.ProjectConfigurationPlatforms.Remove(project);
}
- public void Transform(IRename rename, IProjectFilter filter,
ITransform transform)
- {
- Transform(rename, new TransformCommand(filter, transform));
- }
+ public void Add(SolutionProject project) {
+ chapters.Add(project);
+ Globals.ProjectConfigurationPlatforms.Add(project);
+ }
- public void Transform(IRename rename, IProjectFilter filter, params
ITransform[] transforms) {
- Transform(rename, filter, new
CompositeTransform(transforms));
- }
-
- private void Save(string destination)
- {
+ internal void Save(string destination) {
// 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))
- {
- writer.WriteLine(); // Guarantee a blank line
- foreach (var line in
lines.SkipWhile(string.IsNullOrEmpty)) // Skip any others
- {
- writer.WriteLine(line);
- }
- writer.Flush();
- }
- }
-
- internal string BasePath
- {
- get
- {
- return Path.GetDirectoryName(path);
- }
- }
- }
- */
+ using (var writer = new StreamWriter(destination, false,
Encoding.Unicode)) {
+ writer.WriteLine();
+ foreach (var line in Lines()) {
+ writer.WriteLine(line);
+ }
+ writer.Flush();
+ }
+ }
+ }
File [modified]: SolutionFile.cs
Delta lines: +4 -45
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/SolutionFile2.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/SolutionFile2.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -3,57 +3,16 @@
using System.IO;
using System.Linq;
using System.Text;
-using SolutionTransform.ProjectFile;
namespace SolutionTransform.Solutions
{
- public class ExternalSolutionApi
+ public class SolutionFile
{
- private readonly SolutionFile2 solutionFile;
-
- public ExternalSolutionApi(SolutionFile2 solutionFile)
- {
- this.solutionFile = solutionFile;
- }
-
- public void Transform(IRename rename, ISolutionCommand
solutionCommand) {
- solutionCommand.Process(solutionFile);
- var renameCommand = new TransformCommand(new DontFilter(), new
NameTransform(rename));
- renameCommand.Process(solutionFile);
-
- foreach (var project in solutionFile.Projects.Where(p =>
!p.IsFolder)) {
- project.Name = rename.RenameSolutionProjectName(project.Name);
- project.Path = rename.RenameCsproj(project.Path);
-
project.XmlFile.Document.Save(rename.RenameCsproj(project.XmlFile.Path));
- // Note that project.Path and project.XmlFile.Path have
different values....
- }
- solutionFile.Save(rename.RenameSln(solutionFile.FullPath));
- }
-
- public void Transform(IRename rename, IProjectFilter filter,
ITransform transform) {
- Transform(rename, new TransformCommand(filter, transform));
- }
-
- public void Transform(IRename rename, IProjectFilter filter, params
ITransform[] transforms) {
- Transform(rename, filter, new CompositeTransform(transforms));
- }
-
- public string BasePath
- {
- get
- {
- return Path.GetDirectoryName(solutionFile.FullPath);
- }
- }
- }
-
- public class SolutionFile2
- {
- private readonly string solutionPath;
+ private readonly FilePath solutionPath;
List<string> preamble;
List<SolutionChapter> chapters;
- public SolutionFile2(string solutionPath, IEnumerable<string>
preamble, IEnumerable<SolutionChapter> chapters)
+ public SolutionFile(FilePath solutionPath, IEnumerable<string>
preamble, IEnumerable<SolutionChapter> chapters)
{
this.solutionPath = solutionPath;
this.preamble = preamble.ToList();
@@ -81,7 +40,7 @@
}
}
- public string FullPath
+ public FilePath FullPath
{
get { return solutionPath; }
File [modified]: SolutionFile2.cs
Delta lines: +3 -4
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/SolutionFileParser.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/SolutionFileParser.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -6,17 +6,16 @@
namespace SolutionTransform.Solutions {
public class SolutionFileParser {
- public SolutionFile2 Parse(string solutionPath, IEnumerable<string>
lines) {
+ public SolutionFile Parse(FilePath solutionPath, IEnumerable<string>
lines) {
Func<string, bool> chapter = l => l.StartsWith("Project") ||
l.StartsWith("Global");
- var basePath = Path.GetDirectoryName(solutionPath);
var chapterLines = Split(lines, chapter).ToList();
var preamble = chapterLines[0];
chapterLines.RemoveAt(0);
- return new SolutionFile2(solutionPath, preamble,
chapterLines.Select(l => ParseChapter(basePath, l)));
+ return new SolutionFile(solutionPath, preamble,
chapterLines.Select(l => ParseChapter(solutionPath, l)));
}
- SolutionChapter ParseChapter(string basePath, List<string> lines) {
+ SolutionChapter ParseChapter(FilePath basePath, List<string> lines) {
SolutionChapter result = null;
var start = lines[0];
File [modified]: SolutionFileParser.cs
Delta lines: +10 -9
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/SolutionProject.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/SolutionProject.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -23,25 +23,26 @@
public class SolutionProject : SolutionChapter {
private Guid type;
private string name;
- private string path;
+ private FilePath path;
private XmlFile xmlFile;
private Guid id;
- public SolutionProject(string start, string end, string basePath) :
base(start, end) {
+ public SolutionProject(string start, string end, FilePath basePath) :
base(start, end) {
var components = start.Split('"');
type = new Guid(components[1]);
name = components[3];
- path = components[5];
- xmlFile = new XmlFile(System.IO.Path.Combine(basePath, path));
+ path = new FilePath(components[5], false);
+ xmlFile = new XmlFile(path.ToAbsolutePath(basePath));
id = new Guid(components[7]);
}
- public SolutionProject(string relativePath, string basePath, Guid
projectType) : base("", "EndProject")
+ public SolutionProject(FilePath relativePath, FilePath basePath, Guid
projectType)
+ : base("", "EndProject")
{
this.type = projectType;
- name = System.IO.Path.GetFileNameWithoutExtension(relativePath);
+ name =
System.IO.Path.GetFileNameWithoutExtension(relativePath.Path);
path = relativePath;
- xmlFile = new XmlFile(System.IO.Path.Combine(basePath, path));
+ xmlFile = new XmlFile(path.ToAbsolutePath(basePath));
id = ProjectGuid(xmlFile.Document);
WriteLineBack();
}
@@ -73,7 +74,7 @@
get { return id; }
}
- public string Path {
+ public FilePath Path {
get { return path; }
set { path = value; WriteLineBack(); }
}
@@ -94,7 +95,7 @@
return string.Format(@"Project(""{{{0}}}"") = ""{1}"",
""{2}"", ""{{{3}}}""",
Type.ToString().ToUpperInvariant(),
Name,
- Path,
+ Path.Path,
Id.ToString().ToUpperInvariant()
);
File [modified]: SolutionProject.cs
Delta lines: +2 -2
===================================================================
--- SolutionTransform/trunk/SolutionTransform/Solutions/TransformCommand.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/Solutions/TransformCommand.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -14,7 +14,7 @@
this.transform = transform;
}
- public void Process(SolutionFile2 solutionFile)
+ public void Process(SolutionFile solutionFile)
{
foreach (var project in
solutionFile.Projects.Where(filter.ShouldApply))
{
@@ -25,7 +25,7 @@
public class AddProjectCommand : ISolutionCommand
{
- public void Process(SolutionFile2 solutionFile)
+ public void Process(SolutionFile solutionFile)
{
throw new NotImplementedException();
File [modified]: TransformCommand.cs
Delta lines: +5 -4
===================================================================
--- SolutionTransform/trunk/SolutionTransform/StandardTransforms.cs
2010-01-06 18:49:16 UTC (rev 707)
+++ SolutionTransform/trunk/SolutionTransform/StandardTransforms.cs
2010-01-10 17:47:31 UTC (rev 708)
@@ -19,13 +19,13 @@
public class StandardTransforms
{
- public static ITransform SilverlightTransform()
+ public static ITransform Silverlight30Transform()
{
return new CompositeTransform(
new MainSolutionTransform(),
RemoveFlavourTargetsAndDefines(),
new AddDefineConstant("SILVERLIGHT"),
- new AddTarget(SilverlightTarget),
+ new AddTarget(Silverlight30Target),
new ReferenceMapTransform
{
{ "System", "mscorlib",
"system" },
@@ -34,11 +34,12 @@
{ "System.Web" },
{ "System.Configuration" },
{ "System.Runtime.Remoting" },
- }
+ },
+ new LocalizeGACedReferences()
);
}
- static readonly string SilverlightTarget =
@"$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets";
+ static readonly string Silverlight30Target =
@"$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets";
static readonly string CsharpTarget =
@"(MSBuildToolsPath)\Microsoft.CSharp.targets";
Directory: /SolutionTransform/trunk/
====================================
File [modified]: SolutionTransform.sln
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.