aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Nodes/MatchNode.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Nodes/MatchNode.cs')
-rw-r--r--Prebuild/src/Core/Nodes/MatchNode.cs598
1 files changed, 299 insertions, 299 deletions
diff --git a/Prebuild/src/Core/Nodes/MatchNode.cs b/Prebuild/src/Core/Nodes/MatchNode.cs
index e0d2fa8..8d7b467 100644
--- a/Prebuild/src/Core/Nodes/MatchNode.cs
+++ b/Prebuild/src/Core/Nodes/MatchNode.cs
@@ -1,299 +1,299 @@
1#region BSD License 1#region BSD License
2/* 2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) 3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4 4
5Redistribution and use in source and binary forms, with or without modification, are permitted 5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met: 6provided that the following conditions are met:
7 7
8* Redistributions of source code must retain the above copyright notice, this list of conditions 8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer. 9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions 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 11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution. 12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software 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. 14 without specific prior written permission.
15 15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 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 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, 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 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 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 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. 22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/ 23*/
24#endregion 24#endregion
25 25
26#region CVS Information 26#region CVS Information
27/* 27/*
28 * $Source$ 28 * $Source$
29 * $Author: jendave $ 29 * $Author: jendave $
30 * $Date: 2006-09-20 09:42:51 +0200 (on, 20 sep 2006) $ 30 * $Date: 2006-09-20 09:42:51 +0200 (on, 20 sep 2006) $
31 * $Revision: 164 $ 31 * $Revision: 164 $
32 */ 32 */
33#endregion 33#endregion
34 34
35using System; 35using System;
36using System.Collections.Specialized; 36using System.Collections.Specialized;
37using System.IO; 37using System.IO;
38using System.Text.RegularExpressions; 38using System.Text.RegularExpressions;
39using System.Xml; 39using System.Xml;
40 40
41using Prebuild.Core.Attributes; 41using Prebuild.Core.Attributes;
42using Prebuild.Core.Interfaces; 42using Prebuild.Core.Interfaces;
43using Prebuild.Core.Utilities; 43using Prebuild.Core.Utilities;
44 44
45namespace Prebuild.Core.Nodes 45namespace Prebuild.Core.Nodes
46{ 46{
47 /// <summary> 47 /// <summary>
48 /// 48 ///
49 /// </summary> 49 /// </summary>
50 [DataNode("Match")] 50 [DataNode("Match")]
51 public class MatchNode : DataNode 51 public class MatchNode : DataNode
52 { 52 {
53 #region Fields 53 #region Fields
54 54
55 private StringCollection m_Files; 55 private StringCollection m_Files;
56 private Regex m_Regex; 56 private Regex m_Regex;
57 private BuildAction m_BuildAction = BuildAction.Compile; 57 private BuildAction m_BuildAction = BuildAction.Compile;
58 private SubType m_SubType = SubType.Code; 58 private SubType m_SubType = SubType.Code;
59 string m_ResourceName = ""; 59 string m_ResourceName = "";
60 private CopyToOutput m_CopyToOutput; 60 private CopyToOutput m_CopyToOutput;
61 private bool m_Link; 61 private bool m_Link;
62 62
63 63
64 #endregion 64 #endregion
65 65
66 #region Constructors 66 #region Constructors
67 67
68 /// <summary> 68 /// <summary>
69 /// 69 ///
70 /// </summary> 70 /// </summary>
71 public MatchNode() 71 public MatchNode()
72 { 72 {
73 m_Files = new StringCollection(); 73 m_Files = new StringCollection();
74 } 74 }
75 75
76 #endregion 76 #endregion
77 77
78 #region Properties 78 #region Properties
79 79
80 /// <summary> 80 /// <summary>
81 /// 81 ///
82 /// </summary> 82 /// </summary>
83 public StringCollection Files 83 public StringCollection Files
84 { 84 {
85 get 85 get
86 { 86 {
87 return m_Files; 87 return m_Files;
88 } 88 }
89 } 89 }
90 90
91 /// <summary> 91 /// <summary>
92 /// 92 ///
93 /// </summary> 93 /// </summary>
94 public BuildAction BuildAction 94 public BuildAction BuildAction
95 { 95 {
96 get 96 get
97 { 97 {
98 return m_BuildAction; 98 return m_BuildAction;
99 } 99 }
100 } 100 }
101 101
102 /// <summary> 102 /// <summary>
103 /// 103 ///
104 /// </summary> 104 /// </summary>
105 public SubType SubType 105 public SubType SubType
106 { 106 {
107 get 107 get
108 { 108 {
109 return m_SubType; 109 return m_SubType;
110 } 110 }
111 } 111 }
112 112
113 public CopyToOutput CopyToOutput 113 public CopyToOutput CopyToOutput
114 { 114 {
115 get 115 get
116 { 116 {
117 return this.m_CopyToOutput; 117 return this.m_CopyToOutput;
118 } 118 }
119 } 119 }
120 120
121 public bool IsLink 121 public bool IsLink
122 { 122 {
123 get 123 get
124 { 124 {
125 return this.m_Link; 125 return this.m_Link;
126 } 126 }
127 } 127 }
128 128
129 /// <summary> 129 /// <summary>
130 /// 130 ///
131 /// </summary> 131 /// </summary>
132 public string ResourceName 132 public string ResourceName
133 { 133 {
134 get 134 get
135 { 135 {
136 return m_ResourceName; 136 return m_ResourceName;
137 } 137 }
138 } 138 }
139 139
140 140
141 #endregion 141 #endregion
142 142
143 #region Private Methods 143 #region Private Methods
144 144
145 /// <summary> 145 /// <summary>
146 /// Recurses the directories. 146 /// Recurses the directories.
147 /// </summary> 147 /// </summary>
148 /// <param name="path">The path.</param> 148 /// <param name="path">The path.</param>
149 /// <param name="pattern">The pattern.</param> 149 /// <param name="pattern">The pattern.</param>
150 /// <param name="recurse">if set to <c>true</c> [recurse].</param> 150 /// <param name="recurse">if set to <c>true</c> [recurse].</param>
151 /// <param name="useRegex">if set to <c>true</c> [use regex].</param> 151 /// <param name="useRegex">if set to <c>true</c> [use regex].</param>
152 private void RecurseDirectories(string path, string pattern, bool recurse, bool useRegex) 152 private void RecurseDirectories(string path, string pattern, bool recurse, bool useRegex)
153 { 153 {
154 try 154 try
155 { 155 {
156 string[] files; 156 string[] files;
157 157
158 if(!useRegex) 158 if(!useRegex)
159 { 159 {
160 files = Directory.GetFiles(path, pattern); 160 files = Directory.GetFiles(path, pattern);
161 if(files != null) 161 if(files != null)
162 { 162 {
163 string fileTemp; 163 string fileTemp;
164 foreach (string file in files) 164 foreach (string file in files)
165 { 165 {
166 if (file.Substring(0,2) == "./" || file.Substring(0,2) == ".\\") 166 if (file.Substring(0,2) == "./" || file.Substring(0,2) == ".\\")
167 { 167 {
168 fileTemp = file.Substring(2); 168 fileTemp = file.Substring(2);
169 } 169 }
170 else 170 else
171 { 171 {
172 fileTemp = file; 172 fileTemp = file;
173 } 173 }
174 174
175 m_Files.Add(fileTemp); 175 m_Files.Add(fileTemp);
176 } 176 }
177 } 177 }
178 else 178 else
179 { 179 {
180 return; 180 return;
181 } 181 }
182 } 182 }
183 else 183 else
184 { 184 {
185 Match match; 185 Match match;
186 files = Directory.GetFiles(path); 186 files = Directory.GetFiles(path);
187 foreach(string file in files) 187 foreach(string file in files)
188 { 188 {
189 match = m_Regex.Match(file); 189 match = m_Regex.Match(file);
190 if(match.Success) 190 if(match.Success)
191 { 191 {
192 m_Files.Add(file); 192 m_Files.Add(file);
193 } 193 }
194 } 194 }
195 } 195 }
196 196
197 if(recurse) 197 if(recurse)
198 { 198 {
199 string[] dirs = Directory.GetDirectories(path); 199 string[] dirs = Directory.GetDirectories(path);
200 if(dirs != null && dirs.Length > 0) 200 if(dirs != null && dirs.Length > 0)
201 { 201 {
202 foreach(string str in dirs) 202 foreach(string str in dirs)
203 { 203 {
204 RecurseDirectories(Helper.NormalizePath(str), pattern, recurse, useRegex); 204 RecurseDirectories(Helper.NormalizePath(str), pattern, recurse, useRegex);
205 } 205 }
206 } 206 }
207 } 207 }
208 } 208 }
209 catch(DirectoryNotFoundException) 209 catch(DirectoryNotFoundException)
210 { 210 {
211 return; 211 return;
212 } 212 }
213 catch(ArgumentException) 213 catch(ArgumentException)
214 { 214 {
215 return; 215 return;
216 } 216 }
217 } 217 }
218 218
219 #endregion 219 #endregion
220 220
221 #region Public Methods 221 #region Public Methods
222 222
223 /// <summary> 223 /// <summary>
224 /// 224 ///
225 /// </summary> 225 /// </summary>
226 /// <param name="node"></param> 226 /// <param name="node"></param>
227 public override void Parse(XmlNode node) 227 public override void Parse(XmlNode node)
228 { 228 {
229 if( node == null ) 229 if( node == null )
230 { 230 {
231 throw new ArgumentNullException("node"); 231 throw new ArgumentNullException("node");
232 } 232 }
233 string path = Helper.AttributeValue(node, "path", "."); 233 string path = Helper.AttributeValue(node, "path", ".");
234 string pattern = Helper.AttributeValue(node, "pattern", "*"); 234 string pattern = Helper.AttributeValue(node, "pattern", "*");
235 bool recurse = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false")); 235 bool recurse = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false"));
236 bool useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false")); 236 bool useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false"));
237 m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), 237 m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction),
238 Helper.AttributeValue(node, "buildAction", m_BuildAction.ToString())); 238 Helper.AttributeValue(node, "buildAction", m_BuildAction.ToString()));
239 m_SubType = (SubType)Enum.Parse(typeof(SubType), 239 m_SubType = (SubType)Enum.Parse(typeof(SubType),
240 Helper.AttributeValue(node, "subType", m_SubType.ToString())); 240 Helper.AttributeValue(node, "subType", m_SubType.ToString()));
241 m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString()); 241 m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString());
242 this.m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString())); 242 this.m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString()));
243 this.m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString)); 243 this.m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
244 244
245 245
246 if(path != null && path.Length == 0) 246 if(path != null && path.Length == 0)
247 { 247 {
248 path = ".";//use current directory 248 path = ".";//use current directory
249 } 249 }
250 //throw new WarningException("Match must have a 'path' attribute"); 250 //throw new WarningException("Match must have a 'path' attribute");
251 251
252 if(pattern == null) 252 if(pattern == null)
253 { 253 {
254 throw new WarningException("Match must have a 'pattern' attribute"); 254 throw new WarningException("Match must have a 'pattern' attribute");
255 } 255 }
256 256
257 path = Helper.NormalizePath(path); 257 path = Helper.NormalizePath(path);
258 if(!Directory.Exists(path)) 258 if(!Directory.Exists(path))
259 { 259 {
260 throw new WarningException("Match path does not exist: {0}", path); 260 throw new WarningException("Match path does not exist: {0}", path);
261 } 261 }
262 262
263 try 263 try
264 { 264 {
265 if(useRegex) 265 if(useRegex)
266 { 266 {
267 m_Regex = new Regex(pattern); 267 m_Regex = new Regex(pattern);
268 } 268 }
269 } 269 }
270 catch(ArgumentException ex) 270 catch(ArgumentException ex)
271 { 271 {
272 throw new WarningException("Could not compile regex pattern: {0}", ex.Message); 272 throw new WarningException("Could not compile regex pattern: {0}", ex.Message);
273 } 273 }
274 274
275 RecurseDirectories(path, pattern, recurse, useRegex); 275 RecurseDirectories(path, pattern, recurse, useRegex);
276 276
277 foreach(XmlNode child in node.ChildNodes) 277 foreach(XmlNode child in node.ChildNodes)
278 { 278 {
279 IDataNode dataNode = Kernel.Instance.ParseNode(child, this); 279 IDataNode dataNode = Kernel.Instance.ParseNode(child, this);
280 if(dataNode is ExcludeNode) 280 if(dataNode is ExcludeNode)
281 { 281 {
282 ExcludeNode excludeNode = (ExcludeNode)dataNode; 282 ExcludeNode excludeNode = (ExcludeNode)dataNode;
283 if (m_Files.Contains(Helper.NormalizePath(excludeNode.Name))) 283 if (m_Files.Contains(Helper.NormalizePath(excludeNode.Name)))
284 { 284 {
285 m_Files.Remove(Helper.NormalizePath(excludeNode.Name)); 285 m_Files.Remove(Helper.NormalizePath(excludeNode.Name));
286 } 286 }
287 } 287 }
288 } 288 }
289 289
290 if(m_Files.Count < 1) 290 if(m_Files.Count < 1)
291 { 291 {
292 throw new WarningException("Match returned no files: {0}{1}", Helper.EndPath(path), pattern); 292 throw new WarningException("Match returned no files: {0}{1}", Helper.EndPath(path), pattern);
293 } 293 }
294 m_Regex = null; 294 m_Regex = null;
295 } 295 }
296 296
297 #endregion 297 #endregion
298 } 298 }
299} 299}