~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/TargetFramework.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
using System;
29
29
using System.IO;
30
 
using System.Reflection;
31
30
using System.Collections.Generic;
32
31
 
33
32
using Mono.Addins;
34
33
using Mono.PkgConfig;
35
34
using MonoDevelop.Core.AddIns;
36
35
using MonoDevelop.Core.Serialization;
 
36
using System.Reflection;
37
37
 
38
38
namespace MonoDevelop.Core.Assemblies
39
39
{
54
54
                ClrVersion clrVersion;
55
55
 
56
56
                List<TargetFrameworkMoniker> includedFrameworks = new List<TargetFrameworkMoniker> ();
57
 
                List<Framework> supportedFrameworks = new List<Framework> ();
 
57
                List<SupportedFramework> supportedFrameworks = new List<SupportedFramework> ();
58
58
 
59
59
                internal bool RelationsBuilt;
60
60
                
143
143
                        return TargetFrameworkToolsVersion.V4_0;
144
144
                }
145
145
 
146
 
                bool HackyCheckForPLPCompatibility (TargetFrameworkMoniker fxId)
 
146
                static bool ProfileMatchesPattern (string profile, string pattern)
147
147
                {
148
 
                        int profile, this_profile;
149
 
 
150
 
                        if (fxId.Profile == null || fxId.Profile.Length < 8 || !int.TryParse (fxId.Profile.Substring (7), out profile))
151
 
                                return false;
152
 
 
153
 
                        switch (this.id.Identifier) {
154
 
                        case TargetFrameworkMoniker.ID_NET_FRAMEWORK:
155
 
                                if (new Version (fxId.Version).CompareTo (new Version (this.id.Version)) > 0)
156
 
                                        return false;
157
 
 
158
 
                                return profile >= 1 && profile <= 3; // Profile4 does not support .NETFramework
159
 
                        case TargetFrameworkMoniker.ID_MONOTOUCH:
160
 
                        case TargetFrameworkMoniker.ID_MONODROID:
161
 
                                return profile >= 1 && profile <= 3;
162
 
                        case TargetFrameworkMoniker.ID_PORTABLE:
163
 
                                if (this.id.Profile == null || this.id.Profile.Length < 8 || !int.TryParse (this.id.Profile.Substring (7), out this_profile))
164
 
                                        return false;
165
 
 
166
 
                                switch (this_profile) {
167
 
                                case 1: return true;
168
 
                                case 2: return profile == 2;
169
 
                                case 3: return profile == 3;
170
 
                                case 4: return profile == 4;
171
 
                                default: return false;
172
 
                                }
173
 
                        default:
174
 
                                return false;
 
148
                        if (string.IsNullOrEmpty (pattern))
 
149
                                return string.IsNullOrEmpty (profile);
 
150
 
 
151
                        int star = pattern.IndexOf ('*');
 
152
 
 
153
                        if (star != -1) {
 
154
                                if (star == 0)
 
155
                                        return true;
 
156
 
 
157
                                if (string.IsNullOrEmpty (profile))
 
158
                                        return false;
 
159
 
 
160
                                var prefix = pattern.Substring (0, star);
 
161
                                return profile.StartsWith (prefix);
175
162
                        }
 
163
 
 
164
                        return profile == pattern;
176
165
                }
177
 
                
 
166
 
 
167
                [Obsolete ("Use CanReferenceAssembliesTargetingFramework() instead")]
178
168
                public bool IsCompatibleWithFramework (TargetFrameworkMoniker fxId)
179
169
                {
180
 
                        // FIXME: this is a hack which should really be done using the xml definitions for each .NETPortable profile
181
 
                        if (fxId.Identifier == ".NETPortable" && fxId.Version == "4.0")
182
 
                                return HackyCheckForPLPCompatibility (fxId);
183
 
 
184
 
                        return fxId.Identifier == this.id.Identifier
185
 
                                && new Version (fxId.Version).CompareTo (new Version (this.id.Version)) <= 0;
 
170
                        return CanReferenceAssembliesTargetingFramework (fxId);
 
171
                }
 
172
 
 
173
                public bool CanReferenceAssembliesTargetingFramework (TargetFrameworkMoniker fxId)
 
174
                {
 
175
                        var fx = Runtime.SystemAssemblyService.GetTargetFramework (fxId);
 
176
 
 
177
                        return fx != null && CanReferenceAssembliesTargetingFramework (fx);
 
178
                }
 
179
 
 
180
                /// <summary>
 
181
                /// Determines whether projects targeting this framework can reference assemblies targeting the framework specified by fx.
 
182
                /// </summary>
 
183
                /// <returns><c>true</c> if projects targeting this framework can reference assemblies targeting the framework specified by fx; otherwise, <c>false</c>.</returns>
 
184
                /// <param name="fx">The target framework</param>
 
185
                public bool CanReferenceAssembliesTargetingFramework (TargetFramework fx)
 
186
                {
 
187
                        foreach (var sfx in fx.SupportedFrameworks) {
 
188
                                if (sfx.Identifier != id.Identifier)
 
189
                                        continue;
 
190
 
 
191
                                if (!ProfileMatchesPattern (id.Profile, sfx.Profile))
 
192
                                        continue;
 
193
 
 
194
                                var version = new Version (id.Version);
 
195
 
 
196
                                if (version >= sfx.MinimumVersion && version <= sfx.MaximumVersion)
 
197
                                        return true;
 
198
                        }
 
199
 
 
200
                        // FIXME: this is a hack for systems w/o Portable Class Library definitions
 
201
                        if (fx.Id.Identifier == TargetFrameworkMoniker.ID_PORTABLE) {
 
202
                                switch (id.Identifier) {
 
203
                                case TargetFrameworkMoniker.ID_NET_FRAMEWORK:
 
204
                                        return new Version (fx.Id.Version).CompareTo (new Version (id.Version)) <= 0;
 
205
                                case TargetFrameworkMoniker.ID_MONOTOUCH:
 
206
                                case TargetFrameworkMoniker.ID_MONODROID:
 
207
                                        return true;
 
208
                                }
 
209
                        }
 
210
 
 
211
                        return fx.Id.Identifier == id.Identifier && new Version (fx.Id.Version).CompareTo (new Version (id.Version)) <= 0;
186
212
                }
187
213
                
188
214
                internal string GetCorlibVersion ()
241
267
                        return new TargetFrameworkMoniker (id.Identifier, version);     
242
268
                }
