1 | |
package org.apache.maven.wagon.providers.coreit; |
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 | 0 | public class CoreItHttpWagon |
47 | |
extends AbstractWagon |
48 | |
{ |
49 | |
public void get( String resourceName, File destination ) |
50 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
51 | |
{ |
52 | 0 | InputData inputData = new InputData(); |
53 | |
|
54 | 0 | Resource resource = new Resource( resourceName ); |
55 | |
|
56 | 0 | fireGetInitiated( resource, destination ); |
57 | |
|
58 | 0 | inputData.setResource( resource ); |
59 | |
|
60 | 0 | fillInputData( inputData ); |
61 | |
|
62 | 0 | InputStream is = inputData.getInputStream(); |
63 | |
|
64 | 0 | if ( is == null ) |
65 | |
{ |
66 | 0 | throw new TransferFailedException( getRepository().getUrl() |
67 | |
+ " - Could not open input stream for resource: '" + resource + "'" ); |
68 | |
} |
69 | |
|
70 | 0 | createParentDirectories( destination ); |
71 | |
|
72 | 0 | getTransfer( inputData.getResource(), destination, is ); |
73 | 0 | } |
74 | |
|
75 | |
public boolean getIfNewer( String resourceName, File destination, long timestamp ) |
76 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
77 | |
{ |
78 | 0 | return false; |
79 | |
} |
80 | |
|
81 | |
public void put( File source, String resourceName ) |
82 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
83 | |
{ |
84 | 0 | OutputData outputData = new OutputData(); |
85 | |
|
86 | 0 | Resource resource = new Resource( resourceName ); |
87 | |
|
88 | 0 | firePutInitiated( resource, source ); |
89 | |
|
90 | 0 | outputData.setResource( resource ); |
91 | |
|
92 | 0 | fillOutputData( outputData ); |
93 | |
|
94 | 0 | OutputStream os = outputData.getOutputStream(); |
95 | |
|
96 | 0 | if ( os == null ) |
97 | |
{ |
98 | 0 | throw new TransferFailedException( getRepository().getUrl() |
99 | |
+ " - Could not open output stream for resource: '" + resource + "'" ); |
100 | |
} |
101 | |
|
102 | 0 | putTransfer( outputData.getResource(), source, os, true ); |
103 | 0 | } |
104 | |
|
105 | |
public void closeConnection() |
106 | |
throws ConnectionException |
107 | |
{ |
108 | 0 | File f = new File( "target/wagon-data" ); |
109 | |
try |
110 | |
{ |
111 | 0 | f.getParentFile().mkdirs(); |
112 | 0 | f.createNewFile(); |
113 | |
} |
114 | 0 | catch ( IOException e ) |
115 | |
{ |
116 | 0 | throw new ConnectionException( e.getMessage(), e ); |
117 | 0 | } |
118 | 0 | } |
119 | |
|
120 | |
public void fillInputData( InputData inputData ) |
121 | |
throws TransferFailedException, ResourceDoesNotExistException |
122 | |
{ |
123 | |
try |
124 | |
{ |
125 | 0 | inputData.setInputStream( new ByteArrayInputStream( "<metadata />".getBytes( "UTF-8" ) ) ); |
126 | |
} |
127 | 0 | catch ( IOException e ) |
128 | |
{ |
129 | 0 | throw new TransferFailedException( "Broken JVM", e ); |
130 | 0 | } |
131 | 0 | } |
132 | |
|
133 | |
public void fillOutputData( OutputData outputData ) |
134 | |
throws TransferFailedException |
135 | |
{ |
136 | 0 | Properties props = new Properties(); |
137 | 0 | if ( getRepository().getPermissions() != null ) |
138 | |
{ |
139 | 0 | String dirPerms = getRepository().getPermissions().getDirectoryMode(); |
140 | |
|
141 | 0 | if ( dirPerms != null ) |
142 | |
{ |
143 | 0 | props.setProperty( "directory.mode", dirPerms ); |
144 | |
} |
145 | |
|
146 | 0 | String filePerms = getRepository().getPermissions().getFileMode(); |
147 | 0 | if ( filePerms != null ) |
148 | |
{ |
149 | 0 | props.setProperty( "file.mode", filePerms ); |
150 | |
} |
151 | |
} |
152 | |
|
153 | |
try |
154 | |
{ |
155 | 0 | new File( "target" ).mkdirs(); |
156 | |
|
157 | 0 | OutputStream os = new FileOutputStream( "target/wagon.properties" ); |
158 | |
try |
159 | |
{ |
160 | 0 | props.store( os, "MAVEN-CORE-IT-WAGON" ); |
161 | |
} |
162 | |
finally |
163 | |
{ |
164 | 0 | os.close(); |
165 | 0 | } |
166 | |
} |
167 | 0 | catch ( IOException e ) |
168 | |
{ |
169 | 0 | throw new TransferFailedException( e.getMessage(), e ); |
170 | 0 | } |
171 | |
|
172 | 0 | outputData.setOutputStream( new ByteArrayOutputStream() ); |
173 | 0 | } |
174 | |
|
175 | |
public void openConnection() |
176 | |
throws ConnectionException, AuthenticationException |
177 | |
{ |
178 | |
|
179 | |
|
180 | 0 | } |
181 | |
} |