added ChangesetPreProcessor api

This commit is contained in:
Sebastian Sdorra
2011-04-18 21:51:54 +02:00
parent 240d42df24
commit eaea1ac61c
3 changed files with 104 additions and 5 deletions

View File

@@ -0,0 +1,55 @@
/**
* 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 sonia.scm.plugin.ExtensionPoint;
/**
*
* @author Sebastian Sdorra
*/
@ExtensionPoint
public interface ChangesetPreProcessor
{
/**
* Method description
*
*
* @param changeset
*/
public void process(Changeset changeset);
}

View File

@@ -46,6 +46,7 @@ import sonia.scm.group.GroupListener;
import sonia.scm.io.FileSystem; import sonia.scm.io.FileSystem;
import sonia.scm.plugin.ext.Extension; import sonia.scm.plugin.ext.Extension;
import sonia.scm.plugin.ext.ExtensionProcessor; import sonia.scm.plugin.ext.ExtensionProcessor;
import sonia.scm.repository.ChangesetPreProcessor;
import sonia.scm.repository.RepositoryHandler; import sonia.scm.repository.RepositoryHandler;
import sonia.scm.repository.RepositoryListener; import sonia.scm.repository.RepositoryListener;
import sonia.scm.resources.ResourceHandler; import sonia.scm.resources.ResourceHandler;
@@ -101,6 +102,8 @@ public class BindingExtensionProcessor implements ExtensionProcessor
Multibinder.newSetBinder(binder, AuthenticationHandler.class); Multibinder.newSetBinder(binder, AuthenticationHandler.class);
Multibinder<ResourceHandler> resourceHandler = Multibinder<ResourceHandler> resourceHandler =
Multibinder.newSetBinder(binder, ResourceHandler.class); Multibinder.newSetBinder(binder, ResourceHandler.class);
Multibinder<ChangesetPreProcessor> changesetPreProcessorBinder =
Multibinder.newSetBinder(binder, ChangesetPreProcessor.class);
authenticators.addBinding().to(XmlAuthenticationHandler.class); authenticators.addBinding().to(XmlAuthenticationHandler.class);
@@ -198,6 +201,16 @@ public class BindingExtensionProcessor implements ExtensionProcessor
fileSystemClass = extensionClass; fileSystemClass = extensionClass;
} }
else if (ChangesetPreProcessor.class.isAssignableFrom(extensionClass))
{
if (logger.isInfoEnabled())
{
logger.info("bind ChangesetPreProcessor {}",
extensionClass.getName());
}
changesetPreProcessorBinder.addBinding().to(extensionClass);
}
else else
{ {
if (logger.isInfoEnabled()) if (logger.isInfoEnabled())

View File

@@ -40,7 +40,9 @@ import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import sonia.scm.config.ScmConfiguration; import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult; import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.ChangesetPreProcessor;
import sonia.scm.repository.ChangesetViewer; import sonia.scm.repository.ChangesetViewer;
import sonia.scm.repository.Permission; import sonia.scm.repository.Permission;
import sonia.scm.repository.PermissionType; import sonia.scm.repository.PermissionType;
@@ -50,12 +52,14 @@ import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RepositoryHandler; import sonia.scm.repository.RepositoryHandler;
import sonia.scm.repository.RepositoryManager; import sonia.scm.repository.RepositoryManager;
import sonia.scm.util.HttpUtil; import sonia.scm.util.HttpUtil;
import sonia.scm.util.Util;
import sonia.scm.web.security.WebSecurityContext; import sonia.scm.web.security.WebSecurityContext;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@@ -92,18 +96,21 @@ public class RepositoryResource
* @param repositoryManager * @param repositoryManager
* @param securityContextProvider * @param securityContextProvider
* @param requestProvider * @param requestProvider
* @param changesetPreProcessorSet
*/ */
@Inject @Inject
public RepositoryResource( public RepositoryResource(
ScmConfiguration configuration, RepositoryManager repositoryManager, ScmConfiguration configuration, RepositoryManager repositoryManager,
Provider<WebSecurityContext> securityContextProvider, Provider<WebSecurityContext> securityContextProvider,
Provider<HttpServletRequest> requestProvider) Provider<HttpServletRequest> requestProvider,
Set<ChangesetPreProcessor> changesetPreProcessorSet)
{ {
super(repositoryManager); super(repositoryManager);
this.configuration = configuration; this.configuration = configuration;
this.repositoryManager = repositoryManager; this.repositoryManager = repositoryManager;
this.securityContextProvider = securityContextProvider; this.securityContextProvider = securityContextProvider;
this.requestProvider = requestProvider; this.requestProvider = requestProvider;
this.changesetPreProcessorSet = changesetPreProcessorSet;
setDisableCache(false); setDisableCache(false);
} }
@@ -124,10 +131,9 @@ public class RepositoryResource
@GET @GET
@Path("{id}/changesets") @Path("{id}/changesets")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getChangesets(@PathParam("id") String id, public Response getChangesets(@PathParam("id") String id, @DefaultValue("0")
@DefaultValue("0") @QueryParam("start") int start, @QueryParam("start") int start, @DefaultValue("20")
@DefaultValue("20") @QueryParam("limit") int limit) @QueryParam("limit") int limit) throws RepositoryException
throws RepositoryException
{ {
Response response = null; Response response = null;
Repository repository = repositoryManager.get(id); Repository repository = repositoryManager.get(id);
@@ -142,6 +148,7 @@ public class RepositoryResource
ChangesetPagingResult changesets = changesetViewer.getChangesets(start, ChangesetPagingResult changesets = changesetViewer.getChangesets(start,
limit); limit);
callPreProcessors(changesets);
response = Response.ok(changesets).build(); response = Response.ok(changesets).build();
} }
else else
@@ -275,6 +282,27 @@ public class RepositoryResource
} }
} }
/**
* Method description
*
*
* @param changesets
*/
private void callPreProcessors(ChangesetPagingResult changesets)
{
if (Util.isNotEmpty(changesetPreProcessorSet)
&& Util.isNotEmpty(changesets.getChangesets()))
{
for (Changeset c : changesets.getChangesets())
{
for (ChangesetPreProcessor cpp : changesetPreProcessorSet)
{
cpp.process(c);
}
}
}
}
/** /**
* Method description * Method description
* *
@@ -314,6 +342,9 @@ public class RepositoryResource
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */
private Set<ChangesetPreProcessor> changesetPreProcessorSet;
/** Field description */ /** Field description */
private ScmConfiguration configuration; private ScmConfiguration configuration;