aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Kernel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Kernel.cs')
-rw-r--r--Prebuild/src/Core/Kernel.cs149
1 files changed, 93 insertions, 56 deletions
diff --git a/Prebuild/src/Core/Kernel.cs b/Prebuild/src/Core/Kernel.cs
index 1f0ad70..95ef04e 100644
--- a/Prebuild/src/Core/Kernel.cs
+++ b/Prebuild/src/Core/Kernel.cs
@@ -36,16 +36,8 @@ POSSIBILITY OF SUCH DAMAGE.
36*/ 36*/
37#endregion 37#endregion
38 38
39#region CVS Information
40/*
41 * $Source$
42 * $Author: cjcollier $
43 * $Date: 2008-02-08 01:31:29 +0900 (Fri, 08 Feb 2008) $
44 * $Revision: 256 $
45 */
46#endregion
47
48using System; 39using System;
40using System.Collections.Generic;
49using System.Diagnostics; 41using System.Diagnostics;
50using System.Collections; 42using System.Collections;
51using System.Collections.Specialized; 43using System.Collections.Specialized;
@@ -80,17 +72,17 @@ namespace Prebuild.Core
80 72
81 #region Fields 73 #region Fields
82 74
83 private static Kernel m_Instance = new Kernel(); 75 private static readonly Kernel m_Instance = new Kernel();
84 76
85 /// <summary> 77 /// <summary>
86 /// This must match the version of the schema that is embeeded 78 /// This must match the version of the schema that is embeeded
87 /// </summary> 79 /// </summary>
88 private static string m_SchemaVersion = "1.7"; 80 private const string m_SchemaVersion = "1.7";
89 private static string m_Schema = "prebuild-" + m_SchemaVersion + ".xsd"; 81 private const string m_Schema = "prebuild-" + m_SchemaVersion + ".xsd";
90 private static string m_SchemaURI = "http://dnpb.sourceforge.net/schemas/" + m_Schema; 82 private const string m_SchemaURI = "http://dnpb.sourceforge.net/schemas/" + m_Schema;
91 bool disposed; 83 bool disposed;
92 private Version m_Version; 84 private Version m_Version;
93 private string m_Revision = ""; 85 private const string m_Revision = "";
94 private CommandLineCollection m_CommandLine; 86 private CommandLineCollection m_CommandLine;
95 private Log m_Log; 87 private Log m_Log;
96 private CurrentDirectory m_CurrentWorkingDirectory; 88 private CurrentDirectory m_CurrentWorkingDirectory;
@@ -98,19 +90,16 @@ namespace Prebuild.Core
98 90
99 private Hashtable m_Targets; 91 private Hashtable m_Targets;
100 private Hashtable m_Nodes; 92 private Hashtable m_Nodes;
101 93
102 ArrayList m_Solutions; 94 readonly List<SolutionNode> m_Solutions = new List<SolutionNode>();
103 string m_Target; 95 string m_Target;
104 string m_Clean; 96 string m_Clean;
105 string[] m_RemoveDirectories; 97 string[] m_RemoveDirectories;
106 string m_CurrentFile; 98 XmlDocument m_CurrentDoc;
107 XmlDocument m_CurrentDoc;
108 bool m_PauseAfterFinish; 99 bool m_PauseAfterFinish;
109 string[] m_ProjectGroups; 100 string[] m_ProjectGroups;
110 StringCollection m_Refs;
111 101
112 102 #endregion
113 #endregion
114 103
115 #region Constructors 104 #region Constructors
116 105
@@ -210,7 +199,7 @@ namespace Prebuild.Core
210 /// Gets the solutions. 199 /// Gets the solutions.
211 /// </summary> 200 /// </summary>
212 /// <value>The solutions.</value> 201 /// <value>The solutions.</value>
213 public ArrayList Solutions 202 public List<SolutionNode> Solutions
214 { 203 {
215 get 204 get
216 { 205 {
@@ -235,7 +224,7 @@ namespace Prebuild.Core
235 224
236 #region Private Methods 225 #region Private Methods
237 226
238 private void RemoveDirectories(string rootDir, string[] dirNames) 227 private static void RemoveDirectories(string rootDir, string[] dirNames)
239 { 228 {
240 foreach(string dir in Directory.GetDirectories(rootDir)) 229 foreach(string dir in Directory.GetDirectories(rootDir))
241 { 230 {
@@ -297,13 +286,15 @@ namespace Prebuild.Core
297 foreach(Type t in assm.GetTypes()) 286 foreach(Type t in assm.GetTypes())
298 { 287 {
299 TargetAttribute ta = (TargetAttribute)Helper.CheckType(t, typeof(TargetAttribute), typeof(ITarget)); 288 TargetAttribute ta = (TargetAttribute)Helper.CheckType(t, typeof(TargetAttribute), typeof(ITarget));
289
300 if(ta == null) 290 if(ta == null)
301 {
302 continue; 291 continue;
303 } 292
304 293 if (t.IsAbstract)
294 continue;
295
305 ITarget target = (ITarget)assm.CreateInstance(t.FullName); 296 ITarget target = (ITarget)assm.CreateInstance(t.FullName);
306 if(target == null) 297 if (target == null)
307 { 298 {
308 throw new MissingMethodException("Could not create ITarget instance"); 299 throw new MissingMethodException("Could not create ITarget instance");
309 } 300 }
@@ -316,16 +307,13 @@ namespace Prebuild.Core
316 { 307 {
317 foreach(Type t in assm.GetTypes()) 308 foreach(Type t in assm.GetTypes())
318 { 309 {
319 DataNodeAttribute dna = (DataNodeAttribute)Helper.CheckType(t, typeof(DataNodeAttribute), typeof(IDataNode)); 310 foreach (DataNodeAttribute dna in t.GetCustomAttributes(typeof(DataNodeAttribute), true))
320 if(dna == null) 311 {
321 { 312 NodeEntry ne = new NodeEntry();
322 continue; 313 ne.Type = t;
323 } 314 ne.Attribute = dna;
324 315 m_Nodes[dna.Name] = ne;
325 NodeEntry ne = new NodeEntry(); 316 }
326 ne.Type = t;
327 ne.Attribute = dna;
328 m_Nodes[dna.Name] = ne;
329 } 317 }
330 } 318 }
331 319
@@ -343,7 +331,32 @@ namespace Prebuild.Core
343 m_Log.Write(); 331 m_Log.Write();
344 } 332 }
345 333
346 private void ProcessFile(string file) 334
335
336 private void ProcessFile(string file)
337 {
338 ProcessFile(file, this.m_Solutions);
339 }
340
341 public void ProcessFile(ProcessNode node, SolutionNode parent)
342 {
343 if (node.IsValid)
344 {
345 List<SolutionNode> list = new List<SolutionNode>();
346 ProcessFile(node.Path, list);
347
348 foreach (SolutionNode solution in list)
349 parent.SolutionsTable[solution.Name] = solution;
350 }
351 }
352
353 /// <summary>
354 ///
355 /// </summary>
356 /// <param name="file"></param>
357 /// <param name="solutions"></param>
358 /// <returns></returns>
359 public void ProcessFile(string file, IList<SolutionNode> solutions)
347 { 360 {
348 m_CurrentWorkingDirectory.Push(); 361 m_CurrentWorkingDirectory.Push();
349 362
@@ -361,8 +374,7 @@ namespace Prebuild.Core
361 return; 374 return;
362 } 375 }
363 376
364 m_CurrentFile = path; 377 Helper.SetCurrentDir(Path.GetDirectoryName(path));
365 Helper.SetCurrentDir(Path.GetDirectoryName(path));
366 378
367 XmlTextReader reader = new XmlTextReader(path); 379 XmlTextReader reader = new XmlTextReader(path);
368 380
@@ -379,6 +391,33 @@ namespace Prebuild.Core
379 391
380 string xml = pre.Process(reader);//remove script and evaulate pre-proccessing to get schema-conforming XML 392 string xml = pre.Process(reader);//remove script and evaulate pre-proccessing to get schema-conforming XML
381 393
394 // See if the user put into a pseudo target of "prebuild:preprocessed-input" to indicate they want to see the
395 // output before the system processes it.
396 if (m_CommandLine.WasPassed("ppi"))
397 {
398 // Get the filename if there is one, otherwise use a default.
399 string ppiFile = m_CommandLine["ppi"];
400 if (ppiFile == null || ppiFile.Trim().Length == 0)
401 {
402 ppiFile = "preprocessed-input.xml";
403 }
404
405 // Write out the string to the given stream.
406 try
407 {
408 using (StreamWriter ppiWriter = new StreamWriter(ppiFile))
409 {
410 ppiWriter.WriteLine(xml);
411 }
412 }
413 catch(IOException ex)
414 {
415 Console.WriteLine("Could not write PPI file '{0}': {1}", ppiFile, ex.Message);
416 }
417
418 // Finish processing this special tag.
419 return;
420 }
382 421
383 m_CurrentDoc = new XmlDocument(); 422 m_CurrentDoc = new XmlDocument();
384 try 423 try
@@ -443,7 +482,7 @@ namespace Prebuild.Core
443 } 482 }
444 else if(dataNode is SolutionNode) 483 else if(dataNode is SolutionNode)
445 { 484 {
446 m_Solutions.Add(dataNode); 485 solutions.Add((SolutionNode)dataNode);
447 } 486 }
448 } 487 }
449 } 488 }
@@ -527,7 +566,7 @@ namespace Prebuild.Core
527 /// <returns></returns> 566 /// <returns></returns>
528 public IDataNode ParseNode(XmlNode node, IDataNode parent, IDataNode preNode) 567 public IDataNode ParseNode(XmlNode node, IDataNode parent, IDataNode preNode)
529 { 568 {
530 IDataNode dataNode = null; 569 IDataNode dataNode;
531 570
532 try 571 try
533 { 572 {
@@ -629,9 +668,6 @@ namespace Prebuild.Core
629 m_PauseAfterFinish = m_CommandLine.WasPassed("pause"); 668 m_PauseAfterFinish = m_CommandLine.WasPassed("pause");
630 669
631 LoadSchema(); 670 LoadSchema();
632
633 m_Solutions = new ArrayList();
634 m_Refs = new StringCollection();
635 } 671 }
636 672
637 /// <summary> 673 /// <summary>
@@ -664,17 +700,18 @@ namespace Prebuild.Core
664 m_Log.Write(LogType.Error, "The options /target and /clean cannot be passed together"); 700 m_Log.Write(LogType.Error, "The options /target and /clean cannot be passed together");
665 return; 701 return;
666 } 702 }
667 else if(m_Target == null && m_Clean == null) 703
668 { 704 if(m_Target == null && m_Clean == null)
669 if(perfomedOtherTask) //finished 705 {
670 { 706 if(perfomedOtherTask) //finished
671 return; 707 {
672 } 708 return;
673 m_Log.Write(LogType.Error, "Must pass either /target or /clean to process a Prebuild file"); 709 }
674 return; 710 m_Log.Write(LogType.Error, "Must pass either /target or /clean to process a Prebuild file");
675 } 711 return;
676 712 }
677 string file = "./prebuild.xml"; 713
714 string file = "./prebuild.xml";
678 if(m_CommandLine.WasPassed("file")) 715 if(m_CommandLine.WasPassed("file"))
679 { 716 {
680 file = m_CommandLine["file"]; 717 file = m_CommandLine["file"];