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.io.IOException;
24  
25  import org.apache.maven.plugin.logging.Log;
26  import org.apache.maven.shared.model.fileset.FileSet;
27  import org.apache.maven.wagon.Wagon;
28  import org.apache.maven.wagon.WagonException;
29  import org.codehaus.plexus.component.annotations.Component;
30  import org.codehaus.plexus.component.annotations.Requirement;
31  import org.codehaus.plexus.util.FileUtils;
32  
33  /**
34   * Copy a set of file from a wagon repo to another wagon repo.
35   */
36  @Component(role = WagonCopy.class, hint = "default")
37  public class DefaultWagonCopy
38      implements WagonCopy
39  {
40      @Requirement
41      private WagonDownload downloader;
42  
43      @Requirement
44      private WagonUpload uploader;
45  
46      @Override
47      public void copy( Wagon src, WagonFileSet wagonFileSet, Wagon target, boolean optimize, Log logger )
48          throws WagonException, IOException
49      {
50          if ( wagonFileSet == null )
51          {
52              wagonFileSet = new WagonFileSet();
53          }
54  
55          boolean removeDownloadDir = false;
56  
57          if ( wagonFileSet.getDownloadDirectory() == null )
58          {
59              File downloadSrcDir = File.createTempFile( "wagon", "wagon" );
60              downloadSrcDir.delete();
61              wagonFileSet.setDownloadDirectory( downloadSrcDir );
62              removeDownloadDir = true;
63          }
64  
65          try
66          {
67              this.downloader.download( src, wagonFileSet, logger );
68  
69              FileSet localFileSet = new FileSet();
70              localFileSet.setDirectory( wagonFileSet.getDownloadDirectory().getAbsolutePath() );
71              localFileSet.setOutputDirectory( wagonFileSet.getOutputDirectory() );
72  
73              this.uploader.upload( target, localFileSet, optimize, logger );
74          }
75          finally
76          {
77              if ( removeDownloadDir )
78              {
79                  FileUtils.deleteDirectory( wagonFileSet.getDownloadDirectory() );
80              }
81          }
82  
83      }
84  }