This commit is contained in:
Philipp Czora
2018-06-20 14:45:55 +02:00
parent b93b291293
commit 89322a0511

View File

@@ -1,19 +1,19 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* <p>
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* <p>
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 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.
* 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.
*
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
* <p>
* 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
@@ -24,20 +24,15 @@
* 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.
*
* <p>
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository.api;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.cache.CacheManager;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.Feature;
@@ -45,8 +40,6 @@ import sonia.scm.repository.PreProcessorUtil;
import sonia.scm.repository.Repository;
import sonia.scm.repository.spi.RepositoryServiceProvider;
//~--- JDK imports ------------------------------------------------------------
import java.io.Closeable;
import java.io.IOException;
@@ -68,8 +61,6 @@ import java.io.IOException;
* {@link #close()} method.
*
* @author Sebastian Sdorra
* @since 1.17
*
* @apiviz.uses sonia.scm.repository.Feature
* @apiviz.uses sonia.scm.repository.api.Command
* @apiviz.uses sonia.scm.repository.api.BlameCommandBuilder
@@ -85,39 +76,34 @@ import java.io.IOException;
* @apiviz.uses sonia.scm.repository.api.PushCommandBuilder
* @apiviz.uses sonia.scm.repository.api.BundleCommandBuilder
* @apiviz.uses sonia.scm.repository.api.UnbundleCommandBuilder
* @since 1.17
*/
public final class RepositoryService implements Closeable
{
/**
* the logger for RepositoryService
*/
public final class RepositoryService implements Closeable {
private CacheManager cacheManager;
private PreProcessorUtil preProcessorUtil;
private RepositoryServiceProvider provider;
private Repository repository;
private static final Logger logger =
LoggerFactory.getLogger(RepositoryService.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs a new {@link RepositoryService}. This constructor should only
* be called from the {@link RepositoryServiceFactory}.
*
* @param cacheManager cache manager
* @param provider implementation for {@link RepositoryServiceProvider}
* @param repository the repository
* @param cacheManager cache manager
* @param provider implementation for {@link RepositoryServiceProvider}
* @param repository the repository
* @param preProcessorUtil
*/
RepositoryService(CacheManager cacheManager,
RepositoryServiceProvider provider, Repository repository,
PreProcessorUtil preProcessorUtil)
{
RepositoryServiceProvider provider, Repository repository,
PreProcessorUtil preProcessorUtil) {
this.cacheManager = cacheManager;
this.provider = provider;
this.repository = repository;
this.preProcessorUtil = preProcessorUtil;
}
//~--- methods --------------------------------------------------------------
/**
* Closes the connection to the repository and releases all locks
* and resources. This method should be called in a finally block e.g.:
@@ -135,34 +121,24 @@ public final class RepositoryService implements Closeable
* </code></pre>
*/
@Override
public void close()
{
try
{
public void close() {
try {
provider.close();
}
catch (IOException ex)
{
logger.error("cound not close repository service provider", ex);
} catch (IOException ex) {
logger.error("Could not close repository service provider", ex);
}
}
//~--- get methods ----------------------------------------------------------
/**
* The blame command shows changeset information by line for a given file.
*
* @return instance of {@link BlameCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
*/
public BlameCommandBuilder getBlameCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create blame command for repository {}",
repository.getName());
}
public BlameCommandBuilder getBlameCommand() {
logger.debug("create blame command for repository {}",
repository.getName());
return new BlameCommandBuilder(cacheManager, provider.getBlameCommand(),
repository, preProcessorUtil);
@@ -173,15 +149,11 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link BranchesCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
*/
public BranchesCommandBuilder getBranchesCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create branches command for repository {}",
repository.getName());
}
public BranchesCommandBuilder getBranchesCommand() {
logger.debug("create branches command for repository {}",
repository.getName());
return new BranchesCommandBuilder(cacheManager,
provider.getBranchesCommand(), repository);
@@ -192,15 +164,11 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link BrowseCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
*/
public BrowseCommandBuilder getBrowseCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create browse command for repository {}",
repository.getName());
}
public BrowseCommandBuilder getBrowseCommand() {
logger.debug("create browse command for repository {}",
repository.getName());
return new BrowseCommandBuilder(cacheManager, provider.getBrowseCommand(),
repository, preProcessorUtil);
@@ -211,16 +179,12 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link BundleCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
* @since 1.43
*/
public BundleCommandBuilder getBundleCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create bundle command for repository {}",
repository.getName());
}
public BundleCommandBuilder getBundleCommand() {
logger.debug("create bundle command for repository {}",
repository.getName());
return new BundleCommandBuilder(provider.getBundleCommand(), repository);
}
@@ -230,15 +194,11 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link CatCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
*/
public CatCommandBuilder getCatCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create cat command for repository {}",
repository.getName());
}
public CatCommandBuilder getCatCommand() {
logger.debug("create cat command for repository {}",
repository.getName());
return new CatCommandBuilder(provider.getCatCommand());
}
@@ -249,15 +209,11 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link DiffCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
*/
public DiffCommandBuilder getDiffCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create diff command for repository {}",
repository.getName());
}
public DiffCommandBuilder getDiffCommand() {
logger.debug("create diff command for repository {}",
repository.getName());
return new DiffCommandBuilder(provider.getDiffCommand());
}
@@ -266,19 +222,14 @@ public final class RepositoryService implements Closeable
* The incoming command shows new {@link Changeset}s found in a different
* repository location.
*
*
* @return instance of {@link IncomingCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
* @since 1.31
*/
public IncomingCommandBuilder getIncomingCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create incoming command for repository {}",
repository.getName());
}
public IncomingCommandBuilder getIncomingCommand() {
logger.debug("create incoming command for repository {}",
repository.getName());
return new IncomingCommandBuilder(cacheManager,
provider.getIncomingCommand(), repository, preProcessorUtil);
@@ -289,36 +240,27 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link LogCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
*/
public LogCommandBuilder getLogCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create log command for repository {}",
repository.getName());
}
public LogCommandBuilder getLogCommand() {
logger.debug("create log command for repository {}",
repository.getName());
return new LogCommandBuilder(cacheManager, provider.getLogCommand(),
repository, preProcessorUtil);
}
/**
* The outgoing command show changesets not found in a remote repository.
*
* The outgoing command show {@link Changeset}s not found in a remote repository.
*
* @return instance of {@link OutgoingCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
* @since 1.31
*/
public OutgoingCommandBuilder getOutgoingCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create outgoing command for repository {}",
repository.getName());
}
public OutgoingCommandBuilder getOutgoingCommand() {
logger.debug("create outgoing command for repository {}",
repository.getName());
return new OutgoingCommandBuilder(cacheManager,
provider.getOutgoingCommand(), repository, preProcessorUtil);
@@ -329,35 +271,27 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link PullCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
* @since 1.31
*/
public PullCommandBuilder getPullCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create pull command for repository {}",
repository.getName());
}
public PullCommandBuilder getPullCommand() {
logger.debug("create pull command for repository {}",
repository.getName());
return new PullCommandBuilder(provider.getPullCommand(), repository);
}
/**
* The push command push changes to a other repository.
* The push command pushes changes to a other repository.
*
* @return instance of {@link PushCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
* @since 1.31
*/
public PushCommandBuilder getPushCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create push command for repository {}",
repository.getName());
}
public PushCommandBuilder getPushCommand() {
logger.debug("create push command for repository {}",
repository.getName());
return new PushCommandBuilder(provider.getPushCommand());
}
@@ -367,8 +301,7 @@ public final class RepositoryService implements Closeable
*
* @return repository of this service
*/
public Repository getRepository()
{
public Repository getRepository() {
return repository;
}
@@ -377,15 +310,11 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link TagsCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
*/
public TagsCommandBuilder getTagsCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create tags command for repository {}",
repository.getName());
}
public TagsCommandBuilder getTagsCommand() {
logger.debug("create tags command for repository {}",
repository.getName());
return new TagsCommandBuilder(cacheManager, provider.getTagsCommand(),
repository);
@@ -396,16 +325,12 @@ public final class RepositoryService implements Closeable
*
* @return instance of {@link UnbundleCommandBuilder}
* @throws CommandNotSupportedException if the command is not supported
* by the implementation of the repository service provider.
* by the implementation of the repository service provider.
* @since 1.43
*/
public UnbundleCommandBuilder getUnbundleCommand()
{
if (logger.isDebugEnabled())
{
logger.debug("create bundle command for repository {}",
repository.getName());
}
public UnbundleCommandBuilder getUnbundleCommand() {
logger.debug("create unbundle command for repository {}",
repository.getName());
return new UnbundleCommandBuilder(provider.getUnbundleCommand(),
repository);
@@ -414,42 +339,23 @@ public final class RepositoryService implements Closeable
/**
* Returns true if the command is supported by the repository service.
*
*
* @param command command
*
* @return true if the command is supported
*/
public boolean isSupported(Command command)
{
public boolean isSupported(Command command) {
return provider.getSupportedCommands().contains(command);
}
/**
* Returns true if the feature is supported by the repository service.
*
*
* @param feature feature
*
* @return true if the feature is supported
*
* @since 1.25
*/
public boolean isSupported(Feature feature)
{
public boolean isSupported(Feature feature) {
return provider.getSupportedFeatures().contains(feature);
}
//~--- fields ---------------------------------------------------------------
/** cache manager */
private CacheManager cacheManager;
/** Field description */
private PreProcessorUtil preProcessorUtil;
/** implementation of the repository service provider */
private RepositoryServiceProvider provider;
/** the repository */
private Repository repository;
}