5 // Leszek Ciesielski (skolima@gmail.com)
6 // Rolf Bjarne Kvinge (rolf@xamarin.com)
8 // (C) 2011 Leszek Ciesielski
9 // Copyright (C) 2011 Xamarin Inc. (http://www.xamarin.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections.Generic;
33 using System.Diagnostics;
38 using Microsoft.Build.Construction;
39 using Microsoft.Build.Internal;
40 using Microsoft.Build.Execution;
41 using Microsoft.Build.Framework;
42 using Microsoft.Build.Logging;
44 namespace Microsoft.Build.Evaluation
46 [DebuggerDisplay ("{FullPath} EffectiveToolsVersion={ToolsVersion} #GlobalProperties="
47 + "{data.globalProperties.Count} #Properties={data.Properties.Count} #ItemTypes="
48 + "{data.ItemTypes.Count} #ItemDefinitions={data.ItemDefinitions.Count} #Items="
49 + "{data.Items.Count} #Targets={data.Targets.Count}")]
52 public Project (XmlReader xml)
53 : this (ProjectRootElement.Create (xml))
57 public Project (XmlReader xml, IDictionary<string, string> globalProperties,
59 : this (ProjectRootElement.Create (xml), globalProperties, toolsVersion)
63 public Project (XmlReader xml, IDictionary<string, string> globalProperties,
64 string toolsVersion, ProjectCollection projectCollection)
65 : this (ProjectRootElement.Create (xml), globalProperties, toolsVersion, projectCollection)
69 public Project (XmlReader xml, IDictionary<string, string> globalProperties,
70 string toolsVersion, ProjectCollection projectCollection,
71 ProjectLoadSettings loadSettings)
72 : this (ProjectRootElement.Create (xml), globalProperties, toolsVersion, projectCollection, loadSettings)
76 public Project (ProjectRootElement xml) : this (xml, null, null)
80 public Project (ProjectRootElement xml, IDictionary<string, string> globalProperties,
82 : this (xml, globalProperties, toolsVersion, ProjectCollection.GlobalProjectCollection)
86 public Project (ProjectRootElement xml, IDictionary<string, string> globalProperties,
87 string toolsVersion, ProjectCollection projectCollection)
88 : this (xml, globalProperties, toolsVersion, projectCollection, ProjectLoadSettings.Default)
92 public Project (ProjectRootElement xml, IDictionary<string, string> globalProperties,
93 string toolsVersion, ProjectCollection projectCollection,
94 ProjectLoadSettings loadSettings)
96 if (projectCollection == null)
97 throw new ArgumentNullException ("projectCollection");
98 this.GlobalProperties = globalProperties ?? new Dictionary<string, string> ();
99 this.ToolsVersion = toolsVersion;
100 this.ProjectCollection = projectCollection;
101 this.load_settings = loadSettings;
106 public Project (string projectFile)
107 : this (projectFile, null, null)
111 public Project (string projectFile, IDictionary<string, string> globalProperties,
113 : this (projectFile, globalProperties, toolsVersion, ProjectCollection.GlobalProjectCollection, ProjectLoadSettings.Default)
117 public Project (string projectFile, IDictionary<string, string> globalProperties,
118 string toolsVersion, ProjectCollection projectCollection)
119 : this (projectFile, globalProperties, toolsVersion, projectCollection, ProjectLoadSettings.Default)
123 public Project (string projectFile, IDictionary<string, string> globalProperties,
124 string toolsVersion, ProjectCollection projectCollection,
125 ProjectLoadSettings loadSettings)
126 : this (ProjectRootElement.Create (projectFile), globalProperties, toolsVersion, projectCollection, loadSettings)
130 ProjectLoadSettings load_settings;
132 public IDictionary<string, string> GlobalProperties { get; private set; }
134 public ProjectCollection ProjectCollection { get; private set; }
136 public string ToolsVersion { get; private set; }
138 public ProjectRootElement Xml { get; private set; }
140 string dir_path, full_path;
141 Dictionary<string, ProjectItemDefinition> item_definitions;
142 List<ResolvedImport> raw_imports;
143 List<ProjectItem> raw_items;
144 List<string> item_types;
145 List<ProjectProperty> properties;
146 Dictionary<string, ProjectTargetInstance> targets;
150 ConditionedProperties = new Dictionary<string, List<string>> ();
151 dir_path = Directory.GetCurrentDirectory ();
152 raw_imports = new List<ResolvedImport> ();
153 item_definitions = new Dictionary<string, ProjectItemDefinition> ();
154 item_types = new List<string> ();
155 properties = new List<ProjectProperty> ();
156 targets = new Dictionary<string, ProjectTargetInstance> ();
159 public ICollection<ProjectItem> GetItemsIgnoringCondition (string itemType)
161 return new CollectionFromEnumerable<ProjectItem> (
162 new FilteredEnumerable<ProjectItemElement> (Xml.Items).
163 Where (p => p.ItemType.Equals (itemType, StringComparison.OrdinalIgnoreCase)).
164 Select (p => new ProjectItem (p)));
167 public void RemoveItems (IEnumerable<ProjectItem> items)
169 var removal = new List<ProjectItem> (items);
170 foreach (var item in removal) {
171 var parent = item.Xml.Parent;
172 parent.RemoveChild (item.Xml);
173 if (parent.Count == 0)
174 parent.Parent.RemoveChild (parent);
178 static readonly Dictionary<string, string> empty_metadata = new Dictionary<string, string> ();
180 public IList<ProjectItem> AddItem (string itemType, string unevaluatedInclude)
182 return AddItem (itemType, unevaluatedInclude, empty_metadata);
185 public IList<ProjectItem> AddItem (string itemType, string unevaluatedInclude,
186 IEnumerable<KeyValuePair<string, string>> metadata)
188 // FIXME: needs several check that AddItemFast() does not process (see MSDN for details).
190 return AddItemFast (itemType, unevaluatedInclude, metadata);
193 public IList<ProjectItem> AddItemFast (string itemType, string unevaluatedInclude)
195 return AddItemFast (itemType, unevaluatedInclude, empty_metadata);
198 public IList<ProjectItem> AddItemFast (string itemType, string unevaluatedInclude,
199 IEnumerable<KeyValuePair<string, string>> metadata)
201 throw new NotImplementedException ();
206 return Build (Xml.DefaultTargets.Split (';'));
209 public bool Build (IEnumerable<ILogger> loggers)
211 return Build (Xml.DefaultTargets.Split (';'), loggers);
214 public bool Build (string target)
216 return string.IsNullOrWhiteSpace (target) ? Build () : Build (new string [] {target});
219 public bool Build (string[] targets)
221 return Build (targets, new ILogger [0]);
224 public bool Build (ILogger logger)
226 return Build (Xml.DefaultTargets.Split (';'), new ILogger [] {logger});
229 public bool Build (string[] targets, IEnumerable<ILogger> loggers)
231 return Build (targets, loggers, new ForwardingLoggerRecord [0]);
234 public bool Build (IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
236 return Build (Xml.DefaultTargets.Split (';'), loggers, remoteLoggers);
239 public bool Build (string target, IEnumerable<ILogger> loggers)
241 return Build (new string [] { target }, loggers);
244 public bool Build (string[] targets, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
246 throw new NotImplementedException ();
249 public bool Build (string target, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
251 return Build (new string [] { target }, loggers, remoteLoggers);
254 public ProjectInstance CreateProjectInstance ()
256 throw new NotImplementedException ();
259 public string ExpandString (string unexpandedValue)
261 throw new NotImplementedException ();
264 public static string GetEvaluatedItemIncludeEscaped (ProjectItem item)
266 throw new NotImplementedException ();
269 public static string GetEvaluatedItemIncludeEscaped (ProjectItemDefinition item)
271 throw new NotImplementedException ();
274 public ICollection<ProjectItem> GetItems (string itemType)
276 throw new NotImplementedException ();
279 public ICollection<ProjectItem> GetItemsByEvaluatedInclude (string evaluatedInclude)
281 throw new NotImplementedException ();
284 public IEnumerable<ProjectElement> GetLogicalProject ()
286 throw new NotImplementedException ();
289 public static string GetMetadataValueEscaped (ProjectMetadata metadatum)
291 throw new NotImplementedException ();
294 public static string GetMetadataValueEscaped (ProjectItem item, string name)
296 throw new NotImplementedException ();
299 public static string GetMetadataValueEscaped (ProjectItemDefinition item, string name)
301 throw new NotImplementedException ();
304 public string GetPropertyValue (string name)
306 throw new NotImplementedException ();
309 public static string GetPropertyValueEscaped (ProjectProperty property)
311 throw new NotImplementedException ();
314 public ProjectProperty GetProperty (string name)
316 throw new NotImplementedException ();
319 public void MarkDirty ()
321 throw new NotImplementedException ();
324 public void ReevaluateIfNecessary ()
326 throw new NotImplementedException ();
329 public bool RemoveGlobalProperty (string name)
331 throw new NotImplementedException ();
334 public bool RemoveItem (ProjectItem item)
336 throw new NotImplementedException ();
339 public bool RemoveProperty (ProjectProperty property)
341 throw new NotImplementedException ();
346 using (var writer = new StreamWriter (FullPath))
350 public void Save (TextWriter writer)
352 throw new NotImplementedException ();
355 public void Save (string path)
357 Save (path, Encoding.Default);
360 public void Save (Encoding encoding)
362 Save (FullPath, encoding);
365 public void Save (string path, Encoding encoding)
367 using (var writer = new StreamWriter (path, false, encoding))
371 public void SaveLogicalProject (TextWriter writer)
373 throw new NotImplementedException ();
376 public bool SetGlobalProperty (string name, string escapedValue)
378 throw new NotImplementedException ();
381 public ProjectProperty SetProperty (string name, string unevaluatedValue)
383 throw new NotImplementedException ();
386 public ICollection<ProjectMetadata> AllEvaluatedItemDefinitionMetadata { get; private set; }
388 public ICollection<ProjectItem> AllEvaluatedItems { get; private set; }
390 public ICollection<ProjectProperty> AllEvaluatedProperties { get; private set; }
392 public IDictionary<string, List<string>> ConditionedProperties { get; private set; }
394 public string DirectoryPath {
395 get { return dir_path; }
398 public bool DisableMarkDirty { get; set; }
400 public int EvaluationCounter {
401 get { throw new NotImplementedException (); }
404 public string FullPath {
405 get { return full_path; }
407 // FIXME: check validity? mark IsDirty?
412 public IList<ResolvedImport> Imports {
413 get { throw new NotImplementedException (); }
416 public IList<ResolvedImport> ImportsIncludingDuplicates {
417 get { return raw_imports; }
420 public bool IsBuildEnabled {
421 get { throw new NotImplementedException (); }
424 public bool IsDirty {
425 get { throw new NotImplementedException (); }
428 public IDictionary<string, ProjectItemDefinition> ItemDefinitions {
429 get { return item_definitions; }
432 public ICollection<ProjectItem> Items {
433 get { throw new NotImplementedException (); }
436 public ICollection<ProjectItem> ItemsIgnoringCondition {
437 get { return raw_items; }
440 public ICollection<string> ItemTypes {
441 get { return item_types; }
444 public ICollection<ProjectProperty> Properties {
445 get { return properties; }
448 public bool SkipEvaluation { get; set; }
450 public IDictionary<string, ProjectTargetInstance> Targets {
451 get { return targets; }