diff options
Diffstat (limited to 'Prebuild/src/Core/Nodes/.svn/text-base/MatchNode.cs.svn-base')
-rw-r--r-- | Prebuild/src/Core/Nodes/.svn/text-base/MatchNode.cs.svn-base | 367 |
1 files changed, 0 insertions, 367 deletions
diff --git a/Prebuild/src/Core/Nodes/.svn/text-base/MatchNode.cs.svn-base b/Prebuild/src/Core/Nodes/.svn/text-base/MatchNode.cs.svn-base deleted file mode 100644 index 9735265..0000000 --- a/Prebuild/src/Core/Nodes/.svn/text-base/MatchNode.cs.svn-base +++ /dev/null | |||
@@ -1,367 +0,0 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
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 | ||
12 | distribution. | ||
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. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | using System; | ||
27 | using System.Collections.Generic; | ||
28 | using System.IO; | ||
29 | using System.Text.RegularExpressions; | ||
30 | using System.Xml; | ||
31 | |||
32 | using Prebuild.Core.Attributes; | ||
33 | using Prebuild.Core.Interfaces; | ||
34 | using Prebuild.Core.Utilities; | ||
35 | |||
36 | namespace Prebuild.Core.Nodes | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// | ||
40 | /// </summary> | ||
41 | [DataNode("Match")] | ||
42 | public class MatchNode : DataNode | ||
43 | { | ||
44 | #region Fields | ||
45 | |||
46 | private readonly List<string> m_Files = new List<string>(); | ||
47 | private Regex m_Regex; | ||
48 | private BuildAction? m_BuildAction; | ||
49 | private SubType? m_SubType; | ||
50 | string m_ResourceName = ""; | ||
51 | private CopyToOutput m_CopyToOutput; | ||
52 | private bool m_Link; | ||
53 | private string m_LinkPath; | ||
54 | private bool m_PreservePath; | ||
55 | private readonly List<ExcludeNode> m_Exclusions = new List<ExcludeNode>(); | ||
56 | |||
57 | #endregion | ||
58 | |||
59 | #region Properties | ||
60 | |||
61 | /// <summary> | ||
62 | /// | ||
63 | /// </summary> | ||
64 | public IEnumerable<string> Files | ||
65 | { | ||
66 | get | ||
67 | { | ||
68 | return m_Files; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | /// <summary> | ||
73 | /// | ||
74 | /// </summary> | ||
75 | public BuildAction? BuildAction | ||
76 | { | ||
77 | get | ||
78 | { | ||
79 | return m_BuildAction; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// | ||
85 | /// </summary> | ||
86 | public SubType? SubType | ||
87 | { | ||
88 | get | ||
89 | { | ||
90 | return m_SubType; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | public CopyToOutput CopyToOutput | ||
95 | { | ||
96 | get | ||
97 | { | ||
98 | return m_CopyToOutput; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public bool IsLink | ||
103 | { | ||
104 | get | ||
105 | { | ||
106 | return m_Link; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | public string LinkPath | ||
111 | { | ||
112 | get | ||
113 | { | ||
114 | return m_LinkPath; | ||
115 | } | ||
116 | } | ||
117 | /// <summary> | ||
118 | /// | ||
119 | /// </summary> | ||
120 | public string ResourceName | ||
121 | { | ||
122 | get | ||
123 | { | ||
124 | return m_ResourceName; | ||
125 | } | ||
126 | } | ||
127 | |||
128 | public bool PreservePath | ||
129 | { | ||
130 | get | ||
131 | { | ||
132 | return m_PreservePath; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | #endregion | ||
137 | |||
138 | #region Private Methods | ||
139 | |||
140 | /// <summary> | ||
141 | /// Recurses the directories. | ||
142 | /// </summary> | ||
143 | /// <param name="path">The path.</param> | ||
144 | /// <param name="pattern">The pattern.</param> | ||
145 | /// <param name="recurse">if set to <c>true</c> [recurse].</param> | ||
146 | /// <param name="useRegex">if set to <c>true</c> [use regex].</param> | ||
147 | private void RecurseDirectories(string path, string pattern, bool recurse, bool useRegex, List<ExcludeNode> exclusions) | ||
148 | { | ||
149 | Match match; | ||
150 | try | ||
151 | { | ||
152 | string[] files; | ||
153 | |||
154 | Boolean excludeFile; | ||
155 | if(!useRegex) | ||
156 | { | ||
157 | try | ||
158 | { | ||
159 | files = Directory.GetFiles(path, pattern); | ||
160 | } | ||
161 | catch (IOException) | ||
162 | { | ||
163 | // swallow weird IOException error when running in a virtual box | ||
164 | // guest OS on a network share when the host OS is not Windows. | ||
165 | // This seems to happen on network shares | ||
166 | // when no files match, and may be related to this report: | ||
167 | // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=254546 | ||
168 | |||
169 | files = null; | ||
170 | } | ||
171 | |||
172 | if(files != null) | ||
173 | { | ||
174 | foreach (string file in files) | ||
175 | { | ||
176 | excludeFile = false; | ||
177 | string fileTemp; | ||
178 | if (file.Substring(0,2) == "./" || file.Substring(0,2) == ".\\") | ||
179 | { | ||
180 | fileTemp = file.Substring(2); | ||
181 | } | ||
182 | else | ||
183 | { | ||
184 | fileTemp = file; | ||
185 | } | ||
186 | |||
187 | // Check all excludions and set flag if there are any hits. | ||
188 | foreach ( ExcludeNode exclude in exclusions ) | ||
189 | { | ||
190 | Regex exRegEx = new Regex( exclude.Pattern ); | ||
191 | match = exRegEx.Match( file ); | ||
192 | excludeFile |= match.Success; | ||
193 | } | ||
194 | |||
195 | if ( !excludeFile ) | ||
196 | { | ||
197 | m_Files.Add( fileTemp ); | ||
198 | } | ||
199 | |||
200 | } | ||
201 | } | ||
202 | |||
203 | // don't call return here, because we may need to recursively search directories below | ||
204 | // this one, even if no matches were found in this directory. | ||
205 | } | ||
206 | else | ||
207 | { | ||
208 | try | ||
209 | { | ||
210 | files = Directory.GetFiles(path); | ||
211 | } | ||
212 | catch (IOException) | ||
213 | { | ||
214 | // swallow weird IOException error when running in a virtual box | ||
215 | // guest OS on a network share. | ||
216 | files = null; | ||
217 | } | ||
218 | |||
219 | if (files != null) | ||
220 | { | ||
221 | foreach (string file in files) | ||
222 | { | ||
223 | excludeFile = false; | ||
224 | |||
225 | match = m_Regex.Match(file); | ||
226 | if (match.Success) | ||
227 | { | ||
228 | // Check all excludions and set flag if there are any hits. | ||
229 | foreach (ExcludeNode exclude in exclusions) | ||
230 | { | ||
231 | Regex exRegEx = new Regex(exclude.Pattern); | ||
232 | match = exRegEx.Match(file); | ||
233 | excludeFile |= !match.Success; | ||
234 | } | ||
235 | |||
236 | if (!excludeFile) | ||
237 | { | ||
238 | m_Files.Add(file); | ||
239 | } | ||
240 | } | ||
241 | } | ||
242 | } | ||
243 | } | ||
244 | |||
245 | if(recurse) | ||
246 | { | ||
247 | string[] dirs = Directory.GetDirectories(path); | ||
248 | if(dirs != null && dirs.Length > 0) | ||
249 | { | ||
250 | foreach (string str in dirs) | ||
251 | { | ||
252 | // hack to skip subversion folders. Not having this can cause | ||
253 | // a significant performance hit when running on a network drive. | ||
254 | if (str.EndsWith(".svn")) | ||
255 | continue; | ||
256 | |||
257 | RecurseDirectories(Helper.NormalizePath(str), pattern, recurse, useRegex, exclusions); | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | catch(DirectoryNotFoundException) | ||
263 | { | ||
264 | return; | ||
265 | } | ||
266 | catch(ArgumentException) | ||
267 | { | ||
268 | return; | ||
269 | } | ||
270 | } | ||
271 | |||
272 | #endregion | ||
273 | |||
274 | #region Public Methods | ||
275 | |||
276 | /// <summary> | ||
277 | /// | ||
278 | /// </summary> | ||
279 | /// <param name="node"></param> | ||
280 | public override void Parse(XmlNode node) | ||
281 | { | ||
282 | if( node == null ) | ||
283 | { | ||
284 | throw new ArgumentNullException("node"); | ||
285 | } | ||
286 | string path = Helper.AttributeValue(node, "path", "."); | ||
287 | string pattern = Helper.AttributeValue(node, "pattern", "*"); | ||
288 | bool recurse = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false")); | ||
289 | bool useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false")); | ||
290 | string buildAction = Helper.AttributeValue(node, "buildAction", String.Empty); | ||
291 | if (buildAction != string.Empty) | ||
292 | m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction); | ||
293 | |||
294 | //TODO: Figure out where the subtype node is being assigned | ||
295 | //string subType = Helper.AttributeValue(node, "subType", string.Empty); | ||
296 | //if (subType != String.Empty) | ||
297 | // m_SubType = (SubType)Enum.Parse(typeof(SubType), subType); | ||
298 | m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName); | ||
299 | m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", m_CopyToOutput.ToString())); | ||
300 | m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString)); | ||
301 | if ( m_Link ) | ||
302 | { | ||
303 | m_LinkPath = Helper.AttributeValue( node, "linkPath", string.Empty ); | ||
304 | } | ||
305 | m_PreservePath = bool.Parse( Helper.AttributeValue( node, "preservePath", bool.FalseString ) ); | ||
306 | |||
307 | |||
308 | if(path != null && path.Length == 0) | ||
309 | { | ||
310 | path = ".";//use current directory | ||
311 | } | ||
312 | //throw new WarningException("Match must have a 'path' attribute"); | ||
313 | |||
314 | if(pattern == null) | ||
315 | { | ||
316 | throw new WarningException("Match must have a 'pattern' attribute"); | ||
317 | } | ||
318 | |||
319 | path = Helper.NormalizePath(path); | ||
320 | if(!Directory.Exists(path)) | ||
321 | { | ||
322 | throw new WarningException("Match path does not exist: {0}", path); | ||
323 | } | ||
324 | |||
325 | try | ||
326 | { | ||
327 | if(useRegex) | ||
328 | { | ||
329 | m_Regex = new Regex(pattern); | ||
330 | } | ||
331 | } | ||
332 | catch(ArgumentException ex) | ||
333 | { | ||
334 | throw new WarningException("Could not compile regex pattern: {0}", ex.Message); | ||
335 | } | ||
336 | |||
337 | |||
338 | foreach(XmlNode child in node.ChildNodes) | ||
339 | { | ||
340 | IDataNode dataNode = Kernel.Instance.ParseNode(child, this); | ||
341 | if(dataNode is ExcludeNode) | ||
342 | { | ||
343 | ExcludeNode excludeNode = (ExcludeNode)dataNode; | ||
344 | m_Exclusions.Add( excludeNode ); | ||
345 | } | ||
346 | } | ||
347 | |||
348 | RecurseDirectories( path, pattern, recurse, useRegex, m_Exclusions ); | ||
349 | |||
350 | if (m_Files.Count < 1) | ||
351 | { | ||
352 | // Include the project name when the match node returns no matches to provide extra | ||
353 | // debug info. | ||
354 | ProjectNode project = Parent.Parent as ProjectNode; | ||
355 | string projectName = ""; | ||
356 | |||
357 | if (project != null) | ||
358 | projectName = " in project " + project.AssemblyName; | ||
359 | |||
360 | throw new WarningException("Match" + projectName + " returned no files: {0}{1}", Helper.EndPath(path), pattern); | ||
361 | } | ||
362 | m_Regex = null; | ||
363 | } | ||
364 | |||
365 | #endregion | ||
366 | } | ||
367 | } | ||