View Javadoc

1   package org.codehaus.mojo.wagon.shared;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  import java.io.File;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.apache.maven.plugin.logging.Log;
23  import org.apache.maven.wagon.Wagon;
24  import org.apache.maven.wagon.WagonException;
25  import org.codehaus.plexus.util.StringUtils;
26  
27  /**
28   * @plexus.component role="org.codehaus.mojo.wagon.shared.WagonDownload" role-hint="default"
29   */
30  
31  public class DefaultWagonDownload implements WagonDownload {
32  
33      @Override
34      public List<?> getFileList(Wagon wagon, WagonFileSet fileSet, Log logger) throws WagonException {
35          logger.info("Scanning remote file system: " + wagon.getRepository().getUrl() + " ...");
36  
37          WagonDirectoryScanner dirScan = new WagonDirectoryScanner();
38          dirScan.setLogger(logger);
39          dirScan.setWagon(wagon);
40          dirScan.setExcludes(fileSet.getExcludes());
41          dirScan.setIncludes(fileSet.getIncludes());
42          dirScan.setCaseSensitive(fileSet.isCaseSensitive());
43          dirScan.setDirectory(fileSet.getDirectory());
44          if (fileSet.isUseDefaultExcludes()) {
45              dirScan.addDefaultExcludes();
46          }
47  
48          dirScan.scan();
49  
50          return dirScan.getFilesIncluded();
51      }
52  
53      @Override
54      public void download(Wagon wagon, WagonFileSet remoteFileSet, Log logger) throws WagonException {
55          List<?> fileList = this.getFileList(wagon, remoteFileSet, logger);
56  
57          String url = wagon.getRepository().getUrl() + "/";
58  
59          if (fileList.size() == 0) {
60              logger.info("Nothing to download.");
61              return;
62          }
63  
64          for (Iterator<?> iterator = fileList.iterator(); iterator.hasNext();) {
65              String remoteFile = (String) iterator.next();
66  
67              File destination = new File(remoteFileSet.getDownloadDirectory() + "/" + remoteFile);
68  
69              if (!StringUtils.isBlank(remoteFileSet.getDirectory())) {
70                  remoteFile = remoteFileSet.getDirectory() + "/" + remoteFile;
71              }
72  
73              logger.info("Downloading " + url + remoteFile + " to " + destination + " ...");
74  
75              wagon.get(remoteFile, destination);
76          }
77      }
78  
79      /**
80       *
81       * @param wagon
82       *            - a Wagon instance
83       * @param resource
84       *            - Remote resource to check
85       * @throws WagonException
86       */
87      @Override
88      public boolean exists(Wagon wagon, String resource) throws WagonException {
89          return wagon.resourceExists(resource);
90      }
91  
92  }