Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
2010-07-16 Ankit Jain <jankit@novell.com>
* AbsoluteToRelativePath: New.
* RelativeToAbsolutePath: New. Taken from monodevelop.
* GetReservedMetadata: Correctly handle 'RelativeDir' .
2010-02-19 Ankit Jain <jankit@novell.com>
* ReservedNameUtils.cs (GetReservedMetadata): Add dictionary param
@metadata. Use this to check for existing value of "RecursiveDir"
metadata, use that if present.
2009-10-08 Ankit Jain <jankit@novell.com>
* ReservedNameUtils.cs: Fix 'RootDir', 'Directory'.
(WithTrailingSlash): New.
Update to use the new WithTrailingSlash method.
2009-09-08 Ankit Jain <jankit@novell.com>
* ReservedNameUtils.cs (RelativeDir): Add a trailing \ .
2007-01-24 Marek Sieradzki <marek.sieradzki@gmail.com>
* MonoLocationHelper.cs: Made class internal. It will be removed soon
(all its functionality is in ToolLocationHelper and it wasn't
documented yet)
2007-01-06 Marek Sieradzki <marek.sieradzi@gmail.com>
* MonoLocationHelper.cs: Commented GetXBuildDir () out.
2006-08-15 Marek Sieradzki <marek.sieradzki@gmail.com>
* ReservedNameUtils.cs: Removed redundant function call.
2006-04-14 Marek Sieradzki <marek.sieradzki@gmail.com>
* ReservedNameUtils.cs: Added.
2005-09-22 Marek Sieradzki <marek.sieradzki@gmail.com>
* MonoLocationHelper.cs: Added GetXBuildDir ().
2005-09-21 Marek Sieradzki <marek.sieradzki@gmail.com>
* MonoLocationHelper.cs: Added.

View File

@@ -0,0 +1,227 @@
//
// Utilities.cs:
//
// Author:
// Ankit Jain (jankit@novell.com)
//
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using System.Collections;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace Mono.XBuild.Utilities {
internal static class MSBuildUtils {
public readonly static bool RunningOnMac;
public readonly static bool RunningOnWindows;
static Hashtable charsToEscape;
static MSBuildUtils ()
{
RunningOnWindows = Path.DirectorySeparatorChar == '\\';
RunningOnMac = !RunningOnWindows && IsRunningOnMac ();
charsToEscape = new Hashtable ();
charsToEscape.Add ('$', null);
charsToEscape.Add ('%', null);
charsToEscape.Add ('\'', null);
charsToEscape.Add ('(', null);
charsToEscape.Add (')', null);
charsToEscape.Add ('*', null);
charsToEscape.Add (';', null);
charsToEscape.Add ('?', null);
charsToEscape.Add ('@', null);
}
public static string Escape (string unescapedExpression)
{
StringBuilder sb = new StringBuilder ();
foreach (char c in unescapedExpression) {
if (charsToEscape.Contains (c))
sb.AppendFormat ("%{0:x2}", (int) c);
else
sb.Append (c);
}
return sb.ToString ();
}
// FIXME: add tests for this
internal static string Unescape (string escapedExpression)
{
StringBuilder sb = new StringBuilder ();
int i = 0;
while (i < escapedExpression.Length) {
sb.Append (Uri.HexUnescape (escapedExpression, ref i));
}
return sb.ToString ();
}
internal static string UnescapeFromXml (string text)
{
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < text.Length; i++) {
char c1 = text[i];
if (c1 == '&') {
int end = text.IndexOf (';', i);
if (end == -1)
throw new FormatException ("Unterminated XML entity.");
string entity = text.Substring (i+1, end - i - 1);
switch (entity) {
case "lt":
sb.Append ('<');
break;
case "gt":
sb.Append ('>');
break;
case "amp":
sb.Append ('&');
break;
case "apos":
sb.Append ('\'');
break;
case "quot":
sb.Append ('"');
break;
default:
throw new FormatException ("Unrecognized XML entity '&" + entity + ";'.");
}
i = end;
} else
sb.Append (c1);
}
return sb.ToString ();
}
[DllImport ("libc")]
static extern int uname (IntPtr buf);
//From Managed.Windows.Forms/XplatUI
static bool IsRunningOnMac ()
{
IntPtr buf = IntPtr.Zero;
try {
buf = System.Runtime.InteropServices.Marshal.AllocHGlobal (8192);
// This is a hacktastic way of getting sysname from uname ()
if (uname (buf) == 0) {
string os = System.Runtime.InteropServices.Marshal.PtrToStringAnsi (buf);
if (os == "Darwin")
return true;
}
} catch {
} finally {
if (buf != IntPtr.Zero)
System.Runtime.InteropServices.Marshal.FreeHGlobal (buf);
}
return false;
}
internal static string FromMSBuildPath (string relPath)
{
string result = null;
FromMSBuildPath (String.Empty, relPath, out result);
return result;
}
internal static bool FromMSBuildPath (string basePath, string relPath, out string resultPath)
{
resultPath = relPath;
if (string.IsNullOrEmpty (relPath))
return false;
string path = relPath;
if (!RunningOnWindows)
path = path.Replace ("\\", "/");
path = Unescape (path);
if (char.IsLetter (path [0]) && path.Length > 1 && path[1] == ':') {
if (RunningOnWindows) {
resultPath = path; // Return the escaped value
return true;
} else
return false;
}
if (basePath != null)
path = Path.Combine (basePath, path);
if (System.IO.File.Exists (path) || System.IO.Directory.Exists (path)){
resultPath = Path.GetFullPath (path);
return true;
}
if (Path.IsPathRooted (path) && !RunningOnWindows) {
// Windows paths are case-insensitive. When mapping an absolute path
// we can try to find the correct case for the path.
string[] names = path.Substring (1).Split ('/');
string part = "/";
for (int n=0; n<names.Length; n++) {
string[] entries;
if (names [n] == ".."){
if (part == "/")
return false; // Can go further back. It's not an existing file
part = Path.GetFullPath (part + "/..");
continue;
}
entries = Directory.GetFileSystemEntries (part);
string fpath = null;
foreach (string e in entries) {
if (string.Compare (Path.GetFileName (e), names[n], true) == 0) {
fpath = e;
break;
}
}
if (fpath == null) {
// Part of the path does not exist. Can't do any more checking.
part = Path.GetFullPath (part);
for (; n < names.Length; n++)
part += "/" + names[n];
resultPath = part;
return true;
}
part = fpath;
}
resultPath = Path.GetFullPath (part);
} else {
resultPath = Path.GetFullPath (path);
}
return true;
}
}
}

