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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/SupportedFramework.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:
 
1
// 
 
2
// SupportedFramework.cs
 
3
//  
 
4
// Author: Jeffrey Stedfast <jeff@xamarin.com>
 
5
// 
 
6
// Copyright (c) 2012 Xamarin Inc.
 
7
// 
 
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
9
// of this software and associated documentation files (the "Software"), to deal
 
10
// in the Software without restriction, including without limitation the rights
 
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
12
// copies of the Software, and to permit persons to whom the Software is
 
13
// furnished to do so, subject to the following conditions:
 
14
// 
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
// 
 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
24
// THE SOFTWARE.
 
25
 
 
26
using System;
 
27
using System.IO;
 
28
using System.Xml;
 
29
 
 
30
namespace MonoDevelop.Core.Assemblies
 
31
{
 
32
        public class SupportedFramework
 
33
        {
 
34
                public static readonly Version NoMaximumVersion = new Version (int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue);
 
35
                public static readonly Version NoMinumumVersion = new Version (0, 0, 0, 0);
 
36
 
 
37
                public SupportedFramework (TargetFramework target, string identifier, string display, string profile, Version minVersion, string minDisplayVersion)
 
38
                {
 
39
                        MinimumVersionDisplayName = minDisplayVersion;
 
40
                        MinimumVersion = minVersion;
 
41
                        MaximumVersion = NoMaximumVersion;
 
42
                        DisplayName = display;
 
43
                        Identifier = identifier;
 
44
                        Profile = profile;
 
45
                        
 
46
                        TargetFramework = target;
 
47
                }
 
48
 
 
49
                internal SupportedFramework (TargetFramework target)
 
50
                {
 
51
                        MinimumVersionDisplayName = string.Empty;
 
52
                        MinimumVersion = NoMinumumVersion;
 
53
                        MaximumVersion = NoMaximumVersion;
 
54
                        DisplayName = string.Empty;
 
55
                        Identifier = string.Empty;
 
56
                        Profile = string.Empty;
 
57
                        
 
58
                        TargetFramework = target;
 
59
                }
 
60
                
 
61
                public string DisplayName {
 
62
                        get; internal set;
 
63
                }
 
64
                
 
65
                public string Identifier {
 
66
                        get; internal set;
 
67
                }
 
68
                
 
69
                public string Profile {
 
70
                        get; internal set;
 
71
                }
 
72
                
 
73
                public string MinimumVersionDisplayName {
 
74
                        get; internal set;
 
75
                }
 
76
                
 
77
                public Version MinimumVersion {
 
78
                        get; internal set;
 
79
                }
 
80
                
 
81
                public Version MaximumVersion {
 
82
                        get; internal set;
 
83
                }
 
84
                
 
85
                public TargetFramework TargetFramework {
 
86
                        get; private set;
 
87
                }
 
88
                
 
89
                static Version ParseVersion (string version, Version wildcard)
 
90
                {
 
91
                        if (version == "*")
 
92
                                return wildcard;
 
93
                        
 
94
                        return Version.Parse (version);
 
95
                }
 
96
                
 
97
                internal static SupportedFramework Load (TargetFramework target, FilePath path)
 
98
                {
 
99
                        SupportedFramework fx = new SupportedFramework (target);
 
100
 
 
101
                        fx.DisplayName = path.FileNameWithoutExtension;
 
102
                        
 
103
                        using (var reader = XmlReader.Create (path)) {
 
104
                                if (!reader.ReadToDescendant ("Framework"))
 
105
                                        throw new Exception ("Missing Framework element");
 
106
                                
 
107
                                if (!reader.HasAttributes)
 
108
                                        throw new Exception ("Framework element does not contain any attributes");
 
109
                                
 
110
                                while (reader.MoveToNextAttribute ()) {
 
111
                                        switch (reader.Name) {
 
112
                                        case "MaximumVersion":
 
113
                                                fx.MaximumVersion = ParseVersion (reader.Value, NoMaximumVersion);
 
114
                                                break;
 
115
                                        case "MinimumVersion":
 
116
                                                fx.MinimumVersion = ParseVersion (reader.Value, NoMinumumVersion);
 
117
                                                break;
 
118
                                        case "Profile":
 
119
                                                fx.Profile = reader.Value;
 
120
                                                break;
 
121
                                        case "Identifier":
 
122
                                                fx.Identifier = reader.Value;
 
123
                                                break;
 
124
                                        case "MinimumVersionDisplayName":
 
125
                                                fx.MinimumVersionDisplayName = reader.Value;
 
126
                                                break;
 
127
                                        case "DisplayName":
 
128
                                                fx.DisplayName = reader.Value;
 
129
                                                break;
 
130
                                        }
 
131
                                }
 
132
                        }
 
133
 
 
134
                        if (string.IsNullOrEmpty (fx.Identifier))
 
135
                                throw new Exception ("Framework element did not specify an Identifier attribute");
 
136
                        
 
137
                        return fx;
 
138
                }
 
139
        }
 
140
}