Source Code Cross Referenced for SourceFileScanner.java in  » Build » ANT » org » apache » tools » ant » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Build » ANT » org.apache.tools.ant.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.ant.util;
020:
021:        import java.io.File;
022:        import java.util.Vector;
023:        import org.apache.tools.ant.Task;
024:        import org.apache.tools.ant.types.Resource;
025:        import org.apache.tools.ant.types.ResourceFactory;
026:        import org.apache.tools.ant.types.resources.FileResource;
027:
028:        /**
029:         * Utility class that collects the functionality of the various
030:         * scanDir methods that have been scattered in several tasks before.
031:         *
032:         * <p>The only method returns an array of source files. The array is a
033:         * subset of the files given as a parameter and holds only those that
034:         * are newer than their corresponding target files.</p>
035:         *
036:         */
037:        public class SourceFileScanner implements  ResourceFactory {
038:
039:            // CheckStyle:VisibilityModifier OFF - bc
040:            protected Task task;
041:            // CheckStyle:VisibilityModifier ON
042:
043:            private static final FileUtils FILE_UTILS = FileUtils
044:                    .getFileUtils();
045:            private File destDir; // base directory of the fileset
046:
047:            /**
048:             * Construct a new SourceFileScanner.
049:             * @param task The task we should log messages through.
050:             */
051:            public SourceFileScanner(Task task) {
052:                this .task = task;
053:            }
054:
055:            /**
056:             * Restrict the given set of files to those that are newer than
057:             * their corresponding target files.
058:             *
059:             * @param files   the original set of files.
060:             * @param srcDir  all files are relative to this directory.
061:             * @param destDir target files live here. if null file names
062:             *                returned by the mapper are assumed to be absolute.
063:             * @param mapper  knows how to construct a target file names from
064:             *                source file names.
065:             * @return an array of filenames.
066:             */
067:            public String[] restrict(String[] files, File srcDir, File destDir,
068:                    FileNameMapper mapper) {
069:                return restrict(files, srcDir, destDir, mapper, FILE_UTILS
070:                        .getFileTimestampGranularity());
071:            }
072:
073:            /**
074:             * Restrict the given set of files to those that are newer than
075:             * their corresponding target files.
076:             *
077:             * @param files   the original set of files.
078:             * @param srcDir  all files are relative to this directory.
079:             * @param destDir target files live here. If null file names
080:             *                returned by the mapper are assumed to be absolute.
081:             * @param mapper  knows how to construct a target file names from
082:             *                source file names.
083:             * @param granularity The number of milliseconds leeway to give
084:             *                    before deciding a target is out of date.
085:             * @return an array of filenames.
086:             *
087:             * @since Ant 1.6.2
088:             */
089:            public String[] restrict(String[] files, File srcDir, File destDir,
090:                    FileNameMapper mapper, long granularity) {
091:                // record destdir for later use in getResource
092:                this .destDir = destDir;
093:                Vector v = new Vector();
094:                for (int i = 0; i < files.length; i++) {
095:                    File src = FILE_UTILS.resolveFile(srcDir, files[i]);
096:                    v.addElement(new Resource(files[i], src.exists(), src
097:                            .lastModified(), src.isDirectory()));
098:                }
099:                Resource[] sourceresources = new Resource[v.size()];
100:                v.copyInto(sourceresources);
101:
102:                // build the list of sources which are out of date with
103:                // respect to the target
104:                Resource[] outofdate = ResourceUtils.selectOutOfDateSources(
105:                        task, sourceresources, mapper, this , granularity);
106:                String[] result = new String[outofdate.length];
107:                for (int counter = 0; counter < outofdate.length; counter++) {
108:                    result[counter] = outofdate[counter].getName();
109:                }
110:                return result;
111:            }
112:
113:            /**
114:             * Convenience layer on top of restrict that returns the source
115:             * files as File objects (containing absolute paths if srcDir is
116:             * absolute).
117:             * @param files   the original set of files.
118:             * @param srcDir  all files are relative to this directory.
119:             * @param destDir target files live here. If null file names
120:             *                returned by the mapper are assumed to be absolute.
121:             * @param mapper  knows how to construct a target file names from
122:             *                source file names.
123:             * @return an array of files.
124:             */
125:            public File[] restrictAsFiles(String[] files, File srcDir,
126:                    File destDir, FileNameMapper mapper) {
127:                return restrictAsFiles(files, srcDir, destDir, mapper,
128:                        FILE_UTILS.getFileTimestampGranularity());
129:            }
130:
131:            /**
132:             * Convenience layer on top of restrict that returns the source
133:             * files as File objects (containing absolute paths if srcDir is
134:             * absolute).
135:             *
136:             * @param files   the original set of files.
137:             * @param srcDir  all files are relative to this directory.
138:             * @param destDir target files live here. If null file names
139:             *                returned by the mapper are assumed to be absolute.
140:             * @param mapper  knows how to construct a target file names from
141:             *                source file names.
142:             * @param granularity The number of milliseconds leeway to give
143:             *                    before deciding a target is out of date.
144:             * @return an array of files.
145:             * @since Ant 1.6.2
146:             */
147:            public File[] restrictAsFiles(String[] files, File srcDir,
148:                    File destDir, FileNameMapper mapper, long granularity) {
149:                String[] res = restrict(files, srcDir, destDir, mapper,
150:                        granularity);
151:                File[] result = new File[res.length];
152:                for (int i = 0; i < res.length; i++) {
153:                    result[i] = new File(srcDir, res[i]);
154:                }
155:                return result;
156:            }
157:
158:            /**
159:             * Returns resource information for a file at destination.
160:             * @param name relative path of file at destination.
161:             * @return data concerning a file whose relative path to destDir is name.
162:             *
163:             * @since Ant 1.5.2
164:             */
165:            public Resource getResource(String name) {
166:                return new FileResource(destDir, name);
167:            }
168:
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.