Mercurial > hg > mercurial
diff mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java @ 27:7944e8985ebd
prepare modules structure for agent side checkout
author | Pavel.Sher |
---|---|
date | Wed, 23 Jul 2008 09:18:03 +0400 |
parents | |
children | 798e750e4f26 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java Wed Jul 23 09:18:03 2008 +0400 @@ -0,0 +1,102 @@ +/* + * Copyright 2000-2007 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; + +import jetbrains.buildServer.buildTriggers.vcs.mercurial.Constants; +import jetbrains.buildServer.buildTriggers.vcs.mercurial.PathUtil; +import jetbrains.buildServer.vcs.VcsRoot; +import jetbrains.buildServer.util.Hash; +import jetbrains.buildServer.util.FileUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +/** + * Represents Mercurial repository settings + */ +public class Settings { + private String myRepository; + private String myHgCommandPath; + private File myWorkingDir; + private File myWorkFolderParentDir; + + public Settings(@NotNull File workFolderParentDir, @NotNull VcsRoot vcsRoot) { + myWorkFolderParentDir = workFolderParentDir; + setRepository(vcsRoot.getProperty(Constants.REPOSITORY_PROP)); + setHgCommandPath(vcsRoot.getProperty(Constants.HG_COMMAND_PATH_PROP)); + } + + public Settings() { + } + + public void setRepository(@NotNull final String repository) { + myRepository = repository; + } + + /** + * Returns repository path + * @return repository path + */ + @NotNull + public String getRepository() { + return myRepository; + } + + /** + * Returns path to hg command + * @return path to hg command + */ + @NotNull + public String getHgCommandPath() { + return myHgCommandPath; + } + + public void setHgCommandPath(@NotNull final String hgCommandPath) { + myHgCommandPath = hgCommandPath; + } + + public void setWorkingDir(@NotNull final File workingDir) { + myWorkingDir = FileUtil.getCanonicalFile(workingDir); + } + + /** + * Returns repository working directory where all mercurial commands should be invoked + * @return repository working directory + */ + @NotNull + public File getWorkingDir() { + if (myWorkingDir != null) { + return myWorkingDir; + } + + return getDefaultWorkDir(myWorkFolderParentDir, myRepository); + } + + public static String DEFAULT_WORK_DIR_PREFIX = "hg_"; + + private static File getDefaultWorkDir(@NotNull File workFolderParentDir, @NotNull String repPath) { + String workingDirname = DEFAULT_WORK_DIR_PREFIX + String.valueOf(Hash.calc(normalize(repPath))); + return FileUtil.getCanonicalFile(new File(workFolderParentDir, workingDirname)); + } + + private static String normalize(final String path) { + String normalized = PathUtil.normalizeSeparator(path); + if (path.endsWith("/")) { + return normalized.substring(0, normalized.length()-1); + } + return normalized; + } +}