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