public interface

PluginCommandFactory

com.atlassian.stash.scm.PluginCommandFactory
Known Indirect Subclasses

Class Overview

Provides backing functionality for the ScmCommandFactory.

This interface is intended to be implemented by plugin developers. Functionality provided by this interface is intended to be consumed using the ScmCommandFactory exposed by the ScmService. Only the system should ever deal with this interface directly.

All command types on this interface are required to have a working implementation, as this factory describes the basic SCM commands used by the system to provide day-to-day functionality, unless documented otherwise. The following commands are optional:

In addition to these optional commands, ScmFeature#CROSS_REPOSITORY cross-repository support is also optional. Where factory methods accept secondary repositories, with the exception of fork which has its own ScmFeature#FORK feature, SCMs which do not support cross-repository operations should fail fast, throwing an UnsupportedOperationException rather than returning a Command; they should not return a command which throws that exception.

SCM implementations may also provide additional functionality to allow the system to offer enhanced features, such as pull requests. Such functionality is exposed by other interfaces:

SCMs which support additional functionality, or have custom Command types, are encouraged to provide a sub-interface extending from this one exposing that functionality. For example:

     //Extends Command to allow canceling it after it has been called and checking whether it's been canceled.
     public interface CancelableCommand<T> extends Command<T> {
         void cancel();

         boolean isCanceled();
     }

     //Overrides methods on the PluginCommandFactory interface using covariant return types to return the
     //enhanced CancelableCommand instead of simple Command
     public interface MyScmCommandFactory extends PluginCommandFactory {
         @Nonnull
         @Override
         CancelableCommand<List<Blame>> blame(@Nonnull Repository repository,
                                              @Nonnull BlameCommandParameters parameters,
                                              @Nonnull PageRequest pageRequest);

         //Overrides for other methods as appropriate
     }
 
The SCM plugin would then expose the class implementing their custom MyScmCommandFactory using a component directive:
     <!-- Note: This should be in the SCM provider's atlassian-plugin.xml -->
     <component key="myScmCommandFactory"
                class="com.example.DefaultMyScmCommandFactory"
                public="true">
         <interface>com.example.MyScmCommandFactory</interface>
     </component>
 
The public="true" allows other plugins to import the component. This approach allows other plugin developers to import the SCM plugin's command factory and leverage its enhanced functionality with a component-import directive:
     <!-- Note: This should be in the SCM consumer's atlassian-plugin.xml -->
     <component-import key="myScmCommandFactory"
                       interface="com.example.MyScmCommandFactory"/>
 

Summary

