diff options
Diffstat (limited to 'Prebuild/src/Core/Kernel.cs')
-rw-r--r-- | Prebuild/src/Core/Kernel.cs | 149 |
1 files changed, 56 insertions, 93 deletions
diff --git a/Prebuild/src/Core/Kernel.cs b/Prebuild/src/Core/Kernel.cs index 95ef04e..1f0ad70 100644 --- a/Prebuild/src/Core/Kernel.cs +++ b/Prebuild/src/Core/Kernel.cs | |||
@@ -36,8 +36,16 @@ 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 | |||
39 | using System; | 48 | using System; |
40 | using System.Collections.Generic; | ||
41 | using System.Diagnostics; | 49 | using System.Diagnostics; |
42 | using System.Collections; | 50 | using System.Collections; |
43 | using System.Collections.Specialized; | 51 | using System.Collections.Specialized; |
@@ -72,17 +80,17 @@ namespace Prebuild.Core | |||
72 | 80 | ||
73 | #region Fields | 81 | #region Fields |
74 | 82 | ||
75 | private static readonly Kernel m_Instance = new Kernel(); | 83 | private static Kernel m_Instance = new Kernel(); |
76 | 84 | ||
77 | /// <summary> | 85 | /// <summary> |
78 | /// This must match the version of the schema that is embeeded | 86 | /// This must match the version of the schema that is embeeded |
79 | /// </summary> | 87 | /// </summary> |
80 | private const string m_SchemaVersion = "1.7"; | 88 | private static string m_SchemaVersion = "1.7"; |
81 | private const string m_Schema = "prebuild-" + m_SchemaVersion + ".xsd"; | 89 | private static string m_Schema = "prebuild-" + m_SchemaVersion + ".xsd"; |
82 | private const string m_SchemaURI = "http://dnpb.sourceforge.net/schemas/" + m_Schema; | 90 | private static string m_SchemaURI = "http://dnpb.sourceforge.net/schemas/" + m_Schema; |
83 | bool disposed; | 91 | bool disposed; |
84 | private Version m_Version; | 92 | private Version m_Version; |
85 | private const string m_Revision = ""; | 93 | private string m_Revision = ""; |
86 | private CommandLineCollection m_CommandLine; | 94 | private CommandLineCollection m_CommandLine; |
87 | private Log m_Log; | 95 | private Log m_Log; |
88 | private CurrentDirectory m_CurrentWorkingDirectory; | 96 | private CurrentDirectory m_CurrentWorkingDirectory; |
@@ -90,16 +98,19 @@ namespace Prebuild.Core | |||
90 | 98 | ||
91 | private Hashtable m_Targets; | 99 | private Hashtable m_Targets; |
92 | private Hashtable m_Nodes; | 100 | private Hashtable m_Nodes; |
93 | 101 | ||
94 | readonly List<SolutionNode> m_Solutions = new List<SolutionNode>(); | 102 | ArrayList m_Solutions; |
95 | string m_Target; | 103 | string m_Target; |
96 | string m_Clean; | 104 | string m_Clean; |
97 | string[] m_RemoveDirectories; | 105 | string[] m_RemoveDirectories; |
98 | XmlDocument m_CurrentDoc; | 106 | string m_CurrentFile; |
107 | XmlDocument m_CurrentDoc; | ||
99 | bool m_PauseAfterFinish; | 108 | bool m_PauseAfterFinish; |
100 | string[] m_ProjectGroups; | 109 | string[] m_ProjectGroups; |
110 | StringCollection m_Refs; | ||
101 | 111 | ||
102 | #endregion | 112 | |
113 | #endregion | ||
103 | 114 | ||
104 | #region Constructors | 115 | #region Constructors |
105 | 116 | ||
@@ -199,7 +210,7 @@ namespace Prebuild.Core | |||
199 | /// Gets the solutions. | 210 | /// Gets the solutions. |
200 | /// </summary> | 211 | /// </summary> |
201 | /// <value>The solutions.</value> | 212 | /// <value>The solutions.</value> |
202 | public List<SolutionNode> Solutions | 213 | public ArrayList Solutions |
203 | { | 214 | { |
204 | get | 215 | get |
205 | { | 216 | { |
@@ -224,7 +235,7 @@ namespace Prebuild.Core | |||
224 | 235 | ||
225 | #region Private Methods | 236 | #region Private Methods |
226 | 237 | ||
227 | private static void RemoveDirectories(string rootDir, string[] dirNames) | 238 | private void RemoveDirectories(string rootDir, string[] dirNames) |
228 | { | 239 | { |
229 | foreach(string dir in Directory.GetDirectories(rootDir)) | 240 | foreach(string dir in Directory.GetDirectories(rootDir)) |
230 | { | 241 | { |
@@ -286,15 +297,13 @@ namespace Prebuild.Core | |||
286 | foreach(Type t in assm.GetTypes()) | 297 | foreach(Type t in assm.GetTypes()) |
287 | { | 298 | { |
288 | TargetAttribute ta = (TargetAttribute)Helper.CheckType(t, typeof(TargetAttribute), typeof(ITarget)); | 299 | TargetAttribute ta = (TargetAttribute)Helper.CheckType(t, typeof(TargetAttribute), typeof(ITarget)); |
289 | |||
290 | if(ta == null) | 300 | if(ta == null) |
301 | { | ||
291 | continue; | 302 | continue; |
292 | 303 | } | |
293 | if (t.IsAbstract) | 304 | |
294 | continue; | ||
295 | |||
296 | ITarget target = (ITarget)assm.CreateInstance(t.FullName); | 305 | ITarget target = (ITarget)assm.CreateInstance(t.FullName); |
297 | if (target == null) | 306 | if(target == null) |
298 | { | 307 | { |
299 | throw new MissingMethodException("Could not create ITarget instance"); | 308 | throw new MissingMethodException("Could not create ITarget instance"); |
300 | } | 309 | } |
@@ -307,13 +316,16 @@ namespace Prebuild.Core | |||
307 | { | 316 | { |
308 | foreach(Type t in assm.GetTypes()) | 317 | foreach(Type t in assm.GetTypes()) |
309 | { | 318 | { |
310 | foreach (DataNodeAttribute dna in t.GetCustomAttributes(typeof(DataNodeAttribute), true)) | 319 | DataNodeAttribute dna = (DataNodeAttribute)Helper.CheckType(t, typeof(DataNodeAttribute), typeof(IDataNode)); |
311 | { | 320 | if(dna == null) |
312 | NodeEntry ne = new NodeEntry(); | 321 | { |
313 | ne.Type = t; | 322 | continue; |
314 | ne.Attribute = dna; | 323 | } |
315 | m_Nodes[dna.Name] = ne; | 324 | |
316 | } | 325 | NodeEntry ne = new NodeEntry(); |
326 | ne.Type = t; | ||
327 | ne.Attribute = dna; | ||
328 | m_Nodes[dna.Name] = ne; | ||
317 | } | 329 | } |
318 | } | 330 | } |
319 | 331 | ||
@@ -331,32 +343,7 @@ namespace Prebuild.Core | |||
331 | m_Log.Write(); | 343 | m_Log.Write(); |
332 | } | 344 | } |
333 | 345 | ||
334 | 346 | private void ProcessFile(string file) | |
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) | ||
360 | { | 347 | { |
361 | m_CurrentWorkingDirectory.Push(); | 348 | m_CurrentWorkingDirectory.Push(); |
362 | 349 | ||
@@ -374,7 +361,8 @@ namespace Prebuild.Core | |||
374 | return; | 361 | return; |
375 | } | 362 | } |
376 | 363 | ||
377 | Helper.SetCurrentDir(Path.GetDirectoryName(path)); | 364 | m_CurrentFile = path; |
365 | Helper.SetCurrentDir(Path.GetDirectoryName(path)); | ||
378 | 366 | ||
379 | XmlTextReader reader = new XmlTextReader(path); | 367 | XmlTextReader reader = new XmlTextReader(path); |
380 | 368 | ||
@@ -391,33 +379,6 @@ namespace Prebuild.Core | |||
391 | 379 | ||
392 | string xml = pre.Process(reader);//remove script and evaulate pre-proccessing to get schema-conforming XML | 380 | string xml = pre.Process(reader);//remove script and evaulate pre-proccessing to get schema-conforming XML |
393 | 381 | ||
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 | } | ||
421 | 382 | ||
422 | m_CurrentDoc = new XmlDocument(); | 383 | m_CurrentDoc = new XmlDocument(); |
423 | try | 384 | try |
@@ -482,7 +443,7 @@ namespace Prebuild.Core | |||
482 | } | 443 | } |
483 | else if(dataNode is SolutionNode) | 444 | else if(dataNode is SolutionNode) |
484 | { | 445 | { |
485 | solutions.Add((SolutionNode)dataNode); | 446 | m_Solutions.Add(dataNode); |
486 | } | 447 | } |
487 | } | 448 | } |
488 | } | 449 | } |
@@ -566,7 +527,7 @@ namespace Prebuild.Core | |||
566 | /// <returns></returns> | 527 | /// <returns></returns> |
567 | public IDataNode ParseNode(XmlNode node, IDataNode parent, IDataNode preNode) | 528 | public IDataNode ParseNode(XmlNode node, IDataNode parent, IDataNode preNode) |
568 | { | 529 | { |
569 | IDataNode dataNode; | 530 | IDataNode dataNode = null; |
570 | 531 | ||
571 | try | 532 | try |
572 | { | 533 | { |
@@ -668,6 +629,9 @@ namespace Prebuild.Core | |||
668 | m_PauseAfterFinish = m_CommandLine.WasPassed("pause"); | 629 | m_PauseAfterFinish = m_CommandLine.WasPassed("pause"); |
669 | 630 | ||
670 | LoadSchema(); | 631 | LoadSchema(); |
632 | |||
633 | m_Solutions = new ArrayList(); | ||
634 | m_Refs = new StringCollection(); | ||
671 | } | 635 | } |
672 | 636 | ||
673 | /// <summary> | 637 | /// <summary> |
@@ -700,18 +664,17 @@ namespace Prebuild.Core | |||
700 | m_Log.Write(LogType.Error, "The options /target and /clean cannot be passed together"); | 664 | m_Log.Write(LogType.Error, "The options /target and /clean cannot be passed together"); |
701 | return; | 665 | return; |
702 | } | 666 | } |
703 | 667 | else if(m_Target == null && m_Clean == null) | |
704 | if(m_Target == null && m_Clean == null) | 668 | { |
705 | { | 669 | if(perfomedOtherTask) //finished |
706 | if(perfomedOtherTask) //finished | 670 | { |
707 | { | 671 | return; |
708 | return; | 672 | } |
709 | } | 673 | m_Log.Write(LogType.Error, "Must pass either /target or /clean to process a Prebuild file"); |
710 | m_Log.Write(LogType.Error, "Must pass either /target or /clean to process a Prebuild file"); | 674 | return; |
711 | return; | 675 | } |
712 | } | 676 | |
713 | 677 | string file = "./prebuild.xml"; | |
714 | string file = "./prebuild.xml"; | ||
715 | if(m_CommandLine.WasPassed("file")) | 678 | if(m_CommandLine.WasPassed("file")) |
716 | { | 679 | { |
717 | file = m_CommandLine["file"]; | 680 | file = m_CommandLine["file"]; |