diff --git a/scm-core/src/main/java/sonia/scm/repository/ChangesetPreProcessor.java b/scm-core/src/main/java/sonia/scm/repository/ChangesetPreProcessor.java index 3e6db77967..5c3b064c85 100644 --- a/scm-core/src/main/java/sonia/scm/repository/ChangesetPreProcessor.java +++ b/scm-core/src/main/java/sonia/scm/repository/ChangesetPreProcessor.java @@ -40,7 +40,9 @@ import sonia.scm.plugin.ExtensionPoint; /** * * @author Sebastian Sdorra + * @deprecated use {@link ExtendedChangesetPreProcessor} instead. */ +@Deprecated @ExtensionPoint public interface ChangesetPreProcessor { diff --git a/scm-core/src/main/java/sonia/scm/repository/ExtendedChangesetPreProcessor.java b/scm-core/src/main/java/sonia/scm/repository/ExtendedChangesetPreProcessor.java new file mode 100644 index 0000000000..7c8db8be59 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/ExtendedChangesetPreProcessor.java @@ -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); +} diff --git a/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java b/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java index be49d54df7..741da9961d 100644 --- a/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java +++ b/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java @@ -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 changesetPreProcessorBinder = Multibinder.newSetBinder(binder, ChangesetPreProcessor.class); + Multibinder 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()) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index 5d440269f6..1d346d4f87 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -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 securityContextProvider, Set changesetPreProcessorSet, + Set 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); @@ -213,7 +217,12 @@ public class RepositoryResource if (changesets != null) { - callPreProcessors(changesets); + 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 extChangesetPreProcessorSet; + /** Field description */ private RepositoryBrowserUtil repositoryBrowserUtil;