mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
added api for blame pre processors
This commit is contained in:
@@ -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<BlameLine> {}
|
||||
@@ -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<BlameLine> {}
|
||||
@@ -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
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,13 +71,17 @@ public class PreProcessorUtil
|
||||
* @param changesetPreProcessorFactorySet
|
||||
* @param fileObjectPreProcessorSet
|
||||
* @param fileObjectPreProcessorFactorySet
|
||||
* @param blameLinePreProcessorSet
|
||||
* @param blameLinePreProcessorFactorySet
|
||||
*/
|
||||
@Inject
|
||||
public PreProcessorUtil(
|
||||
Set<ChangesetPreProcessor> changesetPreProcessorSet,
|
||||
Set<ChangesetPreProcessorFactory> changesetPreProcessorFactorySet,
|
||||
Set<FileObjectPreProcessor> fileObjectPreProcessorSet,
|
||||
Set<FileObjectPreProcessorFactory> fileObjectPreProcessorFactorySet)
|
||||
Set<FileObjectPreProcessorFactory> fileObjectPreProcessorFactorySet,
|
||||
Set<BlameLinePreProcessor> blameLinePreProcessorSet,
|
||||
Set<BlameLinePreProcessorFactory> 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<BlameLine> handler =
|
||||
new PreProcessorHandler<BlameLine>(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<BlameLine> handler =
|
||||
new PreProcessorHandler<BlameLine>(blameLinePreProcessorFactorySet,
|
||||
blameLinePreProcessorSet, repository);
|
||||
|
||||
handler.callPreProcessors(blameResult.getBlameLines());
|
||||
handler.callPreProcessorFactories(blameResult.getBlameLines());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -551,6 +607,12 @@ public class PreProcessorUtil
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Collection<BlameLinePreProcessorFactory> blameLinePreProcessorFactorySet;
|
||||
|
||||
/** Field description */
|
||||
private Collection<BlameLinePreProcessor> blameLinePreProcessorSet;
|
||||
|
||||
/** Field description */
|
||||
private Collection<ChangesetPreProcessorFactoryWrapper> changesetPreProcessorFactorySet;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user