improve changeset preprocessor api

This commit is contained in:
Sebastian Sdorra
2011-08-15 14:53:35 +02:00
parent e667932ef6
commit c3b8fc8e72
4 changed files with 118 additions and 3 deletions

View File

@@ -40,7 +40,9 @@ import sonia.scm.plugin.ExtensionPoint;
/** /**
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @deprecated use {@link ExtendedChangesetPreProcessor} instead.
*/ */
@Deprecated
@ExtensionPoint @ExtensionPoint
public interface ChangesetPreProcessor public interface ChangesetPreProcessor
{ {

View File

@@ -0,0 +1,57 @@
/**
* 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
* @since 1.7
*/
@ExtensionPoint
public interface ExtendedChangesetPreProcessor
{
/**
* Method description
*
*
* @param repository
* @param changeset
*/
public void process(Repository repository, Changeset changeset);
}

View File

@@ -47,6 +47,7 @@ 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.ChangesetPreProcessor;
import sonia.scm.repository.ExtendedChangesetPreProcessor;
import sonia.scm.repository.RepositoryHandler; import sonia.scm.repository.RepositoryHandler;
import sonia.scm.repository.RepositoryHook; import sonia.scm.repository.RepositoryHook;
import sonia.scm.repository.RepositoryListener; import sonia.scm.repository.RepositoryListener;
@@ -105,6 +106,8 @@ public class BindingExtensionProcessor implements ExtensionProcessor
Multibinder.newSetBinder(binder, ResourceHandler.class); Multibinder.newSetBinder(binder, ResourceHandler.class);
Multibinder<ChangesetPreProcessor> changesetPreProcessorBinder = Multibinder<ChangesetPreProcessor> changesetPreProcessorBinder =
Multibinder.newSetBinder(binder, ChangesetPreProcessor.class); Multibinder.newSetBinder(binder, ChangesetPreProcessor.class);
Multibinder<ExtendedChangesetPreProcessor> extChangesetPreProcessorBinder =
Multibinder.newSetBinder(binder, ExtendedChangesetPreProcessor.class);
authenticators.addBinding().to(XmlAuthenticationHandler.class); authenticators.addBinding().to(XmlAuthenticationHandler.class);
@@ -212,6 +215,17 @@ public class BindingExtensionProcessor implements ExtensionProcessor
changesetPreProcessorBinder.addBinding().to(extensionClass); changesetPreProcessorBinder.addBinding().to(extensionClass);
} }
else if (ExtendedChangesetPreProcessor.class.isAssignableFrom(
extensionClass))
{
if (logger.isInfoEnabled())
{
logger.info("bind ExtendedChangesetPreProcessor {}",
extensionClass.getName());
}
extChangesetPreProcessorBinder.addBinding().to(extensionClass);
}
else if (RepositoryHook.class.isAssignableFrom(extensionClass)) else if (RepositoryHook.class.isAssignableFrom(extensionClass))
{ {
if (logger.isInfoEnabled()) if (logger.isInfoEnabled())

View File

@@ -49,6 +49,7 @@ import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult; import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.ChangesetPreProcessor; import sonia.scm.repository.ChangesetPreProcessor;
import sonia.scm.repository.ChangesetViewerUtil; import sonia.scm.repository.ChangesetViewerUtil;
import sonia.scm.repository.ExtendedChangesetPreProcessor;
import sonia.scm.repository.PathNotFoundException; import sonia.scm.repository.PathNotFoundException;
import sonia.scm.repository.Permission; import sonia.scm.repository.Permission;
import sonia.scm.repository.PermissionType; import sonia.scm.repository.PermissionType;
@@ -113,6 +114,7 @@ public class RepositoryResource
* @param repositoryManager * @param repositoryManager
* @param securityContextProvider * @param securityContextProvider
* @param changesetPreProcessorSet * @param changesetPreProcessorSet
* @param extChangesetPreProcessorSet
* @param changesetViewerUtil * @param changesetViewerUtil
* @param repositoryBrowserUtil * @param repositoryBrowserUtil
*/ */
@@ -121,6 +123,7 @@ public class RepositoryResource
ScmConfiguration configuration, RepositoryManager repositoryManager, ScmConfiguration configuration, RepositoryManager repositoryManager,
Provider<WebSecurityContext> securityContextProvider, Provider<WebSecurityContext> securityContextProvider,
Set<ChangesetPreProcessor> changesetPreProcessorSet, Set<ChangesetPreProcessor> changesetPreProcessorSet,
Set<ExtendedChangesetPreProcessor> extChangesetPreProcessorSet,
ChangesetViewerUtil changesetViewerUtil, ChangesetViewerUtil changesetViewerUtil,
RepositoryBrowserUtil repositoryBrowserUtil) RepositoryBrowserUtil repositoryBrowserUtil)
{ {
@@ -129,6 +132,7 @@ public class RepositoryResource
this.repositoryManager = repositoryManager; this.repositoryManager = repositoryManager;
this.securityContextProvider = securityContextProvider; this.securityContextProvider = securityContextProvider;
this.changesetPreProcessorSet = changesetPreProcessorSet; this.changesetPreProcessorSet = changesetPreProcessorSet;
this.extChangesetPreProcessorSet = extChangesetPreProcessorSet;
this.changesetViewerUtil = changesetViewerUtil; this.changesetViewerUtil = changesetViewerUtil;
this.repositoryBrowserUtil = repositoryBrowserUtil; this.repositoryBrowserUtil = repositoryBrowserUtil;
setDisableCache(false); setDisableCache(false);
@@ -213,7 +217,12 @@ public class RepositoryResource
if (changesets != null) if (changesets != null)
{ {
callPreProcessors(changesets); if (Util.isNotEmpty(changesets.getChangesets()))
{
callPreProcessors(changesets);
callExtendedPreProcessors(id, changesets);
}
response = Response.ok(changesets).build(); response = Response.ok(changesets).build();
} }
else else
@@ -385,6 +394,37 @@ public class RepositoryResource
} }
} }
/**
* Method description
*
*
* @param id
* @param changesets
*/
private void callExtendedPreProcessors(String id,
ChangesetPagingResult changesets)
{
if (Util.isNotEmpty(extChangesetPreProcessorSet))
{
Repository repository = repositoryManager.get(id);
if (repository != null)
{
for (Changeset c : changesets.getChangesets())
{
for (ExtendedChangesetPreProcessor ecpp : extChangesetPreProcessorSet)
{
ecpp.process(repository, c);
}
}
}
else if (logger.isWarnEnabled())
{
logger.warn("could not find repository {}", id);
}
}
}
/** /**
* Method description * Method description
* *
@@ -393,8 +433,7 @@ public class RepositoryResource
*/ */
private void callPreProcessors(ChangesetPagingResult changesets) private void callPreProcessors(ChangesetPagingResult changesets)
{ {
if (Util.isNotEmpty(changesetPreProcessorSet) if (Util.isNotEmpty(changesetPreProcessorSet))
&& Util.isNotEmpty(changesets.getChangesets()))
{ {
for (Changeset c : changesets.getChangesets()) for (Changeset c : changesets.getChangesets())
{ {
@@ -541,6 +580,9 @@ public class RepositoryResource
/** Field description */ /** Field description */
private ScmConfiguration configuration; private ScmConfiguration configuration;
/** Field description */
private Set<ExtendedChangesetPreProcessor> extChangesetPreProcessorSet;
/** Field description */ /** Field description */
private RepositoryBrowserUtil repositoryBrowserUtil; private RepositoryBrowserUtil repositoryBrowserUtil;