aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Kernel.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Prebuild/src/Core/Kernel.cs83
1 files changed, 42 insertions, 41 deletions
diff --git a/Prebuild/src/Core/Kernel.cs b/Prebuild/src/Core/Kernel.cs
index 95ef04e..67051d5 100644
--- a/Prebuild/src/Core/Kernel.cs
+++ b/Prebuild/src/Core/Kernel.cs
@@ -36,21 +36,17 @@ POSSIBILITY OF SUCH DAMAGE.
36*/ 36*/
37#endregion 37#endregion
38 38
39#define NO_VALIDATE
40
39using System; 41using System;
40using System.Collections.Generic; 42using System.Collections.Generic;
41using System.Diagnostics;
42using System.Collections;
43using System.Collections.Specialized;
44using System.IO; 43using System.IO;
45using System.Reflection; 44using System.Reflection;
46using System.Xml; 45using System.Xml;
47using System.Xml.Schema; 46using System.Xml.Schema;
48using System.Text;
49
50using Prebuild.Core.Attributes; 47using Prebuild.Core.Attributes;
51using Prebuild.Core.Interfaces; 48using Prebuild.Core.Interfaces;
52using Prebuild.Core.Nodes; 49using Prebuild.Core.Nodes;
53using Prebuild.Core.Parse;
54using Prebuild.Core.Utilities; 50using Prebuild.Core.Utilities;
55 51
56namespace Prebuild.Core 52namespace Prebuild.Core
@@ -77,7 +73,7 @@ namespace Prebuild.Core
77 /// <summary> 73 /// <summary>
78 /// This must match the version of the schema that is embeeded 74 /// This must match the version of the schema that is embeeded
79 /// </summary> 75 /// </summary>
80 private const string m_SchemaVersion = "1.7"; 76 private const string m_SchemaVersion = "1.9";
81 private const string m_Schema = "prebuild-" + m_SchemaVersion + ".xsd"; 77 private const string m_Schema = "prebuild-" + m_SchemaVersion + ".xsd";
82 private const string m_SchemaURI = "http://dnpb.sourceforge.net/schemas/" + m_Schema; 78 private const string m_SchemaURI = "http://dnpb.sourceforge.net/schemas/" + m_Schema;
83 bool disposed; 79 bool disposed;
@@ -87,9 +83,9 @@ namespace Prebuild.Core
87 private Log m_Log; 83 private Log m_Log;
88 private CurrentDirectory m_CurrentWorkingDirectory; 84 private CurrentDirectory m_CurrentWorkingDirectory;
89 private XmlSchemaCollection m_Schemas; 85 private XmlSchemaCollection m_Schemas;
90 86
91 private Hashtable m_Targets; 87 private readonly Dictionary<string, ITarget> m_Targets = new Dictionary<string, ITarget>();
92 private Hashtable m_Nodes; 88 private readonly Dictionary<string, NodeEntry> m_Nodes = new Dictionary<string, NodeEntry>();
93 89
94 readonly List<SolutionNode> m_Solutions = new List<SolutionNode>(); 90 readonly List<SolutionNode> m_Solutions = new List<SolutionNode>();
95 string m_Target; 91 string m_Target;
@@ -163,7 +159,7 @@ namespace Prebuild.Core
163 /// Gets the targets. 159 /// Gets the targets.
164 /// </summary> 160 /// </summary>
165 /// <value>The targets.</value> 161 /// <value>The targets.</value>
166 public Hashtable Targets 162 public Dictionary<string, ITarget> Targets
167 { 163 {
168 get 164 get
169 { 165 {
@@ -259,7 +255,7 @@ namespace Prebuild.Core
259 255
260 private void LoadSchema() 256 private void LoadSchema()
261 { 257 {
262 Assembly assembly = this.GetType().Assembly; 258 Assembly assembly = GetType().Assembly;
263 Stream stream = assembly.GetManifestResourceStream("Prebuild.data." + m_Schema); 259 Stream stream = assembly.GetManifestResourceStream("Prebuild.data." + m_Schema);
264 if(stream == null) 260 if(stream == null)
265 { 261 {
@@ -319,23 +315,24 @@ namespace Prebuild.Core
319 315
320 private void LogBanner() 316 private void LogBanner()
321 { 317 {
322 m_Log.Write("Prebuild v" + this.Version); 318 m_Log.Write("Prebuild v" + Version);
323 m_Log.Write("Copyright (c) 2004-2008"); 319 m_Log.Write("Copyright (c) 2004-2010");
324 m_Log.Write("Matthew Holmes (matthew@wildfiregames.com),"); 320 m_Log.Write("Matthew Holmes (matthew@wildfiregames.com),");
325 m_Log.Write("Dan Moorehead (dan05a@gmail.com),"); 321 m_Log.Write("Dan Moorehead (dan05a@gmail.com),");
326 m_Log.Write("David Hudson (jendave@yahoo.com),"); 322 m_Log.Write("David Hudson (jendave@yahoo.com),");
327 m_Log.Write("Rob Loach (http://www.robloach.net),"); 323 m_Log.Write("Rob Loach (http://www.robloach.net),");
328 m_Log.Write("C.J. Adams-Collier (cjac@colliertech.org),"); 324 m_Log.Write("C.J. Adams-Collier (cjac@colliertech.org),");
329 325 m_Log.Write("John Hurliman (john.hurliman@intel.com),");
330 m_Log.Write("See 'prebuild /usage' for help"); 326
331 m_Log.Write(); 327 m_Log.Write("See 'prebuild /usage' for help");
328 m_Log.Write();
332 } 329 }
333 330
334 331
335 332
336 private void ProcessFile(string file) 333 private void ProcessFile(string file)
337 { 334 {
338 ProcessFile(file, this.m_Solutions); 335 ProcessFile(file, m_Solutions);
339 } 336 }
340 337
341 public void ProcessFile(ProcessNode node, SolutionNode parent) 338 public void ProcessFile(ProcessNode node, SolutionNode parent)
@@ -381,12 +378,12 @@ namespace Prebuild.Core
381 Core.Parse.Preprocessor pre = new Core.Parse.Preprocessor(); 378 Core.Parse.Preprocessor pre = new Core.Parse.Preprocessor();
382 379
383 //register command line arguments as XML variables 380 //register command line arguments as XML variables
384 IDictionaryEnumerator dict = m_CommandLine.GetEnumerator(); 381 IEnumerator<KeyValuePair<string, string>> dict = m_CommandLine.GetEnumerator();
385 while (dict.MoveNext()) 382 while (dict.MoveNext())
386 { 383 {
387 string name = dict.Key.ToString().Trim(); 384 string name = dict.Current.Key.Trim();
388 if (name.Length > 0) 385 if (name.Length > 0)
389 pre.RegisterVariable(name, dict.Value.ToString()); 386 pre.RegisterVariable(name, dict.Current.Value);
390 } 387 }
391 388
392 string xml = pre.Process(reader);//remove script and evaulate pre-proccessing to get schema-conforming XML 389 string xml = pre.Process(reader);//remove script and evaulate pre-proccessing to get schema-conforming XML
@@ -422,6 +419,10 @@ namespace Prebuild.Core
422 m_CurrentDoc = new XmlDocument(); 419 m_CurrentDoc = new XmlDocument();
423 try 420 try
424 { 421 {
422#if NO_VALIDATE
423 XmlReader validator = XmlReader.Create(new StringReader(xml));
424 m_CurrentDoc.Load(validator);
425#else
425 XmlValidatingReader validator = new XmlValidatingReader(new XmlTextReader(new StringReader(xml))); 426 XmlValidatingReader validator = new XmlValidatingReader(new XmlTextReader(new StringReader(xml)));
426 427
427 //validate while reading from string into XmlDocument DOM structure in memory 428 //validate while reading from string into XmlDocument DOM structure in memory
@@ -430,6 +431,7 @@ namespace Prebuild.Core
430 validator.Schemas.Add(schema); 431 validator.Schemas.Add(schema);
431 } 432 }
432 m_CurrentDoc.Load(validator); 433 m_CurrentDoc.Load(validator);
434#endif
433 } 435 }
434 catch(XmlException e) 436 catch(XmlException e)
435 { 437 {
@@ -541,7 +543,7 @@ namespace Prebuild.Core
541 return null; 543 return null;
542 } 544 }
543 545
544 NodeEntry ne = (NodeEntry)m_Nodes[node.Name]; 546 NodeEntry ne = m_Nodes[node.Name];
545 return ne.Type; 547 return ne.Type;
546 } 548 }
547 549
@@ -578,11 +580,11 @@ namespace Prebuild.Core
578 { 580 {
579 if(!m_Nodes.ContainsKey(node.Name)) 581 if(!m_Nodes.ContainsKey(node.Name))
580 { 582 {
581 //throw new XmlException("Unknown XML node: " + node.Name); 583 Console.WriteLine("WARNING: Unknown XML node: " + node.Name);
582 return null; 584 return null;
583 } 585 }
584 586
585 NodeEntry ne = (NodeEntry)m_Nodes[node.Name]; 587 NodeEntry ne = m_Nodes[node.Name];
586 Type type = ne.Type; 588 Type type = ne.Type;
587 //DataNodeAttribute dna = ne.Attribute; 589 //DataNodeAttribute dna = ne.Attribute;
588 590
@@ -624,10 +626,8 @@ namespace Prebuild.Core
624 /// <param name="args">The args.</param> 626 /// <param name="args">The args.</param>
625 public void Initialize(LogTargets target, string[] args) 627 public void Initialize(LogTargets target, string[] args)
626 { 628 {
627 m_Targets = new Hashtable(); 629 CacheTargets(GetType().Assembly);
628 CacheTargets(this.GetType().Assembly); 630 CacheNodeTypes(GetType().Assembly);
629 m_Nodes = new Hashtable();
630 CacheNodeTypes(this.GetType().Assembly);
631 CacheVersion(); 631 CacheVersion();
632 632
633 m_CommandLine = new CommandLineCollection(args); 633 m_CommandLine = new CommandLineCollection(args);
@@ -750,11 +750,11 @@ namespace Prebuild.Core
750 } 750 }
751 else 751 else
752 { 752 {
753 if (!m_Targets.Contains(target)) { 753 if (!m_Targets.ContainsKey(target)) {
754 m_Log.Write(LogType.Error, "Unknown Target \"{0}\"", target); 754 m_Log.Write(LogType.Error, "Unknown Target \"{0}\"", target);
755 return; 755 return;
756 } 756 }
757 ITarget targ = (ITarget)m_Targets[target]; 757 ITarget targ = m_Targets[target];
758 758
759 if(clean) 759 if(clean)
760 { 760 {
@@ -793,18 +793,19 @@ namespace Prebuild.Core
793 /// </remarks> 793 /// </remarks>
794 protected virtual void Dispose(bool disposing) 794 protected virtual void Dispose(bool disposing)
795 { 795 {
796 if (!this.disposed) 796 if (!disposed)
797 { 797 {
798 if (disposing) 798 if (disposing)
799 { 799 {
800 if (this.m_Log != null) 800 GC.SuppressFinalize(this);
801 if (m_Log != null)
801 { 802 {
802 this.m_Log.Close(); 803 m_Log.Close();
803 this.m_Log = null; 804 m_Log = null;
804 } 805 }
805 } 806 }
806 } 807 }
807 this.disposed = true; 808 disposed = true;
808 } 809 }
809 810
810 /// <summary> 811 /// <summary>
@@ -812,7 +813,7 @@ namespace Prebuild.Core
812 /// </summary> 813 /// </summary>
813 ~Kernel() 814 ~Kernel()
814 { 815 {
815 this.Dispose(false); 816 Dispose(false);
816 } 817 }
817 818
818 /// <summary> 819 /// <summary>