Public Methods
@Nonnull Command<List<Blame>> blame(Repository repository, BlameCommandParameters parameters, PageRequest pageRequest)
@Nonnull Command<Page<Branch>> branches(Repository repository, BranchesCommandParameters parameters, PageRequest pageRequest)
@Nonnull Command<Page<Change>> changes(Repository repository, ChangesCommandParameters parameters, PageRequest pageRequest)
@Nonnull Command<Void> changes(Repository repository, ChangesCommandParameters parameters, ChangeCallback callback)
@Nonnull Command<Changeset> commit(Repository repository, CommitCommandParameters parameters)
This method is deprecated. in 3.7 for removal in 4.0. All things "changeset" are being renamed to "commit", the more common term for the data they represent. Owing to Java generics, there is no backward compatible way that change can be applied here. Based on that, this method signature will be changed in 4.0, to return a Command&lt;Commit&gt;. It will not be possible for an SCM to be compatible with both 3.x and 4.x due to this change.
@Deprecated @Nonnull Command<Page<Changeset>> commits(Repository repository, CommitsCommandParameters parameters, PageRequest pageRequest)
This method is deprecated. in 3.7 for removal in 4.0. All things "changeset" are being renamed to "commit", the more common term for the data they represent. Owing to Java generics, there is no backward compatible way that change can be applied here. Based on that, this method signature will be changed in 4.0, to return a Command&lt;Page&lt;Commit&gt;&gt;. It will not be possible for an SCM to be compatible with both 3.x and 4.x due to this change.
@Deprecated @Nonnull Command<Void> commits(Repository repository, CommitsCommandParameters parameters, ChangesetCallback callback)
This method is deprecated. in 3.7 for removal in 4.0. All things "changeset" are being renamed to "commit", the more common term for the data they represent. This method will be replaced by commits(Repository, CommitsCommandParameters, CommitCallback) in 4.0.
@Nonnull Command<Void> create(Repository repository)
Creates and initializes the repository on disk, performing any SCM-specific configuration that is appropriate for new repositories.
@Nonnull Command<Branch> defaultBranch(Repository repository)
@Nonnull AsyncCommand<Void> delete(Repository repository, DeleteCommandParameters parameters)
Deletes the repository, allowing the underlying SCM to carry out any special processing necessary to clean up repository storage.
@Deprecated @Nonnull Command<Page<DetailedChangeset>> detailedCommits(Repository repository, DetailedCommitsCommandParameters parameters, PageRequest pageRequest)
This method is deprecated. in 3.7 for removal in 4.0. All things "changeset" are being renamed to "commit", the more common term for the data they represent, allowing DetailedChangeset to be renamed to what it is: com.atlassian.stash.commit.Changeset Changeset. This method will be replaced by changesets(Repository, ChangesetsCommandParameters, PageRequest) in 4.0.
@Nonnull Command<Void> diff(Repository repository, DiffCommandParameters parameters, DiffContentCallback callback)
@Nonnull Command<Void> directory(Repository repository, DirectoryCommandParameters parameters, ContentTreeCallback callback, PageRequest pageRequest)
@Nonnull Command<Void> file(Repository repository, FileCommandParameters parameters, FileContentCallback callback, PageRequest pageRequest)
@Nonnull Command<Void> fork(Repository repository, Repository fork)
Creates a fork of repository, stored in fork.
@Nonnull Command<Void> heads(Repository repository, RefCallback callback)
@Nonnull Command<Branch> merge(Repository repository, MergeCommandParameters parameters)
Merges the specified fromChangesetId into the specified toBranch.
@Nonnull Command<Void> rawFile(Repository repository, RawFileCommandParameters parameters, TypeAwareOutputSupplier outputSupplier)
@Nonnull Command<Ref> resolveRef(Repository repository, String refId)
@Nonnull Command<Page<Tag>> tags(Repository repository, TagsCommandParameters parameters, PageRequest pageRequest)
Command<Void> traverseCommits(Repository repository, TraversalCallback callback)
Streams all of the commits in the repository in topological order.
@Nonnull Command<ContentTreeNode.Type> type(Repository repository, TypeCommandParameters parameters)
@Nonnull Command<Void> updateDefaultBranch(Repository repository, String branchName)
Set the default branch for the specified repository to the named branch.

Public Methods

@Nonnull public Command<List<Blame>> blame (Repository repository, BlameCommandParameters parameters, PageRequest pageRequest)

@Nonnull public Command<Page<Branch>> branches (Repository repository, BranchesCommandParameters parameters, PageRequest pageRequest)

@Nonnull public Command<Page<Change>> changes (Repository repository, ChangesCommandParameters parameters, PageRequest pageRequest)

@Nonnull public Command<Void> changes (Repository repository, ChangesCommandParameters parameters, ChangeCallback callback)

@Nonnull public Command<Changeset> commit (Repository repository, CommitCommandParameters parameters)

This method is deprecated.
in 3.7 for removal in 4.0. All things "changeset" are being renamed to "commit", the more common term for the data they represent. Owing to Java generics, there is no backward compatible way that change can be applied here. Based on that, this method signature will be changed in 4.0, to return a Command&lt;Commit&gt;. It will not be possible for an SCM to be compatible with both 3.x and 4.x due to this change.

Parameters
repository the repository to retrieve the commit from
parameters parameters describing the commit to retrieve
Returns
  • a command which, when executed, will return the specified commit

@Deprecated @Nonnull public Command<Page<Changeset>> commits (Repository repository, CommitsCommandParameters parameters, PageRequest pageRequest)

