Esempio n. 1
0
        public static void ScanDir(string path, Task task, bool failOnError)
        {
            // don't do anything if we don't have a valid directory path
            if (StringUtils.IsNullOrEmpty(path))
            {
                return;
            }

            task.Log(Level.Info, "Scanning directory \"{0}\" for extension"
                     + " assemblies.", path);

            // scan all dll's for tasks, types and functions
            DirectoryScanner scanner = new DirectoryScanner();

            scanner.BaseDirectory = new DirectoryInfo(path);
            scanner.Includes.Add("*.dll");

            foreach (string assemblyFile in scanner.FileNames)
            {
                try {
                    TypeFactory.ScanAssembly(assemblyFile, task);
                } catch (Exception ex) {
                    if (failOnError)
                    {
                        throw;
                    }

                    task.Log(Level.Error, "Failure scanning \"{0}\" for extensions: {1}",
                             assemblyFile, ex.Message);
                }
            }
        }
Esempio n. 2
0
        public static void ScanDir(string path, Task task, bool failOnError)
        {
            // don't do anything if we don't have a valid directory path
            if (String.IsNullOrEmpty(path))
            {
                return;
            }

            task.Log(Level.Info, "Scanning directory \"{0}\" for extension"
                     + " assemblies.", path);

            // scan all dll's for tasks, types and functions
            DirectoryScanner scanner = new DirectoryScanner();

            scanner.BaseDirectory = new DirectoryInfo(path);
            scanner.Includes.Add("*.dll");

            foreach (string assemblyFile in scanner.FileNames)
            {
                try {
                    TypeFactory.ScanAssembly(assemblyFile, task);
                } catch (Exception ex) {
                    string msg = string.Format(CultureInfo.InvariantCulture,
                                               "Failure scanning \"{0}\" for extensions", assemblyFile);

                    if (failOnError)
                    {
                        throw new BuildException(msg + ".",
                                                 Location.UnknownLocation, ex);
                    }

                    task.Log(Level.Error, msg + ": " + assemblyFile, ex.Message);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a shallow copy of the <see cref="DirectoryScanner" />.
        /// </summary>
        /// <returns>
        /// A shallow copy of the <see cref="DirectoryScanner" />.
        /// </returns>
        public object Clone()
        {
            DirectoryScanner clone = new DirectoryScanner();

            if (_baseDirectory != null)
            {
                clone._baseDirectory = new DirectoryInfo(_baseDirectory.FullName);
            }
            if (_directoryNames != null)
            {
                clone._directoryNames = (DirScannerStringCollection)
                                        _directoryNames.Clone();
            }
            if (_excludePatterns != null)
            {
                clone._excludePatterns = (ArrayList)
                                         _excludePatterns.Clone();
            }
            if (_excludeNames != null)
            {
                clone._excludeNames = (StringCollectionWithGoodToString)
                                      _excludeNames.Clone();
            }
            clone._excludes = (StringCollectionWithGoodToString)_excludes.Clone();
            if (_fileNames != null)
            {
                clone._fileNames = (StringCollectionWithGoodToString)
                                   _fileNames.Clone();
            }
            if (_includePatterns != null)
            {
                clone._includePatterns = (ArrayList)
                                         _includePatterns.Clone();
            }
            if (_includeNames != null)
            {
                clone._includeNames = (StringCollectionWithGoodToString)
                                      _includeNames.Clone();
            }
            clone._includes = (StringCollectionWithGoodToString)_includes.Clone();
            if (_scannedDirectories != null)
            {
                clone._scannedDirectories = (DirScannerStringCollection)
                                            _scannedDirectories.Clone();
            }
            if (_searchDirectories != null)
            {
                clone._searchDirectories = (DirScannerStringCollection)
                                           _searchDirectories.Clone();
            }
            if (_searchDirIsRecursive != null)
            {
                clone._searchDirIsRecursive = (ArrayList)
                                              _searchDirIsRecursive.Clone();
            }
            clone._caseSensitive = _caseSensitive;
            return(clone);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a shallow copy of the <see cref="DirectoryScanner" />.
        /// </summary>
        /// <returns>
        /// A shallow copy of the <see cref="DirectoryScanner" />.
        /// </returns>
        public object Clone() {
            DirectoryScanner clone = new DirectoryScanner();
            if (_baseDirectory != null) {
                clone._baseDirectory = new DirectoryInfo(_baseDirectory.FullName);
            }
            if (_directoryNames != null) {
                clone._directoryNames = (DirScannerStringCollection) 
                    _directoryNames.Clone();
            }
            if (_excludePatterns != null) {
                clone._excludePatterns = (ArrayList) 
                    _excludePatterns.Clone();
            }
            if (_excludeNames != null) {
                clone._excludeNames = (StringCollectionWithGoodToString) 
                    _excludeNames.Clone();
            }
            clone._excludes = (StringCollectionWithGoodToString) _excludes.Clone();
            if (_fileNames != null) {
                clone._fileNames = (StringCollectionWithGoodToString) 
                    _fileNames.Clone();
            }
            if (_excludedFileNames != null)
            {
                clone._excludedFileNames = (StringCollectionWithGoodToString)
                    _excludedFileNames.Clone();
            }
            if (_excludedDirectoryNames != null)
            {
                clone._excludedDirectoryNames = (DirScannerStringCollection)
                    _excludedDirectoryNames.Clone();
            }
            if (_includePatterns != null) {
                clone._includePatterns = (ArrayList) 
                    _includePatterns.Clone();
            }
            if (_includeNames != null) {
                clone._includeNames = (StringCollectionWithGoodToString) 
                    _includeNames.Clone();
            }
            clone._includes = (StringCollectionWithGoodToString) _includes.Clone();
            if (_scannedDirectories != null) {
                clone._scannedDirectories = (DirScannerStringCollection) 
                    _scannedDirectories.Clone();
            }
            if (_searchDirectories != null) {
                clone._searchDirectories = (DirScannerStringCollection) 
                    _searchDirectories.Clone();
            }
            if (_searchDirIsRecursive != null) {
                clone._searchDirIsRecursive = (ArrayList) 
                    _searchDirIsRecursive.Clone();
            }
            if (_baseDirFileSystem != null)
                clone._baseDirFileSystem = new List<FileSystemInfo>(_baseDirFileSystem);

            clone._caseSensitive = _caseSensitive;
            clone._isEverythingIncluded = _isEverythingIncluded;
            clone._hasEmptyDirectories = _hasEmptyDirectories;

            return clone;
        }
Esempio n. 5
0
        public static void ScanDir(string path, Task task, bool failOnError)
        {
            // don't do anything if we don't have a valid directory path
            if (String.IsNullOrEmpty(path)) {
                return;
            }

            task.Log(Level.Info, "Scanning directory \"{0}\" for extension"
                + " assemblies.", path);

            // scan all dll's for tasks, types and functions
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.BaseDirectory = new DirectoryInfo(path);
            scanner.Includes.Add("*.dll");

            foreach (string assemblyFile in scanner.FileNames) {
                try {
                    TypeFactory.ScanAssembly(assemblyFile, task);
                } catch (Exception ex) {
                    string msg = string.Format(CultureInfo.InvariantCulture,
                        "Failure scanning \"{0}\" for extensions", assemblyFile);

                    if (failOnError) {
                        throw new BuildException(msg + ".",
                            Location.UnknownLocation, ex);
                    }

                    task.Log(Level.Error, msg + ": " + assemblyFile, ex.Message);
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Creates a shallow copy of the <see cref="DirectoryScanner" />.
 /// </summary>
 /// <returns>
 /// A shallow copy of the <see cref="DirectoryScanner" />.
 /// </returns>
 public object Clone()
 {
     DirectoryScanner clone = new DirectoryScanner();
     if (_baseDirectory != null) {
         clone._baseDirectory = new DirectoryInfo(_baseDirectory.FullName);
     }
     if (_directoryNames != null) {
         clone._directoryNames = (DirScannerStringCollection)
             _directoryNames.Clone();
     }
     if (_excludePatterns != null) {
         clone._excludePatterns = (ArrayList)
             _excludePatterns.Clone();
     }
     if (_excludeNames != null) {
         clone._excludeNames = (StringCollectionWithGoodToString)
             _excludeNames.Clone();
     }
     clone._excludes = (StringCollectionWithGoodToString) _excludes.Clone();
     if (_fileNames != null) {
         clone._fileNames = (StringCollectionWithGoodToString)
             _fileNames.Clone();
     }
     if (_includePatterns != null) {
         clone._includePatterns = (ArrayList)
             _includePatterns.Clone();
     }
     if (_includeNames != null) {
         clone._includeNames = (StringCollectionWithGoodToString)
             _includeNames.Clone();
     }
     clone._includes = (StringCollectionWithGoodToString) _includes.Clone();
     if (_scannedDirectories != null) {
         clone._scannedDirectories = (DirScannerStringCollection)
             _scannedDirectories.Clone();
     }
     if (_searchDirectories != null) {
         clone._searchDirectories = (DirScannerStringCollection)
             _searchDirectories.Clone();
     }
     if (_searchDirIsRecursive != null) {
         clone._searchDirIsRecursive = (ArrayList)
             _searchDirIsRecursive.Clone();
     }
     clone._caseSensitive = _caseSensitive;
     return clone;
 }
Esempio n. 7
0
        public static void ScanDir(string path, Task task, bool failOnError)
        {
            // don't do anything if we don't have a valid directory path
            if (StringUtils.IsNullOrEmpty(path)) {
                return;
            }

            task.Log(Level.Info, "Scanning directory \"{0}\" for extension"
                + " assemblies.", path);

            // scan all dll's for tasks, types and functions
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.BaseDirectory = new DirectoryInfo(path);
            scanner.Includes.Add("*.dll");

            foreach (string assemblyFile in scanner.FileNames) {
                try {
                    TypeFactory.ScanAssembly(assemblyFile, task);
                } catch (Exception ex) {
                    if (failOnError) {
                        throw;
                    }

                    task.Log(Level.Error, "Failure scanning \"{0}\" for extensions: {1}",
                        assemblyFile, ex.Message);
                }
            }
        }
Esempio n. 8
0
        protected override void SetUp() {
            base.SetUp();

            _folder1 = Path.Combine(TempDirName, "folder1");
            _folder2 = Path.Combine(TempDirName, "folder2");
            _folder3 = Path.Combine(_folder2, "folder3");
            Directory.CreateDirectory(_folder1);
            Directory.CreateDirectory(_folder2);
            Directory.CreateDirectory(_folder3);

            _scanner = new DirectoryScanner();
            _scanner.BaseDirectory = TempDirectory;
        }
Esempio n. 9
0
        public void Test_BaseDir_CaseSensitive() {
            if (!PlatformHelper.IsUnix) {
                return;
            }

            TempFile.Create(Path.Combine(_folder3, "filea.txt"));
            TempFile.Create(Path.Combine(_folder3, "fileb.tlb"));

            _scanner.Includes.Add("folder2/folder3/*.txt");
            _scanner.Scan();
            Assert.AreEqual(1, _scanner.FileNames.Count, "#1");

            _scanner.Includes.Add("Folder2/**/folder3/*.tlb");
            _scanner.Scan();
            Assert.AreEqual(1, _scanner.FileNames.Count, "#2");

            _scanner = new DirectoryScanner();
            _scanner.BaseDirectory = TempDirectory;
            _scanner.Includes.Add("**/*.tlb");
            _scanner.Scan();
            Assert.AreEqual(1, _scanner.FileNames.Count, "#3");

            _scanner.Excludes.Add("folder2/folder3/*.txt");
            _scanner.Excludes.Add("Folder2/**/folder3/*.tlb");
            _scanner.Scan();
            Assert.AreEqual(1, _scanner.FileNames.Count, "#4");
        }
Esempio n. 10
0
        public void Test_Dont_Match_BaseDir_2() {
            string baseDir =  CreateTempDir("NAnt.Tests.DirectoryScannerBaseDirTest");
            TempFile.Create(Path.Combine(baseDir, "filea.txt"));
            TempFile.Create(Path.Combine(baseDir, "fileb.txt"));

            _scanner = new DirectoryScanner();
            _scanner.BaseDirectory = new DirectoryInfo(baseDir + Path.DirectorySeparatorChar);
            _scanner.Includes.Add(@"filea.txt");
            _scanner.Includes.Add(Path.Combine(baseDir, "fileb.txt"));
            _scanner.Scan();

            Assert.AreEqual(2, _scanner.FileNames.Count);
        }