New test.
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / DirectoryScanner.cs
index 9722eda4a473b14a15dcfec9b22d3ac430be85ce..5f93ca38825e4afb3a7f34908164c92e729be739 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
+#if NET_2_0
+
 using System;
-using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 
 namespace Microsoft.Build.BuildEngine {
@@ -43,9 +45,10 @@ namespace Microsoft.Build.BuildEngine {
                
                public void Scan ()
                {
-                       Hashtable temporaryItems;
-                       string[] splittedInclude, splittedExclude;
-               
+                       Dictionary <string, bool> excludedItems;
+                       List <string> includedItems;
+                       string[] splitInclude, splitExclude;
+                       
                        if (includes == null)
                                throw new ArgumentNullException ("Includes");
                        if (excludes == null)
@@ -53,34 +56,35 @@ namespace Microsoft.Build.BuildEngine {
                        if (baseDirectory == null)
                                throw new ArgumentNullException ("BaseDirectory");
                        
-                       temporaryItems = new Hashtable ();
+                       excludedItems = new Dictionary <string, bool> ();
+                       includedItems = new List <string> ();
                        
-                       splittedInclude = includes.Split (';');
-                       splittedExclude = excludes.Split (';');
+                       splitInclude = includes.Split (';');
+                       splitExclude = excludes.Split (';');
                        
-                       foreach (string si in splittedInclude) {
-                               ProcessInclude (si, temporaryItems);
-                       }
                        if (excludes != String.Empty) {
-                               foreach (string si in splittedExclude) {
-                                       ProcessExclude (si, temporaryItems);
+                               foreach (string si in splitExclude) {
+                                       ProcessExclude (si, excludedItems);
                                }
                        }
-                       
-                       matchedFilenames = new string [temporaryItems.Count];
-                       int i = 0;
-                       foreach (DictionaryEntry de in temporaryItems)
-                               matchedFilenames [i++] = (string) de.Value; 
+                       if (includes != String.Empty) {
+                               foreach (string si in splitInclude) {
+                                       ProcessInclude (si, excludedItems, includedItems);
+                               }
+                       }
+
+                       matchedFilenames = includedItems.ToArray ();
                }
                
-               private void ProcessInclude (string name, Hashtable temporaryItems)
+               private void ProcessInclude (string name, Dictionary <string, bool> excludedItems, List <string> includedItems)
                {
                        string[] separatedPath;
                        FileInfo[] fileInfo;
-                       
-                       if (name.IndexOf ('?') == -1 && name.IndexOf ('*') == -1)
-                               temporaryItems.Add (Path.GetFullPath (name), name);
-                       else {
+
+                       if (name.IndexOf ('?') == -1 && name.IndexOf ('*') == -1) {
+                               if (!excludedItems.ContainsKey (Path.GetFullPath(name)))
+                                       includedItems.Add (name);
+                       } else {
                                if (name.Split (Path.DirectorySeparatorChar).Length > name.Split (Path.AltDirectorySeparatorChar).Length) {
                                        separatedPath = name.Split (Path.DirectorySeparatorChar);
                                } else {
@@ -90,18 +94,19 @@ namespace Microsoft.Build.BuildEngine {
                                        return;
                                fileInfo = ParseIncludeExclude (separatedPath, 0, baseDirectory);
                                foreach (FileInfo fi in fileInfo)
-                                       temporaryItems.Add (fi.FullName, fi.FullName);
+                                       if (!excludedItems.ContainsKey (fi.FullName))
+                                               includedItems.Add (fi.FullName);
                        }
                }
                
-               private void ProcessExclude (string name, Hashtable temporaryItems)
+               private void ProcessExclude (string name, Dictionary <string, bool> excludedItems)
                {
                        string[] separatedPath;
                        FileInfo[] fileInfo;
                        
                        if (name.IndexOf ('?') == -1 && name.IndexOf ('*') == -1) {
-                               if (temporaryItems.Contains (Path.GetFullPath (name)))
-                                       temporaryItems.Remove (Path.GetFullPath (name));
+                               if (!excludedItems.ContainsKey (Path.GetFullPath (name)))
+                                       excludedItems.Add (Path.GetFullPath (name), true);
                        } else {
                                if (name.Split (Path.DirectorySeparatorChar).Length > name.Split (Path.AltDirectorySeparatorChar).Length) {
                                        separatedPath = name.Split (Path.DirectorySeparatorChar);
@@ -112,8 +117,8 @@ namespace Microsoft.Build.BuildEngine {
                                        return;
                                fileInfo = ParseIncludeExclude (separatedPath, 0, baseDirectory);
                                foreach (FileInfo fi in fileInfo)
-                                       if (temporaryItems.Contains (fi.FullName))
-                                               temporaryItems.Remove (fi.FullName);
+                                       if (!excludedItems.ContainsKey (fi.FullName))
+                                               excludedItems.Add (fi.FullName, true);
                        }
                }
                
@@ -128,7 +133,7 @@ namespace Microsoft.Build.BuildEngine {
                        } else {
                                DirectoryInfo[] di;
                                FileInfo[] fi;
-                               ArrayList fileInfos = new ArrayList ();
+                               List <FileInfo> fileInfos = new List <FileInfo> ();
                                if (input [ptr] == ".") {
                                        di = new DirectoryInfo [1];
                                        di [0] = directory;
@@ -170,4 +175,6 @@ namespace Microsoft.Build.BuildEngine {
                }
                
        }
-}
\ No newline at end of file
+}
+
+#endif