View File

@@ -0,0 +1,79 @@
//
// MonoLocationHelper.cs: Returns paths like libdir, bindir etc.
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2005 Marek Sieradzki
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#if NET_2_0
using System;
using System.IO;
namespace Mono.XBuild.Utilities {
internal class MonoLocationHelper {
static string binDir;
static string libDir;
static string assembliesDir;
//static string xbuildDir;
static MonoLocationHelper ()
{
string assemblyLocation;
DirectoryInfo t1, t2, t3, t4;
assemblyLocation = Path.GetDirectoryName (typeof (object).Assembly.Location);
assembliesDir = assemblyLocation;
// /usr/local/lib/mono/1.0
t1 = new DirectoryInfo (assemblyLocation);
// /usr/local/lib/mono
t2 = t1.Parent;
// /usr/local/lib/mono/xbuild
//xbuildDir = Path.Combine (t2.FullName, "xbuild");
// /usr/local/lib
t3 = t2.Parent;
// /usr/local
t4 = t3.Parent;
binDir = Path.Combine (t4.FullName, "bin");
libDir = Path.Combine (t4.FullName, "lib");
}
internal static string GetBinDir ()
{
return binDir;
}
internal static string GetLibDir ()
{
return libDir;
}
internal static string GetAssembliesDir ()
{
return assembliesDir;
}
}
}
#endif

View File

