annotate mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BranchesCommand.java @ 181:0ea2ad14ce97

Add local mirrors for agent checkout. To turn them on set agent property teamcity.hg.use.local.mirrors = true.
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Tue, 01 Mar 2011 17:55:41 +0300
parents 5198b02fc5e9
children 643fa1236f4e e8f0eb6d4ca4
rev   line source
95
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
1 /*
160
5198b02fc5e9 Update copyrights
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents: 95
diff changeset
2 * Copyright 2000-2011 JetBrains s.r.o.
95
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
3 *
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
5 * you may not use this file except in compliance with the License.
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
6 * You may obtain a copy of the License at
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
7 *
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
9 *
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
10 * Unless required by applicable law or agreed to in writing, software
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
11 * distributed under the License is distributed on an "AS IS" BASIS,
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
13 * See the License for the specific language governing permissions and
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
14 * limitations under the License.
6c1cff1f61cc copyright =>2010
Pavel.Sher
parents: 57
diff changeset
15 */
57
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
16 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
17
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
18 import com.intellij.execution.configurations.GeneralCommandLine;
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
19 import jetbrains.buildServer.ExecResult;
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
20 import jetbrains.buildServer.vcs.VcsException;
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
21 import org.jetbrains.annotations.NotNull;
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
22
181
0ea2ad14ce97 Add local mirrors for agent checkout. To turn them on set agent property teamcity.hg.use.local.mirrors = true.
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents: 160
diff changeset
23 import java.io.File;
57
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
24 import java.util.HashMap;
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
25 import java.util.Map;
181
0ea2ad14ce97 Add local mirrors for agent checkout. To turn them on set agent property teamcity.hg.use.local.mirrors = true.
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents: 160
diff changeset
26 import java.util.regex.Matcher;
57
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
27 import java.util.regex.Pattern;
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
28
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
29 /**
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
30 * @author Pavel.Sher
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
31 * Date: 26.10.2008
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
32 */
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
33 public class BranchesCommand extends BaseCommand {
181
0ea2ad14ce97 Add local mirrors for agent checkout. To turn them on set agent property teamcity.hg.use.local.mirrors = true.
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents: 160
diff changeset
34
0ea2ad14ce97 Add local mirrors for agent checkout. To turn them on set agent property teamcity.hg.use.local.mirrors = true.
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents: 160
diff changeset
35 public BranchesCommand(@NotNull Settings settings, @NotNull File workingDir) {
0ea2ad14ce97 Add local mirrors for agent checkout. To turn them on set agent property teamcity.hg.use.local.mirrors = true.
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents: 160
diff changeset
36 super(settings, workingDir);
57
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
37 }
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
38
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
39 /**
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
40 * Returns map of branch name to latest changeset in that branch
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
41 * @return see above
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
42 * @throws jetbrains.buildServer.vcs.VcsException if error occurs
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
43 */
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
44 public Map<String, ChangeSet> execute() throws VcsException {
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
45 GeneralCommandLine cli = createCommandLine();
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
46 cli.addParameter("branches");
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
47 ExecResult res = runCommand(cli);
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
48 String stdout = res.getStdout();
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
49 Map<String, ChangeSet> result = new HashMap<String, ChangeSet>();
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
50 Pattern branchPattern = Pattern.compile("(.*)[\\s]+([0-9]+:[A-Za-z0-9]+).*");
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
51 for (String line: stdout.split("[\r\n]+")) {
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
52 Matcher matcher = branchPattern.matcher(line);
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
53 if (matcher.matches()) {
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
54 String branchName = matcher.group(1).trim();
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
55 String changeId = matcher.group(2).trim();
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
56 result.put(branchName, new ChangeSet(changeId));
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
57 }
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
58 }
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
59 return result;
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
60 }
99e757f2527b branches support
Pavel.Sher
parents:
diff changeset
61 }