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

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins.Setup/Mono.Addins.Setup/AddinInfo.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
// AddinInfo.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.IO;
 
31
using System.Collections;
 
32
using System.Xml;
 
33
using System.Xml.Serialization;
 
34
using Mono.Addins.Description;
 
35
 
 
36
namespace Mono.Addins.Setup
 
37
{
 
38
        internal class AddinInfo: AddinHeader
 
39
        {
 
40
                string id = "";
 
41
                string namspace = "";
 
42
                string name = "";
 
43
                string version = "";
 
44
                string baseVersion = "";
 
45
                string author = "";
 
46
                string copyright = "";
 
47
                string url = "";
 
48
                string description = "";
 
49
                string category = "";
 
50
                DependencyCollection dependencies;
 
51
                DependencyCollection optionalDependencies;
 
52
                AddinPropertyCollectionImpl properties;
 
53
                
 
54
                public AddinInfo ()
 
55
                {
 
56
                        dependencies = new DependencyCollection ();
 
57
                        optionalDependencies = new DependencyCollection ();
 
58
                        properties = new AddinPropertyCollectionImpl ();
 
59
                }
 
60
                
 
61
                public string Id {
 
62
                        get { return Addin.GetFullId (namspace, id, version); }
 
63
                }
 
64
                
 
65
                [XmlElement ("Id")]
 
66
                public string LocalId {
 
67
                        get { return id; }
 
68
                        set { id = value; }
 
69
                }
 
70
                
 
71
                public string Namespace {
 
72
                        get { return namspace; }
 
73
                        set { namspace = value; }
 
74
                }
 
75
                
 
76
                public string Name {
 
77
                        get {
 
78
                                string s = Properties.GetPropertyValue ("Name");
 
79
                                if (s.Length > 0)
 
80
                                        return s;
 
81
                                if (name != null && name.Length > 0)
 
82
                                        return name;
 
83
                                string sid = id;
 
84
                                if (sid.StartsWith ("__"))
 
85
                                        sid = sid.Substring (2);
 
86
                                return Addin.GetFullId (namspace, sid, null); 
 
87
                        }
 
88
                        set { name = value; }
 
89
                }
 
90
                
 
91
                public string Version {
 
92
                        get { return version; }
 
93
                        set { version = value; }
 
94
                }
 
95
                
 
96
                public string BaseVersion {
 
97
                        get { return baseVersion; }
 
98
                        set { baseVersion = value; }
 
99
                }
 
100
                
 
101
                public string Author {
 
102
                        get {
 
103
                                string s = Properties.GetPropertyValue ("Author");
 
104
                                if (s.Length > 0)
 
105
                                        return s;
 
106
                                return author;
 
107
                        }
 
108
                        set { author = value; }
 
109
                }
 
110
                
 
111
                public string Copyright {
 
112
                        get {
 
113
                                string s = Properties.GetPropertyValue ("Copyright");
 
114
                                if (s.Length > 0)
 
115
                                        return s;
 
116
                                return copyright;
 
117
                        }
 
118
                        set { copyright = value; }
 
119
                }
 
120
                
 
121
                public string Url {
 
122
                        get {
 
123
                                string s = Properties.GetPropertyValue ("Url");
 
124
                                if (s.Length > 0)
 
125
                                        return s;
 
126
                                return url;
 
127
                        }
 
128
                        set { url = value; }
 
129
                }
 
130
                
 
131
                public string Description {
 
132
                        get {
 
133
                                string s = Properties.GetPropertyValue ("Description");
 
134
                                if (s.Length > 0)
 
135
                                        return s;
 
136
                                return description;
 
137
                        }
 
138
                        set { description = value; }
 
139
                }
 
140
                
 
141
                public string Category {
 
142
                        get {
 
143
                                string s = Properties.GetPropertyValue ("Category");
 
144
                                if (s.Length > 0)
 
145
                                        return s;
 
146
                                return category;
 
147
                        }
 
148
                        set { category = value; }
 
149
                }
 
150
                
 
151
                [XmlArrayItem ("AddinDependency", typeof(AddinDependency))]
 
152
                [XmlArrayItem ("NativeDependency", typeof(NativeDependency))]
 
153
                [XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))]
 
154
                public DependencyCollection Dependencies {
 
155
                        get { return dependencies; }
 
156
                }
 
157
                
 
158
                [XmlArrayItem ("AddinDependency", typeof(AddinDependency))]
 
159
                [XmlArrayItem ("NativeDependency", typeof(NativeDependency))]
 
160
                [XmlArrayItem ("AssemblyDependency", typeof(AssemblyDependency))]
 
