View Javadoc

1   /**
2    * Copyright 2008-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.mojo.wagon.shared;
17  
18  /*
19   * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
20   * agreements. See the NOTICE file distributed with this work for additional information regarding
21   * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
22   * "License"); you may not use this file except in compliance with the License. You may obtain a
23   * copy of the License at
24   *
25   * http://www.apache.org/licenses/LICENSE-2.0
26   *
27   * Unless required by applicable law or agreed to in writing, software distributed under the License
28   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29   * or implied. See the License for the specific language governing permissions and limitations under
30   * the License.
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   * @plexus.component role="org.codehaus.mojo.wagon.shared.WagonDownload" role-hint="default"
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       * @param wagon
97       *            - a Wagon instance
98       * @param resource
99       *            - Remote resource to check
100      * @throws WagonException
101      */
102     @Override
103     public boolean exists(Wagon wagon, String resource) throws WagonException {
104         return wagon.resourceExists(resource);
105     }
106 
107 }