mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
improve changeset preprocessor api
This commit is contained in:
@@ -40,7 +40,9 @@ import sonia.scm.plugin.ExtensionPoint;
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @deprecated use {@link ExtendedChangesetPreProcessor} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@ExtensionPoint
|
||||
public interface ChangesetPreProcessor
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import sonia.scm.io.FileSystem;
|
||||
import sonia.scm.plugin.ext.Extension;
|
||||
import sonia.scm.plugin.ext.ExtensionProcessor;
|
||||
import sonia.scm.repository.ChangesetPreProcessor;
|
||||
import sonia.scm.repository.ExtendedChangesetPreProcessor;
|
||||
import sonia.scm.repository.RepositoryHandler;
|
||||
import sonia.scm.repository.RepositoryHook;
|
||||
import sonia.scm.repository.RepositoryListener;
|
||||
@@ -105,6 +106,8 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
Multibinder.newSetBinder(binder, ResourceHandler.class);
|
||||
Multibinder<ChangesetPreProcessor> changesetPreProcessorBinder =
|
||||
Multibinder.newSetBinder(binder, ChangesetPreProcessor.class);
|
||||
Multibinder<ExtendedChangesetPreProcessor> extChangesetPreProcessorBinder =
|
||||
Multibinder.newSetBinder(binder, ExtendedChangesetPreProcessor.class);
|
||||
|
||||
authenticators.addBinding().to(XmlAuthenticationHandler.class);
|
||||
|
||||
@@ -212,6 +215,17 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
|
||||
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))
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
|
||||
@@ -49,6 +49,7 @@ import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.ChangesetPreProcessor;
|
||||
import sonia.scm.repository.ChangesetViewerUtil;
|
||||
import sonia.scm.repository.ExtendedChangesetPreProcessor;
|
||||
import sonia.scm.repository.PathNotFoundException;
|
||||
import sonia.scm.repository.Permission;
|
||||
import sonia.scm.repository.PermissionType;
|
||||
@@ -113,6 +114,7 @@ public class RepositoryResource
|
||||
* @param repositoryManager
|
||||
* @param securityContextProvider
|
||||
* @param changesetPreProcessorSet
|
||||
* @param extChangesetPreProcessorSet
|
||||
* @param changesetViewerUtil
|
||||
* @param repositoryBrowserUtil
|
||||
*/
|
||||
@@ -121,6 +123,7 @@ public class RepositoryResource
|
||||
ScmConfiguration configuration, RepositoryManager repositoryManager,
|
||||
Provider<WebSecurityContext> securityContextProvider,
|
||||
Set<ChangesetPreProcessor> changesetPreProcessorSet,
|
||||
Set<ExtendedChangesetPreProcessor> extChangesetPreProcessorSet,
|
||||
ChangesetViewerUtil changesetViewerUtil,
|
||||
RepositoryBrowserUtil repositoryBrowserUtil)
|
||||
{
|
||||
@@ -129,6 +132,7 @@ public class RepositoryResource
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.securityContextProvider = securityContextProvider;
|
||||
this.changesetPreProcessorSet = changesetPreProcessorSet;
|
||||
this.extChangesetPreProcessorSet = extChangesetPreProcessorSet;
|
||||
this.changesetViewerUtil = changesetViewerUtil;
|
||||
this.repositoryBrowserUtil = repositoryBrowserUtil;
|
||||
setDisableCache(false);
|
||||
@@ -212,8 +216,13 @@ public class RepositoryResource
|
||||
start, limit);
|
||||
|
||||
if (changesets != null)
|
||||
{
|
||||
if (Util.isNotEmpty(changesets.getChangesets()))
|
||||
{
|
||||
callPreProcessors(changesets);
|
||||
callExtendedPreProcessors(id, changesets);
|
||||
}
|
||||
|
||||
response = Response.ok(changesets).build();
|
||||
}
|
||||
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
|
||||
*
|
||||
@@ -393,8 +433,7 @@ public class RepositoryResource
|
||||
*/
|
||||
private void callPreProcessors(ChangesetPagingResult changesets)
|
||||
{
|
||||
if (Util.isNotEmpty(changesetPreProcessorSet)
|
||||
&& Util.isNotEmpty(changesets.getChangesets()))
|
||||
if (Util.isNotEmpty(changesetPreProcessorSet))
|
||||
{
|
||||
for (Changeset c : changesets.getChangesets())
|
||||
{
|
||||
@@ -541,6 +580,9 @@ public class RepositoryResource
|
||||
/** Field description */
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private Set<ExtendedChangesetPreProcessor> extChangesetPreProcessorSet;
|
||||
|
||||
/** Field description */
|
||||
private RepositoryBrowserUtil repositoryBrowserUtil;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user