public interface

PluginCommandFactory

com.atlassian.stash.scm.PluginCommandFactory

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. 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.

For SCMs which support additional functionality, or have custom Command types, it is encouraged for them 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<Void> changes(Repository repository, ChangesCommandParameters parameters, ChangeCallback callback)
@Nonnull Command<Page<Change>> changes(Repository repository, ChangesCommandParameters parameters, PageRequest pageRequest)
@Nonnull Command<Changeset> commit(Repository repository, CommitCommandParameters parameters)
@Nonnull Command<Page<Changeset>> commits(Repository repository, CommitsCommandParameters parameters, PageRequest pageRequest)
@Nonnull Command<Void> commits(Repository repository, CommitsCommandParameters parameters, ChangesetCallback callback)
Retrieves all descendant commits of any of the refs (commitHash, tagname, branchname) in refs.
@Nonnull Command<Void> create(Repository repository)
Creates and initializes the repository on disk
@Nonnull Command<Branch> defaultBranch(Repository repository)
Retrieves a Command which will resolve the default branch for the specified repository when executed.
@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.
@Nonnull @Deprecated Command<Void> deleteBranch(Repository repository, String branch)
This method is deprecated. in 2.1 for removal in 3.0. Deleting branches is SCM-specific.
@Nonnull Command<Page<DetailedChangeset>> detailedCommits(Repository repository, DetailedCommitsCommandParameters parameters, PageRequest pageRequest)
@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 parent, Repository fork)
Creates a fork of repository parent
@Nonnull Command<Void> heads(Repository repository, RefCallback callback)
@Nonnull Command<Branch> merge(Repository repository, MergeCommandParameters parameters)
Creates a command that, when executed, will merge the specified fromChangesetId into the specified toBranch.
@Nonnull Command<Void> rawFile(Repository repository, RawFileCommandParameters parameters, TypeAwareOutputSupplier outputSupplier)
Returns a com.atlassian.stash.scm.Command that will, when executed, retrieve the content of the given file, try to detect its mime-type, obtain an java.io.OutputStream from the given com.atlassian.stash.io.TypeAwareOutputSupplier and copy all the content into it.
@Deprecated @Nonnull Command<Void> reparent(Repository repository, Repository newParent)
This method is deprecated. in 2.4 for removal in 3.0, with no replacement. If reparenting is necessary, it should be handled automatically during repository deletion.
@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)
Traverse the commit graph in topological order
@Nonnull Command<ContentTreeNode.Type> type(Repository repository, TypeCommandParameters parameters)
@Nonnull Command<Void> updateDefaultBranch(Repository repository, String branchName)
Returns a com.atlassian.stash.scm.Command which, when executed, will 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<Void> changes (Repository repository, ChangesCommandParameters parameters, ChangeCallback callback)

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

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

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

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

Retrieves all descendant commits of any of the refs (commitHash, tagname, branchname) in refs.

Parameters
repository the repository to query
parameters previous heads
callback the changeset callback that will be called for each of the matching commits.
Returns
  • a command to asynchronously retrieve the commits.

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

Creates and initializes the repository on disk

Parameters
repository the repository to create

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

Retrieves a Command which will resolve the default branch for the specified repository when executed.

The returned command may throw com.atlassian.stash.exception.NoDefaultBranchException NoDefaultBranchException, when executed, if the specified repository does not have a resolvable default branch. This might happen, for example, on a new repository with no commits, or if the only commits to a repository have been to a branch other than the default branch.

Parameters
repository the repository to retrieve the default branch for
Returns
  • a command which, when executed, will retrieve the default branch
Throws
NoDefaultBranchException if the repository does not have a resolvable default branch.

@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

@Nonnull @Deprecated public Command<Void> deleteBranch (Repository repository, String branch)

This method is deprecated.
in 2.1 for removal in 3.0. Deleting branches is SCM-specific.

Returns a Command which, when executed, will delete the specified branch.

Parameters
branch to be deleted
Returns
  • a command which, when executed, will delete the specified branch

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

@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 parent, Repository fork)

Creates a fork of repository parent

Parameters
parent the repository to be forked
fork the fork

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

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

Creates a command that, when executed, will merge the specified fromChangesetId into the specified toBranch.

The provided fromChangesetId may be:

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

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

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

Returns a com.atlassian.stash.scm.Command that will, when executed, retrieve the content of the given file, try to detect its mime-type, obtain an java.io.OutputStream from the given com.atlassian.stash.io.TypeAwareOutputSupplier and copy all the content into it.

Parameters
repository the repository that contains the file
parameters parameters used to specify the path and version of the file to stream
outputSupplier the supplier which, when given a content type, will provide an output stream
Returns
  • a command which, when executed, will determine the file's type and then stream its data

@Deprecated @Nonnull public Command<Void> reparent (Repository repository, Repository newParent)

This method is deprecated.
in 2.4 for removal in 3.0, with no replacement. If reparenting is necessary, it should be handled automatically during repository deletion.

Returns a Command that will, when executed, update the origin for the specified repository to reference the newParent.

Parameters
newParent the new parent which should be used as the repository's origin
Returns
  • a command which, when executed, will reparent the repository

@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)

Traverse the commit graph in topological order

Parameters
repository the repository to traverse
callback the callback for traversing the commit graph
Returns
  • the command to execute the traversal

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

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

Returns a com.atlassian.stash.scm.Command which, when executed, will set the default branch for the specified repository to the named branch. This operation may not be supported by all SCM implementations. Such implementations should throw an UnsupportedOperationException.

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 Thrown if the provided branchName is null or blank.
UnsupportedOperationException Thrown if the underlying SCM does not support setting the default branch.