Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@ -27,6 +27,7 @@
//
using System;
using System.IO;
using Mono.XBuild.Utilities;
namespace Microsoft.Build.BuildEngine
@ -121,7 +122,20 @@ namespace Microsoft.Build.BuildEngine
public static string GetDirectoryNameOfFileAbove (string path, string file)
{
throw new NotImplementedException ("GetDirectoryNameOfFileAbove");
string filePath;
path = Path.GetFullPath (path);
while (true) {
filePath = Path.Combine (path, file);
if (File.Exists (filePath))
return path;
path = Path.GetDirectoryName (path);
if (path == null) // we traversed up until root without a match, return empty string
return "";
}
}
public static object GetRegistryValue (string key, string value)
@ -136,7 +150,18 @@ namespace Microsoft.Build.BuildEngine
public static string MakeRelative (string basePath, string path)
{
throw new NotImplementedException ("MakeRelative");
if (String.IsNullOrEmpty (basePath))
return path;
// ensure trailing slash for basePath
if (basePath [basePath.Length - 1] != '\\' && basePath [basePath.Length - 1] != '/')
basePath += '/';
var uriBasePath = new Uri (basePath, UriKind.Absolute);
var uriPath = new Uri (path);
var uriRelative = uriBasePath.MakeRelativeUri (uriPath);
return Uri.UnescapeDataString (uriRelative.ToString ()).Replace ('/', '\\'); // msbuild uses backslash paths everywhere
}
public static string ValueOrDefault (string value, string defaultValue)
@ -144,4 +169,4 @@ namespace Microsoft.Build.BuildEngine
return string.IsNullOrEmpty (value) ? defaultValue : value;
}
}
}
}