Class RepositoryService

java.lang.Object
sonia.scm.repository.api.RepositoryService
All Implemented Interfaces:
Closeable, AutoCloseable

public final class RepositoryService extends Object implements Closeable
From the RepositoryService it is possible to access all commands for a single Repository. The RepositoryService is only access able from the RepositoryServiceFactory.

Note: Not every RepositoryService supports every command. If the command is not supported the method will trow a CommandNotSupportedException. It is possible to check if the command is supported by the RepositoryService with the isSupported(Command) method.

Warning: You should always close the connection to the repository after work is finished. For closing the connection to the repository use the close() method.
Since:
1.17
  • Method Details

    • close

      public void close()
      Closes the connection to the repository and releases all locks and resources. This method should be called in a finally block e.g.:
      
       RepositoryService service = null;
       try {
         service = factory.create("repositoryId");
         // do something with the service
       } finally {
         if ( service != null ){
           service.close();
         }
       }
       
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getBlameCommand

      public BlameCommandBuilder getBlameCommand()
      The blame command shows changeset information by line for a given file.
      Returns:
      instance of BlameCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getBranchesCommand

      public BranchesCommandBuilder getBranchesCommand()
      The branches command list all repository branches.
      Returns:
      instance of BranchesCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getBranchCommand

      public BranchCommandBuilder getBranchCommand()
      The branch command creates new branches.
      Returns:
      instance of BranchCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getBrowseCommand

      public BrowseCommandBuilder getBrowseCommand()
      The browse command allows browsing of a repository.
      Returns:
      instance of BrowseCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getBundleCommand

      public BundleCommandBuilder getBundleCommand()
      The bundle command creates an archive from the repository.
      Returns:
      instance of BundleCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      1.43
    • getCatCommand

      public CatCommandBuilder getCatCommand()
      The cat command show the content of a given file.
      Returns:
      instance of CatCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getDiffCommand

      public DiffCommandBuilder getDiffCommand()
      The diff command shows differences between revisions for a specified file or the entire revision.
      Returns:
      instance of DiffCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getDiffResultCommand

      public DiffResultCommandBuilder getDiffResultCommand()
      The diff command shows differences between revisions for a specified file or the entire revision.
      Returns:
      instance of DiffResultCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getIncomingCommand

      public IncomingCommandBuilder getIncomingCommand()
      The incoming command shows new Changesets found in a different repository location.
      Returns:
      instance of IncomingCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      1.31
    • getLogCommand

      public LogCommandBuilder getLogCommand()
      The log command shows revision history of entire repository or files.
      Returns:
      instance of LogCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getModificationsCommand

      public ModificationsCommandBuilder getModificationsCommand()
      The modification command shows file modifications in a revision.
      Returns:
      instance of ModificationsCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getOutgoingCommand

      public OutgoingCommandBuilder getOutgoingCommand()
      The outgoing command show Changesets not found in a remote repository.
      Returns:
      instance of OutgoingCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      1.31
    • getPullCommand

      public PullCommandBuilder getPullCommand()
      The pull command pull changes from a other repository.
      Returns:
      instance of PullCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      1.31
    • getPushCommand

      public PushCommandBuilder getPushCommand()
      The push command pushes changes to a other repository.
      Returns:
      instance of PushCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      1.31
    • getRepository

      public Repository getRepository()
      Returns the repository of this service.
      Returns:
      repository of this service
    • getTagsCommand

      public TagsCommandBuilder getTagsCommand()
      The tags command list all repository tag.
      Returns:
      instance of TagsCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getTagCommand

      public TagCommandBuilder getTagCommand()
      The tag command allows the management of repository tags.
      Returns:
      instance of TagCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
    • getUnbundleCommand

      public UnbundleCommandBuilder getUnbundleCommand()
      The unbundle command restores a repository from the given bundle.
      Returns:
      instance of UnbundleCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      1.43
    • getMergeCommand

      public MergeCommandBuilder getMergeCommand()
      The merge command executes a merge of two branches. It is possible to do a dry run to check, whether the given branches can be merged without conflicts.
      Returns:
      instance of MergeCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      2.0.0
    • getModifyCommand

      public ModifyCommandBuilder getModifyCommand()
      The modify command makes changes to the head of a branch. It is possible to
      • create new files
      • delete existing files
      • modify/replace files
      • move files
      Returns:
      instance of ModifyCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      2.0.0
    • getLookupCommand

      public LookupCommandBuilder getLookupCommand()
      The lookup command executes a lookup which returns additional information for the repository.
      Returns:
      instance of LookupCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      2.10.0
    • getFullCheckCommand

      public FullHealthCheckCommandBuilder getFullCheckCommand()
      The full health check command inspects a repository in a way, that might take a while in contrast to the light checks executed at startup.
      Returns:
      instance of FullHealthCheckCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      2.17.0
    • getMirrorCommand

      public MirrorCommandBuilder getMirrorCommand()
      The mirror command creates a 'mirror' of an existing repository (specified by a URL) by copying all data to the repository of this service. Therefore this repository has to be empty (otherwise the behaviour is not specified).
      Returns:
      instance of MirrorCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      2.19.0
    • getLockCommand

      public FileLockCommandBuilder getLockCommand()
      Lock and unlock files.
      Returns:
      instance of FileLockCommandBuilder
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      2.26.0
    • getBranchDetailsCommand

      public BranchDetailsCommandBuilder getBranchDetailsCommand()
      Get details for a branch.
      Returns:
      instance of BranchDetailsCommand
      Throws:
      CommandNotSupportedException - if the command is not supported by the implementation of the repository service provider.
      Since:
      2.28.0
    • getChangesetsCommand

      public ChangesetsCommandBuilder getChangesetsCommand()
    • isSupported

      public boolean isSupported(Command command)
      Returns true if the command is supported by the repository service.
      Parameters:
      command - command
      Returns:
      true if the command is supported
    • isSupported

      public boolean isSupported(Feature feature)
      Returns true if the feature is supported by the repository service.
      Parameters:
      feature - feature
      Returns:
      true if the feature is supported
      Since:
      1.25
    • getSupportedProtocols

      public Stream<ScmProtocol> getSupportedProtocols()
    • getProtocol

      public <T extends ScmProtocol> T getProtocol(Class<T> clazz)