This method is deprecated.
in 3.7 for removal in 4.0. All things "changeset" are being renamed to "commit", the more common term for the data they represent. Owing to Java generics, there is no backward compatible way that change can be applied here. Based on that, this method signature will be changed in 4.0, to return a Command&lt;Page&lt;Commit&gt;&gt;. It will not be possible for an SCM to be compatible with both 3.x and 4.x due to this change.

Retrieves a page of commits which match the provided CommitsCommandParameters paramters.

Implementors: SCMs are required to support this operation. However, they are not required to support CommitsCommandParameters#getSecondaryRepository() secondary repositories unless they offer ScmFeature#CROSS_REPOSITORY cross-repository support. If a secondary repository is provided and cross- repository operations are not supported, implementations should throw an UnsupportedOperationException.

Parameters
repository the repository to retrieve commits from
parameters parameters describing the commits to retrieve
pageRequest describes the page of commits to retrieve
Returns
  • a command which, when executed, will retrieve a page of commits
Throws
UnsupportedOperationException if a CommitsCommandParameters#getSecondaryRepository() secondary repository is provided an ScmFeature#CROSS_REPOSITORY cross- repository operations are not supported
See Also
  • ScmFeature#CROSS_REPOSITORY

@Deprecated @Nonnull public Command<Void> commits (Repository repository, CommitsCommandParameters parameters, ChangesetCallback callback)

This method is deprecated.
in 3.7 for removal in 4.0. All things "changeset" are being renamed to "commit", the more common term for the data they represent. This method will be replaced by commits(Repository, CommitsCommandParameters, CommitCallback) in 4.0.

Streams commits which match the provided CommitsCommandParameters paramters to the provided callback.

Implementors: SCMs are required to support this operation. However, they are not required to support CommitsCommandParameters#getSecondaryRepository() secondary repositories unless they offer ScmFeature#CROSS_REPOSITORY cross-repository support. If a secondary repository is provided and cross- repository operations are not supported, implementations should throw an UnsupportedOperationException.

Parameters
repository the repository to retrieve commits from
parameters parameters describing the commits to retrieve
callback a callback to receive the streamed commits
Returns
  • a command which, when executed, will stream commits to the provided callback
Throws
UnsupportedOperationException if a CommitsCommandParameters#getSecondaryRepository() secondary repository is provided an ScmFeature#CROSS_REPOSITORY cross- repository operations are not supported
See Also
  • ScmFeature#CROSS_REPOSITORY

@Nonnull public Command<Void> create (Repository repository)

Creates and initializes the repository on disk, performing any SCM-specific configuration that is appropriate for new repositories. repository does not exist on disk when this method is called. It is expected that the SCM will create it with contents that are appropriate for an empty new repository.

Parameters
repository the repository to create

@Nonnull public Command<Branch> defaultBranch (Repository repository)

@Nonnull public AsyncCommand<Void> delete (Repository repository, DeleteCommandParameters parameters)

Deletes the repository, allowing the underlying SCM to carry out any special processing necessary to clean up repository storage.

Note: By the time this method is called, the repository has already been deleted from the database, and the associated database transaction has been committed.

Warning: This method is irreversible. It should never be called by a plugin. It is intended solely for use by the system.

Parameters
repository the repository to delete
parameters additional parameters, such as IDs for forks of the deleted repository
Returns
  • a command which, when executed, will delete the repository's storage

@Deprecated @Nonnull public Command<Page<DetailedChangeset>> detailedCommits (Repository repository, DetailedCommitsCommandParameters parameters, PageRequest pageRequest)

This method is deprecated.
in 3.7 for removal in 4.0. All things "changeset" are being renamed to "commit", the more common term for the data they represent, allowing DetailedChangeset to be renamed to what it is: com.atlassian.stash.commit.Changeset Changeset. This method will be replaced by changesets(Repository, ChangesetsCommandParameters, PageRequest) in 4.0.

Parameters
repository the repository to retreive the changesets from
parameters parameters describing the changesets to retrieve
pageRequest describes the page of changesets to retrieve
Returns
  • the requested page of DetailedChangeset changesets

