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.io.IOException;
35 import java.util.List;
36
37 import org.apache.commons.io.FileUtils;
38 import org.apache.maven.plugin.logging.Log;
39 import org.apache.maven.wagon.TransferFailedException;
40 import org.apache.maven.wagon.Wagon;
41 import org.apache.maven.wagon.WagonException;
42 import org.codehaus.plexus.util.StringUtils;
43
44
45
46
47
48 public class DefaultWagonDownload implements WagonDownload {
49
50 @Override
51 public List<String> getFileList(Wagon wagon, WagonFileSet fileSet, Log logger) throws WagonException {
52 logger.info("Scanning repository - " + wagon.getRepository().getUrl());
53
54 WagonDirectoryScanner dirScan = new WagonDirectoryScanner();
55 dirScan.setLogger(logger);
56 dirScan.setWagon(wagon);
57 dirScan.setExcludes(fileSet.getExcludes());
58 dirScan.setIncludes(fileSet.getIncludes());
59 dirScan.setCaseSensitive(fileSet.isCaseSensitive());
60 dirScan.setDirectory(fileSet.getDirectory());
61 if (fileSet.isUseDefaultExcludes()) {
62 dirScan.addDefaultExcludes();
63 }
64
65 dirScan.scan();
66
67 return dirScan.getFilesIncluded();
68 }
69
70 @Override
71 public void download(Wagon wagon, WagonFileSet remoteFileSet, Log logger, boolean skipExisting)
72 throws WagonException {
73 List<String> fileList = getFileList(wagon, remoteFileSet, logger);
74
75 String url = wagon.getRepository().getUrl();
76 url = url.endsWith("/") ? url : url + "/";
77
78 if (fileList.size() == 0) {
79 logger.info("Nothing to download.");
80 return;
81 } else {
82 logger.info("Located " + fileList.size() + " files to download");
83 }
84
85 int count = 0;
86 for (String remoteFile : fileList) {
87 String index = StringUtils.leftPad((++count) + "", 5, " ");
88
89 File destination = new File(remoteFileSet.getDownloadDirectory() + "/" + remoteFile);
90
91 if (skipExisting && destination.exists()) {
92 logger.info(index + " Skipping " + url + remoteFile + " - " + destination + " already exists");
93 continue;
94 }
95
96 if (!StringUtils.isBlank(remoteFileSet.getDirectory())) {
97 remoteFile = remoteFileSet.getDirectory() + "/" + remoteFile;
98 }
99
100 logger.info(index + " Downloading " + url + remoteFile + " to " + destination);
101 try {
102 FileUtils.touch(destination);
103 } catch (IOException e) {
104 throw new TransferFailedException("Unexpected IO error", e);
105 }
106
107 wagon.get(remoteFile, destination);
108 }
109 }
110
111
112
113
114
115
116
117
118
119 @Override
120 public boolean exists(Wagon wagon, String resource) throws WagonException {
121 return wagon.resourceExists(resource);
122 }
123
124 }