mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
merge with branch 1.x
This commit is contained in:
@@ -43,7 +43,7 @@ import sonia.scm.installer.HgInstallerFactory;
|
||||
import sonia.scm.installer.HgPackage;
|
||||
import sonia.scm.installer.HgPackageReader;
|
||||
import sonia.scm.installer.HgPackages;
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
|
||||
@@ -89,8 +89,8 @@ public class HgConfigResource
|
||||
* @param pkgReader
|
||||
*/
|
||||
@Inject
|
||||
public HgConfigResource(HttpClient client, HgRepositoryHandler handler,
|
||||
HgPackageReader pkgReader)
|
||||
public HgConfigResource(AdvancedHttpClient client,
|
||||
HgRepositoryHandler handler, HgPackageReader pkgReader)
|
||||
{
|
||||
this.client = client;
|
||||
this.handler = handler;
|
||||
@@ -158,7 +158,7 @@ public class HgConfigResource
|
||||
if (pkg != null)
|
||||
{
|
||||
if (HgInstallerFactory.createInstaller().installPackage(client, handler,
|
||||
SCMContext.getContext().getBaseDirectory(), pkg))
|
||||
SCMContext.getContext().getBaseDirectory(), pkg))
|
||||
{
|
||||
response = Response.noContent().build();
|
||||
}
|
||||
@@ -262,7 +262,7 @@ public class HgConfigResource
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response setConfig(@Context UriInfo uriInfo, HgConfig config)
|
||||
throws IOException
|
||||
throws IOException
|
||||
{
|
||||
handler.setConfig(config);
|
||||
handler.storeConfig();
|
||||
@@ -338,7 +338,7 @@ public class HgConfigResource
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private HttpClient client;
|
||||
private AdvancedHttpClient client;
|
||||
|
||||
/** Field description */
|
||||
private HgRepositoryHandler handler;
|
||||
|
||||
@@ -35,7 +35,6 @@ package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.util.IOUtil;
|
||||
@@ -44,6 +43,7 @@ import sonia.scm.util.IOUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -93,7 +93,7 @@ public abstract class AbstractHgInstaller implements HgInstaller
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean installPackage(HttpClient client, HgRepositoryHandler handler,
|
||||
public boolean installPackage(AdvancedHttpClient client, HgRepositoryHandler handler,
|
||||
File baseDirectory, HgPackage pkg)
|
||||
{
|
||||
return new HgPackageInstaller(client, handler, baseDirectory,
|
||||
|
||||
@@ -35,7 +35,7 @@ package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
|
||||
@@ -78,8 +78,8 @@ public interface HgInstaller
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean installPackage(HttpClient client, HgRepositoryHandler handler,
|
||||
File baseDirectory, HgPackage pkg);
|
||||
public boolean installPackage(AdvancedHttpClient client,
|
||||
HgRepositoryHandler handler, File baseDirectory, HgPackage pkg);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
|
||||
@@ -40,10 +40,10 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.io.ZipUnArchiver;
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.repository.HgWindowsPackageFix;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.HgWindowsPackageFix;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -80,8 +80,8 @@ public class HgPackageInstaller implements Runnable
|
||||
* @param baseDirectory
|
||||
* @param pkg
|
||||
*/
|
||||
public HgPackageInstaller(HttpClient client, HgRepositoryHandler handler,
|
||||
File baseDirectory, HgPackage pkg)
|
||||
public HgPackageInstaller(AdvancedHttpClient client,
|
||||
HgRepositoryHandler handler, File baseDirectory, HgPackage pkg)
|
||||
{
|
||||
this.client = client;
|
||||
this.handler = handler;
|
||||
@@ -155,7 +155,7 @@ public class HgPackageInstaller implements Runnable
|
||||
}
|
||||
|
||||
// TODO error handling
|
||||
input = client.get(pkg.getUrl()).getContent();
|
||||
input = client.get(pkg.getUrl()).request().contentAsStream();
|
||||
output = new FileOutputStream(file);
|
||||
IOUtil.copy(input, output);
|
||||
}
|
||||
@@ -265,7 +265,7 @@ public class HgPackageInstaller implements Runnable
|
||||
private File baseDirectory;
|
||||
|
||||
/** Field description */
|
||||
private HttpClient client;
|
||||
private AdvancedHttpClient client;
|
||||
|
||||
/** Field description */
|
||||
private HgRepositoryHandler handler;
|
||||
|
||||
@@ -36,7 +36,6 @@ package sonia.scm.installer;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -44,22 +43,17 @@ import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.PlatformType;
|
||||
import sonia.scm.cache.Cache;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.net.HttpResponse;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
import sonia.scm.util.SystemUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -85,14 +79,13 @@ public class HgPackageReader
|
||||
*
|
||||
*
|
||||
* @param cacheManager
|
||||
* @param httpClientProvider
|
||||
* @param httpClient
|
||||
*/
|
||||
@Inject
|
||||
public HgPackageReader(CacheManager cacheManager,
|
||||
Provider<HttpClient> httpClientProvider)
|
||||
public HgPackageReader(CacheManager cacheManager, AdvancedHttpClient httpClient)
|
||||
{
|
||||
cache = cacheManager.getCache(CACHENAME);
|
||||
this.httpClientProvider = httpClientProvider;
|
||||
this.cache = cacheManager.getCache(CACHENAME);
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -167,7 +160,7 @@ public class HgPackageReader
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("reject package {}, because of wrong platform {}",
|
||||
pkg.getId(), pkg.getPlatform());
|
||||
pkg.getId(), pkg.getPlatform());
|
||||
}
|
||||
|
||||
add = false;
|
||||
@@ -181,7 +174,7 @@ public class HgPackageReader
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("reject package {}, because of wrong arch {}",
|
||||
pkg.getId(), pkg.getArch());
|
||||
pkg.getId(), pkg.getArch());
|
||||
}
|
||||
|
||||
add = false;
|
||||
@@ -218,23 +211,19 @@ public class HgPackageReader
|
||||
}
|
||||
|
||||
HgPackages packages = null;
|
||||
InputStream input = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response = httpClientProvider.get().get(PACKAGEURL);
|
||||
|
||||
input = response.getContent();
|
||||
packages = JAXB.unmarshal(input, HgPackages.class);
|
||||
//J-
|
||||
packages = httpClient.get(PACKAGEURL)
|
||||
.request()
|
||||
.contentFromXml(HgPackages.class);
|
||||
//J+
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not read HgPackages from ".concat(PACKAGEURL), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(input);
|
||||
}
|
||||
|
||||
if (packages == null)
|
||||
{
|
||||
@@ -251,5 +240,5 @@ public class HgPackageReader
|
||||
private final Cache<String, HgPackages> cache;
|
||||
|
||||
/** Field description */
|
||||
private final Provider<HttpClient> httpClientProvider;
|
||||
private final AdvancedHttpClient httpClient;
|
||||
}
|
||||
|
||||
@@ -48,10 +48,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.config.ScmConfigurationChangedEvent;
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.net.HttpRequest;
|
||||
import sonia.scm.net.HttpResponse;
|
||||
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -62,6 +59,8 @@ import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import sonia.scm.config.ScmConfigurationChangedEvent;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -88,16 +87,16 @@ public class HgHookManager
|
||||
*
|
||||
* @param configuration
|
||||
* @param httpServletRequestProvider
|
||||
* @param httpClientProvider
|
||||
* @param httpClient
|
||||
*/
|
||||
@Inject
|
||||
public HgHookManager(ScmConfiguration configuration,
|
||||
Provider<HttpServletRequest> httpServletRequestProvider,
|
||||
Provider<HttpClient> httpClientProvider)
|
||||
AdvancedHttpClient httpClient)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.httpServletRequestProvider = httpServletRequestProvider;
|
||||
this.httpClientProvider = httpClientProvider;
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -360,20 +359,16 @@ public class HgHookManager
|
||||
{
|
||||
url = url.concat("?ping=true");
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("check hook url {}", url);
|
||||
}
|
||||
|
||||
HttpRequest request = new HttpRequest(url);
|
||||
|
||||
request.setDisableCertificateValidation(true);
|
||||
request.setDisableHostnameValidation(true);
|
||||
request.setIgnoreProxySettings(true);
|
||||
|
||||
HttpResponse response = httpClientProvider.get().get(request);
|
||||
|
||||
result = response.getStatusCode() == 204;
|
||||
logger.trace("check hook url {}", url);
|
||||
//J-
|
||||
int sc = httpClient.get(url)
|
||||
.disableHostnameValidation(true)
|
||||
.disableCertificateValidation(true)
|
||||
.ignoreProxySettings(true)
|
||||
.request()
|
||||
.getStatus();
|
||||
//J+
|
||||
result = sc == 204;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@@ -398,7 +393,7 @@ public class HgHookManager
|
||||
private volatile String hookUrl;
|
||||
|
||||
/** Field description */
|
||||
private Provider<HttpClient> httpClientProvider;
|
||||
private AdvancedHttpClient httpClient;
|
||||
|
||||
/** Field description */
|
||||
private Provider<HttpServletRequest> httpServletRequestProvider;
|
||||
|
||||
@@ -89,7 +89,7 @@ public class HgRepositoryHandler
|
||||
|
||||
/** Field description */
|
||||
public static final String RESOURCE_VERSION =
|
||||
"/sonia/scm/version/scm-hg-plugin";
|
||||
"sonia/scm/version/scm-hg-plugin";
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_DISPLAYNAME = "Mercurial";
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* Copyright (c) 2014, 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.api;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.spi.HookChangesetProvider;
|
||||
import sonia.scm.repository.spi.HookChangesetRequest;
|
||||
import sonia.scm.repository.spi.javahg.AbstractChangesetCommand;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Mercurial hook branch provider implementation.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgHookBranchProvider implements HookBranchProvider
|
||||
{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HgHookBranchProvider.class);
|
||||
|
||||
private static final HookChangesetRequest REQUEST =
|
||||
new HookChangesetRequest();
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
*
|
||||
* @param changesetProvider changeset provider
|
||||
*/
|
||||
public HgHookBranchProvider(HookChangesetProvider changesetProvider)
|
||||
{
|
||||
this.changesetProvider = changesetProvider;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public List<String> getCreatedOrModified()
|
||||
{
|
||||
if (createdOrModified == null)
|
||||
{
|
||||
collect();
|
||||
}
|
||||
|
||||
return createdOrModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDeletedOrClosed()
|
||||
{
|
||||
if (deletedOrClosed == null)
|
||||
{
|
||||
collect();
|
||||
}
|
||||
|
||||
return deletedOrClosed;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
private List<String> appendBranches(Builder<String> builder, Changeset c)
|
||||
{
|
||||
List<String> branches = c.getBranches();
|
||||
|
||||
if (Util.isEmpty(branches))
|
||||
{
|
||||
builder.add(AbstractChangesetCommand.BRANCH_DEFAULT);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addAll(branches);
|
||||
}
|
||||
|
||||
return branches;
|
||||
}
|
||||
|
||||
private Iterable<Changeset> changesets()
|
||||
{
|
||||
return changesetProvider.handleRequest(REQUEST).getChangesets();
|
||||
}
|
||||
|
||||
private void collect()
|
||||
{
|
||||
Builder<String> createdOrModifiedBuilder = ImmutableList.builder();
|
||||
Builder<String> deletedOrClosedBuilder = ImmutableList.builder();
|
||||
|
||||
logger.trace("collecting branches from hook changesets");
|
||||
|
||||
for (Changeset c : changesets())
|
||||
{
|
||||
if (c.getProperty(AbstractChangesetCommand.PROPERTY_CLOSE) != null)
|
||||
{
|
||||
appendBranches(deletedOrClosedBuilder, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
appendBranches(createdOrModifiedBuilder, c);
|
||||
}
|
||||
}
|
||||
|
||||
createdOrModified = createdOrModifiedBuilder.build();
|
||||
deletedOrClosed = deletedOrClosedBuilder.build();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
private final HookChangesetProvider changesetProvider;
|
||||
|
||||
private List<String> createdOrModified;
|
||||
|
||||
private List<String> deletedOrClosed;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* *
|
||||
* Copyright (c) 2015, 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.
|
||||
*
|
||||
* https://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
package sonia.scm.repository.api;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.Tag;
|
||||
import sonia.scm.repository.spi.HookChangesetProvider;
|
||||
import sonia.scm.repository.spi.HookChangesetRequest;
|
||||
import sonia.scm.repository.spi.HookChangesetResponse;
|
||||
|
||||
/**
|
||||
* Mercurial tag provider implementation.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.50
|
||||
*/
|
||||
public class HgHookTagProvider implements HookTagProvider {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HgHookTagProvider.class);
|
||||
|
||||
private static final HookChangesetRequest REQUEST = new HookChangesetRequest();
|
||||
|
||||
private final HookChangesetProvider changesetProvider;
|
||||
|
||||
private List<Tag> createdTags;
|
||||
private final List<Tag> deletedTags = Collections.emptyList();
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param changesetProvider changeset provider
|
||||
*/
|
||||
public HgHookTagProvider(HookChangesetProvider changesetProvider) {
|
||||
this.changesetProvider = changesetProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> getCreatedTags() {
|
||||
if (createdTags == null) {
|
||||
collect();
|
||||
}
|
||||
return createdTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> getDeletedTags() {
|
||||
logger.warn("detecting deleted tags with mercurial is currently not supported");
|
||||
return deletedTags;
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
ImmutableList.Builder<Tag> createdTagsBuilder = ImmutableList.builder();
|
||||
|
||||
logger.trace("collecting tags from hook changesets");
|
||||
HookChangesetResponse response = changesetProvider.handleRequest(REQUEST);
|
||||
for ( Changeset c : response.getChangesets() ){
|
||||
appendTags(createdTagsBuilder, c);
|
||||
}
|
||||
|
||||
createdTags = createdTagsBuilder.build();
|
||||
}
|
||||
|
||||
private void appendTags(ImmutableList.Builder<Tag> tags, Changeset c){
|
||||
List<String> tagNames = c.getTags();
|
||||
if (tagNames != null){
|
||||
for ( String tagName : tagNames ){
|
||||
logger.trace("found tag {} at changeset {}", tagName, c.getId());
|
||||
tags.add(new Tag(tagName, c.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,10 +30,13 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.aragost.javahg.Changeset;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -92,7 +95,15 @@ public class HgBranchesCommand extends AbstractCommand
|
||||
@Override
|
||||
public Branch apply(com.aragost.javahg.commands.Branch hgBranch)
|
||||
{
|
||||
return new Branch(hgBranch.getName());
|
||||
String node = null;
|
||||
Changeset changeset = hgBranch.getBranchTip();
|
||||
|
||||
if (changeset != null)
|
||||
{
|
||||
node = changeset.getNode();
|
||||
}
|
||||
|
||||
return new Branch(hgBranch.getName(), node);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ package sonia.scm.repository.spi;
|
||||
import sonia.scm.repository.HgHookManager;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.RepositoryHookType;
|
||||
import sonia.scm.repository.api.HgHookBranchProvider;
|
||||
import sonia.scm.repository.api.HgHookMessageProvider;
|
||||
import sonia.scm.repository.api.HookBranchProvider;
|
||||
import sonia.scm.repository.api.HookFeature;
|
||||
import sonia.scm.repository.api.HookMessageProvider;
|
||||
|
||||
@@ -44,29 +46,31 @@ import sonia.scm.repository.api.HookMessageProvider;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import sonia.scm.repository.api.HgHookTagProvider;
|
||||
import sonia.scm.repository.api.HookTagProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* Mercurial implementation of {@link HookContextProvider}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgHookContextProvider extends HookContextProvider
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final Set<HookFeature> SUPPORTED_FEATURES =
|
||||
EnumSet.of(HookFeature.CHANGESET_PROVIDER, HookFeature.MESSAGE_PROVIDER);
|
||||
EnumSet.of(HookFeature.CHANGESET_PROVIDER, HookFeature.MESSAGE_PROVIDER,
|
||||
HookFeature.BRANCH_PROVIDER, HookFeature.TAG_PROVIDER);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
* Constructs a new instance.
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param repositoryName
|
||||
* @param hookManager
|
||||
* @param startRev
|
||||
* @param type
|
||||
* @param handler mercurial repository handler
|
||||
* @param repositoryName name of changed repository
|
||||
* @param hookManager mercurial hook manager
|
||||
* @param startRev start revision
|
||||
* @param type type of hook
|
||||
*/
|
||||
public HgHookContextProvider(HgRepositoryHandler handler,
|
||||
String repositoryName, HgHookManager hookManager, String startRev,
|
||||
@@ -78,24 +82,34 @@ public class HgHookContextProvider extends HookContextProvider
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HookBranchProvider getBranchProvider()
|
||||
{
|
||||
if (hookBranchProvider == null)
|
||||
{
|
||||
hookBranchProvider = new HgHookBranchProvider(hookChangesetProvider);
|
||||
}
|
||||
|
||||
return hookBranchProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookTagProvider getTagProvider()
|
||||
{
|
||||
if (hookTagProvider == null)
|
||||
{
|
||||
hookTagProvider = new HgHookTagProvider(hookChangesetProvider);
|
||||
}
|
||||
|
||||
return hookTagProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookChangesetProvider getChangesetProvider()
|
||||
{
|
||||
return hookChangesetProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
public HgHookMessageProvider getHgMessageProvider()
|
||||
{
|
||||
if (hgMessageProvider == null)
|
||||
@@ -106,12 +120,6 @@ public class HgHookContextProvider extends HookContextProvider
|
||||
return hgMessageProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Set<HookFeature> getSupportedFeatures()
|
||||
{
|
||||
@@ -120,12 +128,6 @@ public class HgHookContextProvider extends HookContextProvider
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected HookMessageProvider createMessageProvider()
|
||||
{
|
||||
@@ -134,9 +136,11 @@ public class HgHookContextProvider extends HookContextProvider
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final HgHookChangesetProvider hookChangesetProvider;
|
||||
|
||||
private HgHookMessageProvider hgMessageProvider;
|
||||
|
||||
/** Field description */
|
||||
private HgHookChangesetProvider hookChangesetProvider;
|
||||
private HgHookBranchProvider hookBranchProvider;
|
||||
|
||||
private HgHookTagProvider hookTagProvider;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.spi.javahg;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -63,7 +64,7 @@ public abstract class AbstractChangesetCommand extends AbstractCommand
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String BRANCH_DEFAULT = "default";
|
||||
public static final String BRANCH_DEFAULT = "default";
|
||||
|
||||
/**
|
||||
* Character sequence that indicate the begin and end of the
|
||||
@@ -87,6 +88,9 @@ public abstract class AbstractChangesetCommand extends AbstractCommand
|
||||
private static final String NULL_ID =
|
||||
"0000000000000000000000000000000000000000";
|
||||
|
||||
/** changeset property for closed branch */
|
||||
public static final String PROPERTY_CLOSE = "hg.close";
|
||||
|
||||
/** changeset property for parent1 revision */
|
||||
private static final String PROPERTY_PARENT1_REVISION = "hg.p1.rev";
|
||||
|
||||
@@ -114,12 +118,80 @@ public abstract class AbstractChangesetCommand extends AbstractCommand
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param stream
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected List<Integer> loadRevisionsFromStream(HgInputStream stream)
|
||||
{
|
||||
List<Integer> revisions = Lists.newArrayList();
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
try
|
||||
{
|
||||
while (stream.peek() != -1)
|
||||
{
|
||||
int rev = stream.revisionUpTo(' ');
|
||||
|
||||
if (rev >= 0)
|
||||
{
|
||||
revisions.add(rev);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new RuntimeIOException(ex);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
return revisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param in
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected List<Changeset> readListFromStream(HgInputStream in)
|
||||
{
|
||||
List<Changeset> changesets = Lists.newArrayList();
|
||||
|
||||
try
|
||||
{
|
||||
boolean found = in.find(CHANGESET_PATTERN);
|
||||
|
||||
if (found)
|
||||
{
|
||||
while (!in.match(CHANGESET_PATTERN))
|
||||
{
|
||||
|
||||
Changeset cset = createFromInputStream(in);
|
||||
|
||||
if (cset != null)
|
||||
{
|
||||
changesets.add(cset);
|
||||
}
|
||||
}
|
||||
|
||||
Utils.consumeAll(in);
|
||||
}
|
||||
|
||||
// If the pattern is not found there is no changsets
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
|
||||
return changesets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -168,7 +240,16 @@ public abstract class AbstractChangesetCommand extends AbstractCommand
|
||||
changeset.getParents().add(p2);
|
||||
}
|
||||
|
||||
in.mustMatch(' '); // skip space part of {parents}
|
||||
// skip space part of {parents}
|
||||
in.mustMatch(' ');
|
||||
|
||||
// read extras
|
||||
String extraLine = in.textUpTo('\n');
|
||||
|
||||
if (extraLine.contains("close=1"))
|
||||
{
|
||||
changeset.getProperties().put(PROPERTY_CLOSE, "true");
|
||||
}
|
||||
|
||||
Modifications modifications = changeset.getModifications();
|
||||
|
||||
@@ -204,39 +285,6 @@ public abstract class AbstractChangesetCommand extends AbstractCommand
|
||||
return changeset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param stream
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected List<Integer> loadRevisionsFromStream(HgInputStream stream)
|
||||
{
|
||||
List<Integer> revisions = Lists.newArrayList();
|
||||
|
||||
try
|
||||
{
|
||||
while (stream.peek() != -1)
|
||||
{
|
||||
int rev = stream.revisionUpTo(' ');
|
||||
|
||||
if (rev >= 0)
|
||||
{
|
||||
revisions.add(rev);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new RuntimeIOException(ex);
|
||||
}
|
||||
|
||||
return revisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -268,48 +316,6 @@ public abstract class AbstractChangesetCommand extends AbstractCommand
|
||||
return in.nextAsText(40);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param in
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected List<Changeset> readListFromStream(HgInputStream in)
|
||||
{
|
||||
List<Changeset> changesets = Lists.newArrayList();
|
||||
|
||||
try
|
||||
{
|
||||
boolean found = in.find(CHANGESET_PATTERN);
|
||||
|
||||
if (found)
|
||||
{
|
||||
while (!in.match(CHANGESET_PATTERN))
|
||||
{
|
||||
|
||||
Changeset cset = createFromInputStream(in);
|
||||
|
||||
if (cset != null)
|
||||
{
|
||||
changesets.add(cset);
|
||||
}
|
||||
}
|
||||
|
||||
Utils.consumeAll(in);
|
||||
}
|
||||
|
||||
// If the pattern is not found there is no changsets
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
|
||||
return changesets;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -130,6 +131,7 @@ public class HgCGIServlet extends HttpServlet
|
||||
this.hookManager = hookManager;
|
||||
this.requestListenerUtil = requestListenerUtil;
|
||||
this.exceptionHandler = new HgCGIExceptionHandler();
|
||||
this.command = HgPythonScript.HGWEB.getFile(SCMContext.getContext());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -143,7 +145,7 @@ public class HgCGIServlet extends HttpServlet
|
||||
@Override
|
||||
public void init() throws ServletException
|
||||
{
|
||||
command = HgPythonScript.HGWEB.getFile(SCMContext.getContext());
|
||||
|
||||
super.init();
|
||||
}
|
||||
|
||||
@@ -184,7 +186,11 @@ public class HgCGIServlet extends HttpServlet
|
||||
{
|
||||
handleRequest(request, response, repository);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (ServletException ex)
|
||||
{
|
||||
exceptionHandler.handleException(request, response, ex);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
exceptionHandler.handleException(request, response, ex);
|
||||
}
|
||||
@@ -241,7 +247,9 @@ public class HgCGIServlet extends HttpServlet
|
||||
{
|
||||
if (requestListenerUtil.callListeners(request, response, repository))
|
||||
{
|
||||
Stopwatch sw = Stopwatch.createStarted();
|
||||
process(request, response, repository);
|
||||
logger.debug("mercurial request finished in {}", sw.stop());
|
||||
}
|
||||
else if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -358,26 +366,26 @@ public class HgCGIServlet extends HttpServlet
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private CGIExecutorFactory cgiExecutorFactory;
|
||||
private final CGIExecutorFactory cgiExecutorFactory;
|
||||
|
||||
/** Field description */
|
||||
private File command;
|
||||
private final File command;
|
||||
|
||||
/** Field description */
|
||||
private ScmConfiguration configuration;
|
||||
private final ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private HgCGIExceptionHandler exceptionHandler;
|
||||
private final HgCGIExceptionHandler exceptionHandler;
|
||||
|
||||
/** Field description */
|
||||
private HgRepositoryHandler handler;
|
||||
private final HgRepositoryHandler handler;
|
||||
|
||||
/** Field description */
|
||||
private HgHookManager hookManager;
|
||||
private final HgHookManager hookManager;
|
||||
|
||||
/** Field description */
|
||||
private RepositoryProvider repositoryProvider;
|
||||
private final RepositoryProvider repositoryProvider;
|
||||
|
||||
/** Field description */
|
||||
private RepositoryRequestListenerUtil requestListenerUtil;
|
||||
private final RepositoryRequestListenerUtil requestListenerUtil;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import sonia.scm.Priority;
|
||||
@@ -46,22 +47,27 @@ import sonia.scm.web.filter.ProviderPermissionFilter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
* Permission filter for mercurial repositories.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Priority(Filters.PRIORITY_AUTHORIZATION)
|
||||
@WebElement(value = HgServletModule.MAPPING_HG)
|
||||
public class HgPermissionFilter extends ProviderPermissionFilter
|
||||
{
|
||||
|
||||
private static final Set<String> READ_METHODS = ImmutableSet.of("GET", "HEAD", "OPTIONS", "TRACE");
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param configuration
|
||||
* @param repositoryProvider
|
||||
* @param configuration scm configuration
|
||||
* @param repositoryProvider repository provider
|
||||
*/
|
||||
@Inject
|
||||
public HgPermissionFilter(ScmConfiguration configuration,
|
||||
@@ -72,17 +78,9 @@ public class HgPermissionFilter extends ProviderPermissionFilter
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected boolean isWriteRequest(HttpServletRequest request)
|
||||
{
|
||||
return !request.getMethod().equalsIgnoreCase("GET");
|
||||
return !READ_METHODS.contains(request.getMethod());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import sonia.scm.plugin.Extension;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra <s.sdorra@gmail.com>
|
||||
* @since 1.45
|
||||
*/
|
||||
@Extension
|
||||
public class HgUserAgentProvider implements UserAgentProvider
|
||||
{
|
||||
|
||||
/** mercurial seems to use system encoding */
|
||||
@VisibleForTesting
|
||||
static UserAgent HG = UserAgent.builder("Mercurial").browser(
|
||||
false).basicAuthenticationCharset(
|
||||
Charset.defaultCharset()).build();
|
||||
|
||||
/** Field description */
|
||||
private static final String PREFIX = "mercurial";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param userAgentString
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserAgent parseUserAgent(String userAgentString)
|
||||
{
|
||||
UserAgent ua = null;
|
||||
|
||||
if (userAgentString.startsWith(PREFIX))
|
||||
{
|
||||
ua = HG;
|
||||
}
|
||||
|
||||
return ua;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user