@@ -0,0 +1,182 @@
//
// ReservedNameUtils.cs
//
// Author:
// Marek Sieradzki (marek.sieradzki@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Text;
namespace Mono.XBuild.Utilities {
internal static class ReservedNameUtils {
static string[] reservedMetadataNames;
static Hashtable reservedMetadataHash;
static ReservedNameUtils ()
{
reservedMetadataNames = new string [] {
"FullPath", "RootDir", "Filename", "Extension", "RelativeDir", "Directory",
"RecursiveDir", "Identity", "ModifiedTime", "CreatedTime", "AccessedTime"};
reservedMetadataHash = CollectionsUtil.CreateCaseInsensitiveHashtable (ReservedMetadataNameCount);
foreach (string s in reservedMetadataNames) {
reservedMetadataHash.Add (s, null);
}
}
public static ICollection ReservedMetadataNames {
get {
return (ICollection) reservedMetadataNames.Clone ();
}
}
public static int ReservedMetadataNameCount {
get {
return reservedMetadataNames.Length;
}
}
public static bool IsReservedMetadataName (string metadataName)
{
return reservedMetadataHash.Contains (metadataName);
}
public static string GetReservedMetadata (string itemSpec,
string metadataName, IDictionary metadata)
{
if (metadataName == null)
throw new ArgumentNullException ();
if (String.IsNullOrEmpty (itemSpec))
return String.Empty;
switch (metadataName.ToLowerInvariant ()) {
case "fullpath":
var unescapedItemSpec = MSBuildUtils.Unescape (itemSpec);
return MSBuildUtils.Escape (Path.GetFullPath (unescapedItemSpec));
case "rootdir":
if (Path.IsPathRooted (itemSpec))
return Path.GetPathRoot (itemSpec);
else
return Path.GetPathRoot (Environment.CurrentDirectory);
case "filename":
return Path.GetFileNameWithoutExtension (itemSpec);
case "extension":
return Path.GetExtension (itemSpec);
case "relativedir":
return WithTrailingSlash (AbsoluteToRelativePath (Environment.CurrentDirectory, Path.GetDirectoryName (itemSpec)));
case "directory":
string fullpath = Path.GetFullPath (itemSpec);
return WithTrailingSlash (
Path.GetDirectoryName (fullpath).Substring (Path.GetPathRoot (fullpath).Length));
case "recursivedir":
if (metadata != null && metadata.Contains ("RecursiveDir"))
return (string)metadata ["RecursiveDir"];
else
return String.Empty;
case "identity":
return Path.Combine (Path.GetDirectoryName (itemSpec), Path.GetFileName (itemSpec));
case "modifiedtime":
if (File.Exists (itemSpec))
return File.GetLastWriteTime (itemSpec).ToString ();
else if (Directory.Exists (itemSpec))
return Directory.GetLastWriteTime (itemSpec).ToString ();
else
return String.Empty;
case "createdtime":
if (File.Exists (itemSpec))
return File.GetCreationTime (itemSpec).ToString ();
else if (Directory.Exists (itemSpec))
return Directory.GetCreationTime (itemSpec).ToString ();
else
return String.Empty;
case "accessedtime":
if (File.Exists (itemSpec))
return File.GetLastAccessTime (itemSpec).ToString ();
else if (Directory.Exists (itemSpec))
return Directory.GetLastAccessTime (itemSpec).ToString ();
else
return String.Empty;
default:
throw new ArgumentException ("Invalid reserved metadata name");
}
}
static string WithTrailingSlash (string path)
{
if (String.IsNullOrEmpty (path))
return String.Empty;
if (path.Length > 0)
return path + Path.DirectorySeparatorChar;
else
return path;
}
readonly static char[] separators = { Path.DirectorySeparatorChar, Path.VolumeSeparatorChar, Path.AltDirectorySeparatorChar };
static string AbsoluteToRelativePath (string baseDirectoryPath, string absPath)
{
if (!Path.IsPathRooted (absPath))
return absPath;
absPath = Path.GetFullPath (absPath);
baseDirectoryPath = Path.GetFullPath (baseDirectoryPath.TrimEnd (Path.DirectorySeparatorChar));
string[] bPath = baseDirectoryPath.Split (separators);
string[] aPath = absPath.Split (separators);
int indx = 0;
for (; indx < System.Math.Min (bPath.Length, aPath.Length); indx++) {
if (!bPath[indx].Equals(aPath[indx]))
break;
}
if (indx == 0)
return absPath;
StringBuilder result = new StringBuilder ();
for (int i = indx; i < bPath.Length; i++) {
result.Append ("..");
if (i + 1 < bPath.Length || aPath.Length - indx > 0)
result.Append (Path.DirectorySeparatorChar);
}
result.Append (String.Join(Path.DirectorySeparatorChar.ToString(), aPath, indx, aPath.Length - indx));
if (result.Length == 0)
return ".";
return result.ToString ();
}
static string RelativeToAbsolutePath (string baseDirectoryPath, string relPath)
{
return Path.GetFullPath (Path.Combine (baseDirectoryPath, relPath));
}
}
}