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,169 @@
// BuildManager.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
// Atsushi Enomoto (atsushi@xamarin.com)
//
// Copyright (C) 2011,2013 Xamarin Inc.
//
// 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 Microsoft.Build.Evaluation;
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.Build.Internal;
using System.Linq;
namespace Microsoft.Build.Execution
{
public class BuildManager
{
static BuildManager default_manager = new BuildManager ();
public static BuildManager DefaultBuildManager {
get { return default_manager; }
}
public BuildManager ()
{
}
public BuildManager (string hostName)
{
throw new NotImplementedException ();
}
public void Dispose ()
{
WaitHandle.WaitAll (submissions.Select (s => s.WaitHandle).ToArray ());
BuildNodeManager.Stop ();
}
~BuildManager ()
{
// maybe processes created by out-of-process nodes should be signaled.
BuildNodeManager.Stop ();
}
readonly List<BuildSubmission> submissions = new List<BuildSubmission> ();
BuildParameters ongoing_build_parameters;
internal BuildParameters OngoingBuildParameters {
get { return ongoing_build_parameters; }
}
public void BeginBuild (BuildParameters parameters)
{
if (ongoing_build_parameters != null)
throw new InvalidOperationException ("There is already ongoing build");
ongoing_build_parameters = parameters.Clone ();
}
public BuildResult Build (BuildParameters parameters, BuildRequestData requestData)
{
BeginBuild (parameters);
var ret = BuildRequest (requestData);
EndBuild ();
return ret;
}
public BuildResult BuildRequest (BuildRequestData requestData)
{
var sub = PendBuildRequest (requestData);
sub.Execute ();
return sub.BuildResult;
}
public void CancelAllSubmissions ()
{
foreach (var sub in submissions) {
try {
if (!sub.IsCompleted)
sub.Cancel ();
} catch (InvalidOperationException) {
// some submissions could be already done during this iteration. Ignore that.
}
}
submissions.Clear ();
}
public void EndBuild ()
{
if (ongoing_build_parameters == null)
throw new InvalidOperationException ("Build has not started");
if (submissions.Count > 0)
WaitHandle.WaitAll (submissions.Select (s => s.WaitHandle).ToArray ());
BuildNodeManager.Stop ();
ongoing_build_parameters = null;
}
Dictionary<Project,ProjectInstance> instances = new Dictionary<Project, ProjectInstance> ();
public ProjectInstance GetProjectInstanceForBuild (Project project)
{
if (project == null)
throw new ArgumentNullException ("project");
if (project.FullPath == null)
throw new ArgumentNullException ("project", "FullPath parameter in the project cannot be null.");
if (project.FullPath == string.Empty)
throw new ArgumentException ("FullPath parameter in the project cannot be empty.", "project");
// other than that, any invalid path character is accepted...
return GetProjectInstanceForBuildInternal (project);
}
internal ProjectInstance GetProjectInstanceForBuildInternal (Project project)
{
if (!instances.ContainsKey (project))
instances [project] = project.CreateProjectInstance ();
return instances [project];
}
public BuildSubmission PendBuildRequest (BuildRequestData requestData)
{
if (ongoing_build_parameters == null)
throw new InvalidOperationException ("This method cannot be called before calling BeginBuild method.");
var sub = new BuildSubmission (this, requestData);
submissions.Add (sub);
return sub;
}
public void ResetCaches ()
{
if (OngoingBuildParameters != null)
throw new InvalidOperationException ("Cannot reset caches while builds are in progress.");
BuildNodeManager.ResetCaches ();
}
BuildNodeManager build_node_manager;
internal BuildNodeManager BuildNodeManager {
get {
if (build_node_manager == null)
build_node_manager = new BuildNodeManager (this);
return build_node_manager;
}
}
}
}

View File

