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