243
269
                
244
 
                public List<Framework> SupportedFrameworks {
 
270
                public List<SupportedFramework> SupportedFrameworks {
245
271
                        get { return supportedFrameworks; }
246
272
                }
247
273
                
291
317
                                        case "4.0":
292
318
                                                fx.clrVersion = ClrVersion.Net_4_0;
293
319
                                                break;
 
320
                                        case "4.5":
 
321
                                                fx.clrVersion = ClrVersion.Net_4_5;
 
322
                                                break;
294
323
                                        default:
295
324
                                                throw new Exception ("Unknown RuntimeVersion '" + runtimeVersion + "'");
296
325
                                        }
308
337
                                        case "4.0":
309
338
                                                fx.toolsVersion = TargetFrameworkToolsVersion.V4_0;
310
339
                                                break;
 
340
                                        case "4.5":
 
341
                                                fx.toolsVersion = TargetFrameworkToolsVersion.V4_5;
 
342
                                                break;
311
343
                                        default:
312
344
                                                throw new Exception ("Unknown ToolsVersion '" + runtimeVersion + "'");
313
345
                                        }
351
383
                                                        ainfo.InGac = reader.ReadContentAsBoolean ();
352
384
                                        } while (reader.ReadToFollowing ("File"));
353
385
                                } else {
 
386
 
 
387
                                        // HACK: we were using EnumerateFiles but it's broken in some Mono releases
 
388
                                        // https://bugzilla.xamarin.com/show_bug.cgi?id=2975
354
389
                                        var files = System.IO.Directory.GetFiles (dir, "*.dll");
355
390
                                        foreach (var f in files) {
356
391
                                                try {
370
405
                        
371
406
                        var supportedFrameworksDir = dir.Combine ("SupportedFrameworks");
372
407
                        if (Directory.Exists (supportedFrameworksDir)) {
373
 
                                foreach (var sfx in Directory.EnumerateFiles (supportedFrameworksDir))
374
 
                                        fx.SupportedFrameworks.Add (Framework.Load (fx, sfx));
 
408
                                foreach (var sfx in Directory.GetFiles (supportedFrameworksDir))
 
409
                                        fx.SupportedFrameworks.Add (SupportedFramework.Load (fx, sfx));
375
410
                        }
376
411
                        
377
412
                        return fx;
444
479
                V2_0,
445
480
                V3_5,
446
481
                V4_0,
 
482
                V4_5
447
483
        }
448
484
}