apply patch for blame support from naver.com

This commit is contained in:
Sebastian Sdorra
2011-09-14 11:13:14 +02:00
parent b75d8c8a0d
commit 8dc56330c2
14 changed files with 1158 additions and 4 deletions

View File

@@ -186,6 +186,20 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repository
*
* @return
*/
@Override
public BlameViewer getBlameViewer(Repository repository)
{
return null;
}
/**
* Method description
*

View File

@@ -0,0 +1,206 @@
/**
* 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;
//~--- JDK imports ------------------------------------------------------------
import java.util.Date;
/**
* Class description
*
*
* @version Enter version here..., 11/09/14
* @author Enter your name here...
*/
public class BlameLine
{
/**
* Constructs ...
*
*/
public BlameLine() {}
/**
* Constructs ...
*
*
* @param emailAddress
* @param name
* @param when
* @param code
* @param lineNumber
*/
public BlameLine(String emailAddress, String name, Date when, String code,
int lineNumber)
{
this.emailAddress = emailAddress;
this.name = name;
this.when = when;
this.code = code;
this.lineNumber = lineNumber;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getCode()
{
return code;
}
/**
* Method description
*
*
* @return
*/
public String getEmailAddress()
{
return emailAddress;
}
/**
* Method description
*
*
* @return
*/
public int getLineNumber()
{
return lineNumber;
}
/**
* Method description
*
*
* @return
*/
public String getName()
{
return name;
}
/**
* Method description
*
*
* @return
*/
public Date getWhen()
{
return when;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param code
*/
public void setCode(String code)
{
this.code = code;
}
/**
* Method description
*
*
* @param emailAddress
*/
public void setEmailAddress(String emailAddress)
{
this.emailAddress = emailAddress;
}
/**
* Method description
*
*
* @param lineNumber
*/
public void setLineNumber(int lineNumber)
{
this.lineNumber = lineNumber;
}
/**
* Method description
*
*
* @param name
*/
public void setName(String name)
{
this.name = name;
}
/**
* Method description
*
*
* @param when
*/
public void setWhen(Date when)
{
this.when = when;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String code;
/** Field description */
private String emailAddress;
/** Field description */
private int lineNumber;
/** Field description */
private String name;
/** Field description */
private Date when;
}

View File

@@ -0,0 +1,134 @@
/**
* 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;
//~--- JDK imports ------------------------------------------------------------
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class description
*
*
* @version Enter version here..., 11/09/14
* @author Enter your name here...
*/
@XmlRootElement(name = "blame-paging")
@XmlAccessorType(XmlAccessType.FIELD)
public class BlamePagingResult
{
/**
* Constructs ...
*
*/
public BlamePagingResult() {}
/**
* Constructs ...
*
*
* @param total
* @param blameLines
*/
public BlamePagingResult(int total, List<BlameLine> blameLines)
{
this.total = total;
this.blameLines = blameLines;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public List<BlameLine> getBlameLines()
{
return blameLines;
}
/**
* Method description
*
*
* @return
*/
public int getTotal()
{
return total;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param blameLines
*/
public void setBlameLines(List<BlameLine> blameLines)
{
this.blameLines = blameLines;
}
/**
* Method description
*
*
* @param total
*/
public void setTotal(int total)
{
this.total = total;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
@XmlElement(name = "blameline")
@XmlElementWrapper(name = "blamelines")
private List<BlameLine> blameLines;
/** Field description */
private int total;
}

View File

@@ -0,0 +1,56 @@
/**
* 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;
/**
* Interface description
*
*
* @version Enter version here..., 11/09/14
* @author Enter your name here...
*/
public interface BlameViewer
{
/**
* Method description
*
*
* @param revision
* @param path
*
* @return
*/
public BlamePagingResult getBlame(String revision, String path);
}

View File

@@ -0,0 +1,285 @@
/**
* 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 com.google.inject.Inject;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.NotSupportedFeatuerException;
import sonia.scm.cache.Cache;
import sonia.scm.cache.CacheManager;
import sonia.scm.util.AssertUtil;
/**
* Class description
*
*
* @version Enter version here..., 11/09/14
* @author Enter your name here...
*/
@Singleton
public class BlameViewerUtil extends CacheClearHook
{
/** Field description */
public static final String CACHE_NAME = "sonia.cache.repository.blame";
/** the logger for BlameViewerUtil */
private static final Logger logger =
LoggerFactory.getLogger(BlameViewerUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param repositoryManager
* @param cacheManager
* @return
*/
@Inject
public BlameViewerUtil(RepositoryManager repositoryManager,
CacheManager cacheManager)
{
this.repositoryManager = repositoryManager;
this.cache = cacheManager.getCache(BlameViewerCacheKey.class,
BlamePagingResult.class, CACHE_NAME);
init(repositoryManager, cache);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repositoryId
* @param revision
* @param path
*
* @return
*
* @throws NotSupportedFeatuerException
* @throws RepositoryException
*/
public BlamePagingResult getBlame(String repositoryId, String revision,
String path)
throws RepositoryException, NotSupportedFeatuerException
{
AssertUtil.assertIsNotEmpty(repositoryId);
Repository repository = repositoryManager.get(repositoryId);
if (repository == null)
{
throw new RepositoryNotFoundException(
"could not find repository with id ".concat(repositoryId));
}
return getBlame(repository, revision, path);
}
/**
* Method description
*
*
* @param repository
* @param revision
* @param path
*
* @return
*
* @throws NotSupportedFeatuerException
* @throws RepositoryException
*/
public BlamePagingResult getBlame(Repository repository, String revision,
String path)
throws RepositoryException, NotSupportedFeatuerException
{
AssertUtil.assertIsNotNull(repository);
BlameViewer viewer = repositoryManager.getBlameViewer(repository);
if (viewer == null)
{
throw new NotSupportedFeatuerException(
"BlameViewer is not supported for type ".concat(
repository.getType()));
}
BlameViewerCacheKey key = new BlameViewerCacheKey(repository.getId(),
revision, path);
BlamePagingResult result = cache.get(key);
if (result == null)
{
result = viewer.getBlame(revision, path);
cache.put(key, result);
}
else if (logger.isDebugEnabled())
{
logger.debug("fetch blameviewer results from cache");
}
return result;
}
//~--- inner classes --------------------------------------------------------
/**
* Class description
*
*
* @version Enter version here...
* @author Enter your name here...
*/
private static class BlameViewerCacheKey
{
/**
* Constructs ...
*
*
* @param repositoryId
* @param revision
* @param path
*/
public BlameViewerCacheKey(String repositoryId, String revision,
String path)
{
this.repositoryId = repositoryId;
this.revision = revision;
this.path = path;
}
//~--- methods ------------------------------------------------------------
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final BlameViewerCacheKey other = (BlameViewerCacheKey) obj;
if ((this.repositoryId == null)
? (other.repositoryId != null)
: !this.repositoryId.equals(other.repositoryId))
{
return false;
}
if ((this.revision == null)
? (other.revision != null)
: !this.revision.equals(other.revision))
{
return false;
}
if ((this.path == null)
? (other.path != null)
: !this.path.equals(other.path))
{
return false;
}
return true;
}
/**
* Method description
*
*
* @return
*/
@Override
public int hashCode()
{
int hash = 3;
hash = 53 * hash + ((this.repositoryId != null)
? this.repositoryId.hashCode()
: 0);
hash = 53 * hash + ((this.revision != null)
? this.revision.hashCode()
: 0);
hash = 53 * hash + ((this.path != null)
? this.path.hashCode()
: 0);
return hash;
}
//~--- fields -------------------------------------------------------------
/** Field description */
private String path;
/** Field description */
private String repositoryId;
/** Field description */
private String revision;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Cache<BlameViewerCacheKey, BlamePagingResult> cache;
/** Field description */
private RepositoryManager repositoryManager;
}

View File

@@ -63,6 +63,19 @@ public interface RepositoryHandler
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repository
*
* @return
*
* @throws RepositoryException
*/
public BlameViewer getBlameViewer(Repository repository)
throws RepositoryException;
/**
* Method description
*

View File

@@ -64,6 +64,19 @@ public interface RepositoryManager
*/
public Repository get(String type, String name);
/**
* Method description
*
*
*
* @param repository
* @return null if BlameViewer is not supported
*
* @throws RepositoryException
*/
public BlameViewer getBlameViewer(Repository repository)
throws RepositoryException;
/**
* Method description
*