1 | |
package org.apache.maven.plugins.site.wagon.repository; |
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.plugins.site.wagon.PathUtils; |
23 | |
import org.apache.maven.wagon.WagonConstants; |
24 | |
import org.apache.maven.wagon.repository.RepositoryPermissions; |
25 | |
import org.codehaus.plexus.util.StringUtils; |
26 | |
|
27 | |
import java.util.Properties; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class Repository |
41 | |
extends org.apache.maven.wagon.repository.Repository |
42 | |
{ |
43 | |
private static final long serialVersionUID = 1312227676322136247L; |
44 | |
|
45 | |
private String id; |
46 | |
|
47 | |
private String name; |
48 | |
|
49 | |
private String host; |
50 | |
|
51 | 0 | private int port = WagonConstants.UNKNOWN_PORT; |
52 | |
|
53 | |
private String basedir; |
54 | |
|
55 | |
private String protocol; |
56 | |
|
57 | |
private String url; |
58 | |
|
59 | |
private RepositoryPermissions permissions; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | 0 | private Properties parameters = new Properties(); |
66 | |
|
67 | |
|
68 | 0 | private String username = null; |
69 | |
|
70 | 0 | private String password = null; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public Repository() |
76 | 0 | { |
77 | |
|
78 | 0 | } |
79 | |
|
80 | |
public Repository( String id, String url ) |
81 | 0 | { |
82 | 0 | if ( id == null ) |
83 | |
{ |
84 | 0 | throw new NullPointerException( "id can not be null" ); |
85 | |
} |
86 | |
|
87 | 0 | setId( id ); |
88 | |
|
89 | 0 | if ( url == null ) |
90 | |
{ |
91 | 0 | throw new NullPointerException( "url can not be null" ); |
92 | |
} |
93 | |
|
94 | 0 | setUrl( url ); |
95 | 0 | } |
96 | |
|
97 | |
public String getId() |
98 | |
{ |
99 | 0 | return id; |
100 | |
} |
101 | |
|
102 | |
public void setId( String id ) |
103 | |
{ |
104 | 0 | this.id = id; |
105 | 0 | } |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public String getBasedir() |
114 | |
{ |
115 | 0 | return basedir; |
116 | |
} |
117 | |
|
118 | |
public void setBasedir( String basedir ) |
119 | |
{ |
120 | 0 | this.basedir = basedir; |
121 | 0 | } |
122 | |
|
123 | |
public void setName( String name ) |
124 | |
{ |
125 | 0 | this.name = name; |
126 | 0 | } |
127 | |
|
128 | |
public int getPort() |
129 | |
{ |
130 | 0 | return port; |
131 | |
} |
132 | |
|
133 | |
public void setPort( int port ) |
134 | |
{ |
135 | 0 | this.port = port; |
136 | 0 | } |
137 | |
|
138 | |
public void setUrl( String url ) |
139 | |
{ |
140 | 0 | this.url = url; |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | 0 | this.protocol = PathUtils.protocol( url ); |
147 | |
|
148 | 0 | this.host = PathUtils.host( url ); |
149 | |
|
150 | 0 | this.port = PathUtils.port( url ); |
151 | |
|
152 | 0 | this.basedir = PathUtils.basedir( url ); |
153 | |
|
154 | 0 | String username = PathUtils.user( url ); |
155 | 0 | this.username = username; |
156 | |
|
157 | 0 | if ( username != null ) |
158 | |
{ |
159 | 0 | String password = PathUtils.password( url ); |
160 | |
|
161 | 0 | if ( password != null ) |
162 | |
{ |
163 | 0 | this.password = password; |
164 | |
|
165 | 0 | username += ":" + password; |
166 | |
} |
167 | |
|
168 | 0 | username += "@"; |
169 | |
|
170 | 0 | int index = url.indexOf( username ); |
171 | 0 | this.url = url.substring( 0, index ) + url.substring( index + username.length() ); |
172 | |
} |
173 | 0 | } |
174 | |
|
175 | |
public String getUrl() |
176 | |
{ |
177 | 0 | if ( url != null ) |
178 | |
{ |
179 | 0 | return url; |
180 | |
} |
181 | |
|
182 | 0 | StringBuffer sb = new StringBuffer(); |
183 | |
|
184 | 0 | sb.append( protocol ); |
185 | |
|
186 | 0 | sb.append( "://" ); |
187 | |
|
188 | 0 | sb.append( host ); |
189 | |
|
190 | 0 | if ( port != WagonConstants.UNKNOWN_PORT ) |
191 | |
{ |
192 | 0 | sb.append( ":" ); |
193 | |
|
194 | 0 | sb.append( port ); |
195 | |
} |
196 | |
|
197 | 0 | sb.append( basedir ); |
198 | |
|
199 | 0 | return sb.toString(); |
200 | |
} |
201 | |
|
202 | |
public String getHost() |
203 | |
{ |
204 | 0 | if ( host == null ) |
205 | |
{ |
206 | 0 | return "localhost"; |
207 | |
} |
208 | 0 | return host; |
209 | |
} |
210 | |
|
211 | |
public String getName() |
212 | |
{ |
213 | 0 | if ( name == null ) |
214 | |
{ |
215 | 0 | return getId(); |
216 | |
} |
217 | 0 | return name; |
218 | |
} |
219 | |
|
220 | |
public String toString() |
221 | |
{ |
222 | 0 | StringBuffer sb = new StringBuffer(); |
223 | |
|
224 | 0 | sb.append( "Repository[" ); |
225 | |
|
226 | 0 | if ( StringUtils.isNotEmpty( getName() ) ) |
227 | |
{ |
228 | 0 | sb.append( getName() ).append( "|" ); |
229 | |
} |
230 | |
|
231 | 0 | sb.append( getUrl() ); |
232 | 0 | sb.append( "]" ); |
233 | |
|
234 | 0 | return sb.toString(); |
235 | |
} |
236 | |
|
237 | |
public String getProtocol() |
238 | |
{ |
239 | 0 | return protocol; |
240 | |
} |
241 | |
|
242 | |
public RepositoryPermissions getPermissions() |
243 | |
{ |
244 | 0 | return permissions; |
245 | |
} |
246 | |
|
247 | |
public void setPermissions( RepositoryPermissions permissions ) |
248 | |
{ |
249 | 0 | this.permissions = permissions; |
250 | 0 | } |
251 | |
|
252 | |
public String getParameter( String key ) |
253 | |
{ |
254 | 0 | return parameters.getProperty( key ); |
255 | |
} |
256 | |
|
257 | |
public void setParameters( Properties parameters ) |
258 | |
{ |
259 | 0 | this.parameters = parameters; |
260 | 0 | } |
261 | |
|
262 | |
public int hashCode() |
263 | |
{ |
264 | 0 | final int prime = 31; |
265 | 0 | int result = 1; |
266 | 0 | result = prime * result + ( ( id == null ) ? 0 : id.hashCode() ); |
267 | 0 | return result; |
268 | |
} |
269 | |
|
270 | |
public boolean equals( Object obj ) |
271 | |
{ |
272 | 0 | if ( this == obj ) |
273 | |
{ |
274 | 0 | return true; |
275 | |
} |
276 | 0 | if ( obj == null ) |
277 | |
{ |
278 | 0 | return false; |
279 | |
} |
280 | 0 | if ( getClass() != obj.getClass() ) |
281 | |
{ |
282 | 0 | return false; |
283 | |
} |
284 | 0 | final Repository other = (Repository) obj; |
285 | 0 | if ( id == null ) |
286 | |
{ |
287 | 0 | if ( other.id != null ) |
288 | |
{ |
289 | 0 | return false; |
290 | |
} |
291 | |
} |
292 | 0 | else if ( !id.equals( other.id ) ) |
293 | |
{ |
294 | 0 | return false; |
295 | |
} |
296 | 0 | return true; |
297 | |
} |
298 | |
|
299 | |
public String getUsername() |
300 | |
{ |
301 | 0 | return username; |
302 | |
} |
303 | |
|
304 | |
public String getPassword() |
305 | |
{ |
306 | 0 | return password; |
307 | |
} |
308 | |
|
309 | |
public void setProtocol( String protocol ) |
310 | |
{ |
311 | 0 | this.protocol = protocol; |
312 | 0 | } |
313 | |
|
314 | |
} |