161
                public DependencyCollection OptionalDependencies {
 
162
                        get { return optionalDependencies; }
 
163
                }
 
164
                
 
165
                [XmlArrayItem ("Property", typeof(AddinProperty))]
 
166
                public AddinPropertyCollectionImpl Properties {
 
167
                        get { return properties; }
 
168
                }
 
169
                
 
170
                AddinPropertyCollection AddinHeader.Properties {
 
171
                        get { return properties; }
 
172
                }
 
173
                
 
174
                public static AddinInfo ReadFromAddinFile (StreamReader r)
 
175
                {
 
176
                        XmlDocument doc = new XmlDocument ();
 
177
                        doc.Load (r);
 
178
                        r.Close ();
 
179
                        
 
180
                        AddinInfo info = new AddinInfo ();
 
181
                        info.id = doc.DocumentElement.GetAttribute ("id");
 
182
                        info.namspace = doc.DocumentElement.GetAttribute ("namespace");
 
183
                        info.name = doc.DocumentElement.GetAttribute ("name");
 
184
                        if (info.id == "") info.id = info.name;
 
185
                        info.version = doc.DocumentElement.GetAttribute ("version");
 
186
                        info.author = doc.DocumentElement.GetAttribute ("author");
 
187
                        info.copyright = doc.DocumentElement.GetAttribute ("copyright");
 
188
                        info.url = doc.DocumentElement.GetAttribute ("url");
 
189
                        info.description = doc.DocumentElement.GetAttribute ("description");
 
190
                        info.category = doc.DocumentElement.GetAttribute ("category");
 
191
                        info.baseVersion = doc.DocumentElement.GetAttribute ("compatVersion");
 
192
                        AddinPropertyCollectionImpl props = new AddinPropertyCollectionImpl ();
 
193
                        info.properties = props;
 
194
                        ReadHeader (info, props, doc.DocumentElement);
 
195
                        ReadDependencies (info.Dependencies, info.OptionalDependencies, doc.DocumentElement);
 
196
                        return info;
 
197
                }
 
198
                
 
199
                static void ReadDependencies (DependencyCollection deps, DependencyCollection opDeps, XmlElement elem)
 
200
                {
 
201
                        foreach (XmlElement dep in elem.SelectNodes ("Dependencies/Addin")) {
 
202
                                AddinDependency adep = new AddinDependency ();
 
203
                                adep.AddinId = dep.GetAttribute ("id");
 
204
                                string v = dep.GetAttribute ("version");
 
205
                                if (v.Length != 0)
 
206
                                        adep.Version = v;
 
207
                                deps.Add (adep);
 
208
                        }
 
209
                        
 
210
                        foreach (XmlElement dep in elem.SelectNodes ("Dependencies/Assembly")) {
 
211
                                AssemblyDependency adep = new AssemblyDependency ();
 
212
                                adep.FullName = dep.GetAttribute ("name");
 
213
                                adep.Package = dep.GetAttribute ("package");
 
214
                                deps.Add (adep);
 
215
                        }
 
216
                        
 
217
                        foreach (XmlElement mod in elem.SelectNodes ("Module"))
 
218
                                ReadDependencies (opDeps, opDeps, mod);
 
219
                }
 
220
                
 
221
                static void ReadHeader (AddinInfo info, AddinPropertyCollectionImpl properties, XmlElement elem)
 
222
                {
 
223
                        elem = elem.SelectSingleNode ("Header") as XmlElement;
 
224
                        if (elem == null)
 
225
                                return;
 
226
                        foreach (XmlNode xprop in elem.ChildNodes) {
 
227
                                XmlElement prop = xprop as XmlElement;
 
228
                                if (prop != null) {
 
229
                                        switch (prop.LocalName) {
 
230
                                        case "Id": info.id = prop.InnerText; break;
 
231
                                        case "Namespace": info.namspace = prop.InnerText; break;
 
232
                                        case "Version": info.version = prop.InnerText; break;
 
233
                                        case "CompatVersion": info.baseVersion = prop.InnerText; break;
 
234
                                        default: {
 
235
                                                AddinProperty aprop = new AddinProperty ();
 
236
                                                aprop.Name = prop.LocalName;
 
237
                                                if (prop.HasAttribute ("locale"))
 
238
                                                        aprop.Locale = prop.GetAttribute ("locale");
 
239
                                                aprop.Value = prop.InnerText;
 
240
                                                properties.Add (aprop);
 
241
                                                break;
 
242
                                        }}
 
243
                                }
 
244
                        }
 
245
                }
 
246
                
 
247
                internal static AddinInfo ReadFromDescription (AddinDescription description)
 