@@ -0,0 +1,156 @@
// BuildParameters.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
// Atsushi Enomoto (atsushi@xamarin.com)
//
// Copyright (C) 2011,2013 Xamarin Inc.
//
// 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 Microsoft.Build.Evaluation;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Collections;
namespace Microsoft.Build.Execution
{
public class BuildParameters
{
public BuildParameters ()
: this (new ProjectCollection ())
{
}
public BuildParameters (ProjectCollection projectCollection)
{
if (projectCollection == null)
throw new ArgumentNullException ("projectCollection");
projects = projectCollection;
EnableNodeReuse = true;
Culture = CultureInfo.CurrentCulture;
UICulture = CultureInfo.CurrentUICulture;
MaxNodeCount = projectCollection.MaxNodeCount;
// these properties are copied, while some members (such as Loggers) are not.
this.DefaultToolsVersion = projectCollection.DefaultToolsVersion;
this.ToolsetDefinitionLocations = projectCollection.ToolsetLocations;
this.GlobalProperties = projectCollection.GlobalProperties;
environment_properties = new Dictionary<string,string> ();
foreach (DictionaryEntry p in Environment.GetEnvironmentVariables ())
environment_properties [(string) p.Key] = (string) p.Value;
}
readonly ProjectCollection projects;
Dictionary<string,string> environment_properties;
internal ProjectCollection ProjectCollection {
get { return projects; }
}
public BuildParameters Clone ()
{
var ret = (BuildParameters) MemberwiseClone ();
ret.ForwardingLoggers = ForwardingLoggers == null ? null : ForwardingLoggers.ToArray ();
ret.GlobalProperties = GlobalProperties == null ? null : GlobalProperties.ToDictionary (p => p.Key, p => p.Value);
ret.Loggers = Loggers == null ? null : new List<ILogger> (Loggers);
ret.environment_properties = new Dictionary<string, string> (environment_properties);
return ret;
}
public Toolset GetToolset (string toolsVersion)
{
// can return null.
return projects.Toolsets.FirstOrDefault (t => t.ToolsVersion == toolsVersion);
}
[MonoTODO]
public ThreadPriority BuildThreadPriority { get; set; }
[MonoTODO]
public CultureInfo Culture { get; set; }
public string DefaultToolsVersion { get; set; }
[MonoTODO]
public bool DetailedSummary { get; set; }
public bool EnableNodeReuse { get; set; }
[MonoTODO]
public IDictionary<string, string> EnvironmentProperties {
get { return environment_properties; }
}
[MonoTODO]
public IEnumerable<ForwardingLoggerRecord> ForwardingLoggers { get; set; }
[MonoTODO]
public IDictionary<string, string> GlobalProperties { get; set; }
public HostServices HostServices { get; set; }
[MonoTODO]
public bool LegacyThreadingSemantics { get; set; }
[MonoTODO]
public IEnumerable<ILogger> Loggers { get; set; }
[MonoTODO]
public int MaxNodeCount { get; set; }
[MonoTODO]
public int MemoryUseLimit { get; set; }
[MonoTODO]
public string NodeExeLocation { get; set; }
[MonoTODO]
public bool OnlyLogCriticalEvents { get; set; }
[MonoTODO]
public bool ResetCaches { get; set; }
[MonoTODO]
public bool SaveOperatingEnvironment { get; set; }
[MonoTODO]
public ToolsetDefinitionLocations ToolsetDefinitionLocations { get; set; }
[MonoTODO]
public ICollection<Toolset> Toolsets {
get { return projects.Toolsets; }
}
[MonoTODO]
public CultureInfo UICulture { get; set; }
[MonoTODO]
public bool UseSynchronousLogging { get; set; }
}
}

View File

