Merge branch 'upstream'

Former-commit-id: 70340005d173498c8871669ddb9867e171cbb3e1
This commit is contained in:
Xamarin Public Jenkins 2016-04-12 13:22:08 -04:00
commit 1ffecf6eb5
118 changed files with 4121 additions and 1632 deletions

View File

@ -84,8 +84,8 @@ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/configure $(am__configure_deps) \ $(top_srcdir)/configure $(am__configure_deps) \
$(srcdir)/config.h.in mkinstalldirs \ $(srcdir)/config.h.in mkinstalldirs \
$(srcdir)/mono-uninstalled.pc.in COPYING.LIB ChangeLog NEWS \ $(srcdir)/mono-uninstalled.pc.in COPYING.LIB ChangeLog NEWS \
compile config.guess config.rpath config.sub depcomp \ compile config.guess config.rpath config.sub install-sh \
install-sh missing ltmain.sh missing ltmain.sh
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/iconv.m4 \ am__aclocal_m4_deps = $(top_srcdir)/m4/iconv.m4 \
$(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \

View File

@ -75,6 +75,7 @@ namespace System.Web.Services.Configuration
try { try {
var hack = this.EvaluationContext; var hack = this.EvaluationContext;
} catch (ConfigurationErrorsException) { } catch (ConfigurationErrorsException) {
this.actualPath = GetConfigurationDirectory();
return; return;
} }
#endif #endif
@ -127,6 +128,7 @@ namespace System.Web.Services.Configuration
var hack = this.EvaluationContext; var hack = this.EvaluationContext;
} catch (ConfigurationErrorsException) { } catch (ConfigurationErrorsException) {
base.Reset(parentElement); base.Reset(parentElement);
this.actualPath = GetConfigurationDirectory();
return; return;
} }
#endif #endif

View File

