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