@Nonnull public Command<Void> diff (Repository repository, DiffCommandParameters parameters, DiffContentCallback callback)

@Nonnull public Command<Void> directory (Repository repository, DirectoryCommandParameters parameters, ContentTreeCallback callback, PageRequest pageRequest)

@Nonnull public Command<Void> file (Repository repository, FileCommandParameters parameters, FileContentCallback callback, PageRequest pageRequest)

@Nonnull public Command<Void> fork (Repository repository, Repository fork)

Creates a fork of repository, stored in fork. Similar to creating a repository, fork does not exist on disk when this method is called. It is expected that the SCM will create it with contents based on repository, which becomes its origin.

Implementors: This operation is optional. Implementations which do not support forking should throw an UnsupportedOperationException and omit the ScmFeature#FORK FORK feature.

Parameters
repository the repository to be forked
fork the fork
Throws
UnsupportedOperationException if forking is not a supported feature
See Also
  • ScmFeature#FORK

@Nonnull public Command<Void> heads (Repository repository, RefCallback callback)

@Nonnull public Command<Branch> merge (Repository repository, MergeCommandParameters parameters)

Merges the specified fromChangesetId into the specified toBranch.

SCMs are required to support the following values for fromChangesetId:

  • A 40-byte hash (Note: Short hashes are not supported)
  • A fully-qualified branch name
  • A short branch name
toBranch, as the parameter name suggests, must be a branch name, either fully qualified or short, and the SCM should validate that that is the case; using a hash (full or short) is not supported.

Implementors: This feature is optional. Implementations which do not support merging should throw an UnsupportedOperationException and omit the ScmFeature#MERGE MERGE feature. Additionally, SCMs which support merging are not required to support MergeCommandParameters#getFromRepository() different source repositories unless they offer ScmFeature#CROSS_REPOSITORY cross-repository support. If a different from source repository is provided and cross-repository operations are not supported, implementations should throw an UnsupportedOperationException.

Parameters
repository the repository containing both the source changeset and the target branch
Returns
  • a command to merge the specified branch into the target branch
Throws
UnsupportedOperationException if a MergeCommandParameters#getFromRepository() source repository is specified and ScmFeature#CROSS_REPOSITORY cross-repository operations are not supported
See Also
  • ScmFeature#CROSS_REPOSITORY
  • ScmFeature#MERGE

@Nonnull public Command<Void> rawFile (Repository repository, RawFileCommandParameters parameters, TypeAwareOutputSupplier outputSupplier)

@Nonnull public Command<Ref> resolveRef (Repository repository, String refId)

@Nonnull public Command<Page<Tag>> tags (Repository repository, TagsCommandParameters parameters, PageRequest pageRequest)

public Command<Void> traverseCommits (Repository repository, TraversalCallback callback)

Streams all of the commits in the repository in topological order. Topological order means no parent is output before all of its descendants have been output. It does not require that descendants be streamed in date order, but SCMs may optionally do so (so long as topological order is retained).

Parameters
repository the repository to traverse commits for
callback the callback to receive the streamed commits
Returns
  • a command which, when executed, will stream all of the commits in the repository, topologically ordered

@Nonnull public Command<ContentTreeNode.Type> type (Repository repository, TypeCommandParameters parameters)

@Nonnull public Command<Void> updateDefaultBranch (Repository repository, String branchName)

Set the default branch for the specified repository to the named branch.

Implementors: This feature is optional. Implementations which do not support updating the default branch should throw an UnsupportedOperationException and omit the ScmFeature#UPDATE_DEFAULT_BRANCH UPDATE_DEFAULT_BRANCH feature.

Parameters
repository the repository whose default branch should be updated
branchName the branch to make the default
Returns
  • a command which will update the default branch
Throws
IllegalArgumentException if the provided branchName is null or blank.
UnsupportedOperationException if the underlying SCM does not support setting the default branch.
See Also
  • ScmFeature#UPDATE_DEFAULT_BRANCH