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