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