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