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