Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java @ 494:6ff7f6e77b98
Merge branch Faradi-7.1.x
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Tue, 23 Oct 2012 13:51:23 +0400 |
parents | 493f78cb64dd 236d0866a45f |
children | 575d716a6846 |
line wrap: on
line source
package jetbrains.buildServer.buildTriggers.vcs.mercurial; import jetbrains.buildServer.TempFiles; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.TestCommandSettingsFactory; import jetbrains.buildServer.serverSide.BuildServerListener; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.util.EventDispatcher; import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.cache.ResetCacheHandler; import jetbrains.buildServer.util.cache.ResetCacheRegister; import jetbrains.buildServer.vcs.CheckoutRules; import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.VcsManager; import jetbrains.buildServer.vcs.VcsRoot; import jetbrains.buildServer.vcs.patches.PatchBuilderImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jmock.Expectations; import org.jmock.Mockery; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; /** * @author dmitry.neverov */ public final class Util { private Util() {} public static String getHgPath() throws IOException { String providedHg = System.getenv(Constants.HG_PATH_ENV); if (providedHg != null) { return providedHg; } else { return new File("mercurial-tests/testData/bin/hg.exe").getAbsolutePath(); } } public static MercurialVcsSupport createMercurialServerSupport(@NotNull Mockery context, ServerPluginConfig config) throws IOException { return createMercurialServerSupport(context, config, new RepoFactory(config, new TestCommandSettingsFactory())); } public static MercurialVcsSupport createMercurialServerSupport(@NotNull Mockery context, @NotNull ServerPluginConfig config, @NotNull RepoFactory repoFactory) throws IOException { VcsManager vcsManager = context.mock(VcsManager.class); final SBuildServer server = context.mock(SBuildServer.class); final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); context.checking(new Expectations() {{ allowing(server).getExecutor(); will(returnValue(executor)); }}); EventDispatcher<BuildServerListener> dispatcher = EventDispatcher.create(BuildServerListener.class); HgVcsRootFactory hgVcsRootFactory = new HgVcsRootFactory(config); MirrorManagerImpl mirrorManager = new MirrorManagerImpl(config); ServerHgPathProvider hgPathProvider = new ServerHgPathProvider(config); HgTestConnectionSupport testConnection = new HgTestConnectionSupport(hgVcsRootFactory, repoFactory, mirrorManager, hgPathProvider); final ResetCacheRegister resetCacheManager = context.mock(ResetCacheRegister.class); context.checking(new Expectations() {{ allowing(resetCacheManager).registerHandler(with(any(ResetCacheHandler.class))); }}); return new MercurialVcsSupport(vcsManager, server, dispatcher, resetCacheManager, config, hgPathProvider, repoFactory, mirrorManager, hgVcsRootFactory, testConnection, Collections.<MercurialServerExtension>emptyList()); } public static File copyRepository(@NotNull TempFiles tempFiles, @NotNull String repPath) throws IOException { File tempDir = tempFiles.createTempDir(); copyRepository(new File(repPath), tempDir); return tempDir; } public static void copyRepository(@NotNull File src, @NotNull File dst) throws IOException { FileUtil.copyDir(src, dst); if (new File(dst, "hg").isDirectory()) FileUtil.rename(new File(dst, "hg"), new File(dst, ".hg")); } public static ByteArrayOutputStream buildPatch(@NotNull MercurialVcsSupport vcs, @NotNull VcsRoot vcsRoot, @Nullable String from, @NotNull String to, @NotNull CheckoutRules rules) throws IOException, VcsException { ByteArrayOutputStream output = new ByteArrayOutputStream(); PatchBuilderImpl builder = new PatchBuilderImpl(output); vcs.buildPatch(vcsRoot, from, to, builder, rules); builder.close(); return output; } }