1 | |
package org.apache.maven.scm.provider.cvslib.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.ScmProviderRepositoryWithHost; |
23 | |
import org.apache.maven.scm.provider.cvslib.AbstractCvsScmProvider; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class CvsScmProviderRepository |
31 | |
extends ScmProviderRepositoryWithHost |
32 | |
{ |
33 | |
|
34 | |
private String cvsroot; |
35 | |
|
36 | |
|
37 | |
private String transport; |
38 | |
|
39 | |
|
40 | |
private String path; |
41 | |
|
42 | |
|
43 | |
private String module; |
44 | |
|
45 | |
public CvsScmProviderRepository( String cvsroot, String transport, String user, String password, String host, |
46 | |
String path, String module ) |
47 | |
{ |
48 | 4 | this( cvsroot, transport, user, password, host, -1, path, module ); |
49 | 4 | } |
50 | |
|
51 | |
public CvsScmProviderRepository( String cvsroot, String transport, String user, String password, String host, |
52 | |
int port, String path, String module ) |
53 | 21 | { |
54 | 21 | this.cvsroot = cvsroot; |
55 | |
|
56 | 21 | this.transport = transport; |
57 | |
|
58 | 21 | if ( user == null && AbstractCvsScmProvider.TRANSPORT_EXT.equals( transport ) ) |
59 | |
{ |
60 | 0 | user = System.getProperty( "user.name" ); |
61 | |
} |
62 | |
|
63 | 21 | setUser( user ); |
64 | |
|
65 | 21 | setPassword( password ); |
66 | |
|
67 | 21 | setHost( host ); |
68 | |
|
69 | 21 | setPort( port ); |
70 | |
|
71 | 21 | this.path = path; |
72 | |
|
73 | 21 | this.module = module; |
74 | 21 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public String getCvsRoot() |
80 | |
{ |
81 | 16 | String root = getCvsRootForCvsPass(); |
82 | |
|
83 | 15 | return removeDefaultPortFromCvsRoot( root ); |
84 | |
} |
85 | |
|
86 | |
private String removeDefaultPortFromCvsRoot( String root ) |
87 | |
{ |
88 | 17 | if ( root != null && root.indexOf( ":2401" ) > 0 ) |
89 | |
{ |
90 | 13 | root = root.substring( 0, root.indexOf( ":2401" ) ) + ":" + root.substring( root.indexOf( ":2401" ) + 5 ); |
91 | |
} |
92 | |
|
93 | 17 | return root; |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public String getCvsRootForCvsPass() |
100 | |
{ |
101 | |
String result; |
102 | 24 | String transport = getTransport(); |
103 | 24 | if ( AbstractCvsScmProvider.TRANSPORT_LOCAL.equals( transport ) ) |
104 | |
{ |
105 | 3 | result = ":" + transport + ":" + cvsroot; |
106 | |
} |
107 | 21 | else if ( getUser() != null ) |
108 | |
{ |
109 | 20 | result = getCvsRootWithCorrectUser( getUser() ); |
110 | |
} |
111 | |
else |
112 | |
{ |
113 | 1 | throw new IllegalArgumentException( "Username isn't defined." ); |
114 | |
} |
115 | 23 | return result; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public String getTransport() |
122 | |
{ |
123 | 80 | return transport; |
124 | |
} |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public String getPath() |
130 | |
{ |
131 | 9 | return path; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public String getModule() |
138 | |
{ |
139 | 10 | return module; |
140 | |
} |
141 | |
|
142 | |
private String getCvsRootWithCorrectUser() |
143 | |
{ |
144 | 2 | return getCvsRootWithCorrectUser( null ); |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
private String getCvsRootWithCorrectUser( String user ) |
152 | |
{ |
153 | |
|
154 | 22 | int indexOfUsername = getTransport().length() + 2; |
155 | |
|
156 | 22 | int indexOfAt = cvsroot.indexOf( '@' ); |
157 | |
|
158 | 22 | String userString = user == null ? "" : ":" + user; |
159 | |
|
160 | 22 | if ( indexOfAt > 0 ) |
161 | |
{ |
162 | 20 | cvsroot = ":" + getTransport() + userString + cvsroot.substring( indexOfAt ); |
163 | |
} |
164 | |
else |
165 | |
{ |
166 | 2 | cvsroot = ":" + getTransport() + userString + "@" + cvsroot.substring( indexOfUsername ); |
167 | |
} |
168 | |
|
169 | 22 | return cvsroot; |
170 | |
} |
171 | |
|
172 | |
|
173 | |
public String toString() |
174 | |
{ |
175 | 9 | StringBuilder sb = new StringBuilder(); |
176 | |
|
177 | 9 | if ( getUser() == null ) |
178 | |
{ |
179 | 3 | if ( AbstractCvsScmProvider.TRANSPORT_LOCAL.equals( getTransport() ) ) |
180 | |
{ |
181 | 1 | sb.append( getCvsRoot() ); |
182 | |
} |
183 | |
else |
184 | |
{ |
185 | 2 | sb.append( removeDefaultPortFromCvsRoot( getCvsRootWithCorrectUser() ) ); |
186 | |
} |
187 | |
} |
188 | |
else |
189 | |
{ |
190 | 6 | sb.append( getCvsRoot() ); |
191 | |
} |
192 | 9 | sb.append( ":" ); |
193 | 9 | sb.append( getModule() ); |
194 | |
|
195 | |
|
196 | 9 | if ( sb.charAt( 0 ) == ':' ) |
197 | |
{ |
198 | 9 | sb.deleteCharAt( 0 ); |
199 | |
} |
200 | 9 | return sb.toString(); |
201 | |
} |
202 | |
|
203 | |
} |