changeset 722:1fe708494d46

extract class
author eugene.petrenko@jetbrains.com
date Mon, 13 Jan 2014 19:52:17 +0100
parents 0384dea91185
children 860021731792
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgSubs.java
diffstat 2 files changed, 68 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- 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<String, SubRepo> readSubrepositories(@NotNull final File hgsub, @NotNull final File hgsubstate) {
-    if (hgsub.exists() && hgsubstate.exists()) {
-      try {
-        Map<String, String> path2repo = readHgsub(hgsub);
-        Map<String, String> path2revision = readHgsubstate(hgsubstate);
-        Map<String, SubRepo> result = new HashMap<String, SubRepo>();
-        for (Map.Entry<String, String> 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<String, String> readHgsub(@NotNull final File hgsub) throws IOException {
-    Map<String, String> result = new HashMap<String, String>();
-    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<String, String> readHgsubstate(@NotNull final File hgsubstate) throws IOException {
-    Map<String, String> result = new HashMap<String, String>();
-    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);
   }
 }
--- /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<String, SubRepo> readSubrepositories(@NotNull final File hgsub, @NotNull final File hgsubstate) {
+    if (hgsub.exists() && hgsubstate.exists()) {
+      try {
+        Map<String, String> path2repo = readHgsub(hgsub);
+        Map<String, String> path2revision = readHgsubstate(hgsubstate);
+        Map<String, SubRepo> result = new HashMap<String, SubRepo>();
+        for (Map.Entry<String, String> 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<String, String> readHgsub(@NotNull final File hgsub) throws IOException {
+    Map<String, String> result = new HashMap<String, String>();
+    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<String, String> readHgsubstate(@NotNull final File hgsubstate) throws IOException {
+    Map<String, String> result = new HashMap<String, String>();
+    for (String line : FileUtil.readFile(hgsubstate)) {
+      String[] parts = line.split(" ");
+      if (parts.length == 2)
+        result.put(parts[1], parts[0]);
+    }
+    return result;
+  }
+}