@@ -0,0 +1,98 @@
//
// BuildRequestData.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
// Atsushi Enomoto (atsushi@xamarin.com)
//
// Copyright (C) 2011,2013 Xamarin Inc.
//
// 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.Linq;
using System.Collections.Generic;
namespace Microsoft.Build.Execution
{
public class BuildRequestData
{
public BuildRequestData (ProjectInstance projectInstance, string[] targetsToBuild)
: this (projectInstance, targetsToBuild, null, BuildRequestDataFlags.None)
{
}
public BuildRequestData (ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices)
: this (projectInstance, targetsToBuild, hostServices, BuildRequestDataFlags.None)
{
}
public BuildRequestData (ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices,
BuildRequestDataFlags flags)
{
if (targetsToBuild == null)
throw new ArgumentNullException ("targetsToBuild");
ProjectInstance = projectInstance;
TargetNames = targetsToBuild;
HostServices = hostServices;
Flags = flags;
}
public BuildRequestData (string projectFullPath, IDictionary<string, string> globalProperties,
string toolsVersion, string[] targetsToBuild, HostServices hostServices)
: this (projectFullPath, globalProperties, toolsVersion, targetsToBuild, hostServices, BuildRequestDataFlags.None)
{
}
public BuildRequestData (string projectFullPath, IDictionary<string, string> globalProperties,
string toolsVersion, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags)
: this (new ProjectInstance (projectFullPath, globalProperties, toolsVersion), targetsToBuild, hostServices, flags)
{
ExplicitlySpecifiedToolsVersion = toolsVersion;
}
public string ExplicitlySpecifiedToolsVersion { get; private set; }
[MonoTODO ("unused")]
public BuildRequestDataFlags Flags { get; private set; }
[MonoTODO ("unused")]
public HostServices HostServices { get; private set; }
public string ProjectFullPath {
get { return ProjectInstance.FullPath; }
}
[MonoTODO ("unused")]
public ProjectInstance ProjectInstance { get; private set; }
[MonoTODO]
public IEnumerable<string> PropertiesToTransfer { get; private set; }
[MonoTODO]
public ICollection<string> TargetNames { get; private set; }
ICollection<ProjectPropertyInstance> GlobalProperties {
get { return ProjectInstance.Properties.Where (p => ProjectInstance.GlobalProperties.Any (i => i.Key == p.Name)).ToArray (); } // we can use == as it should be identical match there.
}
}
}

View File

@@ -0,0 +1,40 @@
//
// BuildRequestDataFlags.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright (C) 2011 Xamarin Inc.
//
// 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;
namespace Microsoft.Build.Execution
{
[Flags]
public enum BuildRequestDataFlags
{
None,
ReplaceExistingProjectInstance,
}
}

View File

@@ -0,0 +1,101 @@
// BuildResult.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright (C) 2011 Xamarin Inc.
//
// 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.Generic;
using System.Linq;
namespace Microsoft.Build.Execution
{
public class BuildResult
{
public BuildResult ()
{
ResultsByTarget = new Dictionary<string, TargetResult> ();
}
public void AddResultsForTarget (string target, TargetResult result)
{
ResultsByTarget.Add (target, result);
}
public bool HasResultsForTarget (string target)
{
return ResultsByTarget.ContainsKey (target);
}
public void MergeResults (BuildResult results)
{
if (ConfigurationId != results.ConfigurationId)
throw new InvalidOperationException ("Argument BuildResults have inconsistent ConfigurationId.");
if (GlobalRequestId != results.GlobalRequestId)
throw new InvalidOperationException ("Argument BuildResults have inconsistent GlobalRequestId.");
if (NodeRequestId != results.NodeRequestId)
throw new InvalidOperationException ("Argument BuildResults have inconsistent NodeRequestId.");
if (ParentGlobalRequestId != results.ParentGlobalRequestId)
throw new InvalidOperationException ("Argument BuildResults have inconsistent ParentGlobalRequestId.");
if (SubmissionId != results.SubmissionId)
throw new InvalidOperationException ("Argument BuildResults have inconsistent SubmissionId.");
CircularDependency |= results.CircularDependency;
Exception = Exception ?? results.Exception;
foreach (var p in results.ResultsByTarget)
ResultsByTarget.Add (p.Key, p.Value);
}
public bool CircularDependency { get; internal set; }
public int ConfigurationId { get; internal set; }
public Exception Exception { get; set; }
public int GlobalRequestId { get; internal set; }
public ITargetResult this [string target] {
get { return ResultsByTarget [target]; }
}
public int NodeRequestId { get; internal set; }
BuildResultCode? overall_result;
public BuildResultCode OverallResult {
get {
if (overall_result == null)
throw new InvalidOperationException ("Build has not finished");
return overall_result.Value;
}
internal set { overall_result = value; }
}
public int ParentGlobalRequestId { get; internal set; }
public IDictionary<string, TargetResult> ResultsByTarget { get; private set; }
public int SubmissionId { get; internal set; }
}
}