248
                {
 
249
                        AddinInfo info = new AddinInfo ();
 
250
                        info.id = description.LocalId;
 
251
                        info.namspace = description.Namespace;
 
252
                        info.name = description.Name;
 
253
                        info.version = description.Version;
 
254
                        info.author = description.Author;
 
255
                        info.copyright = description.Copyright;
 
256
                        info.url = description.Url;
 
257
                        info.description = description.Description;
 
258
                        info.category = description.Category;
 
259
                        info.baseVersion = description.CompatVersion;
 
260
                        info.properties = new AddinPropertyCollectionImpl (description.Properties);
 
261
                        
 
262
                        foreach (Dependency dep in description.MainModule.Dependencies)
 
263
                                info.Dependencies.Add (dep);
 
264
                                
 
265
                        foreach (ModuleDescription mod in description.OptionalModules) {
 
266
                                foreach (Dependency dep in mod.Dependencies)
 
267
                                        info.OptionalDependencies.Add (dep);
 
268
                        }
 
269
                        return info;
 
270
                }
 
271
                
 
272
                public bool SupportsVersion (string version)
 
273
                {
 
274
                        if (Addin.CompareVersions (Version, version) > 0)
 
275
                                return false;
 
276
                        if (baseVersion == "")
 
277
                                return true;
 
278
                        return Addin.CompareVersions (BaseVersion, version) >= 0;
 
279
                }
 
280
                
 
281
                public int CompareVersionTo (AddinHeader other)
 
282
                {
 
283
                        return Addin.CompareVersions (this.version, other.Version);
 
284
                }
 
285
        }
 
286
 
 
287
        /// <summary>
 
288
        /// Basic add-in information
 
289
        /// </summary>
 
290
        public interface AddinHeader
 
291
        {
 
292
                /// <summary>
 
293
                /// Full identifier of the add-in
 
294
                /// </summary>
 
295
                string Id {
 
296
                        get;
 
297
                }
 
298
                
 
299
                /// <summary>
 
300
                /// Display name of the add-in
 
301
                /// </summary>
 
302
                string Name {
 
303
                        get;
 
304
                }
 
305
                
 
306
                /// <summary>
 
307
                /// Namespace of the add-in
 
308
                /// </summary>
 
309
                string Namespace {
 
310
                        get;
 
311
                }
 
312
                
 
313
                /// <summary>
 
314
                /// Version of the add-in
 
315
                /// </summary>
 
316
                string Version {
 
317
                        get;
 
318
                }
 
319
                
 
320
                /// <summary>
 
321
                /// Version with which this add-in is compatible
 
322
                /// </summary>
 
323
                string BaseVersion {
 
324
                        get;
 
325
                }
 
326
                
 
327
                /// <summary>
 
328
                /// Add-in author
 
329
                /// </summary>
 
330
                string Author {
 
331
                        get;
 
332
                }
 
333
                
 
334
                /// <summary>
 
335
                /// Add-in copyright
 
336
                /// </summary>
 
337
                string Copyright {
 
338
                        get;
 
339
                }
 
340
                
 
341
                /// <summary>
 
342
                /// Web page URL with more information about the add-in
 
343
                /// </summary>
 
344
                string Url {
 
345
                        get;
 
346
                }
 
347
                
 
348
                /// <summary>
 
349
                /// Description of the add-in
 
350
                /// </summary>
 
351
                string Description {
 
352
                        get;
 
353
                }
 
354
                
 
355
                /// <summary>
 
356
                /// Category of the add-in
 
357
                /// </summary>
 
358
                string Category {
 
359
                        get;
 
360
                }
 
361
                
 
362
                /// <summary>
 
363
                /// Dependencies of the add-in
 
364
                /// </summary>
 
365
                DependencyCollection Dependencies {
 
366
                        get;
 
367
                }
 
368
                
 
369
                /// <summary>
 
370
                /// Optional dependencies of the add-in
 
371
                /// </summary>
 
372
                DependencyCollection OptionalDependencies {
 
373
                        get;
 
374
                }
 
375
                
 
376
                /// <summary>
 
377
                /// Custom properties specified in the add-in header
 
378
                /// </summary>
 
379
                AddinPropertyCollection Properties {
 
380
                        get;
 
381
                }
 
382
                
 
383
                /// <summary>
 
384
                /// Compares the versions of two add-ins
 
385
                /// </summary>
 
386
                /// <param name="other">
 
387
                /// Another add-in
 
388
                /// </param>
 
389
                /// <returns>
 
390
                /// Result of comparison
 
391
                /// </returns>
 
392
                int CompareVersionTo (AddinHeader other);
 
393
        }
 
394
}