aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Nodes/ProjectNode.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Nodes/ProjectNode.cs')
-rw-r--r--Prebuild/src/Core/Nodes/ProjectNode.cs490
1 files changed, 490 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Nodes/ProjectNode.cs b/Prebuild/src/Core/Nodes/ProjectNode.cs
new file mode 100644
index 0000000..7ac0a36
--- /dev/null
+++ b/Prebuild/src/Core/Nodes/ProjectNode.cs
@@ -0,0 +1,490 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26#region CVS Information
27/*
28 * $Source$
29 * $Author: jendave $
30 * $Date: 2006-11-11 05:43:20 +0100 (lö, 11 nov 2006) $
31 * $Revision: 192 $
32 */
33#endregion
34
35using System;
36using System.Collections;
37using System.IO;
38using System.Xml;
39
40using Prebuild.Core.Attributes;
41using Prebuild.Core.Interfaces;
42using Prebuild.Core.Utilities;
43
44namespace Prebuild.Core.Nodes
45{
46 /// <summary>
47 ///
48 /// </summary>
49 public enum ProjectType
50 {
51 /// <summary>
52 ///
53 /// </summary>
54 Exe,
55 /// <summary>
56 ///
57 /// </summary>
58 WinExe,
59 /// <summary>
60 ///
61 /// </summary>
62 Library
63 }
64
65 /// <summary>
66 ///
67 /// </summary>
68 public enum ClrRuntime
69 {
70 /// <summary>
71 ///
72 /// </summary>
73 Microsoft,
74 /// <summary>
75 ///
76 /// </summary>
77 Mono
78 }
79
80 /// <summary>
81 ///
82 /// </summary>
83 [DataNode("Project")]
84 public class ProjectNode : DataNode
85 {
86 #region Fields
87
88 private string m_Name = "unknown";
89 private string m_Path = "";
90 private string m_FullPath = "";
91 private string m_AssemblyName;
92 private string m_AppIcon = "";
93 private string m_DesignerFolder = "";
94 private string m_Language = "C#";
95 private ProjectType m_Type = ProjectType.Exe;
96 private ClrRuntime m_Runtime = ClrRuntime.Microsoft;
97 private string m_StartupObject = "";
98 private string m_RootNamespace;
99 private string m_FilterGroups = "";
100 private Guid m_Guid;
101
102 private Hashtable m_Configurations;
103 private ArrayList m_ReferencePaths;
104 private ArrayList m_References;
105 private FilesNode m_Files;
106
107 #endregion
108
109 #region Constructors
110
111 /// <summary>
112 /// Initializes a new instance of the <see cref="ProjectNode"/> class.
113 /// </summary>
114 public ProjectNode()
115 {
116 m_Configurations = new Hashtable();
117 m_ReferencePaths = new ArrayList();
118 m_References = new ArrayList();
119 }
120
121 #endregion
122
123 #region Properties
124
125 /// <summary>
126 /// Gets the name.
127 /// </summary>
128 /// <value>The name.</value>
129 public string Name
130 {
131 get
132 {
133 return m_Name;
134 }
135 }
136
137 /// <summary>
138 /// Gets the path.
139 /// </summary>
140 /// <value>The path.</value>
141 public string Path
142 {
143 get
144 {
145 return m_Path;
146 }
147 }
148
149 /// <summary>
150 /// Gets the filter groups.
151 /// </summary>
152 /// <value>The filter groups.</value>
153 public string FilterGroups
154 {
155 get
156 {
157 return m_FilterGroups;
158 }
159 }
160
161 /// <summary>
162 /// Gets the full path.
163 /// </summary>
164 /// <value>The full path.</value>
165 public string FullPath
166 {
167 get
168 {
169 return m_FullPath;
170 }
171 }
172
173 /// <summary>
174 /// Gets the name of the assembly.
175 /// </summary>
176 /// <value>The name of the assembly.</value>
177 public string AssemblyName
178 {
179 get
180 {
181 return m_AssemblyName;
182 }
183 }
184
185 /// <summary>
186 /// Gets the app icon.
187 /// </summary>
188 /// <value>The app icon.</value>
189 public string AppIcon
190 {
191 get
192 {
193 return m_AppIcon;
194 }
195 }
196
197 /// <summary>
198 ///
199 /// </summary>
200 public string DesignerFolder
201 {
202 get
203 {
204 return m_DesignerFolder;
205 }
206 }
207
208 /// <summary>
209 /// Gets the language.
210 /// </summary>
211 /// <value>The language.</value>
212 public string Language
213 {
214 get
215 {
216 return m_Language;
217 }
218 }
219
220 /// <summary>
221 /// Gets the type.
222 /// </summary>
223 /// <value>The type.</value>
224 public ProjectType Type
225 {
226 get
227 {
228 return m_Type;
229 }
230 }
231
232 /// <summary>
233 /// Gets the runtime.
234 /// </summary>
235 /// <value>The runtime.</value>
236 public ClrRuntime Runtime
237 {
238 get
239 {
240 return m_Runtime;
241 }
242 }
243
244 private bool m_GenerateAssemblyInfoFile = false;
245
246 /// <summary>
247 ///
248 /// </summary>
249 public bool GenerateAssemblyInfoFile
250 {
251 get
252 {
253 return m_GenerateAssemblyInfoFile;
254 }
255 set
256 {
257 m_GenerateAssemblyInfoFile = value;
258 }
259 }
260
261 /// <summary>
262 /// Gets the startup object.
263 /// </summary>
264 /// <value>The startup object.</value>
265 public string StartupObject
266 {
267 get
268 {
269 return m_StartupObject;
270 }
271 }
272
273 /// <summary>
274 /// Gets the root namespace.
275 /// </summary>
276 /// <value>The root namespace.</value>
277 public string RootNamespace
278 {
279 get
280 {
281 return m_RootNamespace;
282 }
283 }
284
285 /// <summary>
286 /// Gets the configurations.
287 /// </summary>
288 /// <value>The configurations.</value>
289 public ICollection Configurations
290 {
291 get
292 {
293 return m_Configurations.Values;
294 }
295 }
296
297 /// <summary>
298 /// Gets the configurations table.
299 /// </summary>
300 /// <value>The configurations table.</value>
301 public Hashtable ConfigurationsTable
302 {
303 get
304 {
305 return m_Configurations;
306 }
307 }
308
309 /// <summary>
310 /// Gets the reference paths.
311 /// </summary>
312 /// <value>The reference paths.</value>
313 public ArrayList ReferencePaths
314 {
315 get
316 {
317 return m_ReferencePaths;
318 }
319 }
320
321 /// <summary>
322 /// Gets the references.
323 /// </summary>
324 /// <value>The references.</value>
325 public ArrayList References
326 {
327 get
328 {
329 return m_References;
330 }
331 }
332
333 /// <summary>
334 /// Gets the files.
335 /// </summary>
336 /// <value>The files.</value>
337 public FilesNode Files
338 {
339 get
340 {
341 return m_Files;
342 }
343 }
344
345 /// <summary>
346 /// Gets or sets the parent.
347 /// </summary>
348 /// <value>The parent.</value>
349 public override IDataNode Parent
350 {
351 get
352 {
353 return base.Parent;
354 }
355 set
356 {
357 base.Parent = value;
358 if(base.Parent is SolutionNode && m_Configurations.Count < 1)
359 {
360 SolutionNode parent = (SolutionNode)base.Parent;
361 foreach(ConfigurationNode conf in parent.Configurations)
362 {
363 m_Configurations[conf.Name] = conf.Clone();
364 }
365 }
366 }
367 }
368
369 /// <summary>
370 /// Gets the GUID.
371 /// </summary>
372 /// <value>The GUID.</value>
373 public Guid Guid
374 {
375 get
376 {
377 return m_Guid;
378 }
379 }
380
381 #endregion
382
383 #region Private Methods
384
385 private void HandleConfiguration(ConfigurationNode conf)
386 {
387 if(String.Compare(conf.Name, "all", true) == 0) //apply changes to all, this may not always be applied first,
388 //so it *may* override changes to the same properties for configurations defines at the project level
389 {
390 foreach(ConfigurationNode confNode in this.m_Configurations.Values)
391 {
392 conf.CopyTo(confNode);//update the config templates defines at the project level with the overrides
393 }
394 }
395 if(m_Configurations.ContainsKey(conf.Name))
396 {
397 ConfigurationNode parentConf = (ConfigurationNode)m_Configurations[conf.Name];
398 conf.CopyTo(parentConf);//update the config templates defines at the project level with the overrides
399 }
400 else
401 {
402 m_Configurations[conf.Name] = conf;
403 }
404 }
405
406 #endregion
407
408 #region Public Methods
409
410 /// <summary>
411 /// Parses the specified node.
412 /// </summary>
413 /// <param name="node">The node.</param>
414 public override void Parse(XmlNode node)
415 {
416 m_Name = Helper.AttributeValue(node, "name", m_Name);
417 m_Path = Helper.AttributeValue(node, "path", m_Path);
418 m_FilterGroups = Helper.AttributeValue(node, "filterGroups", m_FilterGroups);
419 m_AppIcon = Helper.AttributeValue(node, "icon", m_AppIcon);
420 m_DesignerFolder = Helper.AttributeValue(node, "designerFolder", m_DesignerFolder);
421 m_AssemblyName = Helper.AttributeValue(node, "assemblyName", m_AssemblyName);
422 m_Language = Helper.AttributeValue(node, "language", m_Language);
423 m_Type = (ProjectType)Helper.EnumAttributeValue(node, "type", typeof(ProjectType), m_Type);
424 m_Runtime = (ClrRuntime)Helper.EnumAttributeValue(node, "runtime", typeof(ClrRuntime), m_Runtime);
425 m_StartupObject = Helper.AttributeValue(node, "startupObject", m_StartupObject);
426 m_RootNamespace = Helper.AttributeValue(node, "rootNamespace", m_RootNamespace);
427 m_Guid = Guid.NewGuid();
428 m_GenerateAssemblyInfoFile = Helper.ParseBoolean(node, "generateAssemblyInfoFile", false);
429
430 if(m_AssemblyName == null || m_AssemblyName.Length < 1)
431 {
432 m_AssemblyName = m_Name;
433 }
434
435 if(m_RootNamespace == null || m_RootNamespace.Length < 1)
436 {
437 m_RootNamespace = m_Name;
438 }
439
440 m_FullPath = m_Path;
441 try
442 {
443 m_FullPath = Helper.ResolvePath(m_FullPath);
444 }
445 catch
446 {
447 throw new WarningException("Could not resolve Solution path: {0}", m_Path);
448 }
449
450 Kernel.Instance.CurrentWorkingDirectory.Push();
451 try
452 {
453 Helper.SetCurrentDir(m_FullPath);
454
455 if( node == null )
456 {
457 throw new ArgumentNullException("node");
458 }
459
460 foreach(XmlNode child in node.ChildNodes)
461 {
462 IDataNode dataNode = Kernel.Instance.ParseNode(child, this);
463 if(dataNode is ConfigurationNode)
464 {
465 HandleConfiguration((ConfigurationNode)dataNode);
466 }
467 else if(dataNode is ReferencePathNode)
468 {
469 m_ReferencePaths.Add(dataNode);
470 }
471 else if(dataNode is ReferenceNode)
472 {
473 m_References.Add(dataNode);
474 }
475 else if(dataNode is FilesNode)
476 {
477 m_Files = (FilesNode)dataNode;
478 }
479 }
480 }
481 finally
482 {
483 Kernel.Instance.CurrentWorkingDirectory.Pop();
484 }
485 }
486
487
488 #endregion
489 }
490}