View | Details | Raw Unified | Return to bug 44726
Collapse All | Expand All

(-)main/org/apache/tools/ant/taskdefs/optional/net/FTP.java (-18 / +149 lines)
Lines 32-43 Link Here
32
import java.util.Date;
32
import java.util.Date;
33
import java.util.Enumeration;
33
import java.util.Enumeration;
34
import java.util.HashMap;
34
import java.util.HashMap;
35
import java.util.HashSet;
36
import java.util.Hashtable;
35
import java.util.Hashtable;
37
import java.util.Iterator;
36
import java.util.Iterator;
38
import java.util.Locale;
37
import java.util.Locale;
39
import java.util.Map;
38
import java.util.Map;
40
import java.util.Set;
41
import java.util.StringTokenizer;
39
import java.util.StringTokenizer;
42
import java.util.Vector;
40
import java.util.Vector;
43
41
Lines 170-177 Link Here
170
        "site command"
168
        "site command"
171
        };
169
        };
172
170
171
    /**
172
	 * internal class providing a File-like interface to some of the information
173
	 * available from the FTP server
174
	 * 
175
	 */
176
    protected class FTPFileProxy extends File {
173
177
174
    /**
178
    	private FTPFile m_file;
179
		private String[] m_parts;
180
		private String m_name;
181
182
		/**
183
		 * creates a proxy to a FTP file
184
		 * @param file
185
		 */
186
		public FTPFileProxy(FTPFile file) {
187
			super(file.getName());
188
			m_name = file.getName();
189
    		m_file = file;
190
			m_parts = FileUtils.getPathStack(m_file.getName());
191
		}
192
193
		/**
194
		 * creates a proxy to a FTP directory
195
		 * @param completePath the remote directory.
196
		 */
197
		public FTPFileProxy(String completePath) {
198
			super(completePath);
199
			m_file = null;
200
			m_name = completePath;
201
			m_parts = FileUtils.getPathStack(completePath);
202
		}
203
204
205
		/* (non-Javadoc)
206
		 * @see java.io.File#exists()
207
		 */
208
		public boolean exists() {
209
			return true;
210
		}
211
212
213
		/* (non-Javadoc)
214
		 * @see java.io.File#getAbsolutePath()
215
		 */
216
		public String getAbsolutePath() {
217
			return m_name;
218
		}
219
220
221
		/* (non-Javadoc)
222
		 * @see java.io.File#getName()
223
		 */
224
		public String getName() {
225
			return m_parts[m_parts.length-1];
226
		}
227
228
229
		/* (non-Javadoc)
230
		 * @see java.io.File#getParent()
231
		 */
232
		public String getParent() {
233
			String result = "";
234
			for(int i=0; i<m_parts.length-1; i++){
235
				result += File.separatorChar + m_parts[i];
236
			}
237
			return result;
238
		}
239
240
241
		/* (non-Javadoc)
242
		 * @see java.io.File#getPath()
243
		 */
244
		public String getPath() {
245
			return m_name;
246
		}
247
248
249
		/**
250
		 * FTP files are stored as absolute paths
251
		 * @return true
252
		 */
253
		public boolean isAbsolute() {
254
			return true;
255
		}
256
257
258
		/* (non-Javadoc)
259
		 * @see java.io.File#isDirectory()
260
		 */
261
		public boolean isDirectory() { 
262
			return m_file == null;
263
		}
264
265
266
		/* (non-Javadoc)
267
		 * @see java.io.File#isFile()
268
		 */
269
		public boolean isFile() {
270
			return m_file != null;
271
		}
272
273
274
		/**
275
		 * FTP files cannot be hidden
276
		 * 
277
		 * @return  false
278
		 */
279
		public boolean isHidden() {
280
			return false;
281
		}
282
283
284
		/* (non-Javadoc)
285
		 * @see java.io.File#lastModified()
286
		 */
287
		public long lastModified() {
288
			if (m_file != null)
289
				return m_file.getTimestamp().getTimeInMillis();
290
			return 0;
291
		}
292
293
294
		/* (non-Javadoc)
295
		 * @see java.io.File#length()
296
		 */
297
		public long length() {
298
			if(m_file != null)
299
				return m_file.getSize();
300
			return 0;
301
		}
302
303
304
		/**
305
		 * 
306
		 */
307
		private static final long serialVersionUID = 1L;
308
    	
309
    }
310
    
311
	/**
175
     * internal class allowing to read the contents of a remote file system
312
     * internal class allowing to read the contents of a remote file system
176
     * using the FTP protocol
313
     * using the FTP protocol
177
     * used in particular for ftp get operations
314
     * used in particular for ftp get operations
Lines 206-212 Link Here
206
343
207
        /**
344
        /**
208
         * scans the remote directory,
345
         * scans the remote directory,
209
         * storing internally the included files, directories, ...
346
         * storing internally the included files, directories, ... 
210
         */
347
         */
