Mercurial > hg > mercurial
view mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentPluginConfigImpl.java @ 919:16ad8d51b001
fix non-ascii characters support in commandline arguments
author | eugene.petrenko@jetbrains.com |
---|---|
date | Mon, 19 Jan 2015 18:30:08 +0100 |
parents | 638d979c6117 |
children | 7bf4d943d5bb |
line wrap: on
line source
/* * Copyright 2000-2014 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; import jetbrains.buildServer.agent.AgentRunningBuild; import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.vcs.VcsRoot; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; /** * @author dmitry.neverov */ public class AgentPluginConfigImpl implements AgentPluginConfig { private static final String PULL_TIMEOUT_SECONDS = "teamcity.hg.pull.timeout.seconds"; private static final int DEFAULT_PULL_TIMEOUT_SECONDS = 3600; public static final String VCS_ROOT_MIRRORS_STRATEGY = "teamcity.hg.mirrorStrategy"; public static final String VCS_ROOT_MIRRORS_STRATEGY_SHARED_MIRRORS = "sharedMirrors"; public static final String VCS_ROOT_MIRRORS_STRATEGY_MIRRORS_ONLY = "mirrors"; private final BuildAgentConfiguration myAgentConfig; public AgentPluginConfigImpl(@NotNull BuildAgentConfiguration agentConfig) { myAgentConfig = agentConfig; } public boolean isUseLocalMirrors(@NotNull AgentRunningBuild build, @NotNull VcsRoot root) { String buildValue = build.getSharedConfigParameters().get("teamcity.hg.use.local.mirrors"); if (!StringUtil.isEmpty(buildValue)) return Boolean.parseBoolean(buildValue); HgVcsRoot hgRoot = new HgVcsRoot(root); Boolean rootValue = hgRoot.getUseAgentMirrors(); String mirrorStrategy = getMirrorStrategy(build); if (rootValue != null && rootValue && (VCS_ROOT_MIRRORS_STRATEGY_SHARED_MIRRORS.equals(mirrorStrategy) || VCS_ROOT_MIRRORS_STRATEGY_MIRRORS_ONLY.equals(mirrorStrategy))) return true; return false; } @SuppressWarnings("ConstantConditions") public boolean shareLocalMirrors(@NotNull AgentRunningBuild build, @NotNull VcsRoot root) { String buildValue = build.getSharedConfigParameters().get("teamcity.hg.shareLocalMirrors"); if (!StringUtil.isEmpty(buildValue)) return Boolean.parseBoolean(buildValue); HgVcsRoot hgRoot = new HgVcsRoot(root); Boolean rootValue = hgRoot.getUseAgentMirrors(); String mirrorStrategy = getMirrorStrategy(build); if (rootValue != null && rootValue && VCS_ROOT_MIRRORS_STRATEGY_SHARED_MIRRORS.equals(mirrorStrategy)) return true; return false; } @NotNull private String getMirrorStrategy(@NotNull AgentRunningBuild build) { String strategy = build.getSharedConfigParameters().get(VCS_ROOT_MIRRORS_STRATEGY); if (!StringUtil.isEmpty(strategy)) return strategy; return VCS_ROOT_MIRRORS_STRATEGY_SHARED_MIRRORS; } @NotNull public File getCachesDir() { return myAgentConfig.getCacheDirectory("mercurial"); } public int getPullTimeout(@NotNull AgentRunningBuild build) { Integer timeout = parseTimeout(build.getSharedConfigParameters().get(PULL_TIMEOUT_SECONDS)); if (timeout != null) return timeout; return DEFAULT_PULL_TIMEOUT_SECONDS; } public boolean runWithTraceback(@NotNull AgentRunningBuild build) { return Boolean.valueOf(build.getSharedConfigParameters().get("teamcity.hg.run.commands.with.traceback")); } public boolean runWithProfile(@NotNull AgentRunningBuild build) { return Boolean.valueOf(build.getSharedConfigParameters().get("teamcity.hg.runCommandsWithProfile")); } @Nullable public Integer parseTimeout(@Nullable String timeoutStr) { if (timeoutStr == null) return null; try { int timeout = Integer.parseInt(timeoutStr); if (timeout > 0) return timeout; else return null; } catch (NumberFormatException e) { return null; } } @NotNull public File getTempDir() { return myAgentConfig.getTempDirectory(); } }