Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FileSet.cs « src « nant « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4e934fc82d22451b603c98824d5b1ca6deb3d3bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// NAnt - A .NET build tool
// Copyright (C) 2001 Gerry Shaw
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Gerry Shaw (gerry_shaw@yahoo.com)

namespace SourceForge.NAnt {

    using System;
    using System.Collections.Specialized;
    using System.IO;

    public class FileSet {

        /// <summary>
        /// Used to determine if a file has a more recent last write time then the specified write time.
        /// </summary>
        /// <param name="fileNames">A collection of filenames to check last write times against.</param>
        /// <param name="targetLastWriteTime">The datetime to compare against.</param>
        /// <returns><c>True</c> if at least one file in <c>fileNames</c> has a last write time greater than <c>targetLastWriteTime</c>.</returns>
        public static bool MoreRecentLastWriteTime(StringCollection fileNames, DateTime targetLastWriteTime) {
            foreach (string fileName in fileNames) {
                FileInfo fileInfo = new FileInfo(fileName);
                if (!fileInfo.Exists) {
                    return true;
                }
                if (fileInfo.LastWriteTime > targetLastWriteTime) {
                    return true;
                }
            }
            return false;
        }

        // We can't just use the DirectoryScanner's includes/excludes collections
        // because when we do a Scan() we need to first expand any macros.

        StringCollection _includes = new StringCollection();
        StringCollection _excludes = new StringCollection();
        DirectoryScanner _scanner = null;
        string _baseDirectory;
        bool _includeAllByDefault;
        Task _task = null;

        public FileSet(bool includeAllByDefault) {
            IncludeAllByDefault = includeAllByDefault;
            Excludes.Add("**/CVS/*");
            Excludes.Add("**/.cvsignore");
        }

        /// <remarks>
        /// Will be automagically set in Task.AutoInitializeAttributes() if
        /// file set has TaskFileSetAttribute set on it.
        /// </remarks>
        // TODO: change this to IMacroExpander
        public Task Task {
            get { return _task; }
            set { _task = value; }
        }

        public string BaseDirectory {
            get { return _baseDirectory; }
            set { _baseDirectory = value; }
        }

        /// <summary>Determines if scan should produce everything or nothing
        /// if there are no Includes set.  Default false.</summary>
        public bool IncludeAllByDefault {
            get { return _includeAllByDefault; }
            set { _includeAllByDefault = value; }
        }

        public StringCollection Includes {
            get { return _includes; }
        }

        public StringCollection Excludes {
            get { return _excludes; }
        }

        public void Scan() {
            // get project (only for expanding macros)
            Project expander = Task.Project;

            _scanner = new DirectoryScanner();
            _scanner.BaseDirectory = expander.GetFullPath(BaseDirectory);;

            foreach (string path in Includes) {
                _scanner.Includes.Add(expander.ExpandText(path));
            }
            if (Includes.Count <= 0 && IncludeAllByDefault) {
                _scanner.Includes.Add("**");
            }

            foreach (string path in Excludes) {
                _scanner.Excludes.Add(expander.ExpandText(path));
            }

            _scanner.Scan();
        }

        public StringCollection DirectoryNames {
            get {
                if (_scanner == null) {
                    Scan();
                }
                return _scanner.DirectoryNames;
            }
        }

        public StringCollection FileNames {
            get {
                if (_scanner == null) {
                    Scan();
                }
                return _scanner.FileNames;
            }
        }
    }
}