View File

@@ -0,0 +1,36 @@
// BuildResultCode.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright (C) 2011 Xamarin Inc.
//
// 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.
//
namespace Microsoft.Build.Execution
{
public enum BuildResultCode
{
Success,
Failure
}
}

View File

@@ -0,0 +1,120 @@
// BuildSubmission.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
// Atsushi Enomoto (atsushi@xamarin.com)
//
// Copyright (C) 2011,2013 Xamarin Inc.
//
// 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.Threading;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Internal;
using System.Collections.Generic;
namespace Microsoft.Build.Execution
{
public class BuildSubmission
{
static Random rnd = new Random ();
internal BuildSubmission (BuildManager build, BuildRequestData requestData)
{
BuildManager = build;
this.request = requestData;
SubmissionId = rnd.Next ();
}
BuildRequestData request;
BuildSubmissionCompleteCallback callback;
bool is_started, is_completed, is_canceled;
ManualResetEvent wait_handle = new ManualResetEvent (true);
public object AsyncContext { get; private set; }
public BuildManager BuildManager { get; private set; }
public BuildResult BuildResult { get; set; }
public bool IsCompleted {
get { return is_completed; }
}
public int SubmissionId { get; private set; }
public WaitHandle WaitHandle {
get { return wait_handle; }
}
internal BuildRequestData BuildRequest {
get { return this.request; }
}
internal void Cancel ()
{
if (is_canceled)
throw new InvalidOperationException ("Build has already canceled");
is_canceled = true;
}
public BuildResult Execute ()
{
ExecuteAsync (null, null);
WaitHandle.WaitOne ();
return BuildResult;
}
internal BuildResult InternalExecute ()
{
BuildResult = new BuildResult () { SubmissionId = SubmissionId };
try {
var engine = new BuildEngine4 (this);
string toolsVersion = request.ExplicitlySpecifiedToolsVersion ?? request.ProjectInstance.ToolsVersion ?? BuildManager.OngoingBuildParameters.DefaultToolsVersion;
var outputs = new Dictionary<string,string> ();
engine.BuildProject (() => is_canceled, BuildResult, request.ProjectInstance, request.TargetNames, BuildManager.OngoingBuildParameters.GlobalProperties, outputs, toolsVersion);
} catch (Exception ex) {
BuildResult.Exception = ex;
BuildResult.OverallResult = BuildResultCode.Failure;
}
is_completed = true;
if (callback != null)
callback (this);
wait_handle.Set ();
return BuildResult;
}
public void ExecuteAsync (BuildSubmissionCompleteCallback callback, object context)
{
if (is_completed)
throw new InvalidOperationException ("Build has already completed");
if (is_canceled)
throw new InvalidOperationException ("Build has already canceled");
if (is_started)
throw new InvalidOperationException ("Build has already started");
is_started = true;
this.AsyncContext = context;
this.callback = callback;
wait_handle.Reset ();
BuildManager.BuildNodeManager.Enqueue (this);
}
}
}

View File

@@ -0,0 +1,5 @@
namespace Microsoft.Build.Execution
{
public delegate void BuildSubmissionCompleteCallback (BuildSubmission submission);
}

View File

