changeset 409:4fcc61e5d8ea

Merge branch Faradi-7.0.x
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Mon, 05 Mar 2012 13:24:20 +0400
parents 5a26330117bc (current diff) b34ffc622efc (diff)
children 490024d8e5fd
files
diffstat 9 files changed, 34 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Mon Mar 05 13:24:20 2012 +0400
@@ -83,6 +83,11 @@
       }
 
       @Override
+      public void serverShutdown() {
+        myRepoFactory.dispose();
+      }
+
+      @Override
       public void sourcesVersionReleased(@NotNull final BuildAgent agent) {
         super.sourcesVersionReleased(agent);
         server.getExecutor().submit(new Runnable() {
@@ -746,11 +751,11 @@
     }
   }
 
-  private ServerHgRepo createRepo(@NotNull Settings s) {
+  private ServerHgRepo createRepo(@NotNull Settings s) throws VcsException {
     return myRepoFactory.create(getWorkingDir(s), s.getHgCommandPath(), s.getAuthSettings());
   }
 
-  private HgRepo createRepo(@NotNull Settings s, @NotNull File customDir) {
+  private HgRepo createRepo(@NotNull Settings s, @NotNull File customDir) throws VcsException {
     return myRepoFactory.create(customDir, s.getHgCommandPath(), s.getAuthSettings());
   }
 
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RepoFactory.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RepoFactory.java	Mon Mar 05 13:24:20 2012 +0400
@@ -2,30 +2,48 @@
 
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings;
 import jetbrains.buildServer.util.FileUtil;
+import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
 import java.io.IOException;
 
+import static com.intellij.openapi.util.io.FileUtil.createTempFile;
+import static com.intellij.openapi.util.io.FileUtil.delete;
+
 /**
  * @author dmitry.neverov
  */
 public final class RepoFactory {
 
-  private final static String LOG_TEMPLATE_NAME = "log.template";
-  private final File myLogTemplate;
+  private File myLogTemplate;
 
-  public RepoFactory(@NotNull ServerPluginConfig config) throws IOException {
-    myLogTemplate = createLogTemplate(config.getPluginDataDir());
+  public RepoFactory() throws IOException {
+    myLogTemplate = createLogTemplate();
   }
 
   @NotNull
-  public ServerHgRepo create(@NotNull File workingDir, @NotNull String hgPath, @NotNull AuthSettings authSettings) {
-    return new ServerHgRepo(workingDir, hgPath, authSettings).withLogTemplate(myLogTemplate);
+  public ServerHgRepo create(@NotNull File workingDir, @NotNull String hgPath, @NotNull AuthSettings authSettings) throws VcsException {
+    return new ServerHgRepo(workingDir, hgPath, authSettings).withLogTemplate(getTemplate());
   }
 
-  private File createLogTemplate(@NotNull final File templateFileDir) throws IOException {
-    File template = new File(templateFileDir, LOG_TEMPLATE_NAME);
+  public void dispose() {
+    delete(myLogTemplate);
+  }
+
+  private File getTemplate() throws VcsException {
+    if (myLogTemplate.isFile() && myLogTemplate.exists())
+      return myLogTemplate;
+    try {
+      myLogTemplate = createLogTemplate();
+      return myLogTemplate;
+    } catch (IOException e) {
+      throw new VcsException("Cannot create mercurial log template", e);
+    }
+  }
+
+  private File createLogTemplate() throws IOException {
+    File template = createTempFile("teamcity", "hg.log.template");
     FileUtil.copyResource(RepoFactory.class, "/buildServerResources/log.template", template);
     return template;
   }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java	Mon Mar 05 13:24:20 2012 +0400
@@ -1,10 +1,7 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
-import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.io.File;
-
 /**
  * @author dmitry.neverov
  */
@@ -15,8 +12,5 @@
 
   public boolean isUsePullProtocol();
 
-  @NotNull
-  public File getPluginDataDir();
-
   int getPullTimeout();
 }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java	Mon Mar 05 13:24:20 2012 +0400
@@ -16,11 +16,9 @@
   public static final int DEFAULT_PULL_TIMEOUT_SECONDS = 3600;
 
   private final File myCachesDir;
-  private final File myPluginDataDir;
 
   public ServerPluginConfigImpl(@NotNull final ServerPaths paths) {
     myCachesDir = new File(paths.getCachesDir(), "mercurial");
-    myPluginDataDir = paths.getPluginDataDirectory();
   }
 
   public boolean isUsePullProtocol() {
@@ -37,11 +35,6 @@
     return myCachesDir;
   }
 
-  @NotNull
-  public File getPluginDataDir() {
-    return myPluginDataDir;
-  }
-
   public int getPullTimeout() {
     int timeout = TeamCityProperties.getInteger(PULL_TIMEOUT_SECONDS, DEFAULT_PULL_TIMEOUT_SECONDS);
     return timeout > 0 ? timeout : DEFAULT_PULL_TIMEOUT_SECONDS;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/DagFeaturesTest.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/DagFeaturesTest.java	Mon Mar 05 13:24:20 2012 +0400
@@ -37,7 +37,6 @@
   public void setUp() throws Exception {
     ServerPluginConfig config = new ServerPluginConfigBuilder()
             .cachesDir(myTempFiles.createTempDir())
-            .pluginDataDir(myTempFiles.createTempDir())
             .build();
     myHg = Util.createMercurialServerSupport(new Mockery(), config);
 
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Mon Mar 05 13:24:20 2012 +0400
@@ -51,7 +51,6 @@
     Mockery context = new Mockery();
     myPluginConfig = new ServerPluginConfigBuilder()
             .cachesDir(myTempFiles.createTempDir())
-            .pluginDataDir(myTempFiles.createTempDir())
             .build();
     myVcs = Util.createMercurialServerSupport(context, myPluginConfig);
   }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java	Mon Mar 05 13:24:20 2012 +0400
@@ -12,7 +12,6 @@
   private boolean myUsePullProtocol = true;
   private String myHgPath;
   private File myCachesDir;
-  private File myPluginDataDir;
 
 
   @NotNull
@@ -34,13 +33,6 @@
         return myCachesDir;
       }
 
-      @NotNull
-      public File getPluginDataDir() {
-        if (myPluginDataDir == null)
-          throw new IllegalStateException("Plugin data dir is not set");
-        return myPluginDataDir;
-      }
-
       public int getPullTimeout() {
         return ServerPluginConfigImpl.DEFAULT_PULL_TIMEOUT_SECONDS;
       }
@@ -62,9 +54,4 @@
     myCachesDir = cachesDir;
     return this;
   }
-
-  public ServerPluginConfigBuilder pluginDataDir(File pluginDataDir) {
-    myPluginDataDir = pluginDataDir;
-    return this;
-  }
 }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/UnrelatedResitoriesTest.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/UnrelatedResitoriesTest.java	Mon Mar 05 13:24:20 2012 +0400
@@ -43,7 +43,6 @@
     myTempFiles = new TempFiles();
     myPluginConfig = new ServerPluginConfigBuilder()
             .cachesDir(myTempFiles.createTempDir())
-            .pluginDataDir(myTempFiles.createTempDir())
             .build();
 
     myRepositoryLocation = myTempFiles.createTempDir();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java	Mon Mar 05 13:08:36 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java	Mon Mar 05 13:24:20 2012 +0400
@@ -32,7 +32,7 @@
 
 
   public static MercurialVcsSupport createMercurialServerSupport(@NotNull Mockery context, ServerPluginConfig config) throws IOException {
-    return createMercurialServerSupport(context, config, new RepoFactory(config));
+    return createMercurialServerSupport(context, config, new RepoFactory());
   }