1 | |
package org.apache.maven.scm.provider.svn.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.scm.provider.ScmProviderRepository; |
23 | |
import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost; |
24 | |
import org.apache.maven.scm.provider.svn.SvnTagBranchUtils; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class SvnScmProviderRepository |
31 | |
extends ScmProviderRepositoryWithHost |
32 | |
{ |
33 | |
|
34 | |
private String url; |
35 | |
|
36 | |
private String protocol; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
private String tagBase; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
private String branchBase; |
47 | |
|
48 | |
public SvnScmProviderRepository( String url ) |
49 | 68 | { |
50 | 68 | parseUrl( url ); |
51 | |
|
52 | 68 | tagBase = SvnTagBranchUtils.resolveTagBase( url ); |
53 | |
|
54 | 68 | branchBase = SvnTagBranchUtils.resolveBranchBase( url ); |
55 | 68 | } |
56 | |
|
57 | |
public SvnScmProviderRepository( String url, String user, String password ) |
58 | |
{ |
59 | 4 | this( url ); |
60 | |
|
61 | 4 | setUser( user ); |
62 | |
|
63 | 4 | setPassword( password ); |
64 | 4 | } |
65 | |
|
66 | |
public String getUrl() |
67 | |
{ |
68 | 107 | return url; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public String getTagBase() |
75 | |
{ |
76 | 37 | return tagBase; |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public void setTagBase( String tagBase ) |
90 | |
{ |
91 | 2 | this.tagBase = tagBase; |
92 | 2 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
public String getBranchBase() |
98 | |
{ |
99 | 18 | return branchBase; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public void setBranchBase( String branchBase ) |
113 | |
{ |
114 | 3 | this.branchBase = branchBase; |
115 | 3 | } |
116 | |
|
117 | |
private void setProtocol( String protocol ) |
118 | |
{ |
119 | 68 | this.protocol = protocol; |
120 | 68 | } |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
public String getProtocol() |
128 | |
{ |
129 | 291 | return protocol; |
130 | |
} |
131 | |
|
132 | |
private void parseUrl( String url ) |
133 | |
{ |
134 | 68 | if ( url.startsWith( "file" ) ) |
135 | |
{ |
136 | 10 | setProtocol( "file://" ); |
137 | |
} |
138 | 58 | else if ( url.startsWith( "https" ) ) |
139 | |
{ |
140 | 5 | setProtocol( "https://" ); |
141 | |
} |
142 | 53 | else if ( url.startsWith( "http" ) ) |
143 | |
{ |
144 | 42 | setProtocol( "http://" ); |
145 | |
} |
146 | 11 | else if ( url.startsWith( "svn+" ) ) |
147 | |
{ |
148 | 7 | setProtocol( url.substring( 0, url.indexOf( "://" ) + 3 ) ); |
149 | |
} |
150 | 4 | else if ( url.startsWith( "svn" ) ) |
151 | |
{ |
152 | 4 | setProtocol( "svn://" ); |
153 | |
} |
154 | |
|
155 | 68 | if ( getProtocol() == null ) |
156 | |
{ |
157 | 0 | return; |
158 | |
} |
159 | |
|
160 | 68 | String urlPath = url.substring( getProtocol().length() ); |
161 | |
|
162 | 68 | int indexAt = urlPath.indexOf( '@' ); |
163 | |
|
164 | 68 | if ( indexAt > 0 && !getProtocol().startsWith( "svn+" ) ) |
165 | |
{ |
166 | 9 | String userPassword = urlPath.substring( 0, indexAt ); |
167 | 9 | if ( userPassword.indexOf( ':' ) < 0 ) |
168 | |
{ |
169 | 6 | setUser( userPassword ); |
170 | |
} |
171 | |
else |
172 | |
{ |
173 | 3 | setUser( userPassword.substring( 0, userPassword.indexOf( ':' ) ) ); |
174 | 3 | setPassword( userPassword.substring( userPassword.indexOf( ':' ) + 1 ) ); |
175 | |
} |
176 | |
|
177 | 9 | urlPath = urlPath.substring( indexAt + 1 ); |
178 | |
|
179 | 9 | this.url = getProtocol() + urlPath; |
180 | 9 | } |
181 | |
else |
182 | |
{ |
183 | 59 | this.url = getProtocol() + urlPath; |
184 | |
} |
185 | |
|
186 | 68 | if ( !"file://".equals( getProtocol() ) ) |
187 | |
{ |
188 | 58 | int indexSlash = urlPath.indexOf( '/' ); |
189 | |
|
190 | 58 | String hostPort = urlPath; |
191 | |
|
192 | 58 | if ( indexSlash > 0 ) |
193 | |
{ |
194 | 46 | hostPort = urlPath.substring( 0, indexSlash ); |
195 | |
} |
196 | |
|
197 | 58 | int indexColon = hostPort.indexOf( ':' ); |
198 | |
|
199 | 58 | if ( indexColon > 0 ) |
200 | |
{ |
201 | 4 | setHost( hostPort.substring( 0, indexColon ) ); |
202 | 4 | setPort( Integer.parseInt( hostPort.substring( indexColon + 1 ) ) ); |
203 | |
} |
204 | |
else |
205 | |
{ |
206 | 54 | setHost( hostPort ); |
207 | |
} |
208 | |
} |
209 | 68 | } |
210 | |
|
211 | |
|
212 | |
public ScmProviderRepository getParent() |
213 | |
{ |
214 | 4 | String newUrl = getUrl().substring( getProtocol().length() ); |
215 | |
|
216 | 10 | while ( newUrl.endsWith( "/." ) ) |
217 | |
{ |
218 | 6 | newUrl = newUrl.substring( 0, newUrl.length() - 2 ); |
219 | |
} |
220 | |
|
221 | 10 | while ( newUrl.endsWith( "/" ) ) |
222 | |
{ |
223 | 6 | newUrl = newUrl.substring( 0, newUrl.length() - 1 ); |
224 | |
} |
225 | |
|
226 | 4 | int i = newUrl.lastIndexOf( '/' ); |
227 | |
|
228 | 4 | if ( i < 0 ) |
229 | |
{ |
230 | 0 | return null; |
231 | |
} |
232 | 4 | newUrl = newUrl.substring( 0, i ); |
233 | |
|
234 | 4 | return new SvnScmProviderRepository( getProtocol() + newUrl, getUser(), getPassword() ); |
235 | |
} |
236 | |
|
237 | |
|
238 | |
public String getRelativePath( ScmProviderRepository ancestor ) |
239 | |
{ |
240 | 0 | if ( ancestor instanceof SvnScmProviderRepository ) |
241 | |
{ |
242 | 0 | SvnScmProviderRepository svnAncestor = (SvnScmProviderRepository) ancestor; |
243 | |
|
244 | 0 | String path = getUrl().replaceFirst( svnAncestor.getUrl() + "/", "" ); |
245 | |
|
246 | 0 | if ( !path.equals( getUrl() ) ) |
247 | |
{ |
248 | 0 | return path; |
249 | |
} |
250 | |
} |
251 | 0 | return null; |
252 | |
} |
253 | |
|
254 | |
|
255 | |
public String toString() |
256 | |
{ |
257 | 18 | return getUrl(); |
258 | |
} |
259 | |
|
260 | |
} |