[RTL]
[reactos.git] / reactos / tools / sysgen / SysGen.BuildEngine / Tasks / BuiltIn / Logic / IfTask.cs
1 using System;
2 using System.IO;
3 using System.Collections;
4 using System.Collections.Specialized;
5
6 using SysGen.BuildEngine.Attributes;
7 using SysGen.BuildEngine.Log;
8
9 namespace SysGen.BuildEngine.Tasks
10 {
11 [TaskName("if")]
12 public class IfTask : TaskContainer
13 {
14 protected string _propName = null;
15 protected string _propValue = null;
16 protected string _propNameTrue = null;
17 protected string _propNameExists = null;
18
19 /// <summary>
20 /// Used to test whether a property is true.
21 /// </summary>
22 [TaskAttribute("propertytrue")]
23 public string PropertyNameTrue {
24 set {_propNameTrue = value;}
25 }
26
27 /// <summary>
28 /// Used to test whether a property exists.
29 /// </summary>
30 [TaskAttribute("propertyexists")]
31 public string PropertyNameExists {
32 set {_propNameExists = value;}
33 }
34
35 /// <summary>
36 /// Used to test whether a property exists.
37 /// </summary>
38 [TaskAttribute("property")]
39 public string PropertyName
40 {
41 set { _propName = value; }
42 }
43
44 /// <summary>
45 /// Used to test whether a property exists.
46 /// </summary>
47 [TaskAttribute("value")]
48 public string PropertyValue
49 {
50 set { _propValue = value; }
51 }
52
53 protected override void PreExecuteTask()
54 {
55 if (!ConditionsTrue)
56 {
57 m_ExecuteChilds = false;
58 }
59 }
60
61 /*
62 protected override void ExecuteTask() {
63 if(!ConditionsTrue) {
64 m_ExecuteChilds = false;
65 }
66 }*/
67
68 protected virtual bool ConditionsTrue
69 {
70 get
71 {
72 bool ret = true;
73
74 if (_propName != null)
75 {
76 if (_propValue != null)
77 {
78 if (SysGen.Project.Properties.PropertyExists(_propName))
79 {
80 return (SysGen.Project.Properties[_propName].Value == _propValue);
81 }
82
83 return false;
84 }
85 else
86 {
87 ret = ret && SysGen.Project.Properties.PropertyExists(_propNameExists);
88 }
89 }
90
91 ////check for target
92 //if(_targetName != null) {
93 // ret = ret && (SysGen.Targets.Find(_targetName) != null);
94 // if (!ret) return false;
95 //}
96
97 //Check for the Property value of true.
98 if (_propNameTrue != null)
99 {
100 try
101 {
102 ret = ret && bool.Parse(SysGen.Project.Properties[_propNameTrue].Value);
103 }
104 catch (Exception e)
105 {
106 throw new BuildException("Property True test failed for '" + _propNameTrue + "'", Location, e);
107 }
108 }
109
110 //Check for Property existence
111 if(_propNameExists != null)
112 {
113 ret = ret && SysGen.Project.Properties.PropertyExists(_propNameExists);
114 }
115
116 ////check for uptodate file
117 //if(_uptodateFile != null) {
118 // FileInfo primaryFile = new FileInfo(_uptodateFile);
119 // if(primaryFile == null) {
120 // ret = true;
121 // }
122 // else {
123 // string newerFile = FileSet.FindMoreRecentLastWriteTime(_compareFiles.FileNames, primaryFile.LastWriteTime);
124 // bool bNeedsAnUpdate = (null == newerFile);
125 // BuildLog.WriteLineIf(SysGen.Verbose && bNeedsAnUpdate, "{0) is newer than {1}" , newerFile, primaryFile.Name);
126 // ret = !bNeedsAnUpdate;
127 // }
128 //}
129
130 return ret;
131 }
132 }
133 }
134 }