Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java @ 693:2c9f7f6d8a12
TODO
author | eugene.petrenko@gmail.com |
---|---|
date | Thu, 19 Dec 2013 19:17:12 +0100 |
parents | 1efd1846f00a |
children | 5ee94ee69b29 |
line wrap: on
line source
package jetbrains.buildServer.buildTriggers.vcs.mercurial; import jetbrains.buildServer.vcs.SVcsRoot; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import org.jetbrains.annotations.NotNull; import org.jmock.Expectations; import org.jmock.Mockery; import java.io.File; import java.io.IOException; /** * @author dmitry.neverov */ public class VcsRootBuilder { private String myRepository; private String myUsername; private String myPassword; private String myBranch; private long myRootId = 1L; private String myHgPath; private String myUserForTag; private boolean myUncompressed = true; private File myCloneRepositoryTo; private boolean myDetectSubrepoChanges = false; private boolean myTagsAsBranches = false; private boolean myIncludeSubreposInPatch = true; private boolean myUseArchiveForPatch = false; public static VcsRootBuilder vcsRoot() { return new VcsRootBuilder(); } public VcsRootImpl build() throws IOException { VcsRootImpl vcsRoot = new VcsRootImpl(myRootId, Constants.VCS_NAME); vcsRoot.addProperty(Constants.REPOSITORY_PROP, myRepository); vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, myHgPath != null ? myHgPath : Util.getHgPath()); vcsRoot.addProperty(Constants.USERNAME, myUsername); vcsRoot.addProperty(Constants.PASSWORD, myPassword); vcsRoot.addProperty(Constants.BRANCH_NAME_PROP, myBranch); vcsRoot.addProperty(Constants.USER_FOR_TAG, myUserForTag); vcsRoot.addProperty(Constants.UNCOMPRESSED_TRANSFER, String.valueOf(myUncompressed)); vcsRoot.addProperty(Constants.DETECT_SUBREPO_CHANGES, String.valueOf(myDetectSubrepoChanges)); vcsRoot.addProperty(Constants.INCLUDE_SUBREPOS_IN_PATCH, String.valueOf(myIncludeSubreposInPatch)); vcsRoot.addProperty(Constants.USE_ARCHIVE_FOR_PATCH, String.valueOf(myUseArchiveForPatch)); if (myCloneRepositoryTo != null) vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, String.valueOf(myCloneRepositoryTo.getAbsolutePath())); vcsRoot.addProperty(Constants.USE_TAGS_AS_BRANCHES, String.valueOf(myTagsAsBranches)); return vcsRoot; } public SVcsRoot build(Mockery context) { final SVcsRoot root = context.mock(SVcsRoot.class, "SVcsRoot" + myRootId); context.checking(new Expectations() {{ allowing(root).describe(false); will(returnValue("toString")); allowing(root).getVcsName(); will(returnValue(Constants.VCS_NAME)); allowing(root).getProperty(with(Constants.REPOSITORY_PROP)); will(returnValue(myRepository)); allowing(root).getProperty(with(Constants.HG_COMMAND_PATH_PROP)); will(returnValue(myHgPath)); allowing(root).getProperty(with(Constants.BRANCH_NAME_PROP)); will(returnValue(myBranch)); allowing(root).getProperty(with(Constants.SERVER_CLONE_PATH_PROP)); will(returnValue(null)); allowing(root).getProperty(with(Constants.USERNAME)); will(returnValue(myUsername)); allowing(root).getProperty(with(Constants.PASSWORD)); will(returnValue(myPassword)); allowing(root).getProperty(with(Constants.UNCOMPRESSED_TRANSFER)); will(returnValue(null)); allowing(root).getProperty(with(Constants.USER_FOR_TAG)); will(returnValue(myUserForTag)); allowing(root).getProperty(with(Constants.DETECT_SUBREPO_CHANGES)); will(returnValue(String.valueOf(myDetectSubrepoChanges))); allowing(root).getProperty(with(Constants.USE_TAGS_AS_BRANCHES)); will(returnValue(String.valueOf(myTagsAsBranches))); }}); if (myCloneRepositoryTo != null) { context.checking(new Expectations() {{ allowing(root).getProperty(with(Constants.SERVER_CLONE_PATH_PROP)); will(returnValue(myCloneRepositoryTo.getAbsolutePath())); }}); } return root; } public VcsRootBuilder withUrl(@NotNull String repository) { myRepository = repository; return this; } public VcsRootBuilder withUrl(@NotNull File repository) { myRepository = repository.getAbsolutePath(); return this; } public VcsRootBuilder withUserName(@NotNull String username) { myUsername = username; return this; } public VcsRootBuilder withPassword(@NotNull String password) { myPassword = password; return this; } public VcsRootBuilder withBranch(@NotNull String branch) { myBranch = branch; return this; } public VcsRootBuilder withId(long rootId) { myRootId = rootId; return this; } public VcsRootBuilder withHgPath(String hgPath) { myHgPath = hgPath; return this; } public VcsRootBuilder withUserForTag(String username) { myUserForTag = username; return this; } public VcsRootBuilder withCloneRepositoryTo(File cloneTo) { myCloneRepositoryTo = cloneTo; return this; } public VcsRootBuilder withSubrepoChanges(boolean detectSubrepoChanges) { myDetectSubrepoChanges = detectSubrepoChanges; return this; } public VcsRootBuilder withSubreposInPatch(boolean includeSubreposInPatch) { myIncludeSubreposInPatch = includeSubreposInPatch; return this; } public VcsRootBuilder withArchiveForPatch(boolean useArchiveForPatch) { myUseArchiveForPatch = useArchiveForPatch; return this; } public VcsRootBuilder withTagsEnabled(boolean useTagsAsBranches) { myTagsAsBranches = useTagsAsBranches; return this; } }