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