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 114-121
Link Here
|
114 |
private long granularityMillis = 0L; |
112 |
private long granularityMillis = 0L; |
115 |
private boolean timeDiffAuto = false; |
113 |
private boolean timeDiffAuto = false; |
116 |
private int action = SEND_FILES; |
114 |
private int action = SEND_FILES; |
117 |
private Vector filesets = new Vector(); |
115 |
private Vector<FileSet> filesets = new Vector<FileSet>(); |
118 |
private Vector dirCache = new Vector(); |
116 |
private Vector<File> dirCache = new Vector<File>(); |
119 |
private int transferred = 0; |
117 |
private int transferred = 0; |
120 |
private String remoteFileSep = "/"; |
118 |
private String remoteFileSep = "/"; |
121 |
private int port = DEFAULT_FTP_PORT; |
119 |
private int port = DEFAULT_FTP_PORT; |
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 |
@Override |
209 |
public boolean exists() { |
210 |
return true; |
211 |
} |
212 |
|
213 |
|
214 |
/* (non-Javadoc) |
215 |
* @see java.io.File#getAbsolutePath() |
216 |
*/ |
217 |
@Override |
218 |
public String getAbsolutePath() { |
219 |
return m_name; |
220 |
} |
221 |
|
222 |
|
223 |
/* (non-Javadoc) |
224 |
* @see java.io.File#getName() |
225 |
*/ |
226 |
@Override |
227 |
public String getName() { |
228 |
return m_parts[m_parts.length-1]; |
229 |
} |
230 |
|
231 |
|
232 |
/* (non-Javadoc) |
233 |
* @see java.io.File#getParent() |
234 |
*/ |
235 |
@Override |
236 |
public String getParent() { |
237 |
String result = ""; |
238 |
for(int i=0; i<m_parts.length-1; i++){ |
239 |
result += File.separatorChar + m_parts[i]; |
240 |
} |
241 |
return result; |
242 |
} |
243 |
|
244 |
|
245 |
/* (non-Javadoc) |
246 |
* @see java.io.File#getPath() |
247 |
*/ |
248 |
@Override |
249 |
public String getPath() { |
250 |
return m_name; |
251 |
} |
252 |
|
253 |
|
254 |
/** |
255 |
* FTP files are stored as absolute paths |
256 |
* @return true |
257 |
*/ |
258 |
@Override |
259 |
public boolean isAbsolute() { |
260 |
return true; |
261 |
} |
262 |
|
263 |
|
264 |
/* (non-Javadoc) |
265 |
* @see java.io.File#isDirectory() |
266 |
*/ |
267 |
@Override |
268 |
public boolean isDirectory() { |
269 |
return m_file == null; |
270 |
} |
271 |
|
272 |
|
273 |
/* (non-Javadoc) |
274 |
* @see java.io.File#isFile() |
275 |
*/ |
276 |
@Override |
277 |
public boolean isFile() { |
278 |
return m_file != null; |
279 |
} |
280 |
|
281 |
|
282 |
/** |
283 |
* FTP files cannot be hidden |
284 |
* |
285 |
* @return false |
286 |
*/ |
287 |
@Override |
288 |
public boolean isHidden() { |
289 |
return false; |
290 |
} |
291 |
|
292 |
|
293 |
/* (non-Javadoc) |
294 |
* @see java.io.File#lastModified() |
295 |
*/ |
296 |
@Override |
297 |
public long lastModified() { |
298 |
if (m_file != null) |
299 |
return m_file.getTimestamp().getTimeInMillis(); |
300 |
return 0; |
301 |
} |
302 |
|
303 |
|
304 |
/* (non-Javadoc) |
305 |
* @see java.io.File#length() |
306 |
*/ |
307 |
@Override |
308 |
public long length() { |
309 |
if(m_file != null) |
310 |
return m_file.getSize(); |
311 |
return 0; |
312 |
} |
313 |
|
314 |
|
315 |
/** |
316 |
* |
317 |
*/ |
318 |
private static final long serialVersionUID = 1L; |
319 |
|
320 |
} |
321 |
|
322 |
/** |
175 |
* internal class allowing to read the contents of a remote file system |
323 |
* internal class allowing to read the contents of a remote file system |
176 |
* using the FTP protocol |
324 |
* using the FTP protocol |
177 |
* used in particular for ftp get operations |
325 |
* used in particular for ftp get operations |
Lines 207-212
Link Here
|
207 |
/** |
355 |
/** |
208 |
* scans the remote directory, |
356 |
* scans the remote directory, |
209 |
* storing internally the included files, directories, ... |
357 |
* storing internally the included files, directories, ... |
|
|
358 |
* |
359 |
* TODO: use the selectors! |
210 |
*/ |
360 |
*/ |
211 |
public void scan() { |
361 |
public void scan() { |
212 |
if (includes == null) { |
362 |
if (includes == null) { |
Lines 218-229
Link Here
|
218 |
excludes = new String[0]; |
368 |
excludes = new String[0]; |
219 |
} |
369 |
} |
220 |
|
370 |
|
221 |
filesIncluded = new Vector(); |
371 |
filesIncluded = new Vector<String>(); |
222 |
filesNotIncluded = new Vector(); |
372 |
filesNotIncluded = new Vector<String>(); |
223 |
filesExcluded = new Vector(); |
373 |
filesExcluded = new Vector<String>(); |
224 |
dirsIncluded = new Vector(); |
374 |
dirsIncluded = new Vector<String>(); |
225 |
dirsNotIncluded = new Vector(); |
375 |
dirsNotIncluded = new Vector<String>(); |
226 |
dirsExcluded = new Vector(); |
376 |
dirsExcluded = new Vector<String>(); |
227 |
|
377 |
|
228 |
try { |
378 |
try { |
229 |
String cwd = ftp.printWorkingDirectory(); |
379 |
String cwd = ftp.printWorkingDirectory(); |
Lines 246-252
Link Here
|
246 |
*/ |
396 |
*/ |
247 |
private void checkIncludePatterns() { |
397 |
private void checkIncludePatterns() { |
248 |
|
398 |
|
249 |
Hashtable newroots = new Hashtable(); |
399 |
// TODO: populate the scannedDirs cache |
|
|
400 |
|
401 |
Hashtable<String,String> newroots = new Hashtable<String,String>(); |
250 |
// put in the newroots vector the include patterns without |
402 |
// put in the newroots vector the include patterns without |
251 |
// wildcard tokens |
403 |
// wildcard tokens |
252 |
for (int icounter = 0; icounter < includes.length; icounter++) { |
404 |
for (int icounter = 0; icounter < includes.length; icounter++) { |
Lines 271-277
Link Here
|
271 |
} else { |
423 |
} else { |
272 |
// only scan directories that can include matched files or |
424 |
// only scan directories that can include matched files or |
273 |
// directories |
425 |
// directories |
274 |
Enumeration enum2 = newroots.keys(); |
426 |
Enumeration<String> enum2 = newroots.keys(); |
275 |
|
427 |
|
276 |
while (enum2.hasMoreElements()) { |
428 |
while (enum2.hasMoreElements()) { |
277 |
String currentelement = (String) enum2.nextElement(); |
429 |
String currentelement = (String) enum2.nextElement(); |
Lines 341-347
Link Here
|
341 |
} |
493 |
} |
342 |
} |
494 |
} |
343 |
/** |
495 |
/** |
344 |
* scans a particular directory |
496 |
* scans a particular directory. populates the scannedDirs cache. |
|
|
497 |
* |
345 |
* @param dir directory to scan |
498 |
* @param dir directory to scan |
346 |
* @param vpath relative path to the base directory of the remote fileset |
499 |
* @param vpath relative path to the base directory of the remote fileset |
347 |
* always ended with a File.separator |
500 |
* always ended with a File.separator |
Lines 363-368
Link Here
|
363 |
} else { |
516 |
} else { |
364 |
completePath = rootPath; |
517 |
completePath = rootPath; |
365 |
} |
518 |
} |
|
|
519 |
scannedDirs.put(completePath, new FTPFileProxy(completePath)); |
366 |
FTPFile[] newfiles = listFiles(completePath, false); |
520 |
FTPFile[] newfiles = listFiles(completePath, false); |
367 |
|
521 |
|
368 |
if (newfiles == null) { |
522 |
if (newfiles == null) { |
Lines 374-381
Link Here
|
374 |
if (file != null |
528 |
if (file != null |
375 |
&& !file.getName().equals(".") |
529 |
&& !file.getName().equals(".") |
376 |
&& !file.getName().equals("..")) { |
530 |
&& !file.getName().equals("..")) { |
|
|
531 |
String name = vpath + file.getName(); |
532 |
scannedDirs.put(name, new FTPFileProxy(file)); |
377 |
if (isFunctioningAsDirectory(ftp, dir, file)) { |
533 |
if (isFunctioningAsDirectory(ftp, dir, file)) { |
378 |
String name = vpath + file.getName(); |
|
|
379 |
boolean slowScanAllowed = true; |
534 |
boolean slowScanAllowed = true; |
380 |
if (!isFollowSymlinks() && file.isSymbolicLink()) { |
535 |
if (!isFollowSymlinks() && file.isSymbolicLink()) { |
381 |
dirsExcluded.addElement(name); |
536 |
dirsExcluded.addElement(name); |
Lines 395-401
Link Here
|
395 |
name + File.separator, fast); |
550 |
name + File.separator, fast); |
396 |
} |
551 |
} |
397 |
} else { |
552 |
} else { |
398 |
String name = vpath + file.getName(); |
|
|
399 |
if (!isFollowSymlinks() && file.isSymbolicLink()) { |
553 |
if (!isFollowSymlinks() && file.isSymbolicLink()) { |
400 |
filesExcluded.addElement(name); |
554 |
filesExcluded.addElement(name); |
401 |
} else if (isFunctioningAsFile(ftp, dir, file)) { |
555 |
} else if (isFunctioningAsFile(ftp, dir, file)) { |
Lines 419-425
Link Here
|
419 |
&& !filesExcluded.contains(name)) { |
573 |
&& !filesExcluded.contains(name)) { |
420 |
|
574 |
|
421 |
if (isIncluded(name)) { |
575 |
if (isIncluded(name)) { |
422 |
if (!isExcluded(name)) { |
576 |
if (!isExcluded(name) && isSelected(name, scannedDirs.get(name))) { |
423 |
filesIncluded.addElement(name); |
577 |
filesIncluded.addElement(name); |
424 |
} else { |
578 |
} else { |
425 |
filesExcluded.addElement(name); |
579 |
filesExcluded.addElement(name); |
Lines 481-504
Link Here
|
481 |
* |
635 |
* |
482 |
* @since Ant 1.6 |
636 |
* @since Ant 1.6 |
483 |
*/ |
637 |
*/ |
484 |
private Map fileListMap = new HashMap(); |
638 |
private Map<String, FTPFile[]> fileListMap = new HashMap<String, FTPFile[]>(); |
485 |
/** |
639 |
/** |
486 |
* List of all scanned directories. |
640 |
* List of all scanned directories. |
487 |
* |
641 |
* |
488 |
* @since Ant 1.6 |
642 |
* @since Ant 1.6 |
489 |
*/ |
643 |
*/ |
490 |
private Set scannedDirs = new HashSet(); |
|
|
491 |
|
644 |
|
|
|
645 |
private Map<String, FTPFileProxy> scannedDirs = new HashMap<String, FTPFileProxy>(); |
646 |
|
492 |
/** |
647 |
/** |
493 |
* Has the directory with the given path relative to the base |
648 |
* Has the directory with the given path relative to the base |
494 |
* directory already been scanned? |
649 |
* directory already been scanned? |
495 |
* |
650 |
* |
496 |
* <p>Registers the given directory as scanned as a side effect.</p> |
|
|
497 |
* |
498 |
* @since Ant 1.6 |
651 |
* @since Ant 1.6 |
499 |
*/ |
652 |
*/ |
500 |
private boolean hasBeenScanned(String vpath) { |
653 |
private boolean hasBeenScanned(String vpath) { |
501 |
return !scannedDirs.add(vpath); |
654 |
return scannedDirs.containsKey(vpath); |
502 |
} |
655 |
} |
503 |
|
656 |
|
504 |
/** |
657 |
/** |
Lines 668-674
Link Here
|
668 |
public AntFTPFile(AntFTPFile parent, String path) { |
821 |
public AntFTPFile(AntFTPFile parent, String path) { |
669 |
this.parent = parent; |
822 |
this.parent = parent; |
670 |
this.client = parent.client; |
823 |
this.client = parent.client; |
671 |
Vector pathElements = SelectorUtils.tokenizePath(path); |
824 |
Vector<String> pathElements = SelectorUtils.tokenizePath(path); |
672 |
try { |
825 |
try { |
673 |
boolean result = this.client.changeWorkingDirectory(parent.getAbsolutePath()); |
826 |
boolean result = this.client.changeWorkingDirectory(parent.getAbsolutePath()); |
674 |
//this should not happen, except if parent has been deleted by another process |
827 |
//this should not happen, except if parent has been deleted by another process |
Lines 803-810
Link Here
|
803 |
* @return relative path |
956 |
* @return relative path |
804 |
*/ |
957 |
*/ |
805 |
private String getRelativePath(String currentPath, String currentRelativePath) { |
958 |
private String getRelativePath(String currentPath, String currentRelativePath) { |
806 |
Vector pathElements = SelectorUtils.tokenizePath(getAbsolutePath(), remoteFileSep); |
959 |
Vector<String> pathElements = SelectorUtils.tokenizePath(getAbsolutePath(), remoteFileSep); |
807 |
Vector pathElements2 = SelectorUtils.tokenizePath(currentPath, remoteFileSep); |
960 |
Vector<String> pathElements2 = SelectorUtils.tokenizePath(currentPath, remoteFileSep); |
808 |
String relPath = currentRelativePath; |
961 |
String relPath = currentRelativePath; |
809 |
for (int pcount = pathElements2.size(); pcount < pathElements.size(); pcount++) { |
962 |
for (int pcount = pathElements2.size(); pcount < pathElements.size(); pcount++) { |
810 |
String currentElement = (String) pathElements.elementAt(pcount); |
963 |
String currentElement = (String) pathElements.elementAt(pcount); |
Lines 1739-1745
Link Here
|
1739 |
} |
1892 |
} |
1740 |
|
1893 |
|
1741 |
|
1894 |
|
1742 |
Vector parents = new Vector(); |
1895 |
Vector<File> parents = new Vector<File>(); |
1743 |
String dirname; |
1896 |
String dirname; |
1744 |
|
1897 |
|
1745 |
while ((dirname = dir.getParent()) != null) { |
1898 |
while ((dirname = dir.getParent()) != null) { |
Lines 2541-2552
Link Here
|
2541 |
getValidLanguageCodes(); |
2694 |
getValidLanguageCodes(); |
2542 |
|
2695 |
|
2543 |
private static String[] getValidLanguageCodes() { |
2696 |
private static String[] getValidLanguageCodes() { |
2544 |
Collection c = FTPClientConfig.getSupportedLanguageCodes(); |
2697 |
Collection<String> c = FTPClientConfig.getSupportedLanguageCodes(); |
2545 |
String[] ret = new String[c.size() + 1]; |
2698 |
String[] ret = new String[c.size() + 1]; |
2546 |
int i = 0; |
2699 |
int i = 0; |
2547 |
ret[i++] = ""; |
2700 |
ret[i++] = ""; |
2548 |
for (Iterator it = c.iterator(); it.hasNext(); i++) { |
2701 |
for (Iterator<String> it = c.iterator(); it.hasNext(); i++) { |
2549 |
ret[i] = (String) it.next(); |
2702 |
ret[i] = it.next(); |
2550 |
} |
2703 |
} |
2551 |
return ret; |
2704 |
return ret; |
2552 |
} |
2705 |
} |