1 package org.apache.maven.wagon;
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 import java.util.LinkedList;
25
26 import org.apache.maven.wagon.authorization.AuthorizationException;
27 import org.codehaus.plexus.util.FileUtils;
28
29
30
31
32
33
34 public final class WagonUtils
35 {
36 private WagonUtils()
37 {
38 }
39
40 public static String toString( String resource, Wagon wagon )
41 throws IOException, TransferFailedException, ResourceDoesNotExistException, AuthorizationException
42 {
43
44 File file = null;
45
46 try
47 {
48 file = File.createTempFile( "wagon", "tmp" );
49
50 wagon.get( resource, file );
51
52 String retValue = FileUtils.fileRead( file );
53
54 return retValue;
55 }
56 finally
57 {
58 if ( file != null )
59 {
60 boolean deleted = file.delete();
61
62 if ( !deleted )
63 {
64 file.deleteOnExit();
65 }
66 }
67 }
68
69 }
70
71
72 public static void putDirectory( File dir, Wagon wagon, boolean includeBasdir )
73 throws ResourceDoesNotExistException, TransferFailedException, AuthorizationException
74 {
75
76 LinkedList queue = new LinkedList();
77
78 if ( includeBasdir )
79 {
80 queue.add( dir.getName() );
81 }
82 else
83 {
84 queue.add( "" );
85 }
86
87 while ( !queue.isEmpty() )
88 {
89 String path = (String) queue.removeFirst();
90
91 File currentDir = new File( dir, path );
92
93 File[] files = currentDir.listFiles();
94
95 for ( int i = 0; i < files.length; i++ )
96 {
97 File file = files[i];
98
99 String resource;
100
101 if ( path.length() > 0 )
102 {
103 resource = path + "/" + file.getName();
104 }
105 else
106 {
107 resource = file.getName();
108 }
109
110 if ( file.isDirectory() )
111 {
112 queue.add( resource );
113 }
114 else
115 {
116 wagon.put( file, resource );
117 }
118
119 }
120
121 }
122
123 }
124 }