+2009-10-08 Ankit Jain <jankit@novell.com>
+
+ * DirectoryScanner.cs: Handle absolute paths. Fix to work
+ correctly on windows. Change order of adding paths to match
+ msbuild, useful to have.
+
2009-10-08 Ankit Jain <jankit@novell.com>
* TaskBatchingImpl.cs (ParseTaskAttributes): Parse attributes
ITaskItem[] includes;
string excludes;
ITaskItem[] matchedItems;
+
+ static bool _runningOnWindows;
+ static DirectoryScanner ()
+ {
+ PlatformID pid = Environment.OSVersion.Platform;
+ _runningOnWindows =((int) pid != 128 && (int) pid != 4 && (int) pid != 6);
+ }
+
public DirectoryScanner ()
{
}
includedItems.Add (include_item);
} else {
if (name.Split (Path.DirectorySeparatorChar).Length > name.Split (Path.AltDirectorySeparatorChar).Length) {
- separatedPath = name.Split (Path.DirectorySeparatorChar);
+ separatedPath = name.Split (new char [] {Path.DirectorySeparatorChar},
+ StringSplitOptions.RemoveEmptyEntries);
} else {
- separatedPath = name.Split (Path.AltDirectorySeparatorChar);
+ separatedPath = name.Split (new char [] {Path.AltDirectorySeparatorChar},
+ StringSplitOptions.RemoveEmptyEntries);
}
if (separatedPath.Length == 1 && separatedPath [0] == String.Empty)
return;
- fileInfo = ParseIncludeExclude (separatedPath, 0, baseDirectory);
+
+ int offset = 0;
+ if (Path.IsPathRooted (name)) {
+ if (!IsRunningOnWindows) {
+ baseDirectory = new DirectoryInfo ("/");
+ } else {
+ baseDirectory = new DirectoryInfo (separatedPath [0]);
+ offset = 1;
+ }
+ }
+
+ fileInfo = ParseIncludeExclude (separatedPath, offset, baseDirectory);
+
foreach (FileInfo fi in fileInfo) {
if (!excludedItems.ContainsKey (fi.FullName)) {
TaskItem item = new TaskItem (include_item);
excludedItems.Add (Path.GetFullPath (name), true);
} else {
if (name.Split (Path.DirectorySeparatorChar).Length > name.Split (Path.AltDirectorySeparatorChar).Length) {
- separatedPath = name.Split (Path.DirectorySeparatorChar);
+ separatedPath = name.Split (new char [] {Path.DirectorySeparatorChar},
+ StringSplitOptions.RemoveEmptyEntries);
} else {
- separatedPath = name.Split (Path.AltDirectorySeparatorChar);
+ separatedPath = name.Split (new char [] {Path.AltDirectorySeparatorChar},
+ StringSplitOptions.RemoveEmptyEntries);
}
if (separatedPath.Length == 1 && separatedPath [0] == String.Empty)
return;
- fileInfo = ParseIncludeExclude (separatedPath, 0, baseDirectory);
+
+ int offset = 0;
+ if (Path.IsPathRooted (name)) {
+ if (IsRunningOnWindows) {
+ // set base dir to drive:, and skip that
+ baseDirectory = new DirectoryInfo (separatedPath [0]);
+ offset = 1;
+ } else {
+ baseDirectory = new DirectoryInfo ("/");
+ }
+ }
+
+ fileInfo = ParseIncludeExclude (separatedPath, offset, baseDirectory);
foreach (FileInfo fi in fileInfo)
if (!excludedItems.ContainsKey (fi.FullName))
excludedItems.Add (fi.FullName, true);
while (currentDirectories.Count > 0)
{
DirectoryInfo current = currentDirectories.Pop();
- allDirectories.Add (current);
+ allDirectories.Insert (0, current);
foreach (DirectoryInfo dir in current.GetDirectories())
{
currentDirectories.Push(dir);
// No further directories shall be read
di = allDirectories.ToArray();
- } else
+ } else {
di = directory.GetDirectories (input [ptr]);
+ }
foreach (DirectoryInfo info in di) {
fi = ParseIncludeExclude (input, ptr + 1, info);
foreach (FileInfo file in fi)
get { return matchedItems; }
}
+ static bool IsRunningOnWindows {
+ get { return _runningOnWindows; }
+ }
}
}
+2009-10-08 Ankit Jain <jankit@novell.com>
+
+ * Items.cs (TestItemsWithWildcards): New.
+
2009-10-08 Ankit Jain <jankit@novell.com>
* Items.cs (TestItems5): Fix to work correctly on windows
Assert.AreEqual ("True", bi.GetEvaluatedMetadata ("M"), "A11");*/
}
+ [Test]
+ public void TestItemsWithWildcards ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+ MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
+ new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
+ engine.RegisterLogger (logger);
+
+ // Setup
+
+ string basedir = PathCombine ("Test", "resources", "dir");
+ string aaa = PathCombine ("a", "aa", "aaa");
+ string bb = Path.Combine ("b", "bb");
+
+ string[] dirs = { aaa, bb, "c" };
+ string [] files = {
+ PathCombine (basedir, aaa, "foo.dll"),
+ PathCombine (basedir, bb, "bar.dll"),
+ PathCombine (basedir, bb, "sample.txt"),
+ Path.Combine (basedir, "xyz.dll")
+ };
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <ItemGroup>
+ <ItemsRel Include='dir\**\*.dll' />
+ <ItemsRelExpanded Include=""@(ItemsRel->'%(FullPath)')"" />
+ <ItemsAbs Include='$(MSBuildProjectDirectory)\dir\**\*.dll' />
+ </ItemGroup>
+
+ <Target Name='Main'>
+ <Message Text=""ItemsRelExpanded: %(ItemsRelExpanded.Identity)""/>
+ <Message Text='ItemsAbs: %(ItemsAbs.Identity)'/>
+ </Target>
+ </Project>";
+
+ try {
+ CreateDirectoriesAndFiles (basedir, dirs, files);
+ string projectdir = Path.Combine ("Test", "resources");
+ File.WriteAllText (Path.Combine (projectdir, "wild1.proj"), documentString);
+ proj.Load (Path.Combine (projectdir, "wild1.proj"));
+ if (!proj.Build ("Main"))
+ Assert.Fail ("Build failed");
+
+ string full_base_dir = Path.GetFullPath (basedir);
+
+ foreach (string prefix in new string[] { "ItemsRelExpanded: ", "ItemsAbs: " }) {
+ logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, aaa, "foo.dll"),
+ MessageImportance.Normal, "A1");
+ logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, bb, "bar.dll"), MessageImportance.Normal, "A2");
+ logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, "xyz.dll"), MessageImportance.Normal, "A3");
+ }
+ } catch (AssertionException) {
+ logger.DumpMessages ();
+ throw;
+ } finally {
+ Directory.Delete (basedir, true);
+ }
+ }
+
[Test]
public void TestReservedMetadata ()
{
Assert.Fail ("Unexpected extra messages found");
}
}
+
+ void CreateDirectoriesAndFiles (string basedir, string[] dirs, string[] files)
+ {
+ foreach (string dir in dirs)
+ Directory.CreateDirectory (Path.Combine (basedir, dir));
+
+ foreach (string file in files)
+ File.WriteAllText (file, String.Empty);
+ }
+
+ string PathCombine (string path1, params string[] parts)
+ {
+ if (parts == null || parts.Length == 0)
+ return path1;
+
+ string final_path = path1;
+ foreach (string part in parts)
+ final_path = Path.Combine (final_path, part);
+
+ return final_path;
+ }
}
}