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