@ -43,7 +43,7 @@ namespace System.Runtime.InteropServices {
// Should not have been instantiable - here for binary compatibility in V4. // Should not have been instantiable - here for binary compatibility in V4.
} }
#endif #endif
#if !MONO
[System.Security.SecurityCritical] // auto-generated [System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)] [ResourceExposure(ResourceScope.Machine)]
[MethodImplAttribute(MethodImplOptions.InternalCall)] [MethodImplAttribute(MethodImplOptions.InternalCall)]
@ -58,8 +58,8 @@ namespace System.Runtime.InteropServices {
[ResourceExposure(ResourceScope.Machine)] [ResourceExposure(ResourceScope.Machine)]
[MethodImplAttribute(MethodImplOptions.InternalCall)] [MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern String GetHostBindingFile(); internal static extern String GetHostBindingFile();
#endif
#if !FEATURE_CORECLR #if !FEATURE_CORECLR && !MONO
[System.Security.SecurityCritical] // auto-generated [System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)] [ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
@ -78,7 +78,7 @@ namespace System.Runtime.InteropServices {
[MethodImpl (MethodImplOptions.NoInlining)] [MethodImpl (MethodImplOptions.NoInlining)]
public static String GetSystemVersion() public static String GetSystemVersion()
{ {
#if FEATURE_CORECLR #if FEATURE_CORECLR || MONO
return Assembly.GetExecutingAssembly().ImageRuntimeVersion; return Assembly.GetExecutingAssembly().ImageRuntimeVersion;
@ -97,15 +97,36 @@ namespace System.Runtime.InteropServices {
[ResourceConsumption(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)]
public static String GetRuntimeDirectory() public static String GetRuntimeDirectory()
{ {
#if !MOBILE
//
// Workaround for csc hardcoded behaviour where executing mscorlib
// location is always the first path to search for references unless
// they have full path. Mono build is using simple assembly names for
// references and -lib for path which is by default csc dehaviour never
// used
//
var sdk = Environment.GetEnvironmentVariable ("CSC_SDK_PATH_DISABLED");
if (sdk != null)
return null;
#endif
String dir = GetRuntimeDirectoryImpl(); String dir = GetRuntimeDirectoryImpl();
#if !DISABLE_CAS_USE
new FileIOPermission(FileIOPermissionAccess.PathDiscovery, dir).Demand(); new FileIOPermission(FileIOPermissionAccess.PathDiscovery, dir).Demand();
#endif
return dir; return dir;
} }
#if MONO
static String GetRuntimeDirectoryImpl()
{
return Path.GetDirectoryName (typeof (object).Assembly.Location);
}
#else
[System.Security.SecurityCritical] // auto-generated [System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)] [ResourceExposure(ResourceScope.Machine)]
[MethodImplAttribute(MethodImplOptions.InternalCall)] [MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern String GetRuntimeDirectoryImpl(); internal static extern String GetRuntimeDirectoryImpl();
#endif
// Returns the system ConfigurationFile // Returns the system ConfigurationFile
public static String SystemConfigurationFile { public static String SystemConfigurationFile {
@ -113,19 +134,24 @@ namespace System.Runtime.InteropServices {
[ResourceExposure(ResourceScope.Machine)] [ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)]
get { get {
#if MONO
String path = Environment.GetMachineConfigPath ();
#else
StringBuilder sb = new StringBuilder(Path.MAX_PATH); StringBuilder sb = new StringBuilder(Path.MAX_PATH);
sb.Append(GetRuntimeDirectory()); sb.Append(GetRuntimeDirectory());
sb.Append(AppDomainSetup.RuntimeConfigurationFile); sb.Append(AppDomainSetup.RuntimeConfigurationFile);
String path = sb.ToString(); String path = sb.ToString();
#endif
#if !DISABLE_CAS_USE
// Do security check // Do security check
new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand(); new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
#endif
return path; return path;
} }
} }
#if FEATURE_COMINTEROP #if FEATURE_COMINTEROP && !MONO
[System.Security.SecurityCritical] [System.Security.SecurityCritical]
[ResourceExposure(ResourceScope.Process)] [ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)] [ResourceConsumption(ResourceScope.Process)]

View File

@ -1 +1 @@
f0d95f2e3a9502289ad1dba49a96fc174998e83f 7f83cf34517d801b0428a702ae9dd6fa9d28a79b

View File

@ -233,10 +233,8 @@ AM_CONDITIONAL(POWERPC_DARWIN,test x$powerpc_darwin = xtrue)
AC_MSG_CHECKING(for __sync_bool_compare_and_swap) AC_MSG_CHECKING(for __sync_bool_compare_and_swap)
AC_TRY_COMPILE([],[ AC_TRY_COMPILE([],[
volatile unsigned int foo = 0; volatile unsigned int foo = 0;
int main(int argc, char** argv) {
unsigned int r1 = __sync_bool_compare_and_swap(&foo, 0, 1); unsigned int r1 = __sync_bool_compare_and_swap(&foo, 0, 1);
return 0; return 0;
}
], [ ], [
AC_MSG_RESULT(yes) AC_MSG_RESULT(yes)
AC_DEFINE(HAS___SYNC_BOOL_COMPARE_AND_SWAP) AC_DEFINE(HAS___SYNC_BOOL_COMPARE_AND_SWAP)

View File

@ -41,6 +41,8 @@ namespace Microsoft.Build.Tasks {
ITaskItem[] assignedProjects; ITaskItem[] assignedProjects;
string solutionConfigurationContents; string solutionConfigurationContents;
ITaskItem[] unassignedProjects; ITaskItem[] unassignedProjects;
Dictionary<Guid, string> guidToConfigPlatform;
Dictionary<string, string> absolutePathToConfigPlatform;
public AssignProjectConfiguration () public AssignProjectConfiguration ()
{ {
@ -53,10 +55,10 @@ namespace Microsoft.Build.Tasks {
return true; return true;
XmlReader xr = null; XmlReader xr = null;
Dictionary<Guid, string> guidToConfigPlatform = null; guidToConfigPlatform = new Dictionary<Guid, string> ();
absolutePathToConfigPlatform = new Dictionary<string, string> ();
try { try {
xr = XmlReader.Create (new StringReader (solutionConfigurationContents)); xr = XmlReader.Create (new StringReader (solutionConfigurationContents));
guidToConfigPlatform = new Dictionary<Guid, string> ();
xr.Read (); xr.Read ();
while (!xr.EOF) { while (!xr.EOF) {
@ -65,12 +67,20 @@ namespace Microsoft.Build.Tasks {
continue; continue;
string guid_str = xr.GetAttribute ("Project"); string guid_str = xr.GetAttribute ("Project");
string abs_path = xr.GetAttribute ("AbsolutePath");
string config_str = xr.ReadString (); string config_str = xr.ReadString ();
if (String.IsNullOrEmpty (config_str))
continue;
Guid guid; Guid guid;
if (!String.IsNullOrEmpty (guid_str) && !String.IsNullOrEmpty (config_str) && if (TryParseGuid (guid_str, out guid))
TryParseGuid (guid_str, out guid))
guidToConfigPlatform [guid] = config_str; guidToConfigPlatform [guid] = config_str;
if (!String.IsNullOrEmpty (abs_path)) {
abs_path = Path.GetFullPath (abs_path);
absolutePathToConfigPlatform [abs_path] = config_str;
}
} }
} catch (XmlException xe) { } catch (XmlException xe) {
Log.LogError ("XmlException while parsing SolutionConfigurationContents: {0}", Log.LogError ("XmlException while parsing SolutionConfigurationContents: {0}",
@ -84,18 +94,13 @@ namespace Microsoft.Build.Tasks {
List<ITaskItem> tempAssignedProjects = new List<ITaskItem> (); List<ITaskItem> tempAssignedProjects = new List<ITaskItem> ();
List<ITaskItem> tempUnassignedProjects = new List<ITaskItem> (); List<ITaskItem> tempUnassignedProjects = new List<ITaskItem> ();
foreach (ITaskItem item in ProjectReferences) { foreach (ITaskItem item in ProjectReferences) {
string config; string config = GetConfigPlatformFromProjectReference (item);
string guid_str = item.GetMetadata ("Project"); if (String.IsNullOrEmpty (config)) {
tempUnassignedProjects.Add (item);
Guid guid = Guid.Empty; continue;
if (!string.IsNullOrEmpty(guid_str) && !TryParseGuid (guid_str, out guid)) {
Log.LogError ("Project reference '{0}' has invalid or missing guid for metadata 'Project'.",
item.ItemSpec);
return false;
} }
if (guid != Guid.Empty && guidToConfigPlatform.TryGetValue (guid, out config)) {
string [] parts = config.Split (new char [] {'|'}, 2); string [] parts = config.Split (new char [] {'|'}, 2);
ITaskItem new_item = new TaskItem (item); ITaskItem new_item = new TaskItem (item);
@ -105,11 +110,6 @@ namespace Microsoft.Build.Tasks {
((parts.Length > 1) ? parts [1] : String.Empty)); ((parts.Length > 1) ? parts [1] : String.Empty));
tempAssignedProjects.Add (new_item); tempAssignedProjects.Add (new_item);
} else {
Log.LogWarning ("Project reference '{0}' could not be resolved.",
item.ItemSpec);
tempUnassignedProjects.Add (item);
}
} }
assignedProjects = tempAssignedProjects.ToArray (); assignedProjects = tempAssignedProjects.ToArray ();
@ -118,9 +118,29 @@ namespace Microsoft.Build.Tasks {
return true; return true;
} }
string GetConfigPlatformFromProjectReference (ITaskItem item)
{
string guid_str = item.GetMetadata ("Project");
string proj_full_path = item.GetMetadata ("FullPath");
string config;
Guid guid = Guid.Empty;
if (TryParseGuid (guid_str, out guid) && guidToConfigPlatform.TryGetValue (guid, out config))
return config;
string abs_path = item.GetMetadata ("FullPath");
if (absolutePathToConfigPlatform.TryGetValue (abs_path, out config))
return config;
return null;
}
bool TryParseGuid (string guid_str, out Guid guid) bool TryParseGuid (string guid_str, out Guid guid)
{ {
guid = Guid.Empty; guid = Guid.Empty;
if (String.IsNullOrEmpty (guid_str))
return false;
try { try {
guid = new Guid (guid_str); guid = new Guid (guid_str);
} catch (ArgumentNullException) { } catch (ArgumentNullException) {

View File

@ -32,6 +32,7 @@ using Microsoft.Build.Framework;
using Microsoft.Build.Tasks; using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
using NUnit.Framework; using NUnit.Framework;
using System.IO;
using System.Text; using System.Text;
namespace MonoTests.Microsoft.Build.Tasks namespace MonoTests.Microsoft.Build.Tasks
@ -58,22 +59,73 @@ namespace MonoTests.Microsoft.Build.Tasks
"{DAE34193-B5C7-4488-A911-29EE15C84CBE}" "{DAE34193-B5C7-4488-A911-29EE15C84CBE}"
}; };
CreateAndCheckProject (guids, project_ref_guids, new string[] { CreateAndCheckProject (guids, new bool[] {true, true, true, true, true, true},
"AssignedProjects : foo0.csproj;foo1.csproj;foo2.csproj;foo3.csproj: SetConfig: Configuration=Release", project_ref_guids, new string[] {
"AssignedProjects : foo0.csproj;foo1.csproj;foo2.csproj;foo3.csproj;foo4.csproj: SetConfig: Configuration=Release",
"AssignedProjects : foo0.csproj: SetPlatform: Platform=AnyCPU0", "AssignedProjects : foo0.csproj: SetPlatform: Platform=AnyCPU0",
"AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU1", "AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU1",
"AssignedProjects : foo2.csproj: SetPlatform: Platform=AnyCPU2", "AssignedProjects : foo2.csproj: SetPlatform: Platform=AnyCPU2",
"AssignedProjects : foo3.csproj: SetPlatform: Platform=AnyCPU3", "AssignedProjects : foo3.csproj: SetPlatform: Platform=AnyCPU3",
"UnassignedProjects : foo4.csproj"}, "AssignedProjects : foo4.csproj: SetPlatform: Platform=AnyCPU4",
"UnassignedProjects : "},
true, true,
"A1#"); "A1#");
} }
[Test] [Test]
public void TestInvalidProjectGuid () public void TestNoGuidAndNoAbsolutePathFound()
{ {
string[] guids = new string[] { string[] guids = new string[] {
"asd"
};
string[] project_ref_guids = new string[] {
"{DAE34193-B5C7-4488-A911-29EE15C84CB8}",
"invalid guid",
""
};
CreateAndCheckProject (guids, new bool[]{false},
project_ref_guids,
new string[] {
"AssignedProjects : : SetConfig: ",
"AssignedProjects : : SetPlatform: ",
"UnassignedProjects : foo0.csproj;foo1.csproj;foo2.csproj"
},
true, "A1#");
}
[Test]
public void TestInvalidProjectGuidWithAbsolutePath ()
{
string[] guids = new string[] {
null, // no AbsPath
"another invalid guid", // has AbsPath
};
string[] project_ref_guids = new string[] {
"1234zxc", // this won't match because no AbsPath
"xzxoiu", // match with the second project, foo1.csproj
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}", "{23F291D9-78DF-4133-8CF2-78CE104DDE63}",
"badref" // no corresponding project at all
};
CreateAndCheckProject (guids, new bool[]{false, true},
project_ref_guids,
new string[] {
"AssignedProjects : foo1.csproj: SetConfig: Configuration=Release",
"AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU1",
"UnassignedProjects : foo0.csproj;foo2.csproj;foo3.csproj"
},
true, "A1#");
}
[Test]
public void TestNoGuidWithAbsolutePath ()
{
string[] guids = new string[] {
"",
null
}; };
string[] project_ref_guids = new string[] { string[] project_ref_guids = new string[] {
@ -82,7 +134,14 @@ namespace MonoTests.Microsoft.Build.Tasks
"invalid guid" "invalid guid"
}; };
CreateAndCheckProject (guids, project_ref_guids, null, false, "A1#"); CreateAndCheckProject (guids, new bool[]{true, false},
project_ref_guids,
new string[] {
"AssignedProjects : foo0.csproj: SetConfig: Configuration=Release",
"AssignedProjects : foo0.csproj: SetPlatform: Platform=AnyCPU0",
"UnassignedProjects : foo1.csproj;foo2.csproj"
},
true, "A1#");
} }
[Test] [Test]
@ -97,7 +156,8 @@ namespace MonoTests.Microsoft.Build.Tasks
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}" "{23F291D9-78DF-4133-8CF2-78CE104DDE63}"
}; };
CreateAndCheckProject (guids, project_ref_guids, CreateAndCheckProject (guids, new bool[]{false, true},
project_ref_guids,
new string [] { new string [] {
"AssignedProjects : foo1.csproj: SetConfig: Configuration=Release", "AssignedProjects : foo1.csproj: SetConfig: Configuration=Release",
"AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU0", "AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU0",
@ -106,14 +166,14 @@ namespace MonoTests.Microsoft.Build.Tasks
} }
void CreateAndCheckProject (string[] guids, string[] project_ref_guids, string[] messages, bool build_result, string prefix) void CreateAndCheckProject (string[] guids, bool[] set_project_paths, string[] project_ref_guids, string[] messages, bool build_result, string prefix)
{ {
Engine engine = new Engine (Consts.BinPath); Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject (); Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger (); TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger); engine.RegisterLogger (testLogger);
string projectString = CreateProject (guids, project_ref_guids); string projectString = CreateProject (guids, set_project_paths, project_ref_guids);
project.LoadXml (projectString); project.LoadXml (projectString);
try { try {
@ -131,12 +191,12 @@ namespace MonoTests.Microsoft.Build.Tasks
} }
} }
string CreateProject (string[] guids, string[] project_ref_guids) string CreateProject (string[] guids, bool[] set_project_paths, string[] project_ref_guids)
{ {
StringBuilder sb = new StringBuilder (); StringBuilder sb = new StringBuilder ();
sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">"); sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">");
sb.Append ("\n" + GetUsingTask ("AssignProjectConfiguration")); sb.Append ("\n" + GetUsingTask ("AssignProjectConfiguration"));
sb.AppendFormat (@"<PropertyGroup>{0}</PropertyGroup>", CreateSolutionConfigurationProperty (guids, "Release|AnyCPU")); sb.AppendFormat (@"<PropertyGroup>{0}</PropertyGroup>", CreateSolutionConfigurationProperty (guids, set_project_paths, "Release|AnyCPU"));
sb.Append (CreateProjectReferencesItemGroup (project_ref_guids)); sb.Append (CreateProjectReferencesItemGroup (project_ref_guids));
sb.Append ("\n\t<Target Name=\"1\">\n"); sb.Append ("\n\t<Target Name=\"1\">\n");
@ -154,13 +214,19 @@ namespace MonoTests.Microsoft.Build.Tasks
return sb.ToString (); return sb.ToString ();
} }
string CreateSolutionConfigurationProperty (string[] guids, string config_str) string CreateSolutionConfigurationProperty (string[] guids, bool[] set_project_paths, string config_str)
{ {
string abs_proj_path_prefix = Path.GetFullPath ("foo");
StringBuilder sb = new StringBuilder (); StringBuilder sb = new StringBuilder ();
sb.Append ("\n<CurrentSolutionConfigurationContents>\n"); sb.Append ("\n<CurrentSolutionConfigurationContents>\n");
sb.Append ("\t<foo xmlns=\"\">\n"); sb.Append ("\t<foo xmlns=\"\">\n");
for (int i = 0; i < guids.Length; i++) { for (int i = 0; i < guids.Length; i++) {
sb.AppendFormat ("\t\t<bar Project=\"{0}\">{1}{2}</bar>\n", sb.Append ("\t\t<bar");
if (guids[i] != null)
sb.AppendFormat (" Project=\"{0}\"", guids[i]);
if (set_project_paths[i])
sb.AppendFormat (" AbsolutePath=\"{0}{1}.csproj\" ", abs_proj_path_prefix, i);
sb.AppendFormat (">{1}{2}</bar>\n",
guids[i], config_str, i); guids[i], config_str, i);
} }
sb.Append ("\t</foo>\n"); sb.Append ("\t</foo>\n");
@ -173,8 +239,12 @@ namespace MonoTests.Microsoft.Build.Tasks
{ {
StringBuilder sb = new StringBuilder (); StringBuilder sb = new StringBuilder ();
sb.Append ("\n<ItemGroup>\n"); sb.Append ("\n<ItemGroup>\n");
for (int i = 0; i < guids.Length; i ++) for (int i = 0; i < guids.Length; i ++) {
sb.AppendFormat ("\t<ProjectReference Include=\"foo{1}.csproj\"><Project>{0}</Project></ProjectReference>\n", guids [i], i); sb.AppendFormat ("\t<ProjectReference Include=\"foo{0}.csproj\">", i);
if (guids[i] != null)
sb.AppendFormat ("<Project>{0}</Project>", guids[i]);
sb.Append ("</ProjectReference>\n");
}
sb.Append ("</ItemGroup>\n"); sb.Append ("</ItemGroup>\n");
return sb.ToString (); return sb.ToString ();
} }

View File

@ -145,13 +145,6 @@ namespace MonoTests.Microsoft.Build.Tasks {
Assert.AreEqual (0, testLogger.CheckHead ("Text", "HelpKeyword", "Code"), "A1"); Assert.AreEqual (0, testLogger.CheckHead ("Text", "HelpKeyword", "Code"), "A1");
} }
[Test]
public void TestExecute1 ()
{
Error error = new Error ();
Assert.AreEqual (false, error.Execute (), "A1");
}
} }
} }

View File

@ -197,6 +197,19 @@ namespace MonoTests.Microsoft.Build.Tasks
return 0; return 0;
} }
public int CheckFullLog (string text)
{
for (int i = 0; i < all_messages.Count; i ++) {
BuildEventArgs arg = all_messages [i];
if (text == arg.Message) {
all_messages.RemoveAt (i);
return 0;
}
}
return 1;
}
public void DumpMessages () public void DumpMessages ()
{ {
foreach (BuildEventArgs arg in all_messages) foreach (BuildEventArgs arg in all_messages)

View File

@ -16,7 +16,18 @@ LIB_MCS_FLAGS = \
/r:System.Xml.dll \ /r:System.Xml.dll \
/r:$(XBUILD_FRAMEWORK) /r:$(XBUILD_FRAMEWORK)
TEST_MCS_FLAGS = /r:$(XBUILD_ENGINE) /r:$(XBUILD_FRAMEWORK) -r:System.dll -r:System.Core.dll TEST_RESX_RESOURCES = Test/Microsoft.Build.Utilities/Strings.resources
TEST_MCS_FLAGS = /r:$(XBUILD_ENGINE) /r:$(XBUILD_FRAMEWORK) -r:System.dll -r:System.Core.dll $(TEST_RESX_RESOURCES:%=-resource:%)
include $(XBUILD_DIR)/xbuild_test.make include $(XBUILD_DIR)/xbuild_test.make
include ../../build/library.make include ../../build/library.make
EXTRA_DISTFILES = $(TEST_RESX_RESOURCES:.resources=.resx)
CLEAN_FILES += $(TEST_RESX_RESOURCES)
$(TEST_RESX_RESOURCES): %.resources: %.resx
$(RESGEN) $< || cp $@.prebuilt $@
$(test_lib): $(TEST_RESX_RESOURCES)

View File

@ -38,7 +38,6 @@ namespace Microsoft.Build.Utilities
string helpKeywordPrefix; string helpKeywordPrefix;
ITaskHost hostObject; ITaskHost hostObject;
TaskLoggingHelper log; TaskLoggingHelper log;
ResourceManager taskResources;
protected Task() protected Task()
: this (null, null) : this (null, null)
@ -53,7 +52,8 @@ namespace Microsoft.Build.Utilities
protected Task(ResourceManager taskResources, protected Task(ResourceManager taskResources,
string helpKeywordPrefix) string helpKeywordPrefix)
{ {
this.taskResources = taskResources; log = new TaskLoggingHelper (this);
log.TaskResources = taskResources;
this.helpKeywordPrefix = helpKeywordPrefix; this.helpKeywordPrefix = helpKeywordPrefix;
} }
@ -65,7 +65,6 @@ namespace Microsoft.Build.Utilities
} }
set { set {
buildEngine = value; buildEngine = value;
log = new TaskLoggingHelper (this);
} }
} }
@ -99,10 +98,10 @@ namespace Microsoft.Build.Utilities
protected ResourceManager TaskResources { protected ResourceManager TaskResources {
get { get {
return taskResources; return log.TaskResources;
} }
set { set {
taskResources = value; log.TaskResources = value;
} }
} }
} }

View File

@ -41,11 +41,14 @@ namespace Microsoft.Build.Utilities
string helpKeywordPrefix; string helpKeywordPrefix;
string taskName; string taskName;
ResourceManager taskResources; ResourceManager taskResources;
ITask taskInstance;
public TaskLoggingHelper (ITask taskInstance) public TaskLoggingHelper (ITask taskInstance)
{ {
if (taskInstance != null) if (taskInstance == null)
this.buildEngine = taskInstance.BuildEngine; throw new ArgumentNullException ("taskInstance");
this.taskInstance = taskInstance;
taskName = null; taskName = null;
} }
@ -67,7 +70,14 @@ namespace Microsoft.Build.Utilities
if (resourceName == null) if (resourceName == null)
throw new ArgumentNullException ("resourceName"); throw new ArgumentNullException ("resourceName");
return null; if (taskResources == null)
throw new InvalidOperationException ("Task did not register any task resources");
string resourceString = taskResources.GetString (resourceName);
if (resourceString == null)
throw new ArgumentException ($"No resource string found for resource named {resourceName}");
return FormatString (resourceString, args);
} }
[MonoTODO] [MonoTODO]
@ -100,10 +110,12 @@ namespace Microsoft.Build.Utilities
if (message == null) if (message == null)
throw new ArgumentNullException ("message"); throw new ArgumentNullException ("message");
ThrowInvalidOperationIf (BuildEngine == null, "Task is attempting to log before it was initialized");
BuildErrorEventArgs beea = new BuildErrorEventArgs ( BuildErrorEventArgs beea = new BuildErrorEventArgs (
null, null, buildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, FormatString (message, messageArgs), null, null, BuildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, FormatString (message, messageArgs),
helpKeywordPrefix, null); helpKeywordPrefix, null);
buildEngine.LogErrorEvent (beea); BuildEngine.LogErrorEvent (beea);
hasLoggedErrors = true; hasLoggedErrors = true;
} }
@ -117,12 +129,14 @@ namespace Microsoft.Build.Utilities
if (message == null) if (message == null)
throw new ArgumentNullException ("message"); throw new ArgumentNullException ("message");
ThrowInvalidOperationIf (BuildEngine == null, "Task is attempting to log before it was initialized");
BuildErrorEventArgs beea = new BuildErrorEventArgs ( BuildErrorEventArgs beea = new BuildErrorEventArgs (
subcategory, errorCode, file, lineNumber, subcategory, errorCode, file, lineNumber,
columnNumber, endLineNumber, endColumnNumber, columnNumber, endLineNumber, endColumnNumber,
FormatString (message, messageArgs), helpKeyword /*it's helpKeyword*/, FormatString (message, messageArgs), helpKeyword /*it's helpKeyword*/,
null /*it's senderName*/); null /*it's senderName*/);
buildEngine.LogErrorEvent (beea); BuildEngine.LogErrorEvent (beea);
hasLoggedErrors = true; hasLoggedErrors = true;
} }
@ -144,14 +158,16 @@ namespace Microsoft.Build.Utilities
if (exception == null) if (exception == null)
throw new ArgumentNullException ("exception"); throw new ArgumentNullException ("exception");
ThrowInvalidOperationIf (BuildEngine == null, "Task is attempting to log before it was initialized");
StringBuilder sb = new StringBuilder (); StringBuilder sb = new StringBuilder ();
sb.Append (exception.Message); sb.Append (exception.Message);
if (showStackTrace == true) if (showStackTrace == true)
sb.Append (exception.StackTrace); sb.Append (exception.StackTrace);
BuildErrorEventArgs beea = new BuildErrorEventArgs ( BuildErrorEventArgs beea = new BuildErrorEventArgs (
null, null, buildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, sb.ToString (), null, null, BuildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, sb.ToString (),
exception.HelpLink, exception.Source); exception.HelpLink, exception.Source);
buildEngine.LogErrorEvent (beea); BuildEngine.LogErrorEvent (beea);
hasLoggedErrors = true; hasLoggedErrors = true;
} }
@ -159,7 +175,7 @@ namespace Microsoft.Build.Utilities
params object[] messageArgs) params object[] messageArgs)
{ {
LogErrorFromResources (null, null, null, null, 0, 0, 0, LogErrorFromResources (null, null, null, null, 0, 0, 0,
0, messageResourceName, null); 0, messageResourceName, messageArgs);
} }
public void LogErrorFromResources (string subcategoryResourceName, public void LogErrorFromResources (string subcategoryResourceName,
@ -172,13 +188,22 @@ namespace Microsoft.Build.Utilities
string messageResourceName, string messageResourceName,
params object[] messageArgs) params object[] messageArgs)
{ {
if (messageResourceName == null)
throw new ArgumentNullException ("messageResourceName");
ThrowInvalidOperationIf (BuildEngine == null, "Task is attempting to log before it was initialized");
string subcategory = null;
if (!String.IsNullOrEmpty (subcategoryResourceName))
subcategory = taskResources.GetString (subcategoryResourceName);
BuildErrorEventArgs beea = new BuildErrorEventArgs ( BuildErrorEventArgs beea = new BuildErrorEventArgs (
taskResources.GetString (subcategoryResourceName), subcategory,
errorCode, file, lineNumber, columnNumber, errorCode, file, lineNumber, columnNumber,
endLineNumber, endColumnNumber, endLineNumber, endColumnNumber,
taskResources.GetString (messageResourceName), FormatResourceString (messageResourceName, messageArgs),
helpKeyword, null ); helpKeyword, null );
buildEngine.LogErrorEvent (beea); BuildEngine.LogErrorEvent (beea);
hasLoggedErrors = true; hasLoggedErrors = true;
} }
@ -226,16 +251,17 @@ namespace Microsoft.Build.Utilities
public void LogMessageFromResources (string messageResourceName, public void LogMessageFromResources (string messageResourceName,
params object[] messageArgs) params object[] messageArgs)
{ {
LogMessage (taskResources.GetString (messageResourceName), LogMessageFromResources (MessageImportance.Normal, messageResourceName, messageArgs);
messageArgs);
} }
public void LogMessageFromResources (MessageImportance importance, public void LogMessageFromResources (MessageImportance importance,
string messageResourceName, string messageResourceName,
params object[] messageArgs) params object[] messageArgs)
{ {
LogMessage (importance, taskResources.GetString ( if (messageResourceName == null)
messageResourceName), messageArgs); throw new ArgumentNullException ("messageResourceName");
LogMessage (importance, FormatResourceString (messageResourceName, messageArgs));
} }
public bool LogMessagesFromFile (string fileName) public bool LogMessagesFromFile (string fileName)
@ -280,10 +306,12 @@ namespace Microsoft.Build.Utilities
if (lineOfText == null) if (lineOfText == null)
throw new ArgumentNullException ("lineOfText"); throw new ArgumentNullException ("lineOfText");
ThrowInvalidOperationIf (BuildEngine == null, "Task is attempting to log before it was initialized");
BuildMessageEventArgs bmea = new BuildMessageEventArgs ( BuildMessageEventArgs bmea = new BuildMessageEventArgs (
lineOfText, helpKeywordPrefix, lineOfText, helpKeywordPrefix,
null, messageImportance); null, messageImportance);
buildEngine.LogMessageEvent (bmea); BuildEngine.LogMessageEvent (bmea);
return true; return true;
} }
@ -291,11 +319,13 @@ namespace Microsoft.Build.Utilities
public void LogWarning (string message, public void LogWarning (string message,
params object[] messageArgs) params object[] messageArgs)
{ {
ThrowInvalidOperationIf (BuildEngine == null, "Task is attempting to log before it was initialized");
// FIXME: what about all the parameters? // FIXME: what about all the parameters?
BuildWarningEventArgs bwea = new BuildWarningEventArgs ( BuildWarningEventArgs bwea = new BuildWarningEventArgs (
null, null, buildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, FormatString (message, messageArgs), null, null, BuildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, FormatString (message, messageArgs),
helpKeywordPrefix, null); helpKeywordPrefix, null);
buildEngine.LogWarningEvent (bwea); BuildEngine.LogWarningEvent (bwea);
} }
public void LogWarning (string subcategory, string warningCode, public void LogWarning (string subcategory, string warningCode,
@ -305,11 +335,13 @@ namespace Microsoft.Build.Utilities
string message, string message,
params object[] messageArgs) params object[] messageArgs)
{ {
ThrowInvalidOperationIf (BuildEngine == null, "Task is attempting to log before it was initialized");
BuildWarningEventArgs bwea = new BuildWarningEventArgs ( BuildWarningEventArgs bwea = new BuildWarningEventArgs (
subcategory, warningCode, file, lineNumber, subcategory, warningCode, file, lineNumber,
columnNumber, endLineNumber, endColumnNumber, columnNumber, endLineNumber, endColumnNumber,
FormatString (message, messageArgs), helpKeyword, null); FormatString (message, messageArgs), helpKeyword, null);
buildEngine.LogWarningEvent (bwea); BuildEngine.LogWarningEvent (bwea);
} }
public void LogWarningFromException (Exception exception) public void LogWarningFromException (Exception exception)
@ -331,8 +363,10 @@ namespace Microsoft.Build.Utilities
public void LogWarningFromResources (string messageResourceName, public void LogWarningFromResources (string messageResourceName,
params object[] messageArgs) params object[] messageArgs)
{ {
LogWarning (taskResources.GetString (messageResourceName), if (messageResourceName == null)
messageArgs); throw new ArgumentNullException ("messageResourceName");
LogWarningFromResources (null, null, null, null, 0, 0, 0, 0, messageResourceName, messageArgs);
} }
public void LogWarningFromResources (string subcategoryResourceName, public void LogWarningFromResources (string subcategoryResourceName,
@ -346,11 +380,17 @@ namespace Microsoft.Build.Utilities
string messageResourceName, string messageResourceName,
params object[] messageArgs) params object[] messageArgs)
{ {
LogWarning (taskResources.GetString (subcategoryResourceName), if (messageResourceName == null)
throw new ArgumentNullException ("messageResourceName");
string subcategory = null;
if (!String.IsNullOrEmpty (subcategoryResourceName))
subcategory = taskResources.GetString (subcategoryResourceName);
LogWarning (subcategory,
warningCode, helpKeyword, file, lineNumber, warningCode, helpKeyword, file, lineNumber,
columnNumber, endLineNumber, endColumnNumber, columnNumber, endLineNumber, endColumnNumber,
taskResources.GetString (messageResourceName), FormatResourceString (messageResourceName, messageArgs));
messageArgs);
} }
public void LogWarningWithCodeFromResources (string messageResourceName, public void LogWarningWithCodeFromResources (string messageResourceName,
@ -391,9 +431,15 @@ namespace Microsoft.Build.Utilities
{ {
} }
void ThrowInvalidOperationIf (bool condition, string message)
{
if (condition)
throw new InvalidOperationException (message);
}
protected IBuildEngine BuildEngine { protected IBuildEngine BuildEngine {
get { get {
return buildEngine; return taskInstance?.BuildEngine;
} }
} }

View File

@ -4,3 +4,5 @@ Microsoft.Build.Utilities/TaskItemTest.cs
Microsoft.Build.Utilities/TaskLoggingHelperTest.cs Microsoft.Build.Utilities/TaskLoggingHelperTest.cs
Microsoft.Build.Utilities/ToolLocationHelperTest.cs Microsoft.Build.Utilities/ToolLocationHelperTest.cs
Microsoft.Build.Utilities/ToolTaskTest.cs Microsoft.Build.Utilities/ToolTaskTest.cs
../../Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/TestMessageLogger.cs
../../Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/Consts.cs

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used forserialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="MessageResource1">
<value>Message from resources with arg '{0}'</value>
</data>
</root>

View File

@ -3,8 +3,10 @@
// //
// Author: // Author:
// Marek Sieradzki (marek.sieradzki@gmail.com) // Marek Sieradzki (marek.sieradzki@gmail.com)
// Ankit Jain (ankit.jain@xamarin.com)
// //
// (C) 2005 Marek Sieradzki // (C) 2005 Marek Sieradzki
// (C) 2016 Xamarin, Inc. (http://www.xamarin.com)
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the // a copy of this software and associated documentation files (the
@ -27,15 +29,27 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Reflection;
using System.Resources;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
using Microsoft.Build.BuildEngine;
using NUnit.Framework; using NUnit.Framework;
using MonoTests.Microsoft.Build.Tasks;
namespace MonoTests.Microsoft.Build.Utilities { namespace MonoTests.Microsoft.Build.Utilities {
class TestTask : Task { class TestTask : Task {
public static Action<TaskLoggingHelper> action = null;
public TestTask ()
: base (new ResourceManager("Strings", typeof(TestTask).GetTypeInfo().Assembly))
{
}
public override bool Execute () public override bool Execute ()
{ {
action (Log);
return true; return true;
} }
} }
@ -46,6 +60,11 @@ namespace MonoTests.Microsoft.Build.Utilities {
TaskLoggingHelper tlh; TaskLoggingHelper tlh;
TestTask task; TestTask task;
public TaskLoggingHelperTest ()
{
task = new TestTask ();
}
[Test] [Test]
public void TestAssignment () public void TestAssignment ()
{ {
@ -77,6 +96,218 @@ namespace MonoTests.Microsoft.Build.Utilities {
string output; string output;
tlh.ExtractMessageCode (null, out output); tlh.ExtractMessageCode (null, out output);
} }
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestLogErrorFromResourcesNullMessage ()
{
tlh = new TaskLoggingHelper (task);
tlh.LogErrorFromResources (null);
} }
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestLogErrorFromResourcesNullMessage2 ()
{
tlh = new TaskLoggingHelper (task);
tlh.LogErrorFromResources (null, null, null, null, 0, 0, 0, 0, null);
}
[Test]
public void TestLogErrorFromResources1 ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.LogErrorFromResources ("MessageResource1", "foo"),
(l) => Assert.IsTrue (l.CheckFullLog ("Message from resources with arg 'foo'") == 0, "Message not found")
);
}
[Test]
public void TestLogErrorFromResourcesNonExistantResourceName ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.LogErrorFromResources ("NonExistantResourceName", "foo"),
null,
(p, l) => {
Assert.IsFalse (p.Build (), "Build should have failed");
Assert.IsTrue (l.CheckFullLog (
"Error executing task TestTask: No resource string found for resource named NonExistantResourceName") == 0,
"Error not found in the log");
}
);
}
[Test]
public void TestLogErrorFromResourcesNullSubcategoryResourceName ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.LogErrorFromResources (null, null, null, null, 0, 0, 0, 0, "MessageResource1", "foo"),
(l) => Assert.IsTrue (l.CheckFullLog ("Message from resources with arg 'foo'") == 0, "Message not found")
);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestLogWarningFromResourcesNullMessage ()
{
tlh = new TaskLoggingHelper (task);
tlh.LogWarningFromResources (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestLogWarningFromResourcesNullMessage2 ()
{
tlh = new TaskLoggingHelper (task);
tlh.LogWarningFromResources (null, null, null, null, 0, 0, 0, 0, null);
}
[Test]
public void TestLogWarningFromResourcesNullSubcategoryResourceName ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.LogWarningFromResources (null, null, null, null, 0, 0, 0, 0, "MessageResource1", "foo"),
(l) => Assert.IsTrue (l.CheckFullLog ("Message from resources with arg 'foo'") == 0, "Message not found")
);
}
[Test]
public void TestLogWarningFromResources1 ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.LogWarningFromResources ("MessageResource1", "foo"),
(l) => Assert.IsTrue (l.CheckFullLog ("Message from resources with arg 'foo'") == 0, "Message not found")
);
}
[Test]
public void TestLogWarningFromResourcesNonExistantResourceName ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.LogWarningFromResources ("NonExistantResourceName", "foo"),
null,
(p, l) => {
if (p.Build ()) { l.DumpMessages (); Assert.Fail ("Build should have failed"); }
Assert.IsTrue (l.CheckFullLog (
"Error executing task TestTask: No resource string found for resource named NonExistantResourceName") == 0,
"Error not found in the log");
}
);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestLogMessageFromResourcesNullMessage ()
{
tlh = new TaskLoggingHelper (task);
tlh.LogMessageFromResources (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestLogMessageFromResourcesNullMessage2 ()
{
tlh = new TaskLoggingHelper (task);
tlh.LogMessageFromResources (MessageImportance.Low, null);
}
[Test]
public void TestLogMessageFromResources1 ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.LogMessageFromResources ("MessageResource1", "foo"),
(l) => Assert.IsTrue (l.CheckFullLog ("Message from resources with arg 'foo'") == 0, "Message not found")
);
}
[Test]
public void TestLogMessageFromResourcesNonExistantResourceName ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.LogMessageFromResources ("NonExistantResourceName", "foo"),
null,
(p, l) => {
if (p.Build ()) { l.DumpMessages (); Assert.Fail ("Build should have failed"); }
l.DumpMessages ();
Assert.IsTrue (l.CheckFullLog (
"Error executing task TestTask: No resource string found for resource named NonExistantResourceName") == 0,
"Error not found in the log");
}
);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestFormatResourceString1 ()
{
tlh = new TaskLoggingHelper (task);
tlh.FormatResourceString (null);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestFormatResourceString2 ()
{
tlh = new TaskLoggingHelper (task);
tlh.FormatResourceString ("MessageResource1");
}
[Test]
public void TestFormatResourceString3 ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => tlh.FormatResourceString ("NonExistantResourceName"),
null,
(p, l) => {
if (p.Build ()) { l.DumpMessages (); Assert.Fail ("Build should have failed"); }
l.DumpMessages ();
Assert.IsTrue (l.CheckFullLog (
"Error executing task TestTask: No resource string found for resource named NonExistantResourceName") == 0,
"Error not found in the log");
}
);
}
[Test]
public void TestFormatResourceString4 ()
{
RunAndCheckTaskLoggingHelper (
(tlh) => Assert.AreEqual (
tlh.FormatResourceString ("MessageResource1", "foo"),
"Message from resources with arg 'foo'"),
null
);
}
void RunAndCheckTaskLoggingHelper (Action<TaskLoggingHelper> taskAction, Action<TestMessageLogger> loggerAction, Action<Project, TestMessageLogger> projectBuildAction = null)
{
string asmLocation = typeof (TaskLoggingHelperTest).Assembly.Location;
string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<UsingTask TaskName='MonoTests.Microsoft.Build.Utilities.TestTask' AssemblyFile='" + asmLocation + @"' />
<Target Name=""1"">
<TestTask />
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project proj = engine.CreateNewProject ();
proj.LoadXml (project_xml);
TestMessageLogger logger = new TestMessageLogger ();
engine.RegisterLogger (logger);
TestTask.action = taskAction;
if (projectBuildAction == null) {
if (!proj.Build ("1")) {
logger.DumpMessages ();
Assert.Fail ("Build failed");
}
} else
projectBuildAction (proj, logger);
if (loggerAction != null)
loggerAction (logger);
}
}
} }

