1 | |
package org.apache.maven.wagon.providers.ssh.external; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.ByteArrayInputStream; |
23 | |
import java.io.ByteArrayOutputStream; |
24 | |
import java.io.File; |
25 | |
import java.io.FileOutputStream; |
26 | |
import java.io.IOException; |
27 | |
import java.io.InputStream; |
28 | |
import java.io.OutputStream; |
29 | |
import java.util.Properties; |
30 | |
|
31 | |
import org.apache.maven.wagon.AbstractWagon; |
32 | |
import org.apache.maven.wagon.ConnectionException; |
33 | |
import org.apache.maven.wagon.InputData; |
34 | |
import org.apache.maven.wagon.OutputData; |
35 | |
import org.apache.maven.wagon.ResourceDoesNotExistException; |
36 | |
import org.apache.maven.wagon.TransferFailedException; |
37 | |
import org.apache.maven.wagon.authentication.AuthenticationException; |
38 | |
import org.apache.maven.wagon.authorization.AuthorizationException; |
39 | |
import org.apache.maven.wagon.resource.Resource; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class ScpExternalWagon |
48 | |
extends AbstractWagon |
49 | |
{ |
50 | |
public void get( String resourceName, File destination ) |
51 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
52 | |
{ |
53 | 0 | InputData inputData = new InputData(); |
54 | |
|
55 | 0 | Resource resource = new Resource( resourceName ); |
56 | |
|
57 | 0 | fireGetInitiated( resource, destination ); |
58 | |
|
59 | 0 | inputData.setResource( resource ); |
60 | |
|
61 | 0 | fillInputData( inputData ); |
62 | |
|
63 | 0 | InputStream is = inputData.getInputStream(); |
64 | |
|
65 | 0 | if ( is == null ) |
66 | |
{ |
67 | 0 | throw new TransferFailedException( getRepository().getUrl() |
68 | |
+ " - Could not open input stream for resource: '" + resource + "'" ); |
69 | |
} |
70 | |
|
71 | 0 | createParentDirectories( destination ); |
72 | |
|
73 | 0 | getTransfer( inputData.getResource(), destination, is ); |
74 | 0 | } |
75 | |
|
76 | |
public boolean getIfNewer( String resourceName, File destination, long timestamp ) |
77 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
78 | |
{ |
79 | 0 | return false; |
80 | |
} |
81 | |
|
82 | |
public void put( File source, String resourceName ) |
83 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
84 | |
{ |
85 | 0 | OutputData outputData = new OutputData(); |
86 | |
|
87 | 0 | Resource resource = new Resource( resourceName ); |
88 | |
|
89 | 0 | firePutInitiated( resource, source ); |
90 | |
|
91 | 0 | outputData.setResource( resource ); |
92 | |
|
93 | 0 | writeTestProperties( source.getParentFile() ); |
94 | |
|
95 | 0 | fillOutputData( outputData ); |
96 | |
|
97 | 0 | OutputStream os = outputData.getOutputStream(); |
98 | |
|
99 | 0 | if ( os == null ) |
100 | |
{ |
101 | 0 | throw new TransferFailedException( getRepository().getUrl() |
102 | |
+ " - Could not open output stream for resource: '" + resource + "'" ); |
103 | |
} |
104 | |
|
105 | 0 | putTransfer( outputData.getResource(), source, os, true ); |
106 | 0 | } |
107 | |
|
108 | |
public void closeConnection() |
109 | |
throws ConnectionException |
110 | |
{ |
111 | 0 | } |
112 | |
|
113 | |
public void fillInputData( InputData inputData ) |
114 | |
throws TransferFailedException, ResourceDoesNotExistException |
115 | |
{ |
116 | |
try |
117 | |
{ |
118 | 0 | inputData.setInputStream( new ByteArrayInputStream( "<metadata />".getBytes( "UTF-8" ) ) ); |
119 | |
} |
120 | 0 | catch ( IOException e ) |
121 | |
{ |
122 | 0 | throw new TransferFailedException( "Broken JVM", e ); |
123 | 0 | } |
124 | 0 | } |
125 | |
|
126 | |
public void writeTestProperties( File dir ) |
127 | |
throws TransferFailedException |
128 | |
{ |
129 | 0 | Properties props = new Properties(); |
130 | 0 | if ( getRepository().getPermissions() != null ) |
131 | |
{ |
132 | 0 | String dirPerms = getRepository().getPermissions().getDirectoryMode(); |
133 | |
|
134 | 0 | if ( dirPerms != null ) |
135 | |
{ |
136 | 0 | props.setProperty( "directory.mode", dirPerms ); |
137 | |
} |
138 | |
|
139 | 0 | String filePerms = getRepository().getPermissions().getFileMode(); |
140 | 0 | if ( filePerms != null ) |
141 | |
{ |
142 | 0 | props.setProperty( "file.mode", filePerms ); |
143 | |
} |
144 | |
} |
145 | |
|
146 | |
try |
147 | |
{ |
148 | 0 | OutputStream os = new FileOutputStream( new File( dir, "wagon.properties" ) ); |
149 | |
try |
150 | |
{ |
151 | 0 | props.store( os, "MAVEN-CORE-IT-WAGON" ); |
152 | |
} |
153 | |
finally |
154 | |
{ |
155 | 0 | os.close(); |
156 | 0 | } |
157 | |
} |
158 | 0 | catch ( IOException e ) |
159 | |
{ |
160 | 0 | throw new TransferFailedException( e.getMessage(), e ); |
161 | 0 | } |
162 | 0 | } |
163 | |
|
164 | |
public void fillOutputData( OutputData outputData ) |
165 | |
throws TransferFailedException |
166 | |
{ |
167 | 0 | outputData.setOutputStream( new ByteArrayOutputStream() ); |
168 | 0 | } |
169 | |
|
170 | |
public void openConnection() |
171 | |
throws ConnectionException, AuthenticationException |
172 | |
{ |
173 | 0 | } |
174 | |
} |