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.cs458
1 files changed, 229 insertions, 229 deletions
diff --git a/Prebuild/src/Core/Nodes/MatchNode.cs b/Prebuild/src/Core/Nodes/MatchNode.cs
index 000bde9..fe02277 100644
--- a/Prebuild/src/Core/Nodes/MatchNode.cs
+++ b/Prebuild/src/Core/Nodes/MatchNode.cs
@@ -5,16 +5,16 @@ Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehea
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
@@ -35,51 +35,51 @@ using Prebuild.Core.Utilities;
35 35
36namespace Prebuild.Core.Nodes 36namespace Prebuild.Core.Nodes
37{ 37{
38 /// <summary> 38 /// <summary>
39 /// 39 ///
40 /// </summary> 40 /// </summary>
41 [DataNode("Match")] 41 [DataNode("Match")]
42 public class MatchNode : DataNode 42 public class MatchNode : DataNode
43 { 43 {
44 #region Fields 44 #region Fields
45 45
46 private readonly List<string> m_Files = new List<string>(); 46 private readonly List<string> m_Files = new List<string>();
47 private Regex m_Regex; 47 private Regex m_Regex;
48 private BuildAction? m_BuildAction; 48 private BuildAction? m_BuildAction;
49 private SubType? m_SubType; 49 private SubType? m_SubType;
50 string m_ResourceName = ""; 50 string m_ResourceName = "";
51 private CopyToOutput m_CopyToOutput; 51 private CopyToOutput m_CopyToOutput;
52 private bool m_Link; 52 private bool m_Link;
53 private string m_LinkPath; 53 private string m_LinkPath;
54 private bool m_PreservePath; 54 private bool m_PreservePath;
55 private string m_Destination = ""; 55 private string m_Destination = "";
56 private readonly List<ExcludeNode> m_Exclusions = new List<ExcludeNode>(); 56 private readonly List<ExcludeNode> m_Exclusions = new List<ExcludeNode>();
57 57
58 #endregion 58 #endregion
59 59
60 #region Properties 60 #region Properties
61 61
62 /// <summary> 62 /// <summary>
63 /// 63 ///
64 /// </summary> 64 /// </summary>
65 public IEnumerable<string> Files 65 public IEnumerable<string> Files
66 { 66 {
67 get 67 get
68 { 68 {
69 return m_Files; 69 return m_Files;
70 } 70 }
71 } 71 }
72 72
73 /// <summary> 73 /// <summary>
74 /// 74 ///
75 /// </summary> 75 /// </summary>
76 public BuildAction? BuildAction 76 public BuildAction? BuildAction
77 { 77 {
78 get 78 get
79 { 79 {
80 return m_BuildAction; 80 return m_BuildAction;
81 } 81 }
82 } 82 }
83 83
84 public string DestinationPath 84 public string DestinationPath
85 { 85 {
@@ -88,50 +88,50 @@ namespace Prebuild.Core.Nodes
88 return m_Destination; 88 return m_Destination;
89 } 89 }
90 } 90 }
91 /// <summary> 91 /// <summary>
92 /// 92 ///
93 /// </summary> 93 /// </summary>
94 public SubType? SubType 94 public SubType? SubType
95 { 95 {
96 get 96 get
97 { 97 {
98 return m_SubType; 98 return m_SubType;
99 } 99 }
100 } 100 }
101 101
102 public CopyToOutput CopyToOutput 102 public CopyToOutput CopyToOutput
103 { 103 {
104 get 104 get
105 { 105 {
106 return m_CopyToOutput; 106 return m_CopyToOutput;
107 } 107 }
108 } 108 }
109 109
110 public bool IsLink 110 public bool IsLink
111 { 111 {
112 get 112 get
113 { 113 {
114 return m_Link; 114 return m_Link;
115 } 115 }
116 } 116 }
117 117
118 public string LinkPath 118 public string LinkPath
119 { 119 {
120 get 120 get
121 { 121 {
122 return m_LinkPath; 122 return m_LinkPath;
123 } 123 }
124 } 124 }
125 /// <summary> 125 /// <summary>
126 /// 126 ///
127 /// </summary> 127 /// </summary>
128 public string ResourceName 128 public string ResourceName
129 { 129 {
130 get 130 get
131 { 131 {
132 return m_ResourceName; 132 return m_ResourceName;
133 } 133 }
134 } 134 }
135 135
136 public bool PreservePath 136 public bool PreservePath
137 { 137 {
@@ -141,27 +141,27 @@ namespace Prebuild.Core.Nodes
141 } 141 }
142 } 142 }
143 143
144 #endregion 144 #endregion
145 145
146 #region Private Methods 146 #region Private Methods
147 147
148 /// <summary> 148 /// <summary>
149 /// Recurses the directories. 149 /// Recurses the directories.
150 /// </summary> 150 /// </summary>
151 /// <param name="path">The path.</param> 151 /// <param name="path">The path.</param>
152 /// <param name="pattern">The pattern.</param> 152 /// <param name="pattern">The pattern.</param>
153 /// <param name="recurse">if set to <c>true</c> [recurse].</param> 153 /// <param name="recurse">if set to <c>true</c> [recurse].</param>
154 /// <param name="useRegex">if set to <c>true</c> [use regex].</param> 154 /// <param name="useRegex">if set to <c>true</c> [use regex].</param>
155 private void RecurseDirectories(string path, string pattern, bool recurse, bool useRegex, List<ExcludeNode> exclusions) 155 private void RecurseDirectories(string path, string pattern, bool recurse, bool useRegex, List<ExcludeNode> exclusions)
156 { 156 {
157 Match match; 157 Match match;
158 try 158 try
159 { 159 {
160 string[] files; 160 string[] files;
161 161
162 Boolean excludeFile; 162 Boolean excludeFile;
163 if(!useRegex) 163 if(!useRegex)
164 { 164 {
165 try 165 try
166 { 166 {
167 files = Directory.GetFiles(path, pattern); 167 files = Directory.GetFiles(path, pattern);
@@ -169,7 +169,7 @@ namespace Prebuild.Core.Nodes
169 catch (IOException) 169 catch (IOException)
170 { 170 {
171 // swallow weird IOException error when running in a virtual box 171 // swallow weird IOException error when running in a virtual box
172 // guest OS on a network share when the host OS is not Windows. 172 // guest OS on a network share when the host OS is not Windows.
173 // This seems to happen on network shares 173 // This seems to happen on network shares
174 // when no files match, and may be related to this report: 174 // when no files match, and may be related to this report:
175 // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=254546 175 // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=254546
@@ -177,20 +177,20 @@ namespace Prebuild.Core.Nodes
177 files = null; 177 files = null;
178 } 178 }
179 179
180 if(files != null) 180 if(files != null)
181 { 181 {
182 foreach (string file in files) 182 foreach (string file in files)
183 { 183 {
184 excludeFile = false; 184 excludeFile = false;
185 string fileTemp; 185 string fileTemp;
186 if (file.Substring(0,2) == "./" || file.Substring(0,2) == ".\\") 186 if (file.Substring(0,2) == "./" || file.Substring(0,2) == ".\\")
187 { 187 {
188 fileTemp = file.Substring(2); 188 fileTemp = file.Substring(2);
189 } 189 }
190 else 190 else
191 { 191 {
192 fileTemp = file; 192 fileTemp = file;
193 } 193 }
194 194
195 // Check all excludions and set flag if there are any hits. 195 // Check all excludions and set flag if there are any hits.
196 foreach ( ExcludeNode exclude in exclusions ) 196 foreach ( ExcludeNode exclude in exclusions )
@@ -205,18 +205,18 @@ namespace Prebuild.Core.Nodes
205 m_Files.Add( fileTemp ); 205 m_Files.Add( fileTemp );
206 } 206 }
207 207
208 } 208 }
209 } 209 }
210 210
211 // don't call return here, because we may need to recursively search directories below 211 // don't call return here, because we may need to recursively search directories below
212 // this one, even if no matches were found in this directory. 212 // this one, even if no matches were found in this directory.
213 } 213 }
214 else 214 else
215 { 215 {
216 try 216 try
217 { 217 {
218 files = Directory.GetFiles(path); 218 files = Directory.GetFiles(path);
219 } 219 }
220 catch (IOException) 220 catch (IOException)
221 { 221 {
222 // swallow weird IOException error when running in a virtual box 222 // swallow weird IOException error when running in a virtual box
@@ -248,12 +248,12 @@ namespace Prebuild.Core.Nodes
248 } 248 }
249 } 249 }
250 } 250 }
251 } 251 }
252 252
253 if(recurse) 253 if(recurse)
254 { 254 {
255 string[] dirs = Directory.GetDirectories(path); 255 string[] dirs = Directory.GetDirectories(path);
256 if(dirs != null && dirs.Length > 0) 256 if(dirs != null && dirs.Length > 0)
257 { 257 {
258 foreach (string str in dirs) 258 foreach (string str in dirs)
259 { 259 {
@@ -265,96 +265,96 @@ namespace Prebuild.Core.Nodes
265 RecurseDirectories(Helper.NormalizePath(str), pattern, recurse, useRegex, exclusions); 265 RecurseDirectories(Helper.NormalizePath(str), pattern, recurse, useRegex, exclusions);
266 } 266 }
267 } 267 }
268 } 268 }
269 } 269 }
270 catch(DirectoryNotFoundException) 270 catch(DirectoryNotFoundException)
271 { 271 {
272 return; 272 return;
273 } 273 }
274 catch(ArgumentException) 274 catch(ArgumentException)
275 { 275 {
276 return; 276 return;
277 } 277 }
278 } 278 }
279 279
280 #endregion 280 #endregion
281 281
282 #region Public Methods 282 #region Public Methods
283 283
284 /// <summary> 284 /// <summary>
285 /// 285 ///
286 /// </summary> 286 /// </summary>
287 /// <param name="node"></param> 287 /// <param name="node"></param>
288 public override void Parse(XmlNode node) 288 public override void Parse(XmlNode node)
289 { 289 {
290 if( node == null ) 290 if( node == null )
291 { 291 {
292 throw new ArgumentNullException("node"); 292 throw new ArgumentNullException("node");
293 } 293 }
294 string path = Helper.AttributeValue(node, "path", "."); 294 string path = Helper.AttributeValue(node, "path", ".");
295 string pattern = Helper.AttributeValue(node, "pattern", "*"); 295 string pattern = Helper.AttributeValue(node, "pattern", "*");
296 string destination = Helper.AttributeValue(node, "destination", string.Empty); 296 string destination = Helper.AttributeValue(node, "destination", string.Empty);
297 bool recurse = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false")); 297 bool recurse = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false"));
298 bool useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false")); 298 bool useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false"));
299 string buildAction = Helper.AttributeValue(node, "buildAction", String.Empty); 299 string buildAction = Helper.AttributeValue(node, "buildAction", String.Empty);
300 if (buildAction != string.Empty) 300 if (buildAction != string.Empty)
301 m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction); 301 m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction);
302 302
303 303
304 //TODO: Figure out where the subtype node is being assigned 304 //TODO: Figure out where the subtype node is being assigned
305 //string subType = Helper.AttributeValue(node, "subType", string.Empty); 305 //string subType = Helper.AttributeValue(node, "subType", string.Empty);
306 //if (subType != String.Empty) 306 //if (subType != String.Empty)
307 // m_SubType = (SubType)Enum.Parse(typeof(SubType), subType); 307 // m_SubType = (SubType)Enum.Parse(typeof(SubType), subType);
308 m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName); 308 m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName);
309 m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", m_CopyToOutput.ToString())); 309 m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", m_CopyToOutput.ToString()));
310 m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString)); 310 m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
311 if ( m_Link ) 311 if ( m_Link )
312 { 312 {
313 m_LinkPath = Helper.AttributeValue( node, "linkPath", string.Empty ); 313 m_LinkPath = Helper.AttributeValue( node, "linkPath", string.Empty );
314 } 314 }
315 m_PreservePath = bool.Parse( Helper.AttributeValue( node, "preservePath", bool.FalseString ) ); 315 m_PreservePath = bool.Parse( Helper.AttributeValue( node, "preservePath", bool.FalseString ) );
316 316
317 if ( buildAction == "Copy") 317 if ( buildAction == "Copy")
318 m_Destination = destination; 318 m_Destination = destination;
319 319
320 if(path != null && path.Length == 0) 320 if(path != null && path.Length == 0)
321 path = ".";//use current directory 321 path = ".";//use current directory
322 322
323 //throw new WarningException("Match must have a 'path' attribute"); 323 //throw new WarningException("Match must have a 'path' attribute");
324 324
325 if(pattern == null) 325 if(pattern == null)
326 { 326 {
327 throw new WarningException("Match must have a 'pattern' attribute"); 327 throw new WarningException("Match must have a 'pattern' attribute");
328 } 328 }
329 329
330 path = Helper.NormalizePath(path); 330 path = Helper.NormalizePath(path);
331 if(!Directory.Exists(path)) 331 if(!Directory.Exists(path))
332 { 332 {
333 throw new WarningException("Match path does not exist: {0}", path); 333 throw new WarningException("Match path does not exist: {0}", path);
334 } 334 }
335 335
336 try 336 try
337 { 337 {
338 if(useRegex) 338 if(useRegex)
339 { 339 {
340 m_Regex = new Regex(pattern); 340 m_Regex = new Regex(pattern);
341 } 341 }
342 } 342 }
343 catch(ArgumentException ex) 343 catch(ArgumentException ex)
344 { 344 {
345 throw new WarningException("Could not compile regex pattern: {0}", ex.Message); 345 throw new WarningException("Could not compile regex pattern: {0}", ex.Message);
346 } 346 }
347 347
348 348
349 foreach(XmlNode child in node.ChildNodes) 349 foreach(XmlNode child in node.ChildNodes)
350 { 350 {
351 IDataNode dataNode = Kernel.Instance.ParseNode(child, this); 351 IDataNode dataNode = Kernel.Instance.ParseNode(child, this);
352 if(dataNode is ExcludeNode) 352 if(dataNode is ExcludeNode)
353 { 353 {
354 ExcludeNode excludeNode = (ExcludeNode)dataNode; 354 ExcludeNode excludeNode = (ExcludeNode)dataNode;
355 m_Exclusions.Add( excludeNode ); 355 m_Exclusions.Add( excludeNode );
356 } 356 }
357 } 357 }
358 358
359 RecurseDirectories( path, pattern, recurse, useRegex, m_Exclusions ); 359 RecurseDirectories( path, pattern, recurse, useRegex, m_Exclusions );
360 360
@@ -371,8 +371,8 @@ namespace Prebuild.Core.Nodes
371 throw new WarningException("Match" + projectName + " returned no files: {0}{1}", Helper.EndPath(path), pattern); 371 throw new WarningException("Match" + projectName + " returned no files: {0}{1}", Helper.EndPath(path), pattern);
372 } 372 }
373 m_Regex = null; 373 m_Regex = null;
374 } 374 }
375 375
376 #endregion 376 #endregion
377 } 377 }
378} 378}