From d84c3ae03a799752e551410440e65f96e1289d4e Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 24 Jun 2012 14:29:20 +0200 Subject: [PATCH] added api for blame pre processors --- .../scm/repository/BlameLinePreProcessor.java | 44 ++++++++++++ .../BlameLinePreProcessorFactory.java | 45 ++++++++++++ .../sonia/scm/repository/BlameResult.java | 5 +- .../java/sonia/scm/repository/EscapeUtil.java | 47 ++++++++++-- .../scm/repository/PreProcessorUtil.java | 72 +++++++++++++++++-- 5 files changed, 201 insertions(+), 12 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/repository/BlameLinePreProcessor.java create mode 100644 scm-core/src/main/java/sonia/scm/repository/BlameLinePreProcessorFactory.java diff --git a/scm-core/src/main/java/sonia/scm/repository/BlameLinePreProcessor.java b/scm-core/src/main/java/sonia/scm/repository/BlameLinePreProcessor.java new file mode 100644 index 0000000000..18a78355fc --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/BlameLinePreProcessor.java @@ -0,0 +1,44 @@ +/** + * 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.17 + */ +@ExtensionPoint +public interface BlameLinePreProcessor extends PreProcessor {} diff --git a/scm-core/src/main/java/sonia/scm/repository/BlameLinePreProcessorFactory.java b/scm-core/src/main/java/sonia/scm/repository/BlameLinePreProcessorFactory.java new file mode 100644 index 0000000000..7d529e487c --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/BlameLinePreProcessorFactory.java @@ -0,0 +1,45 @@ +/** + * 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.17 + */ +@ExtensionPoint +public interface BlameLinePreProcessorFactory + extends PreProcessorFactory {} diff --git a/scm-core/src/main/java/sonia/scm/repository/BlameResult.java b/scm-core/src/main/java/sonia/scm/repository/BlameResult.java index a1ef0db44c..08b6664ac3 100644 --- a/scm-core/src/main/java/sonia/scm/repository/BlameResult.java +++ b/scm-core/src/main/java/sonia/scm/repository/BlameResult.java @@ -48,8 +48,9 @@ import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; /** - * Class description - * + * Changeset information by line for a given file. + * + * TODO for 2.0 implement {@link Iterable} * * @author Sebastian Sdorra * @since 1.8 diff --git a/scm-core/src/main/java/sonia/scm/repository/EscapeUtil.java b/scm-core/src/main/java/sonia/scm/repository/EscapeUtil.java index e3d41c4f1c..b4e85faac0 100644 --- a/scm-core/src/main/java/sonia/scm/repository/EscapeUtil.java +++ b/scm-core/src/main/java/sonia/scm/repository/EscapeUtil.java @@ -30,6 +30,7 @@ */ + package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- @@ -69,6 +70,34 @@ public class EscapeUtil } } + /** + * Method description + * + * + * @param result + * @since 1.17 + */ + public static void escape(BlameResult result) + { + for (BlameLine line : result.getBlameLines()) + { + escape(line); + } + } + + /** + * Method description + * + * + * @param line + * @since 1.17 + */ + public static void escape(BlameLine line) + { + line.setDescription(escape(line.getDescription())); + escape(line.getAuthor()); + } + /** * Method description * @@ -91,17 +120,25 @@ public class EscapeUtil public static void escape(Changeset changeset) { changeset.setDescription(escape(changeset.getDescription())); + escape(changeset.getAuthor()); + changeset.setBranches(escapeList(changeset.getBranches())); + changeset.setTags(escapeList(changeset.getTags())); + } - Person person = changeset.getAuthor(); - + /** + * Method description + * + * + * @param person + * @since 1.17 + */ + public static void escape(Person person) + { if (person != null) { person.setName(escape(person.getName())); person.setMail(escape(person.getMail())); } - - changeset.setBranches(escapeList(changeset.getBranches())); - changeset.setTags(escapeList(changeset.getTags())); } /** diff --git a/scm-core/src/main/java/sonia/scm/repository/PreProcessorUtil.java b/scm-core/src/main/java/sonia/scm/repository/PreProcessorUtil.java index f9251e8f38..0de4157159 100644 --- a/scm-core/src/main/java/sonia/scm/repository/PreProcessorUtil.java +++ b/scm-core/src/main/java/sonia/scm/repository/PreProcessorUtil.java @@ -71,13 +71,17 @@ public class PreProcessorUtil * @param changesetPreProcessorFactorySet * @param fileObjectPreProcessorSet * @param fileObjectPreProcessorFactorySet + * @param blameLinePreProcessorSet + * @param blameLinePreProcessorFactorySet */ @Inject public PreProcessorUtil( Set changesetPreProcessorSet, Set changesetPreProcessorFactorySet, Set fileObjectPreProcessorSet, - Set fileObjectPreProcessorFactorySet) + Set fileObjectPreProcessorFactorySet, + Set blameLinePreProcessorSet, + Set blameLinePreProcessorFactorySet) { this.changesetPreProcessorSet = Collections2.transform(changesetPreProcessorSet, @@ -125,10 +129,62 @@ public class PreProcessorUtil return new FileObjectPreProcessorFactoryWrapper(input); } }); + this.blameLinePreProcessorSet = blameLinePreProcessorSet; + this.blameLinePreProcessorFactorySet = blameLinePreProcessorFactorySet; } //~--- methods -------------------------------------------------------------- + /** + * Method description + * + * + * @param repository + * @param blameLine + */ + public void prepareForReturn(Repository repository, BlameLine blameLine) + { + if (logger.isTraceEnabled()) + { + logger.trace("prepare blame line {} of repository {} for return", + blameLine.getLineNumber(), repository.getName()); + } + + EscapeUtil.escape(blameLine); + + PreProcessorHandler handler = + new PreProcessorHandler(blameLinePreProcessorFactorySet, + blameLinePreProcessorSet, repository); + + handler.callPreProcessors(blameLine); + handler.callPreProcessorFactories(blameLine); + } + + /** + * Method description + * + * + * @param repository + * @param blameResult + */ + public void prepareForReturn(Repository repository, BlameResult blameResult) + { + if (logger.isTraceEnabled()) + { + logger.trace("prepare blame result of repository {} for return", + repository.getName()); + } + + EscapeUtil.escape(blameResult); + + PreProcessorHandler handler = + new PreProcessorHandler(blameLinePreProcessorFactorySet, + blameLinePreProcessorSet, repository); + + handler.callPreProcessors(blameResult.getBlameLines()); + handler.callPreProcessorFactories(blameResult.getBlameLines()); + } + /** * Method description * @@ -213,7 +269,7 @@ public class PreProcessorUtil * * * @version Enter version here..., 12/06/16 - * @author Enter your name here... + * @author Enter your name here... */ private static class ChangesetPreProcessorFactoryWrapper implements PreProcessorFactory @@ -268,7 +324,7 @@ public class PreProcessorUtil * * * @version Enter version here..., 12/06/16 - * @author Enter your name here... + * @author Enter your name here... */ private static class ChangesetPreProcessorWrapper implements PreProcessor @@ -311,7 +367,7 @@ public class PreProcessorUtil * * * @version Enter version here..., 12/06/16 - * @author Enter your name here... + * @author Enter your name here... */ private static class FileObjectPreProcessorFactoryWrapper implements PreProcessorFactory @@ -367,7 +423,7 @@ public class PreProcessorUtil * * * @version Enter version here..., 12/06/16 - * @author Enter your name here... + * @author Enter your name here... */ private static class FileObjectPreProcessorWrapper implements PreProcessor @@ -551,6 +607,12 @@ public class PreProcessorUtil //~--- fields --------------------------------------------------------------- + /** Field description */ + private Collection blameLinePreProcessorFactorySet; + + /** Field description */ + private Collection blameLinePreProcessorSet; + /** Field description */ private Collection changesetPreProcessorFactorySet;