View File

@ -70,3 +70,4 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo ("Mono.Security.Providers.OldTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] [assembly: InternalsVisibleTo ("Mono.Security.Providers.OldTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
[assembly: InternalsVisibleTo ("Mono.Security.Providers.DotNet, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] [assembly: InternalsVisibleTo ("Mono.Security.Providers.DotNet, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
[assembly: InternalsVisibleTo ("Mono.Security.Providers.NewSystemSource, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] [assembly: InternalsVisibleTo ("Mono.Security.Providers.NewSystemSource, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
[assembly: InternalsVisibleTo ("Xamarin.BoringTls, PublicKey=002400000480000094000000060200000024000052534131000400001100000099dd12eda85767ae6f06023ee28e711c7e5a212462095c83868c29db75eddf6d8e296e03824c14fedd5f55553fed0b6173be3cc985a4b7f9fb7c83ccff8ba3938563b3d1f45a81122f12a1bcb73edcaad61a8456c7595a6da5184b4dd9d10f011b949ef1391fccfeab1ba62aa51c267ef8bd57ef1b6ba5a4c515d0badb81a78f")]

View File

@ -21,5 +21,5 @@ EXTRA_DISTFILES = Mono.Security.Interface/README.md
# #
# Update this comment to trigger a build in System # Update this comment to trigger a build in System
# +2 # +3
# #

View File

@ -95,6 +95,14 @@ namespace Mono.Security.Interface
* If @serverMode is true, then we're a server and want to validate a certificate that we received from a client. * If @serverMode is true, then we're a server and want to validate a certificate that we received from a client.
*/ */
ValidationResult ValidateCertificate (string targetHost, bool serverMode, X509CertificateCollection certificates); ValidationResult ValidateCertificate (string targetHost, bool serverMode, X509CertificateCollection certificates);
}
internal interface ICertificateValidator2 : ICertificateValidator
{
/*
* Internal use only.
*/
ValidationResult ValidateCertificate (string targetHost, bool serverMode, X509Certificate leaf, X509Chain chain);
/* /*
* On OS X and Mobile, the @chain will be initialized with the @certificates, but not actually built. * On OS X and Mobile, the @chain will be initialized with the @certificates, but not actually built.
@ -137,25 +145,20 @@ namespace Mono.Security.Interface
get { return supportsTrustAnchors; } get { return supportsTrustAnchors; }
} }
static ICertificateValidator GetDefaultValidator (MonoTlsProvider provider, MonoTlsSettings settings)
{
return (ICertificateValidator)NoReflectionHelper.GetDefaultCertificateValidator (provider, settings);
}
/* /*
* Internal API, intended to be used by MonoTlsProvider implementations. * Internal API, intended to be used by MonoTlsProvider implementations.
*/ */
public static ICertificateValidator GetValidator (MonoTlsProvider provider, MonoTlsSettings settings) internal static ICertificateValidator2 GetDefaultValidator (MonoTlsSettings settings, MonoTlsProvider provider)
{ {
return GetDefaultValidator (provider, settings); return (ICertificateValidator2)NoReflectionHelper.GetDefaultCertificateValidator (provider, settings);
} }
/* /*
* Use this overloaded version in user code. * Use this overloaded version in user code.
*/ */
public static ICertificateValidator GetValidator (MonoTlsSettings settings) public static ICertificateValidator GetValidator (MonoTlsSettings settings, MonoTlsProvider provider = null)
{ {
return GetDefaultValidator (null, settings); return GetDefaultValidator (settings, provider);
} }
} }
} }

View File

@ -124,12 +124,32 @@ namespace Mono.Security.Interface
#endregion #endregion
#region Native Certificate Implementation
internal virtual bool HasNativeCertificates {
get { return false; }
}
internal virtual X509Certificate2Impl GetNativeCertificate (
byte[] data, string password, X509KeyStorageFlags flags)
{
throw new InvalidOperationException ();
}
internal virtual X509Certificate2Impl GetNativeCertificate (
X509Certificate certificate)
{
throw new InvalidOperationException ();
}
#endregion
#region Certificate Validation #region Certificate Validation
/* /*
* Allows a TLS provider to provide a custom system certificiate validator. * Allows a TLS provider to provide a custom system certificiate validator.
*/ */
public virtual bool HasCustomSystemCertificateValidator { internal virtual bool HasCustomSystemCertificateValidator {
get { return false; } get { return false; }
} }
@ -142,13 +162,12 @@ namespace Mono.Security.Interface
* Returns `true` if certificate validation has been performed and `false` to invoke the * Returns `true` if certificate validation has been performed and `false` to invoke the
* default system validator. * default system validator.
*/ */
public virtual bool InvokeSystemCertificateValidator ( internal virtual bool InvokeSystemCertificateValidator (
ICertificateValidator validator, string targetHost, bool serverMode, ICertificateValidator2 validator, string targetHost, bool serverMode,
X509CertificateCollection certificates, X509Chain chain, out bool success, X509CertificateCollection certificates, bool wantsChain, ref X509Chain chain,
ref MonoSslPolicyErrors errors, ref int status11) out bool success, ref MonoSslPolicyErrors errors, ref int status11)
{ {
success = false; throw new InvalidOperationException ();
return false;
} }
#endregion #endregion

View File

@ -313,6 +313,20 @@ namespace System.Net.Http.Headers
start = pos - 1; start = pos - 1;
while (pos < s.Length) { while (pos < s.Length) {
ch = s [pos++]; ch = s [pos++];
//
// The backslash character ("\") MAY be used as a single-character
// quoting mechanism only within quoted-string
//
if (ch == '\\') {
if (pos + 1 < s.Length) {
++pos;
continue;
}
break;
}
if (ch == '"') { if (ch == '"') {
ttype = Token.Type.QuotedString; ttype = Token.Type.QuotedString;
break; break;

Some files were not shown because too many files have changed in this diff Show More