~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Projects/MonoDevelop.Projects/ProjectReference.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
using System;
22
22
using System.Collections;
 
23
using System.Collections.Generic;
23
24
using System.IO;
24
25
using System.Diagnostics;
25
26
using System.Xml;
26
27
using MonoDevelop.Core;
27
28
using System.ComponentModel;
28
29
using MonoDevelop.Projects;
29
 
using MonoDevelop.Projects.Serialization;
 
30
using MonoDevelop.Core.Serialization;
30
31
 
31
32
namespace MonoDevelop.Projects
32
33
{
41
42
        /// This class represent a reference information in an Project object.
42
43
        /// </summary>
43
44
        [DataItem (FallbackType=typeof(UnknownProjectReference))]
44
 
        public class ProjectReference : ICloneable, ICustomDataItem
 
45
        public class ProjectReference : ICloneable, IExtendedDataItem
45
46
        {
46
 
                [ItemProperty ("type")]
 
47
                Hashtable extendedProperties;
47
48
                ReferenceType referenceType;
48
 
                
49
 
                Project ownerProject;
50
 
                
 
49
                DotNetProject ownerProject;
51
50
                string reference = String.Empty;
 
51
                bool localCopy = true;
52
52
                
53
53
                // A project may reference assemblies which are not available
54
54
                // in the system where it is opened. For example, opening
58
58
                // The loadedReference stores the reference initially loaded,
59
59
                // so it can be saved again.
60
60
                string loadedReference;
61
 
                
62
 
                [ItemProperty ("localcopy")]
63
 
                bool localCopy = true;
 
61
                bool specificVersion = true;
 
62
                bool notFound;
64
63
                
65
64
                public ProjectReference ()
66
65
                {
67
66
                }
68
67
                
69
 
                internal void SetOwnerProject (Project project)
 
68
                internal void SetOwnerProject (DotNetProject project)
70
69
                {
71
70
                        ownerProject = project;
 
71
                        UpdateGacReference ();
72
72
                }
73
73
                
74
74
                public ProjectReference(ReferenceType referenceType, string reference)
75
75
                {
 
76
                        if (referenceType == ReferenceType.Assembly)
 
77
                                specificVersion = false;
76
78
                        this.referenceType = referenceType;
77
79
                        this.reference     = reference;
78
80
                        UpdateGacReference ();
84
86
                        reference = referencedProject.Name;
85
87
                }
86
88
                
87
 
                [ReadOnly(true)]
 
89
                public IDictionary ExtendedProperties {
 
90
                        get {
 
91
                                if (extendedProperties == null)
 
92
                                        extendedProperties = new Hashtable ();
 
93
                                return extendedProperties;
 
94
                        }
 
95
                }
 
96
                
 
97
                public Project OwnerProject {
 
98
                        get { return ownerProject; }
 
99
                }
 
100
                
88
101
                public ReferenceType ReferenceType {
89
102
                        get {
90
103
                                return referenceType;
91
104
                        }
92
105
                }
93
106
                
94
 
                [ReadOnly(true)]
95
107
                public string Reference {
96
108
                        get {
97
109
                                return reference;
98
110
                        }
 
111
                        internal set {
 
112
                                reference = value;
 
113
                                UpdateGacReference ();
 
114
                        }
99
115
                }
100
116
                
101
 
                [ReadOnly(true)]
102
117
                public string StoredReference {
103
118
                        get {
104
119
                                if (loadedReference != null)
108
123
                        }
109
124
                }
110
125
                
111
 
                [DefaultValue(true)]
112
126
                public bool LocalCopy {
113
127
                        get {
114
128
                                return localCopy;
117
131
                                localCopy = value;
118
132
                        }
119
133
                }
 
134
 
 
135
                internal string LoadedReference {
 
136
                        get {
 
137
                                return loadedReference;
 
138
                        }
 
139
                        set {
 
140
                                loadedReference = value;
 
141
                        }
 
142
                }
 
143
 
 
144
                internal string Condition { get; set; }
 
145
 
 
146
                public bool SpecificVersion {
 
147
                        get {
 
148
                                return specificVersion;
 
149
                        }
 
150
                        set {
 
151
                                specificVersion = value;
 
152
                        }
 
153
                }
 
154
 
 
155
                public bool IsValid {
 
156
                        get {
 
157
                                if (ReferenceType == ReferenceType.Gac) {
 
158
                                        if (notFound)
 
159
                                                return false;
 
160
                                        if (!IsExactVersion && SpecificVersion)
 
161
                                                return false;
 
162
                                } else if (ReferenceType == ReferenceType.Project) {
 
163
                                        if (ownerProject != null && ownerProject.ParentSolution != null) {
 
164
                                                DotNetProject p = ownerProject.ParentSolution.FindProjectByName (reference) as DotNetProject;
 
165
                                                if (p != null)
 
166
                                                        return ownerProject.TargetFramework.IsCompatibleWithFramework (p.TargetFramework.Id);
 
167
                                        }
 
168
                                }
 
169
                                return true;
 
170
                        }
 
171
                }
 
172
                
 
173
                public bool IsExactVersion {
 
174
                        get {
 
175
                                if (ReferenceType == ReferenceType.Gac) {
 
176
                                        if (StoredReference != Reference && !Reference.StartsWith (StoredReference + ","))
 
177
                                                return false;
 
178
                                }
 
179
                                return true;
 
180
                        }
 
181
                }
120
182
                
121
183
                /// <summary>
122
184
                /// Returns the file name to an assembly, regardless of what 
123
185
                /// type the assembly is.
124
186
                /// </summary>
125
 
                string GetReferencedFileName ()
 
187
                string GetReferencedFileName (string configuration)
126
188
                {
127
189
                        switch (ReferenceType) {
128
190
                                case ReferenceType.Assembly:
133
195
                                        return file == null ? reference : file;
134
196
                                case ReferenceType.Project:
135
197
                                        if (ownerProject != null) {
136
 
                                                Combine c = ownerProject.RootCombine;
137
 
                                                if (c != null) {
138
 
                                                        Project p = c.FindProject (reference);
139
 
                                                        if (p != null) return p.GetOutputFileName ();
 
198
                                                if (ownerProject.ParentSolution != null) {
 
199
                                                        Project p = ownerProject.ParentSolution.FindProjectByName (reference);
 
200
                                                        if (p != null) return p.GetOutputFileName (configuration);
140
201
                                                }
141
202
                                        }
142
203
                                        return null;
146
207
                        }
147
208
                }
148
209
                
149
 
                public virtual string[] GetReferencedFileNames ()
 
210
                public virtual string[] GetReferencedFileNames (string configuration)
150
211
                {
151
 
                        string s = GetReferencedFileName ();
 
212
                        string s = GetReferencedFileName (configuration);
152
213
                        if (s != null)
153
214
                                return new string[] { s };
154
215
                        else
155
216
                                return new string [0];
156
217
                }
157
218
                
158
 
                DataCollection ICustomDataItem.Serialize (ITypeSerializer handler)
159
 
                {
160
 
                        DataCollection data = handler.Serialize (this);
161
 
                        string refto = reference;
162
 
                        if (referenceType == ReferenceType.Assembly) {
163
 
                                string basePath = Path.GetDirectoryName (handler.SerializationContext.BaseFile);
164
 
                                refto = FileService.AbsoluteToRelativePath (basePath, refto);
165
 
                        } else if (referenceType == ReferenceType.Gac && loadedReference != null)
166
 
                                refto = loadedReference;
167
 
 
168
 
                        data.Add (new DataValue ("refto", refto));
169
 
                        return data;
170
 
                }
171
 
                
172
 
                void ICustomDataItem.Deserialize (ITypeSerializer handler, DataCollection data)
173
 
                {
174
 
                        DataValue refto = data.Extract ("refto") as DataValue;
175
 
                        handler.Deserialize (this, data);
176
 
                        if (refto != null) {
177
 
                                reference = refto.Value;
178
 
                                UpdateGacReference ();
179
 
                                if (referenceType == ReferenceType.Assembly) {
180
 
                                        string basePath = Path.GetDirectoryName (handler.SerializationContext.BaseFile);
181
 
                                        reference = FileService.RelativeToAbsolutePath (basePath, reference);
182
 
                                }
183
 
                        }
184
 
                }
185
 
                
186
219
                void UpdateGacReference ()
187
220
                {
188
221
                        if (referenceType == ReferenceType.Gac) {
 
222
                                notFound = false;
189
223
                                string cref = Runtime.SystemAssemblyService.FindInstalledAssembly (reference);
 
224
                                if (ownerProject != null) {
 
225
                                        if (cref == null)
 
226
                                                cref = reference;
 
227
                                        cref = Runtime.SystemAssemblyService.GetAssemblyNameForVersion (cref, ownerProject.TargetFramework);
 
228
                                        notFound = (cref == null);
 
229
                                }
190
230
                                if (cref != null && cref != reference) {
191
 
                                        loadedReference = reference;
 
231
                                        if (loadedReference == null) {
 
232
                                                loadedReference = reference;
 
233
                                        }
192
234
                                        reference = cref;
193
 
                                } else
194
 
                                        loadedReference = null;
 
235
                                }
195
236
                        }
196
237
                }
197
238
                
218
259
        {
219
260
                Hashtable props;
220
261
                
221
 
                public IDictionary ExtendedProperties {
 
262
                IDictionary IExtendedDataItem.ExtendedProperties {
222
263
                        get {
223
264
                                if (props == null)
224
265
                                        props = new Hashtable ();