1 | |
package org.apache.maven.scm.provider.hg; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.List; |
25 | |
|
26 | |
import org.apache.maven.scm.CommandParameters; |
27 | |
import org.apache.maven.scm.ScmException; |
28 | |
import org.apache.maven.scm.ScmFileSet; |
29 | |
import org.apache.maven.scm.command.add.AddScmResult; |
30 | |
import org.apache.maven.scm.command.blame.BlameScmResult; |
31 | |
import org.apache.maven.scm.command.branch.BranchScmResult; |
32 | |
import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
33 | |
import org.apache.maven.scm.command.checkin.CheckInScmResult; |
34 | |
import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
35 | |
import org.apache.maven.scm.command.diff.DiffScmResult; |
36 | |
import org.apache.maven.scm.command.info.InfoScmResult; |
37 | |
import org.apache.maven.scm.command.list.ListScmResult; |
38 | |
import org.apache.maven.scm.command.remove.RemoveScmResult; |
39 | |
import org.apache.maven.scm.command.status.StatusScmResult; |
40 | |
import org.apache.maven.scm.command.tag.TagScmResult; |
41 | |
import org.apache.maven.scm.command.update.UpdateScmResult; |
42 | |
import org.apache.maven.scm.provider.AbstractScmProvider; |
43 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
44 | |
import org.apache.maven.scm.provider.hg.command.add.HgAddCommand; |
45 | |
import org.apache.maven.scm.provider.hg.command.blame.HgBlameCommand; |
46 | |
import org.apache.maven.scm.provider.hg.command.branch.HgBranchCommand; |
47 | |
import org.apache.maven.scm.provider.hg.command.changelog.HgChangeLogCommand; |
48 | |
import org.apache.maven.scm.provider.hg.command.checkin.HgCheckInCommand; |
49 | |
import org.apache.maven.scm.provider.hg.command.checkout.HgCheckOutCommand; |
50 | |
import org.apache.maven.scm.provider.hg.command.diff.HgDiffCommand; |
51 | |
import org.apache.maven.scm.provider.hg.command.info.HgInfoCommand; |
52 | |
import org.apache.maven.scm.provider.hg.command.inventory.HgListCommand; |
53 | |
import org.apache.maven.scm.provider.hg.command.remove.HgRemoveCommand; |
54 | |
import org.apache.maven.scm.provider.hg.command.status.HgStatusCommand; |
55 | |
import org.apache.maven.scm.provider.hg.command.tag.HgTagCommand; |
56 | |
import org.apache.maven.scm.provider.hg.command.update.HgUpdateCommand; |
57 | |
import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository; |
58 | |
import org.apache.maven.scm.repository.ScmRepositoryException; |
59 | |
import org.apache.maven.scm.repository.UnknownRepositoryStructure; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 0 | public class HgScmProvider |
71 | |
extends AbstractScmProvider |
72 | |
{ |
73 | |
|
74 | |
public String getScmSpecificFilename() |
75 | |
{ |
76 | 0 | return ".hg"; |
77 | |
} |
78 | |
|
79 | 0 | private static class HgUrlParserResult |
80 | |
{ |
81 | 0 | private List<String> messages = new ArrayList<String>(); |
82 | |
|
83 | |
private ScmProviderRepository repository; |
84 | |
} |
85 | |
|
86 | |
|
87 | |
public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter ) |
88 | |
throws ScmRepositoryException |
89 | |
{ |
90 | 0 | HgUrlParserResult result = parseScmUrl( scmSpecificUrl ); |
91 | |
|
92 | 0 | if ( result.messages.size() > 0 ) |
93 | |
{ |
94 | 0 | throw new ScmRepositoryException( "The scm url is invalid.", result.messages ); |
95 | |
} |
96 | |
|
97 | 0 | return result.repository; |
98 | |
} |
99 | |
|
100 | |
private HgUrlParserResult parseScmUrl( String scmSpecificUrl ) |
101 | |
{ |
102 | 0 | HgUrlParserResult result = new HgUrlParserResult(); |
103 | |
|
104 | 0 | String url = scmSpecificUrl; |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | 0 | if ( url.startsWith( "file" ) ) |
111 | |
{ |
112 | 0 | if ( !url.startsWith( "file:///" ) && !url.startsWith( "file://localhost/" ) ) |
113 | |
{ |
114 | 0 | result.messages.add( "An hg 'file' url must be on the form 'file:///' or 'file://localhost/'." ); |
115 | |
|
116 | 0 | return result; |
117 | |
} |
118 | |
} |
119 | 0 | else if ( url.startsWith( "https" ) ) |
120 | |
{ |
121 | 0 | if ( !url.startsWith( "https://" ) ) |
122 | |
{ |
123 | 0 | result.messages.add( "An hg 'http' url must be on the form 'https://'." ); |
124 | |
|
125 | 0 | return result; |
126 | |
} |
127 | |
} |
128 | 0 | else if ( url.startsWith( "http" ) ) |
129 | |
{ |
130 | 0 | if ( !url.startsWith( "http://" ) ) |
131 | |
{ |
132 | 0 | result.messages.add( "An hg 'http' url must be on the form 'http://'." ); |
133 | |
|
134 | 0 | return result; |
135 | |
} |
136 | |
} |
137 | |
else |
138 | |
{ |
139 | |
try |
140 | |
{ |
141 | |
@SuppressWarnings( "unused" ) |
142 | 0 | File file = new File( url ); |
143 | |
} |
144 | 0 | catch ( Throwable e ) |
145 | |
{ |
146 | 0 | result.messages.add( "The filename provided is not valid" ); |
147 | |
|
148 | 0 | return result; |
149 | 0 | } |
150 | |
|
151 | |
} |
152 | |
|
153 | 0 | result.repository = new HgScmProviderRepository( url ); |
154 | |
|
155 | 0 | return result; |
156 | |
} |
157 | |
|
158 | |
|
159 | |
public ScmProviderRepository makeProviderScmRepository( File path ) |
160 | |
throws ScmRepositoryException, UnknownRepositoryStructure |
161 | |
{ |
162 | 0 | if ( path == null || !path.isDirectory() ) |
163 | |
{ |
164 | 0 | throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a valid directory." ); |
165 | |
} |
166 | |
|
167 | 0 | File hgDir = new File( path, ".hg" ); |
168 | |
|
169 | 0 | if ( !hgDir.exists() ) |
170 | |
{ |
171 | 0 | throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a hg directory." ); |
172 | |
} |
173 | |
|
174 | 0 | return makeProviderScmRepository( path.getAbsolutePath(), ':' ); |
175 | |
} |
176 | |
|
177 | |
|
178 | |
public List<String> validateScmUrl( String scmSpecificUrl, char delimiter ) |
179 | |
{ |
180 | 0 | HgUrlParserResult result = parseScmUrl( scmSpecificUrl ); |
181 | |
|
182 | 0 | return result.messages; |
183 | |
} |
184 | |
|
185 | |
|
186 | |
public String getScmType() |
187 | |
{ |
188 | 0 | return "hg"; |
189 | |
} |
190 | |
|
191 | |
|
192 | |
public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
193 | |
throws ScmException |
194 | |
{ |
195 | 0 | HgAddCommand command = new HgAddCommand(); |
196 | |
|
197 | 0 | command.setLogger( getLogger() ); |
198 | |
|
199 | 0 | return (AddScmResult) command.execute( repository, fileSet, parameters ); |
200 | |
} |
201 | |
|
202 | |
|
203 | |
public ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet, |
204 | |
CommandParameters parameters ) |
205 | |
throws ScmException |
206 | |
{ |
207 | 0 | HgChangeLogCommand command = new HgChangeLogCommand(); |
208 | |
|
209 | 0 | command.setLogger( getLogger() ); |
210 | |
|
211 | 0 | return (ChangeLogScmResult) command.execute( repository, fileSet, parameters ); |
212 | |
} |
213 | |
|
214 | |
|
215 | |
public CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet, |
216 | |
CommandParameters parameters ) |
217 | |
throws ScmException |
218 | |
{ |
219 | 0 | HgCheckInCommand command = new HgCheckInCommand(); |
220 | |
|
221 | 0 | command.setLogger( getLogger() ); |
222 | |
|
223 | 0 | return (CheckInScmResult) command.execute( repository, fileSet, parameters ); |
224 | |
} |
225 | |
|
226 | |
|
227 | |
public CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet, |
228 | |
CommandParameters parameters ) |
229 | |
throws ScmException |
230 | |
{ |
231 | 0 | HgCheckOutCommand command = new HgCheckOutCommand(); |
232 | |
|
233 | 0 | command.setLogger( getLogger() ); |
234 | |
|
235 | 0 | return (CheckOutScmResult) command.execute( repository, fileSet, parameters ); |
236 | |
} |
237 | |
|
238 | |
|
239 | |
public TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
240 | |
throws ScmException |
241 | |
{ |
242 | 0 | HgTagCommand command = new HgTagCommand(); |
243 | |
|
244 | 0 | command.setLogger( getLogger() ); |
245 | |
|
246 | 0 | return (TagScmResult) command.execute( repository, fileSet, parameters ); |
247 | |
} |
248 | |
|
249 | |
|
250 | |
public DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
251 | |
throws ScmException |
252 | |
{ |
253 | 0 | HgDiffCommand command = new HgDiffCommand(); |
254 | |
|
255 | 0 | command.setLogger( getLogger() ); |
256 | |
|
257 | 0 | return (DiffScmResult) command.execute( repository, fileSet, parameters ); |
258 | |
} |
259 | |
|
260 | |
|
261 | |
public RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet, |
262 | |
CommandParameters parameters ) |
263 | |
throws ScmException |
264 | |
{ |
265 | 0 | HgRemoveCommand command = new HgRemoveCommand(); |
266 | |
|
267 | 0 | command.setLogger( getLogger() ); |
268 | |
|
269 | 0 | return (RemoveScmResult) command.execute( repository, fileSet, parameters ); |
270 | |
} |
271 | |
|
272 | |
|
273 | |
public StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, |
274 | |
CommandParameters parameters ) |
275 | |
throws ScmException |
276 | |
{ |
277 | 0 | HgStatusCommand command = new HgStatusCommand(); |
278 | |
|
279 | 0 | command.setLogger( getLogger() ); |
280 | |
|
281 | 0 | return (StatusScmResult) command.execute( repository, fileSet, parameters ); |
282 | |
} |
283 | |
|
284 | |
|
285 | |
public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, |
286 | |
CommandParameters parameters ) |
287 | |
throws ScmException |
288 | |
{ |
289 | 0 | HgUpdateCommand command = new HgUpdateCommand(); |
290 | |
|
291 | 0 | command.setLogger( getLogger() ); |
292 | |
|
293 | 0 | return (UpdateScmResult) command.execute( repository, fileSet, parameters ); |
294 | |
} |
295 | |
|
296 | |
|
297 | |
protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, |
298 | |
CommandParameters parameters ) |
299 | |
throws ScmException |
300 | |
{ |
301 | 0 | HgBlameCommand command = new HgBlameCommand(); |
302 | |
|
303 | 0 | command.setLogger( getLogger() ); |
304 | |
|
305 | 0 | return (BlameScmResult) command.execute( repository, fileSet, parameters ); |
306 | |
} |
307 | |
|
308 | |
|
309 | |
public BranchScmResult branch( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
310 | |
throws ScmException |
311 | |
{ |
312 | 0 | HgBranchCommand command = new HgBranchCommand(); |
313 | |
|
314 | 0 | command.setLogger( getLogger() ); |
315 | |
|
316 | 0 | return (BranchScmResult) command.execute( repository, fileSet, parameters ); |
317 | |
} |
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
@Override |
324 | |
protected ListScmResult list( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
325 | |
throws ScmException |
326 | |
{ |
327 | 0 | HgListCommand hgListCommand = new HgListCommand(); |
328 | 0 | hgListCommand.setLogger( getLogger() ); |
329 | 0 | return (ListScmResult) hgListCommand.executeCommand( repository, fileSet, parameters ); |
330 | |
|
331 | |
} |
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
@Override |
339 | |
public InfoScmResult info( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
340 | |
throws ScmException |
341 | |
{ |
342 | 0 | HgInfoCommand infoCommand = new HgInfoCommand(); |
343 | 0 | infoCommand.setLogger( getLogger() ); |
344 | 0 | return (InfoScmResult) infoCommand.execute( repository, fileSet, parameters ); |
345 | |
} |
346 | |
} |