@@ -0,0 +1,120 @@
//
// HostServices.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright (C) 2011 Xamarin Inc.
//
// 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.Generic;
using System.Linq;
using Microsoft.Build.Framework;
namespace Microsoft.Build.Execution
{
public class HostServices
{
class HostObjectRegistration
{
public string ProjectFile { get; set; }
public string TargetName { get; set; }
public string TaskName { get; set; }
public ITaskHost HostObject { get; set; }
}
readonly List<HostObjectRegistration> hosts = new List<HostObjectRegistration> ();
readonly Dictionary<string,NodeAffinity> node_affinities = new Dictionary<string, NodeAffinity> ();
HostObjectRegistration GetHostRegistration (string projectFile, string targetName, string taskName)
{
if (projectFile == null)
throw new ArgumentNullException ("projectFile");
if (targetName == null)
throw new ArgumentNullException ("targetName");
if (taskName == null)
throw new ArgumentNullException ("taskName");
return hosts.FirstOrDefault (h =>
string.Equals (projectFile, h.ProjectFile, StringComparison.OrdinalIgnoreCase) &&
string.Equals (targetName, h.TargetName, StringComparison.OrdinalIgnoreCase) &&
string.Equals (taskName, h.TaskName, StringComparison.OrdinalIgnoreCase));
}
public ITaskHost GetHostObject (string projectFile, string targetName, string taskName)
{
var reg = GetHostRegistration (projectFile, targetName, taskName);
return reg != null ? reg.HostObject : null;
}
public NodeAffinity GetNodeAffinity (string projectFile)
{
if (projectFile == null)
throw new ArgumentNullException ("projectFile");
NodeAffinity na;
return node_affinities.TryGetValue (projectFile, out na) ? na : NodeAffinity.Any;
}
IEnumerable<HostObjectRegistration> GetRegistrationsByProject (string project)
{
return hosts.Where (h => string.Equals (project, h.ProjectFile, StringComparison.OrdinalIgnoreCase));
}
public void OnRenameProject (string oldFullPath, string newFullPath)
{
if (oldFullPath == null)
throw new ArgumentNullException ("oldFullPath");
if (newFullPath == null)
throw new ArgumentNullException ("newFullPath");
foreach (var reg in GetRegistrationsByProject (oldFullPath))
reg.ProjectFile = newFullPath;
}
public void RegisterHostObject (string projectFile, string targetName, string taskName, ITaskHost hostObject)
{
if (hostObject == null)
throw new ArgumentNullException ("hostObject");
var reg = GetHostRegistration (projectFile, targetName, taskName);
if (reg != null)
reg.HostObject = hostObject;
else
hosts.Add (new HostObjectRegistration () { ProjectFile = projectFile, TargetName = targetName, TaskName = taskName, HostObject = hostObject });
}
public void SetNodeAffinity (string projectFile, NodeAffinity nodeAffinity)
{
if (projectFile == null)
throw new ArgumentNullException ("projectFile");
node_affinities [projectFile] = nodeAffinity;
}
public void UnregisterProject (string projectFullPath)
{
if (projectFullPath == null)
throw new ArgumentNullException ("projectFullPath");
var removed = GetRegistrationsByProject (projectFullPath).ToArray ();
foreach (var r in removed)
hosts.Remove (r);
}
}
}

View File

@@ -0,0 +1,40 @@
// ITargetResult.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright (C) 2011 Xamarin Inc.
//
// 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 Microsoft.Build.Framework;
using System;
namespace Microsoft.Build.Execution
{
public interface ITargetResult
{
Exception Exception { get; }
ITaskItem[] Items { get; }
TargetResultCode ResultCode { get; }
}
}

View File

@@ -0,0 +1,40 @@
//
// NodeAffinity.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright (C) 2011 Xamarin Inc.
//
// 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;
namespace Microsoft.Build.Execution
{
public enum NodeAffinity
{
InProc,
OutOfProc,
Any,
}
}

View File

@@ -0,0 +1,47 @@
//
// NodeEngineShutdownReason.cs
//
// Author:
// Atsushi Enomoto (atsushi@xamarin.com)
//
// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.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.Collections.Generic;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Evaluation;
using System.Linq;
using System.IO;
namespace Microsoft.Build.Internal
{
public enum NodeEngineShutdownReason
{
BuildComplete,
BuildCompleteReuse,
ConnectionFailed,
Error,
}
}

View File

