~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// SolutionConfiguration.cs
3
 
//  
4
 
// Author:
5
 
//       Lluis Sanchez Gual <lluis@novell.com>
6
 
// 
7
 
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
8
 
// 
9
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
 
// of this software and associated documentation files (the "Software"), to deal
11
 
// in the Software without restriction, including without limitation the rights
12
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 
// copies of the Software, and to permit persons to whom the Software is
14
 
// furnished to do so, subject to the following conditions:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
19
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using System.Xml;
29
 
using System.IO;
30
 
using System.Collections;
31
 
using System.Collections.ObjectModel;
32
 
using System.Collections.Generic;
33
 
using System.Reflection;
34
 
using System.Diagnostics;
35
 
using System.CodeDom.Compiler;
36
 
 
37
 
using MonoDevelop.Projects;
38
 
using MonoDevelop.Core.Serialization;
39
 
 
40
 
using MonoDevelop.Core;
41
 
 
42
 
namespace MonoDevelop.Projects
43
 
{
44
 
        public class SolutionConfiguration : ItemConfiguration
45
 
        {
46
 
                Solution parentSolution;
47
 
                
48
 
                List<SolutionConfigurationEntry> configurations = new List<SolutionConfigurationEntry> ();
49
 
                
50
 
                public SolutionConfiguration ()
51
 
                {
52
 
                }
53
 
                
54
 
                public SolutionConfiguration (string id): base (id)
55
 
                {
56
 
                }
57
 
                
58
 
                public SolutionConfiguration (string name, string platform): base (name, platform)
59
 
                {
60
 
                }
61
 
                
62
 
                public override ConfigurationSelector Selector {
63
 
                        get { return new SolutionConfigurationSelector (Id); }
64
 
                }
65
 
                
66
 
                public Solution ParentSolution {
67
 
                        get { return parentSolution; }
68
 
                        internal set { parentSolution = value; }
69
 
                }
70
 
                
71
 
                public ReadOnlyCollection<SolutionConfigurationEntry> Configurations {
72
 
                        get { return configurations.AsReadOnly (); }
73
 
                }
74
 
                
75
 
                public bool BuildEnabledForItem (SolutionEntityItem item)
76
 
                {
77
 
                        foreach (SolutionConfigurationEntry entry in configurations) {
78
 
                                if (entry.Item == item)
79
 
                                        return entry.Build && item.Configurations [entry.ItemConfiguration] != null;
80
 
                        }
81
 
                        return false;
82
 
                }
83
 
                
84
 
                public string GetMappedConfiguration (SolutionEntityItem item)
85
 
                {
86
 
                        foreach (SolutionConfigurationEntry entry in configurations) {
87
 
                                if (entry.Item == item)
88
 
                                        return entry.ItemConfiguration;
89
 
                        }
90
 
                        return null;
91
 
                }
92
 
                
93
 
                public SolutionConfigurationEntry GetEntryForItem (SolutionEntityItem item)
94
 
                {
95
 
                        foreach (SolutionConfigurationEntry entry in configurations) {
96
 
                                if (entry.Item == item)
97
 
                                        return entry;
98
 
                        }
99
 
                        return null;
100
 
                }
101
 
                
102
 
                public SolutionConfigurationEntry AddItem (SolutionEntityItem item)
103
 
                {
104
 
                        string conf = FindMatchingConfiguration (item);
105
 
                        return AddItem (item, conf != null, conf);
106
 
                }
107
 
                
108
 
                string FindMatchingConfiguration (SolutionEntityItem item)
109
 
                {
110
 
                        if (item.Configurations [Id] != null)
111
 
                                return Id;
112
 
                        
113
 
                        if (item.Configurations.Count == 0)
114
 
                                return null;
115
 
                        
116
 
                        // This configuration is not present in the project. Try to find the best match.
117
 
                        // First of all try matching name
118
 
                        foreach (SolutionItemConfiguration iconf in item.Configurations) {
119
 
                                if (iconf.Name == Name && iconf.Platform.Length == 0)
120
 
                                        return iconf.Id;
121
 
                        }
122
 
                        
123
 
                        if (Platform.Length > 0) {
124
 
                                // No name coincidence, now try matching the platform
125
 
                                foreach (SolutionItemConfiguration iconf in item.Configurations) {
126
 
                                        if (iconf.Platform == Platform)
127
 
                                                return iconf.Id;
128
 
                                }
129
 
                        }
130
 
                        
131
 
                        // Now match name, ignoring platform
132
 
                        foreach (SolutionItemConfiguration iconf in item.Configurations) {
133
 
                                if (iconf.Name == Name)
134
 
                                        return iconf.Id;
135
 
                        }
136
 
                        
137
 
                        // No luck. Pick whatever.
138
 
                        return item.Configurations [0].Id;
139
 
                }
140
 
                
141
 
                public SolutionConfigurationEntry AddItem (SolutionEntityItem item, bool build, string itemConfiguration)
142
 
                {
143
 
                        if (itemConfiguration == null)
144
 
                                itemConfiguration = Name;
145
 
                        SolutionConfigurationEntry conf = new SolutionConfigurationEntry (this, item);
146
 
                        conf.Build = build;
147
 
                        conf.ItemConfiguration = itemConfiguration;
148
 
                        configurations.Add (conf);
149
 
                        if (parentSolution != null)
150
 
                                parentSolution.UpdateDefaultConfigurations ();
151
 
                        return conf;
152
 
                }
153
 
                
154
 
                public void RemoveItem (SolutionEntityItem item)
155
 
                {
156
 
                        for (int n=0; n<configurations.Count; n++) {
157
 
                                if (configurations [n].Item == item) {
158
 
                                        configurations.RemoveAt (n);
159
 
                                        return;
160
 
                                }
161
 
                        }
162
 
                }
163
 
                
164
 
                public override void CopyFrom (ItemConfiguration configuration)
165
 
                {
166
 
                        base.CopyFrom (configuration);
167
 
                        
168
 
                        SolutionConfiguration conf = (SolutionConfiguration) configuration;
169
 
                        if (parentSolution == null)
170
 
                                parentSolution = conf.parentSolution;
171
 
                        
172
 
                        configurations.Clear ();
173
 
                        foreach (SolutionConfigurationEntry entry in conf.configurations)
174
 
                                configurations.Add (new SolutionConfigurationEntry (this, entry));
175
 
 
176
 
                        if (parentSolution != null)
177
 
                                parentSolution.UpdateDefaultConfigurations ();
178
 
                }
179
 
        }
180
 
        
181
 
        public class SolutionConfigurationEntry 
182
 
        {
183
 
                SolutionEntityItem item;
184
 
                SolutionConfiguration parentConfig;
185
 
                
186
 
                [ItemProperty ("name")]
187
 
                string itemId;
188
 
                
189
 
                [ItemProperty]
190
 
                string configuration;
191
 
                
192
 
                [ItemProperty (DefaultValue=true)]
193
 
                bool build = true;
194
 
                
195
 
                internal SolutionConfigurationEntry (SolutionConfiguration parentConfig, SolutionConfigurationEntry other)
196
 
                {
197
 
                        this.parentConfig = parentConfig;
198
 
                        this.itemId = other.itemId;
199
 
                        this.configuration = other.configuration;
200
 
                        this.build = other.build;
201
 
                }
202
 
                
203
 
                internal SolutionConfigurationEntry (SolutionConfiguration parentConfig, SolutionEntityItem item)
204
 
                {
205
 
                        this.parentConfig = parentConfig;
206
 
                        this.item = item;
207
 
                        configuration = parentConfig.Id;
208
 
                        itemId = item.ItemId;
209
 
                }
210
 
                
211
 
                public string ItemConfiguration {
212
 
                        get { return configuration; }
213
 
                        set { 
214
 
                                configuration = value;
215
 
                                if (parentConfig != null && parentConfig.ParentSolution != null)
216
 
                                        parentConfig.ParentSolution.UpdateDefaultConfigurations ();
217
 
                        }
218
 
                }
219
 
                
220
 
                public ConfigurationSelector ItemConfigurationSelector {
221
 
                        get { return new ItemConfigurationSelector (ItemConfiguration); }
222
 
                }
223
 
                
224
 
                public bool Build {
225
 
                        get { return build; }
226
 
                        set { build = value; }
227
 
                }
228
 
                
229
 
                public SolutionEntityItem Item {
230
 
                        get {
231
 
                                if (item == null && parentConfig != null) {
232
 
                                        Solution sol = parentConfig.ParentSolution;
233
 
                                        if (sol != null)
234
 
                                                item = sol.GetSolutionItem (itemId) as SolutionEntityItem;
235
 
                                }
236
 
                                return item;
237
 
                        }
238
 
                }
239
 
        }
240
 
}