# HG changeset patch # User eugene.petrenko@jetbrains.com # Date 1389639137 -3600 # Node ID 1fe708494d46bd93eb46f9cded95d8e0039761b6 # Parent 0384dea9118506a20bd00cf92ae184b51f21fdcf extract class diff -r 0384dea91185 -r 1fe708494d46 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Mon Jan 13 19:50:21 2014 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Mon Jan 13 19:52:17 2014 +0100 @@ -320,47 +320,6 @@ } private Map readSubrepositories(@NotNull final File hgsub, @NotNull final File hgsubstate) { - if (hgsub.exists() && hgsubstate.exists()) { - try { - Map path2repo = readHgsub(hgsub); - Map path2revision = readHgsubstate(hgsubstate); - Map result = new HashMap(); - for (Map.Entry entry : path2repo.entrySet()) { - String path = entry.getKey(); - String url = entry.getValue(); - String revision = path2revision.get(path); - if (revision != null) - result.put(path, new SubRepo(path, url, revision)); - } - return result; - } catch (IOException e) { - return emptyMap(); - } - } else { - return emptyMap(); - } - } - - /*returns map: relative path -> repository url */ - private Map readHgsub(@NotNull final File hgsub) throws IOException { - Map result = new HashMap(); - for (String line : FileUtil.readFile(hgsub)) { - String[] parts = line.split(" = "); - if (parts.length == 2) - result.put(parts[0], parts[1]); - } - return result; - } - - - /*returns map: relative path -> revision */ - private Map readHgsubstate(@NotNull final File hgsubstate) throws IOException { - Map result = new HashMap(); - for (String line : FileUtil.readFile(hgsubstate)) { - String[] parts = line.split(" "); - if (parts.length == 2) - result.put(parts[1], parts[0]); - } - return result; + return HgSubs.readSubrepositories(hgsub, hgsubstate); } } diff -r 0384dea91185 -r 1fe708494d46 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgSubs.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgSubs.java Mon Jan 13 19:52:17 2014 +0100 @@ -0,0 +1,67 @@ +package jetbrains.buildServer.buildTriggers.vcs.mercurial; + +import jetbrains.buildServer.util.FileUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static java.util.Collections.emptyMap; + +/** + * Created 13.01.14 19:51 + * + * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) + */ +public class HgSubs { + + @NotNull + public static Map readSubrepositories(@NotNull final File hgsub, @NotNull final File hgsubstate) { + if (hgsub.exists() && hgsubstate.exists()) { + try { + Map path2repo = readHgsub(hgsub); + Map path2revision = readHgsubstate(hgsubstate); + Map result = new HashMap(); + for (Map.Entry entry : path2repo.entrySet()) { + String path = entry.getKey(); + String url = entry.getValue(); + String revision = path2revision.get(path); + if (revision != null) + result.put(path, new SubRepo(path, url, revision)); + } + return result; + } catch (IOException e) { + return emptyMap(); + } + } else { + return emptyMap(); + } + } + + @NotNull + /*returns map: relative path -> repository url */ + private static Map readHgsub(@NotNull final File hgsub) throws IOException { + Map result = new HashMap(); + for (String line : FileUtil.readFile(hgsub)) { + String[] parts = line.split(" = "); + if (parts.length == 2) + result.put(parts[0], parts[1]); + } + return result; + } + + + @NotNull + /*returns map: relative path -> revision */ + private static Map readHgsubstate(@NotNull final File hgsubstate) throws IOException { + Map result = new HashMap(); + for (String line : FileUtil.readFile(hgsubstate)) { + String[] parts = line.split(" "); + if (parts.length == 2) + result.put(parts[1], parts[0]); + } + return result; + } +}