mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
fix mercurial environment for push and pull commands
This commit is contained in:
@@ -0,0 +1,145 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||||
|
* binary form must reproduce the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer in the documentation and/or other
|
||||||
|
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||||
|
* nor the names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.repository;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
import org.apache.shiro.session.Session;
|
||||||
|
import org.apache.shiro.subject.Subject;
|
||||||
|
|
||||||
|
import sonia.scm.web.HgUtil;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public final class HgEnvironment
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String ENV_PYTHON_PATH = "PYTHONPATH";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String ENV_CHALLENGE = "SCM_CHALLENGE";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String ENV_URL = "SCM_URL";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String SCM_CREDENTIALS = "SCM_CREDENTIALS";
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private HgEnvironment() {}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param environment
|
||||||
|
* @param handler
|
||||||
|
* @param hookManager
|
||||||
|
* @param request
|
||||||
|
*/
|
||||||
|
public static void prepareEnvironment(Map<String, String> environment,
|
||||||
|
HgRepositoryHandler handler, HgHookManager hookManager,
|
||||||
|
HttpServletRequest request)
|
||||||
|
{
|
||||||
|
String hookUrl;
|
||||||
|
|
||||||
|
if (request != null)
|
||||||
|
{
|
||||||
|
hookUrl = hookManager.createUrl(request);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hookUrl = hookManager.createUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
environment.put(ENV_PYTHON_PATH, HgUtil.getPythonPath(handler.getConfig()));
|
||||||
|
environment.put(ENV_URL, hookUrl);
|
||||||
|
environment.put(ENV_CHALLENGE, hookManager.getChallenge());
|
||||||
|
environment.put(SCM_CREDENTIALS, getCredentials());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param environment
|
||||||
|
* @param handler
|
||||||
|
* @param hookManager
|
||||||
|
*/
|
||||||
|
public static void prepareEnvironment(Map<String, String> environment,
|
||||||
|
HgRepositoryHandler handler, HgHookManager hookManager)
|
||||||
|
{
|
||||||
|
prepareEnvironment(environment, handler, hookManager, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String getCredentials()
|
||||||
|
{
|
||||||
|
String credentials = null;
|
||||||
|
|
||||||
|
Subject subject = SecurityUtils.getSubject();
|
||||||
|
Session session = subject.getSession(false);
|
||||||
|
|
||||||
|
if (session != null)
|
||||||
|
{
|
||||||
|
credentials = (String) session.getAttribute(SCM_CREDENTIALS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Strings.nullToEmpty(credentials);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,14 +82,17 @@ public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param configuration
|
* @param configuration
|
||||||
|
* @param httpServletRequestProvider
|
||||||
* @param httpClientProvider
|
* @param httpClientProvider
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public HgHookManager(ScmConfiguration configuration,
|
public HgHookManager(ScmConfiguration configuration,
|
||||||
|
Provider<HttpServletRequest> httpServletRequestProvider,
|
||||||
Provider<HttpClient> httpClientProvider)
|
Provider<HttpClient> httpClientProvider)
|
||||||
{
|
{
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.configuration.addListener(this);
|
this.configuration.addListener(this);
|
||||||
|
this.httpServletRequestProvider = httpServletRequestProvider;
|
||||||
this.httpClientProvider = httpClientProvider;
|
this.httpClientProvider = httpClientProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +139,36 @@ public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
|
|||||||
return hookUrl;
|
return hookUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String createUrl()
|
||||||
|
{
|
||||||
|
String url = hookUrl;
|
||||||
|
|
||||||
|
if (url == null)
|
||||||
|
{
|
||||||
|
HttpServletRequest request = httpServletRequestProvider.get();
|
||||||
|
|
||||||
|
if (request != null)
|
||||||
|
{
|
||||||
|
url = createUrl(request);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.warn(
|
||||||
|
"created hook url {} without request, in some cases this could cause problems",
|
||||||
|
hookUrl);
|
||||||
|
url = createConfiguredUrl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -330,4 +363,7 @@ public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Provider<HttpClient> httpClientProvider;
|
private Provider<HttpClient> httpClientProvider;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Provider<HttpServletRequest> httpServletRequestProvider;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,14 +73,17 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param handler
|
* @param handler
|
||||||
|
* @param hookManager
|
||||||
* @param repositoryName
|
* @param repositoryName
|
||||||
* @param startRev
|
* @param startRev
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public HgRepositoryHookEvent(HgRepositoryHandler handler,
|
public HgRepositoryHookEvent(HgRepositoryHandler handler,
|
||||||
String repositoryName, String startRev, RepositoryHookType type)
|
HgHookManager hookManager, String repositoryName, String startRev,
|
||||||
|
RepositoryHookType type)
|
||||||
{
|
{
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
this.hookManager = hookManager;
|
||||||
this.repositoryName = repositoryName;
|
this.repositoryName = repositoryName;
|
||||||
this.startRev = startRev;
|
this.startRev = startRev;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -153,7 +156,7 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
|
|
||||||
Repository repository = getRepository();
|
Repository repository = getRepository();
|
||||||
|
|
||||||
return new HgCommandContext(handler.getConfig(), repository,
|
return new HgCommandContext(hookManager, handler, repository,
|
||||||
repositoryDirectory, pending);
|
repositoryDirectory, pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +168,9 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private HgRepositoryHandler handler;
|
private HgRepositoryHandler handler;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private HgHookManager hookManager;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String repositoryName;
|
private String repositoryName;
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.repository.HgConfig;
|
import sonia.scm.repository.HgConfig;
|
||||||
|
import sonia.scm.repository.HgEnvironment;
|
||||||
|
import sonia.scm.repository.HgHookManager;
|
||||||
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.repository.spi.javahg.HgFileviewExtension;
|
import sonia.scm.repository.spi.javahg.HgFileviewExtension;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -76,36 +79,44 @@ public class HgCommandContext implements Closeable
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param config
|
*
|
||||||
|
* @param hookManager
|
||||||
|
* @param handler
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param directory
|
* @param directory
|
||||||
*/
|
*/
|
||||||
public HgCommandContext(HgConfig config,
|
public HgCommandContext(HgHookManager hookManager,
|
||||||
sonia.scm.repository.Repository repository, File directory)
|
HgRepositoryHandler handler, sonia.scm.repository.Repository repository,
|
||||||
|
File directory)
|
||||||
{
|
{
|
||||||
this(config, repository, directory, false);
|
this(hookManager, handler, repository, directory, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param hookManager
|
||||||
* @param config
|
* @param config
|
||||||
|
* @param hanlder
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param directory
|
* @param directory
|
||||||
* @param pending
|
* @param pending
|
||||||
*/
|
*/
|
||||||
public HgCommandContext(HgConfig config,
|
public HgCommandContext(HgHookManager hookManager,
|
||||||
sonia.scm.repository.Repository repository, File directory, boolean pending)
|
HgRepositoryHandler hanlder, sonia.scm.repository.Repository repository,
|
||||||
|
File directory, boolean pending)
|
||||||
{
|
{
|
||||||
this.config = config;
|
this.hookManager = hookManager;
|
||||||
|
this.hanlder = hanlder;
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
this.encoding = repository.getProperty(PROPERTY_ENCODING);
|
this.encoding = repository.getProperty(PROPERTY_ENCODING);
|
||||||
this.pending = pending;
|
this.pending = pending;
|
||||||
|
|
||||||
if (Strings.isNullOrEmpty(encoding))
|
if (Strings.isNullOrEmpty(encoding))
|
||||||
{
|
{
|
||||||
encoding = config.getEncoding();
|
encoding = hanlder.getConfig().getEncoding();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +150,9 @@ public class HgCommandContext implements Closeable
|
|||||||
RepositoryConfiguration repoConfiguration =
|
RepositoryConfiguration repoConfiguration =
|
||||||
RepositoryConfiguration.DEFAULT;
|
RepositoryConfiguration.DEFAULT;
|
||||||
|
|
||||||
|
HgEnvironment.prepareEnvironment(repoConfiguration.getEnvironment(),
|
||||||
|
hanlder, hookManager);
|
||||||
|
|
||||||
repoConfiguration.addExtension(HgFileviewExtension.class);
|
repoConfiguration.addExtension(HgFileviewExtension.class);
|
||||||
repoConfiguration.setEnablePendingChangesets(pending);
|
repoConfiguration.setEnablePendingChangesets(pending);
|
||||||
|
|
||||||
@@ -158,7 +172,7 @@ public class HgCommandContext implements Closeable
|
|||||||
logger.error("could not set encoding for mercurial", ex);
|
logger.error("could not set encoding for mercurial", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
repoConfiguration.setHgBin(config.getHgBinary());
|
repoConfiguration.setHgBin(hanlder.getConfig().getHgBinary());
|
||||||
repository = Repository.open(repoConfiguration, directory);
|
repository = Repository.open(repoConfiguration, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,20 +189,23 @@ public class HgCommandContext implements Closeable
|
|||||||
*/
|
*/
|
||||||
public HgConfig getConfig()
|
public HgConfig getConfig()
|
||||||
{
|
{
|
||||||
return config;
|
return hanlder.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private HgConfig config;
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private File directory;
|
private File directory;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String encoding;
|
private String encoding;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private HgRepositoryHandler hanlder;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private HgHookManager hookManager;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private boolean pending;
|
private boolean pending;
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ package sonia.scm.repository.spi;
|
|||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
import sonia.scm.repository.Feature;
|
import sonia.scm.repository.Feature;
|
||||||
|
import sonia.scm.repository.HgHookManager;
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.api.Command;
|
import sonia.scm.repository.api.Command;
|
||||||
@@ -85,16 +86,18 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param hookManager
|
||||||
* @param handler
|
* @param handler
|
||||||
* @param repository
|
* @param repository
|
||||||
*/
|
*/
|
||||||
HgRepositoryServiceProvider(HgRepositoryHandler handler,
|
HgRepositoryServiceProvider(HgRepositoryHandler handler,
|
||||||
Repository repository)
|
HgHookManager hookManager, Repository repository)
|
||||||
{
|
{
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.repositoryDirectory = handler.getDirectory(repository);
|
this.repositoryDirectory = handler.getDirectory(repository);
|
||||||
this.context = new HgCommandContext(handler.getConfig(), repository,
|
this.context = new HgCommandContext(hookManager, handler, repository,
|
||||||
repositoryDirectory);
|
repositoryDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ package sonia.scm.repository.spi;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import sonia.scm.plugin.ext.Extension;
|
import sonia.scm.plugin.ext.Extension;
|
||||||
|
import sonia.scm.repository.HgHookManager;
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
|
||||||
@@ -58,12 +59,16 @@ public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param hookManager
|
||||||
* @param handler
|
* @param handler
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public HgRepositoryServiceResolver(HgRepositoryHandler handler)
|
public HgRepositoryServiceResolver(HgRepositoryHandler handler,
|
||||||
|
HgHookManager hookManager)
|
||||||
{
|
{
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
this.hookManager = hookManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -83,7 +88,8 @@ public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
|||||||
|
|
||||||
if (TYPE.equalsIgnoreCase(repository.getType()))
|
if (TYPE.equalsIgnoreCase(repository.getType()))
|
||||||
{
|
{
|
||||||
provider = new HgRepositoryServiceProvider(handler, repository);
|
provider = new HgRepositoryServiceProvider(handler, hookManager,
|
||||||
|
repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider;
|
return provider;
|
||||||
@@ -93,4 +99,7 @@ public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private HgRepositoryHandler handler;
|
private HgRepositoryHandler handler;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private HgHookManager hookManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import sonia.scm.SCMContext;
|
import sonia.scm.SCMContext;
|
||||||
import sonia.scm.config.ScmConfiguration;
|
import sonia.scm.config.ScmConfiguration;
|
||||||
import sonia.scm.repository.HgConfig;
|
import sonia.scm.repository.HgConfig;
|
||||||
|
import sonia.scm.repository.HgEnvironment;
|
||||||
import sonia.scm.repository.HgHookManager;
|
import sonia.scm.repository.HgHookManager;
|
||||||
import sonia.scm.repository.HgPythonScript;
|
import sonia.scm.repository.HgPythonScript;
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
@@ -51,7 +52,6 @@ import sonia.scm.repository.Repository;
|
|||||||
import sonia.scm.repository.RepositoryProvider;
|
import sonia.scm.repository.RepositoryProvider;
|
||||||
import sonia.scm.repository.RepositoryRequestListenerUtil;
|
import sonia.scm.repository.RepositoryRequestListenerUtil;
|
||||||
import sonia.scm.util.AssertUtil;
|
import sonia.scm.util.AssertUtil;
|
||||||
import sonia.scm.util.Util;
|
|
||||||
import sonia.scm.web.cgi.CGIExecutor;
|
import sonia.scm.web.cgi.CGIExecutor;
|
||||||
import sonia.scm.web.cgi.CGIExecutorFactory;
|
import sonia.scm.web.cgi.CGIExecutorFactory;
|
||||||
import sonia.scm.web.cgi.EnvList;
|
import sonia.scm.web.cgi.EnvList;
|
||||||
@@ -77,12 +77,6 @@ import javax.servlet.http.HttpSession;
|
|||||||
public class HgCGIServlet extends HttpServlet
|
public class HgCGIServlet extends HttpServlet
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String ENV_CHALLENGE = "SCM_CHALLENGE";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String ENV_PYTHON_PATH = "PYTHONPATH";
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ENV_REPOSITORY_NAME = "REPO_NAME";
|
public static final String ENV_REPOSITORY_NAME = "REPO_NAME";
|
||||||
|
|
||||||
@@ -92,12 +86,6 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ENV_SESSION_PREFIX = "SCM_";
|
public static final String ENV_SESSION_PREFIX = "SCM_";
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String ENV_URL = "SCM_URL";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String SCM_CREDENTIALS = "SCM_CREDENTIALS";
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final long serialVersionUID = -3492811300905099810L;
|
private static final long serialVersionUID = -3492811300905099810L;
|
||||||
|
|
||||||
@@ -240,12 +228,6 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
env.set(key, session.getAttribute(key).toString());
|
env.set(key, session.getAttribute(key).toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// issue-97
|
|
||||||
if (!env.containsKey(SCM_CREDENTIALS))
|
|
||||||
{
|
|
||||||
env.set(SCM_CREDENTIALS, Util.EMPTY_STRING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -265,7 +247,6 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
{
|
{
|
||||||
String name = repository.getName();
|
String name = repository.getName();
|
||||||
File directory = handler.getDirectory(repository);
|
File directory = handler.getDirectory(repository);
|
||||||
String pythonPath = HgUtil.getPythonPath(handler.getConfig());
|
|
||||||
CGIExecutor executor = cgiExecutorFactory.createExecutor(configuration,
|
CGIExecutor executor = cgiExecutorFactory.createExecutor(configuration,
|
||||||
getServletContext(), request, response);
|
getServletContext(), request, response);
|
||||||
|
|
||||||
@@ -277,9 +258,15 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
executor.getEnvironment().set(ENV_REPOSITORY_NAME, name);
|
executor.getEnvironment().set(ENV_REPOSITORY_NAME, name);
|
||||||
executor.getEnvironment().set(ENV_REPOSITORY_PATH,
|
executor.getEnvironment().set(ENV_REPOSITORY_PATH,
|
||||||
directory.getAbsolutePath());
|
directory.getAbsolutePath());
|
||||||
executor.getEnvironment().set(ENV_URL, hookManager.createUrl(request));
|
// add hook environment
|
||||||
executor.getEnvironment().set(ENV_CHALLENGE, hookManager.getChallenge());
|
//J-
|
||||||
executor.getEnvironment().set(ENV_PYTHON_PATH, pythonPath);
|
HgEnvironment.prepareEnvironment(
|
||||||
|
executor.getEnvironment().asMutableMap(),
|
||||||
|
handler,
|
||||||
|
hookManager,
|
||||||
|
request
|
||||||
|
);
|
||||||
|
//J+
|
||||||
|
|
||||||
HttpSession session = request.getSession();
|
HttpSession session = request.getSession();
|
||||||
|
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ public class HgHookCallbackServlet extends HttpServlet
|
|||||||
|
|
||||||
repositoryManager.fireHookEvent(HgRepositoryHandler.TYPE_NAME,
|
repositoryManager.fireHookEvent(HgRepositoryHandler.TYPE_NAME,
|
||||||
repositoryName,
|
repositoryName,
|
||||||
new HgRepositoryHookEvent(handler, repositoryName, node, type));
|
new HgRepositoryHookEvent(handler, hookManager, repositoryName, node, type));
|
||||||
}
|
}
|
||||||
catch (RepositoryNotFoundException ex)
|
catch (RepositoryNotFoundException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,12 +41,14 @@ import sonia.scm.SCMContext;
|
|||||||
import sonia.scm.io.FileSystem;
|
import sonia.scm.io.FileSystem;
|
||||||
import sonia.scm.store.MemoryStoreFactory;
|
import sonia.scm.store.MemoryStoreFactory;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -110,4 +112,23 @@ public final class HgTestUtil
|
|||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static HgHookManager createHookManager()
|
||||||
|
{
|
||||||
|
HgHookManager hookManager = mock(HgHookManager.class);
|
||||||
|
|
||||||
|
when(hookManager.getChallenge()).thenReturn("challenge");
|
||||||
|
when(hookManager.createUrl()).thenReturn(
|
||||||
|
"http://localhost:8081/scm/hook/hg/");
|
||||||
|
when(hookManager.createUrl(any(HttpServletRequest.class))).thenReturn(
|
||||||
|
"http://localhost:8081/scm/hook/hg/");
|
||||||
|
|
||||||
|
return hookManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,20 +38,13 @@ package sonia.scm.repository.spi;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import sonia.scm.SCMContext;
|
|
||||||
import sonia.scm.io.FileSystem;
|
|
||||||
import sonia.scm.repository.HgContextProvider;
|
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.repository.HgTestUtil;
|
import sonia.scm.repository.HgTestUtil;
|
||||||
import sonia.scm.repository.RepositoryTestData;
|
import sonia.scm.repository.RepositoryTestData;
|
||||||
import sonia.scm.repository.TempSCMContextProvider;
|
import sonia.scm.util.MockUtil;
|
||||||
import sonia.scm.store.MemoryStoreFactory;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,10 +82,22 @@ public class AbstractHgCommandTestBase extends ZippedRepositoryTestBase
|
|||||||
|
|
||||||
HgTestUtil.checkForSkip(handler);
|
HgTestUtil.checkForSkip(handler);
|
||||||
|
|
||||||
cmdContext = new HgCommandContext(handler.getConfig(),
|
cmdContext = new HgCommandContext(HgTestUtil.createHookManager(), handler,
|
||||||
RepositoryTestData.createHeartOfGold(), repositoryDirectory);
|
RepositoryTestData.createHeartOfGold(), repositoryDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
setSubject(MockUtil.createAdminSubject());
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.aragost.javahg.Changeset;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
|
import sonia.scm.repository.HgTestUtil;
|
||||||
import sonia.scm.repository.RepositoryException;
|
import sonia.scm.repository.RepositoryException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
@@ -145,7 +146,9 @@ public class HgIncomingCommandTest extends IncomingOutgoingTestBase
|
|||||||
*/
|
*/
|
||||||
private HgIncomingCommand createIncomingCommand()
|
private HgIncomingCommand createIncomingCommand()
|
||||||
{
|
{
|
||||||
return new HgIncomingCommand(new HgCommandContext(handler.getConfig(),
|
return new HgIncomingCommand(
|
||||||
incomingRepository, incomingDirectory), incomingRepository, handler);
|
new HgCommandContext(
|
||||||
|
HgTestUtil.createHookManager(), handler, incomingRepository,
|
||||||
|
incomingDirectory), incomingRepository, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.aragost.javahg.Changeset;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
|
import sonia.scm.repository.HgTestUtil;
|
||||||
import sonia.scm.repository.RepositoryException;
|
import sonia.scm.repository.RepositoryException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -148,7 +149,9 @@ public class HgOutgoingCommandTest extends IncomingOutgoingTestBase
|
|||||||
*/
|
*/
|
||||||
private HgOutgoingCommand createOutgoingCommand()
|
private HgOutgoingCommand createOutgoingCommand()
|
||||||
{
|
{
|
||||||
return new HgOutgoingCommand(new HgCommandContext(handler.getConfig(),
|
return new HgOutgoingCommand(
|
||||||
outgoingRepository, outgoingDirectory), outgoingRepository, handler);
|
new HgCommandContext(
|
||||||
|
HgTestUtil.createHookManager(), handler, outgoingRepository,
|
||||||
|
outgoingDirectory), outgoingRepository, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,43 +26,52 @@
|
|||||||
* http://bitbucket.org/sdorra/scm-manager
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.aragost.javahg.BaseRepository;
|
import com.aragost.javahg.BaseRepository;
|
||||||
import com.aragost.javahg.Changeset;
|
import com.aragost.javahg.Changeset;
|
||||||
import com.aragost.javahg.Repository;
|
import com.aragost.javahg.Repository;
|
||||||
import com.aragost.javahg.RepositoryConfiguration;
|
import com.aragost.javahg.RepositoryConfiguration;
|
||||||
import com.aragost.javahg.commands.AddCommand;
|
import com.aragost.javahg.commands.AddCommand;
|
||||||
import com.aragost.javahg.commands.CommitCommand;
|
import com.aragost.javahg.commands.CommitCommand;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
import sonia.scm.AbstractTestBase;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.HgConfig;
|
import sonia.scm.repository.HgConfig;
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.repository.HgTestUtil;
|
import sonia.scm.repository.HgTestUtil;
|
||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
import sonia.scm.user.UserTestData;
|
import sonia.scm.user.UserTestData;
|
||||||
|
import sonia.scm.util.MockUtil;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public abstract class IncomingOutgoingTestBase
|
public abstract class IncomingOutgoingTestBase extends AbstractTestBase
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
@Rule
|
|
||||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
@@ -96,6 +105,20 @@ public abstract class IncomingOutgoingTestBase
|
|||||||
when(handler.getConfig()).thenReturn(temp.getConfig());
|
when(handler.getConfig()).thenReturn(temp.getConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
setSubject(MockUtil.createAdminSubject());
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -130,26 +153,6 @@ public abstract class IncomingOutgoingTestBase
|
|||||||
return c.execute();
|
return c.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param handler
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private RepositoryConfiguration createConfig(HgRepositoryHandler handler)
|
|
||||||
{
|
|
||||||
HgConfig cfg = handler.getConfig();
|
|
||||||
RepositoryConfiguration configuration = RepositoryConfiguration.DEFAULT;
|
|
||||||
|
|
||||||
configuration.setHgBin(cfg.getHgBinary());
|
|
||||||
|
|
||||||
return configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -185,8 +188,30 @@ public abstract class IncomingOutgoingTestBase
|
|||||||
AddCommand.on(repository).execute(file);
|
AddCommand.on(repository).execute(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param handler
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private RepositoryConfiguration createConfig(HgRepositoryHandler handler)
|
||||||
|
{
|
||||||
|
HgConfig cfg = handler.getConfig();
|
||||||
|
RepositoryConfiguration configuration = RepositoryConfiguration.DEFAULT;
|
||||||
|
|
||||||
|
configuration.setHgBin(cfg.getHgBinary());
|
||||||
|
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected HgRepositoryHandler handler;
|
protected HgRepositoryHandler handler;
|
||||||
|
|
||||||
@@ -206,5 +231,5 @@ public abstract class IncomingOutgoingTestBase
|
|||||||
protected File outgoingDirectory;
|
protected File outgoingDirectory;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected sonia.scm.repository.Repository outgoingRepository;
|
protected sonia.scm.repository.Repository outgoingRepository;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user