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