211
        public void scan() {
348
        public void scan() {
212
            if (includes == null) {
349
            if (includes == null) {
Lines 341-347 Link Here
341
            }
478
            }
342
        }
479
        }
343
        /**
480
        /**
344
         * scans a particular directory
481
         * scans a particular directory. populates the scannedDirs cache.
482
         * 
345
         * @param dir directory to scan
483
         * @param dir directory to scan
346
         * @param vpath  relative path to the base directory of the remote fileset
484
         * @param vpath  relative path to the base directory of the remote fileset
347
         * always ended with a File.separator
485
         * always ended with a File.separator
Lines 374-381 Link Here
374
                    if (file != null
512
                    if (file != null
375
                            && !file.getName().equals(".")
513
                            && !file.getName().equals(".")
376
                            && !file.getName().equals("..")) {
514
                            && !file.getName().equals("..")) {
515
                        String name = vpath + file.getName();
516
                        scannedDirs.put(name, new FTPFileProxy(file));
377
                        if (isFunctioningAsDirectory(ftp, dir, file)) {
517
                        if (isFunctioningAsDirectory(ftp, dir, file)) {
378
                            String name = vpath + file.getName();
379
                            boolean slowScanAllowed = true;
518
                            boolean slowScanAllowed = true;
380
                            if (!isFollowSymlinks() && file.isSymbolicLink()) {
519
                            if (!isFollowSymlinks() && file.isSymbolicLink()) {
381
                                dirsExcluded.addElement(name);
520
                                dirsExcluded.addElement(name);
Lines 395-401 Link Here
395
                                        name + File.separator, fast);
534
                                        name + File.separator, fast);
396
                            }
535
                            }
397
                        } else {
536
                        } else {
398
                            String name = vpath + file.getName();
399
                            if (!isFollowSymlinks() && file.isSymbolicLink()) {
537
                            if (!isFollowSymlinks() && file.isSymbolicLink()) {
400
                                filesExcluded.addElement(name);
538
                                filesExcluded.addElement(name);
401
                            } else if (isFunctioningAsFile(ftp, dir, file)) {
539
                            } else if (isFunctioningAsFile(ftp, dir, file)) {
Lines 419-425 Link Here
419
                && !filesExcluded.contains(name)) {
557
                && !filesExcluded.contains(name)) {
420
558
421
                if (isIncluded(name)) {
559
                if (isIncluded(name)) {
422
                    if (!isExcluded(name)) {
560
                    if (!isExcluded(name) && isSelected(name, (File)scannedDirs.get(name))) {
423
                        filesIncluded.addElement(name);
561
                        filesIncluded.addElement(name);
424
                    } else {
562
                    } else {
425
                        filesExcluded.addElement(name);
563
                        filesExcluded.addElement(name);
Lines 487-504 Link Here
487
         *
625
         *
488
         * @since Ant 1.6
626
         * @since Ant 1.6
489
         */
627
         */
490
        private Set scannedDirs = new HashSet();
491
628
629
    	private Map scannedDirs = new HashMap();
630
492
        /**
631
        /**
493
         * Has the directory with the given path relative to the base
632
         * Has the directory with the given path relative to the base
494
         * directory already been scanned?
633
         * directory already been scanned?
495
         *
634
         *
496
         * <p>Registers the given directory as scanned as a side effect.</p>
497
         *
498
         * @since Ant 1.6
635
         * @since Ant 1.6
499
         */
636
         */
500
        private boolean hasBeenScanned(String vpath) {
637
        private boolean hasBeenScanned(String vpath) {
501
            return !scannedDirs.add(vpath);
638
            return scannedDirs.containsKey(vpath);
502
        }
639
        }
503
640
504
        /**
641
        /**
Lines 1566-1576 Link Here
1566
        if (action == SEND_FILES) {
1703
        if (action == SEND_FILES) {
1567
            ds = fs.getDirectoryScanner(getProject());
1704
            ds = fs.getDirectoryScanner(getProject());
1568
        } else {
1705
        } else {
1569
            // warn that selectors are not supported
1570
            if (fs.getSelectors(getProject()).length != 0) {
1571
                getProject().log("selectors are not supported in remote filesets",
1572
                    Project.MSG_WARN);
1573
            }
1574
            ds = new FTPDirectoryScanner(ftp);
1706
            ds = new FTPDirectoryScanner(ftp);
1575
            fs.setupDirectoryScanner(ds, getProject());
1707
            fs.setupDirectoryScanner(ds, getProject());
1576
            ds.setFollowSymlinks(fs.isFollowSymlinks());
1708
            ds.setFollowSymlinks(fs.isFollowSymlinks());
Lines 1738-1744 Link Here
1738
            return;
1870
            return;
1739
        }
1871
        }
1740
1872
1741
1742
        Vector parents = new Vector();
1873
        Vector parents = new Vector();
1743
        String dirname;
1874
        String dirname;
1744
1875

Return to bug 44726