Fix net_4_0 build.
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Evaluation / ProjectCollection.cs
1 //
2 // ProjectCollection.cs
3 //
4 // Author:
5 //   Leszek Ciesielski (skolima@gmail.com)
6 //   Rolf Bjarne Kvinge (rolf@xamarin.com)
7 //
8 // (C) 2011 Leszek Ciesielski
9 // Copyright (C) 2011 Xamarin Inc.
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using Microsoft.Build.Construction;
32 using Microsoft.Build.Execution;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Logging;
35 using Microsoft.Build.Utilities;
36 using System;
37 using System.Collections.Generic;
38 using System.Collections.ObjectModel;
39 using System.IO;
40 using System.Linq;
41
42 namespace Microsoft.Build.Evaluation
43 {
44         public class ProjectCollection : IDisposable
45         {
46                 // static members
47
48                 static readonly ProjectCollection global_project_collection;
49
50                 static ProjectCollection ()
51                 {
52                         #if NET_4_5
53                         global_project_collection = new ProjectCollection (new ReadOnlyDictionary<string, string> (new Dictionary<string, string> ()));
54                         #else
55                         global_project_collection = new ProjectCollection (new Dictionary<string, string> ());
56                         #endif
57                 }
58
59                 public static string Escape (string unescapedString)
60                 {
61                         return unescapedString;
62                 }
63
64                 public static ProjectCollection GlobalProjectCollection {
65                         get { return global_project_collection; }
66                 }
67
68                 // semantic model part
69
70                 public ProjectCollection ()
71                         : this (null)
72                 {
73                 }
74
75                 public ProjectCollection (IDictionary<string, string> globalProperties)
76                 : this (globalProperties, null, ToolsetDefinitionLocations.Registry | ToolsetDefinitionLocations.ConfigurationFile)
77                 {
78                 }
79
80                 public ProjectCollection (ToolsetDefinitionLocations toolsetDefinitionLocations)
81                 : this (null, null, toolsetDefinitionLocations)
82                 {
83                 }
84
85                 public ProjectCollection (IDictionary<string, string> globalProperties, IEnumerable<ILogger> loggers,
86                                 ToolsetDefinitionLocations toolsetDefinitionLocations)
87                         : this (globalProperties, loggers, null, toolsetDefinitionLocations, int.MaxValue, false)
88                 {
89                 }
90
91                 public ProjectCollection (IDictionary<string, string> globalProperties,
92                                 IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers,
93                                 ToolsetDefinitionLocations toolsetDefinitionLocations,
94                                 int maxNodeCount, bool onlyLogCriticalEvents)
95                 {
96                         global_properties = globalProperties ?? new Dictionary<string, string> ();
97                         this.loggers = loggers != null ? loggers.ToList () : new List<ILogger> ();
98                         toolset_locations = toolsetDefinitionLocations;
99                         max_node_count = maxNodeCount;
100                         OnlyLogCriticalEvents = onlyLogCriticalEvents;
101
102                         LoadDefaultToolsets ();
103                 }
104
105                 readonly int max_node_count;
106
107                 [MonoTODO]
108                 public int Count {
109                         get { return loaded_projects.Count; }
110                 }
111
112                 [MonoTODO]
113                 public string DefaultToolsVersion {
114                         get { throw new NotImplementedException (); }
115                 }
116
117                 public void Dispose ()
118                 {
119                         Dispose (true);
120                         GC.SuppressFinalize (this);
121                 }
122
123                 protected virtual void Dispose (bool disposing)
124                 {
125                         if (disposing) {
126                         }
127                 }
128
129                 public ICollection<Project> GetLoadedProjects (string fullPath)
130                 {
131                         return LoadedProjects.Where (p => Path.GetFullPath (p.FullPath) == Path.GetFullPath (fullPath)).ToList ();
132                 }
133
134                 readonly IDictionary<string, string> global_properties;
135
136                 public IDictionary<string, string> GlobalProperties {
137                         get { return global_properties; }
138                 }
139
140                 readonly List<Project> loaded_projects = new List<Project> ();
141
142                 [MonoTODO]
143                 public ICollection<Project> LoadedProjects {
144                         get { return loaded_projects; }
145                 }
146
147                 readonly List<ILogger> loggers = new List<ILogger> ();
148                 [MonoTODO]
149                 public ICollection<ILogger> Loggers {
150                         get { return loggers; }
151                 }
152
153                 [MonoTODO]
154                 public bool OnlyLogCriticalEvents { get; set; }
155
156                 [MonoTODO]
157                 public bool SkipEvaluation { get; set; }
158
159                 readonly ToolsetDefinitionLocations toolset_locations;
160                 public ToolsetDefinitionLocations ToolsetLocations {
161                         get { return toolset_locations; }
162                 }
163
164                 readonly List<Toolset> toolsets = new List<Toolset> ();
165                 [MonoTODO ("unused")]
166                 // so what should we do without ToolLocationHelper in Microsoft.Build.Utilities.dll? There is no reference to it in this dll.
167                 public ICollection<Toolset> Toolsets {
168                         // For ConfigurationFile and None, they cannot be added externally.
169                         get { return (ToolsetLocations & ToolsetDefinitionLocations.Registry) != 0 ? toolsets : toolsets.ToList (); }
170                 }
171
172                 //FIXME: should also support config file, depending on ToolsetLocations
173                 void LoadDefaultToolsets ()
174                 {
175                         toolsets.Add (new Toolset ("2.0",
176                                 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20), this, null));
177                         toolsets.Add (new Toolset ("3.0",
178                                 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version30), this, null));
179                         toolsets.Add (new Toolset ("3.5",
180                                 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version35), this, null));
181 #if NET_4_0
182                         toolsets.Add (new Toolset ("4.0",
183                                 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version40), this, null));
184 #endif
185 #if NET_4_5
186                         toolsets.Add (new Toolset ("4.5",
187                                 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version45), this, null));
188 #endif
189                 }
190
191                 public void UnloadAllProjects ()
192                 {
193                         throw new NotImplementedException ();
194                 }
195
196                 public void UnloadProject (Project project)
197                 {
198                         throw new NotImplementedException ();
199                 }
200
201                 public void UnloadProject (ProjectRootElement projectRootElement)
202                 {
203                         throw new NotImplementedException ();
204                 }
205
206                 public static Version Version {
207                         get { throw new NotImplementedException (); }
208                 }
209
210                 // Execution part
211
212                 [MonoTODO]
213                 public bool DisableMarkDirty { get; set; }
214
215                 [MonoTODO]
216                 public HostServices HostServices { get; set; }
217
218                 [MonoTODO]
219                 public bool IsBuildEnabled { get; set; }
220         }
221 }