1 package org.codehaus.mojo.wagon.shared;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }