1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.mojo.wagon.shared;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 import java.io.File;
34 import java.util.Iterator;
35 import java.util.List;
36
37 import org.apache.maven.plugin.logging.Log;
38 import org.apache.maven.wagon.Wagon;
39 import org.apache.maven.wagon.WagonException;
40 import org.codehaus.plexus.util.StringUtils;
41
42
43
44
45
46 public class DefaultWagonDownload implements WagonDownload {
47
48 @Override
49 public List<?> getFileList(Wagon wagon, WagonFileSet fileSet, Log logger) throws WagonException {
50 logger.info("Scanning remote file system: " + wagon.getRepository().getUrl() + " ...");
51
52 WagonDirectoryScanner dirScan = new WagonDirectoryScanner();
53 dirScan.setLogger(logger);
54 dirScan.setWagon(wagon);
55 dirScan.setExcludes(fileSet.getExcludes());
56 dirScan.setIncludes(fileSet.getIncludes());
57 dirScan.setCaseSensitive(fileSet.isCaseSensitive());
58 dirScan.setDirectory(fileSet.getDirectory());
59 if (fileSet.isUseDefaultExcludes()) {
60 dirScan.addDefaultExcludes();
61 }
62
63 dirScan.scan();
64
65 return dirScan.getFilesIncluded();
66 }
67
68 @Override
69 public void download(Wagon wagon, WagonFileSet remoteFileSet, Log logger) throws WagonException {
70 List<?> fileList = this.getFileList(wagon, remoteFileSet, logger);
71
72 String url = wagon.getRepository().getUrl() + "/";
73
74 if (fileList.size() == 0) {
75 logger.info("Nothing to download.");
76 return;
77 }
78
79 for (Iterator<?> iterator = fileList.iterator(); iterator.hasNext();) {
80 String remoteFile = (String) iterator.next();
81
82 File destination = new File(remoteFileSet.getDownloadDirectory() + "/" + remoteFile);
83
84 if (!StringUtils.isBlank(remoteFileSet.getDirectory())) {
85 remoteFile = remoteFileSet.getDirectory() + "/" + remoteFile;
86 }
87
88 logger.info("Downloading " + url + remoteFile + " to " + destination + " ...");
89
90 wagon.get(remoteFile, destination);
91 }
92 }
93
94
95
96
97
98
99
100
101
102 @Override
103 public boolean exists(Wagon wagon, String resource) throws WagonException {
104 return wagon.resourceExists(resource);
105 }
106
107 }