@@ -0,0 +1,48 @@
//
// OutOfProcNode.cs
//
// Author:
// Atsushi Enomoto (atsushi@xamarin.com)
//
// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.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.Collections.Generic;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Evaluation;
using System.Linq;
using System.IO;
namespace Microsoft.Build.Internal
{
// from MSDN: this class has deprecated and there is no alternative.
public class OutOfProcNode
{
public NodeEngineShutdownReason Run (out Exception shutdownException)
{
throw new NotImplementedException ();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,71 @@
//
// ProjectItemDefinitionInstance.cs
//
// Author:
// Atsushi Enomoto (atsushi@veritas-vos-liberabit.com)
//
// Copyright (C) 2012,2013 Xamarin Inc.
//
// 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 Microsoft.Build.Framework;
using System;
using System.Collections.Generic;
using Microsoft.Build.Construction;
using System.Linq;
namespace Microsoft.Build.Execution
{
public class ProjectItemDefinitionInstance
{
internal ProjectItemDefinitionInstance (ProjectItemDefinitionElement xml)
{
ItemType = xml.ItemType;
AddItems (xml);
}
List<ProjectMetadataInstance> metadata = new List<ProjectMetadataInstance> ();
public string ItemType { get; private set; }
public ICollection<ProjectMetadataInstance> Metadata {
get { return metadata; }
}
public int MetadataCount {
get { return metadata.Count; }
}
public IEnumerable<string> MetadataNames {
get { return metadata.Select (m => m.Name).ToArray (); }
}
internal void AddItems (ProjectItemDefinitionElement xml)
{
foreach (var item in xml.Metadata) {
var existing = metadata.FirstOrDefault (i => i.Name == item.Name);
if (existing != null)
metadata.Remove (existing);
metadata.Add (new ProjectMetadataInstance (item.Name, item.Value));
}
}
}
}

View File

@@ -0,0 +1,82 @@
//
// ProjectItemGroupTaskInstance.cs
//
// Author:
// Atsushi Enomoto (atsushi@xamarin.com)
//
// (C) 2013 Xamarin Inc.
//
// 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.Generic;
using System.Linq;
using Microsoft.Build.Construction;
namespace Microsoft.Build.Execution
{
public sealed class ProjectItemGroupTaskInstance : ProjectTargetInstanceChild
{
internal ProjectItemGroupTaskInstance (ProjectItemGroupElement xml)
{
condition = xml.Condition;
condition_location = xml.ConditionLocation;
//this.FullPath = fullPath;
location = xml.Location;
Items = xml.Items.Select (item => new ProjectItemGroupTaskItemInstance (item)).ToArray ();
}
readonly string condition;
readonly ElementLocation condition_location, location;
public override string Condition {
get { return condition; }
}
#if NET_4_5
public
#else
internal
#endif
override ElementLocation ConditionLocation {
get { return condition_location; }
}
#if NET_4_5
public
#else
internal
#endif
override ElementLocation Location {
get { return location; }
}
#if NET_4_5
public
#else
internal
#endif
ElementLocation ExecuteTargetsLocation { get; private set; }
public ICollection<ProjectItemGroupTaskItemInstance> Items { get; private set; }
}
}

View File

@@ -0,0 +1,95 @@
//
// ProjectItemGroupTaskItemInstance.cs
//
// Author:
// Atsushi Enomoto (atsushi@xamarin.com)
//
// (C) 2013 Xamarin Inc.
//
// 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 Microsoft.Build.Construction;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.Build.Execution
{
public class ProjectItemGroupTaskItemInstance
{
internal ProjectItemGroupTaskItemInstance (ProjectItemElement xml)
{
Condition = xml.Condition;
Exclude = xml.Exclude;
Include = xml.Include;
ItemType = xml.ItemType;
Metadata = xml.Metadata.Select (m => new ProjectItemGroupTaskMetadataInstance (m)).ToArray ();
Remove = xml.Remove;
#if NET_4_5
KeepDuplicates = xml.KeepDuplicates;
KeepMetadata = xml.KeepMetadata;
RemoveMetadata = xml.RemoveMetadata;
ConditionLocation = xml.ConditionLocation;
ExcludeLocation = xml.ExcludeLocation;
IncludeLocation = xml.IncludeLocation;
Location = xml.Location;
KeepDuplicatesLocation = xml.KeepDuplicatesLocation;
RemoveLocation = xml.RemoveLocation;
RemoveMetadataLocation = xml.RemoveMetadataLocation;
#endif
}
public string Condition { get; private set; }
public string Exclude { get; private set; }
public string Include { get; private set; }
public string ItemType { get; private set; }
public string KeepDuplicates { get; private set; }
public string KeepMetadata { get; private set; }
public ICollection<ProjectItemGroupTaskMetadataInstance> Metadata { get; private set; }
public string Remove { get; private set; }
public string RemoveMetadata { get; private set; }
#if NET_4_5
public ElementLocation ConditionLocation { get; private set; }
public ElementLocation ExcludeLocation { get; private set; }
public ElementLocation IncludeLocation { get; private set; }
public ElementLocation KeepDuplicatesLocation { get; private set; }
public ElementLocation KeepMetadataLocation { get; private set; }
public ElementLocation Location { get; private set; }
public ElementLocation RemoveLocation { get; private set; }
public ElementLocation RemoveMetadataLocation { get; private set; }
#endif
}
}

View File

@@ -0,0 +1,58 @@
//
// ProjectItemGroupTaskMetadataInstance.cs
//
// Author:
// Atsushi Enomoto (atsushi@xamarin.com)
//
// (C) 2013 Xamarin Inc.
//
// 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.Generic;
using Microsoft.Build.Construction;
namespace Microsoft.Build.Execution
{
public sealed class ProjectItemGroupTaskMetadataInstance
{
internal ProjectItemGroupTaskMetadataInstance (ProjectMetadataElement xml)
{
Condition = xml.Condition;
Name = xml.Name;
Value = xml.Value;
#if NET_4_5
ConditionLocation = xml.ConditionLocation;
Location = xml.Location;
#endif
}
public string Condition { get; private set; }
public string Name { get; private set; }
public string Value { get; private set; }
#if NET_4_5
public ElementLocation ConditionLocation { get; private set; }
public ElementLocation Location { get; private set; }
#endif
}
}

View File

@@ -0,0 +1,217 @@
//
// ProjectItemInstance.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
// Atsushi Enomoto (atsushi@xamarin.com)
//
// Copyright (C) 2011,2013 Xamarin Inc.
//
// 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.Generic;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Evaluation;
using System.Collections;
using Microsoft.Build.Construction;
using System.Globalization;
using System.IO;
namespace Microsoft.Build.Execution
{
public class ProjectItemInstance
: ITaskItem2
{
internal ProjectItemInstance (ProjectInstance project, string itemType, IEnumerable<KeyValuePair<string,string>> metadata, string evaluatedInclude)
{
this.project = project;
this.evaluated_include = evaluatedInclude;
this.item_type = itemType;
this.metadata = new List<ProjectMetadataInstance> ();
SetMetadata (metadata);
}
readonly ProjectInstance project;
readonly string item_type;
string evaluated_include;
readonly List<ProjectMetadataInstance> metadata;
public ProjectMetadataInstance GetMetadata (string name)
{
if (name == null)
throw new ArgumentNullException ("name");
// This does not return any Well Known metadata
return Metadata.FirstOrDefault (m => m.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
}
public string GetMetadataValue (string name)
{
if (name == null)
throw new ArgumentNullException ("name");
var wk = ProjectCollection.GetWellKnownMetadata (name, EvaluatedInclude, project.GetFullPath, RecursiveDir);
if (wk != null)
return wk;
var m = GetMetadata (name);
return m != null ? m.EvaluatedValue : string.Empty;
}
public bool HasMetadata (string name)
{
return GetMetadata (name) != null;
}
public void RemoveMetadata (string metadataName)
{
var m = GetMetadata (metadataName);
if (m != null)
metadata.Remove (m);
}
public void SetMetadata (IEnumerable<KeyValuePair<string, string>> metadataDictionary)
{
foreach (var p in metadataDictionary)
SetMetadata (p.Key, p.Value);
}
public ProjectMetadataInstance SetMetadata (string name, string evaluatedValue)
{
var m = metadata.FirstOrDefault (_ => _.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
if (m != null)
metadata.Remove (m);
m = new ProjectMetadataInstance (name, evaluatedValue);
metadata.Add (m);
return m;
}
public int DirectMetadataCount {
get { throw new NotImplementedException (); }
}
public string EvaluatedInclude {
get { return evaluated_include; }
set {
if (value == null)
throw new ArgumentNullException ("value");
evaluated_include = value;
}
}
public string ItemType {
get { return item_type; }
}
public IEnumerable<ProjectMetadataInstance> Metadata {
get { return metadata; }
}
public int MetadataCount {
get { return metadata.Count; }
}
public ICollection<string> MetadataNames {
get { return metadata.Select (m => m.Name).ToArray (); }
}
public ProjectInstance Project {
get { return project; }
}
internal string RecursiveDir { get; set; }
#region ITaskItem2 implementation
string ITaskItem2.GetMetadataValueEscaped (string metadataName)
{
return ProjectCollection.Escape (GetMetadataValue (metadataName));
}
void ITaskItem2.SetMetadataValueLiteral (string metadataName, string metadataValue)
{
SetMetadata (metadataName, metadataValue);
}
System.Collections.IDictionary ITaskItem2.CloneCustomMetadataEscaped ()
{
var dic = ((ITaskItem) this).CloneCustomMetadata ();
foreach (DictionaryEntry p in dic)
dic [p.Key] = ProjectCollection.Escape ((string) p.Value);
return dic;
}
string ITaskItem2.EvaluatedIncludeEscaped {
get { return ProjectCollection.Escape (EvaluatedInclude); }
set { EvaluatedInclude = ProjectCollection.Unescape (value); }
}
#endregion
#region ITaskItem implementation
IDictionary ITaskItem.CloneCustomMetadata ()
{
var dic = new Hashtable ();
foreach (var md in Metadata)
dic [md.Name] = md.EvaluatedValue;
return dic;
}
void ITaskItem.CopyMetadataTo (ITaskItem destinationItem)
{
if (destinationItem == null)
throw new ArgumentNullException ("destinationItem");
foreach (var md in Metadata)
destinationItem.SetMetadata (md.Name, md.EvaluatedValue);
}
string ITaskItem.GetMetadata (string metadataName)
{
return GetMetadataValue (metadataName);
}
void ITaskItem.RemoveMetadata (string metadataName)
{
RemoveMetadata (metadataName);
}
void ITaskItem.SetMetadata (string metadataName, string metadataValue)
{
SetMetadata (metadataName, ProjectCollection.Unescape (metadataValue));
}
string ITaskItem.ItemSpec {
get { return EvaluatedInclude; }
set { EvaluatedInclude = value; }
}
int ITaskItem.MetadataCount {
get { return MetadataCount; }
}
ICollection ITaskItem.MetadataNames {
get { return MetadataNames.ToArray (); }
}
#endregion
}
}

View File

@@ -0,0 +1,55 @@
//
// ProjectMetadataInstance.cs
//
// Author:
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
// Copyright (C) 2011 Xamarin Inc.
//
// 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 Microsoft.Build.Construction;
namespace Microsoft.Build.Execution
{
public class ProjectMetadataInstance
{
internal ProjectMetadataInstance (string name, string value)
{
Name = name;
EvaluatedValue = value;
}
public string EvaluatedValue { get; private set; }
public string Name { get; private set; }
public ProjectMetadataInstance DeepClone ()
{
return new ProjectMetadataInstance (Name, EvaluatedValue);
}
public override string ToString ()
{
return string.Format ("{0}={1}", Name, EvaluatedValue);
}
}
}

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