Class AbstractIssueProvider
- java.lang.Object
-
- jetbrains.buildServer.issueTracker.AbstractIssueProvider
-
- All Implemented Interfaces:
IssueBatchProviderSupport,IssueProvider,SIssueProvider
- Direct Known Subclasses:
AbstractPatternBasedIssueProvider,AbstractPrefixBasedIssueProvider
public abstract class AbstractIssueProvider extends Object implements SIssueProvider
Represents a default implementation ofIssueProviderinterface. This class resolves related issues using pattern matching, and fetches them usingIssueFetcher.Class doesn't use any cache (fetcher does).
- Author:
- Maxim Podkolzine (maxim.podkolzine@jetbrains.com)
-
-
Field Summary
Fields Modifier and Type Field Description protected static PatternEMPTY_PATTERNprotected static LoggerLOGprotected org.apache.commons.httpclient.CredentialsmyCredentialsprotected IssueFetchermyFetcherprotected StringmyFetchHostprotected StringmyHostprotected PatternmyPatternprotected Map<String,String>myPropertiesprotected StringmyTypeprotected static intREGEX_ISSUES_TIMEOUS_MS-
Fields inherited from interface jetbrains.buildServer.issueTracker.IssueProvider
SECURE_PROPERTY_PREFIX
-
-
Constructor Summary
Constructors Modifier Constructor Description AbstractIssueProvider(String type, IssueFetcher fetcher)protectedAbstractIssueProvider(Pattern pattern, IssueFetcher fetcher)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected StringcheckIssueIdBeforeTestConnection(String issueId)protected static PatterncompileDisjunction(String prefixes, String suffix)Given a string containing the prefixes, composes the reg.exp pattern that accepts any of them plus suffix.protected PatterncompilePattern(Map<String,String> properties)voiddispose()Disposes the provider (releases all necessary resources, dumps caches on disk, etc).protected StringextractId(String match)List<String>fetchProjectIds()Deprecated.IssueDatafindIssueById(String id)Returns the issue by the specified id.Map<String,IssueData>findIssuesByIds(Collection<String> ids)Finds and returns the specified collection of issue ids.protected Map<String,IssueData>findIssuesByIdsImpl(Collection<String> ids)IssueDatafindPossiblyExpiredIssue(String id)Returns the issue data corresponding to theid.protected IssueDatafixUrl(IssueData issueData, String issueId)Issue is fetched usingmyFetchHostthat is not the URL to be shown in UI.protected IssueFetcherAuthenticatorgetAuthenticator()CommentTransformationHelpergetCommentTransformationHelper()Returns the instance of helper class to support comment transformation (i.e.StringgetConfigurationSummary()Returns the basic summary of current configuration, for instance, "Jira" provider might return:"Projects: P1, P2".protected StringgetFetchHost()protected StringgetIssueViewUrl(String id)Map<String,String>getProperties()Returns the map of provider properties.PropertiesProcessorgetPropertiesProcessor()Returns the properties processor instance (validator).Collection<IssueMention>getRelatedIssues(String comment)Returns the collection of issues related, or mentioned in the comment.Collection<IssueMention>getRelatedIssues(VcsModification modification)Returns the collection of issues related to a modification.IssueTestConnectionSupportgetTestConnectionSupport()Returns the test connection support.StringgetType()Returns the type of this provider (the type of the corresponding factory).booleanisBatchFetchSupported()Returns whether the issue provider supports fetching in batch.booleanisFailedToFetch(String id)Returns whether the issue could not be fetched due to error.booleanisFetched(String id)Returns whether the issue is fetched and can be efficiently returned usingIssueProvider.findIssueById(String)method.booleanisHasRelatedIssues(String comment)Returns whether there are related issues in the specifiedcomment.booleanisHasRelatedIssues(VcsModification modification)Returns whether there are related issues in the specifiedmodification.protected booleanisIdPrefixMandatory(Map<String,String> properties)protected booleanquickCheck(String comment)Helper methods.protected static PatternsafeCompile(String pattern)The same asPattern.compile(pattern), but returns an empty pattern if the provided pattern is incorrect.protected StringsanitizeHost(String host)voidsetProperties(Map<String,String> map)Sets the provider properties (seeIssueProvider.getProperties()method for the details).StringtoString()protected booleanuseIdPrefix()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.issueTracker.SIssueProvider
getAdditionalTestData
-
-
-
-
Field Detail
-
LOG
protected static final Logger LOG
-
EMPTY_PATTERN
protected static final Pattern EMPTY_PATTERN
-
REGEX_ISSUES_TIMEOUS_MS
protected static final int REGEX_ISSUES_TIMEOUS_MS
- See Also:
- Constant Field Values
-
myType
protected final String myType
-
myHost
protected String myHost
-
myFetchHost
protected String myFetchHost
-
myCredentials
protected org.apache.commons.httpclient.Credentials myCredentials
-
myPattern
protected Pattern myPattern
-
myFetcher
protected final IssueFetcher myFetcher
-
-
Constructor Detail
-
AbstractIssueProvider
public AbstractIssueProvider(@NotNull String type, @NotNull IssueFetcher fetcher)
-
AbstractIssueProvider
protected AbstractIssueProvider(@NotNull Pattern pattern, @NotNull IssueFetcher fetcher)
-
-
Method Detail
-
fetchProjectIds
@Nullable @Deprecated public List<String> fetchProjectIds()
Deprecated.
-
getType
@NotNull public String getType()
Description copied from interface:IssueProviderReturns the type of this provider (the type of the corresponding factory). The type is immutable and consists of alpha-numeric characters.- Specified by:
getTypein interfaceIssueProvider- Returns:
- provider type
-
getRelatedIssues
@NotNull public Collection<IssueMention> getRelatedIssues(@NotNull String comment)
Description copied from interface:IssueProviderReturns the collection of issues related, or mentioned in the comment. The relation can be defined by a mention in the text (a mention means thatcommentcontains the substring that matches a certain pattern), or by any way the plugin chooses.- Specified by:
getRelatedIssuesin interfaceIssueProvider- Parameters:
comment- the comment- Returns:
- collection of related issues
- See Also:
IssueProvider.isHasRelatedIssues(String)
-
isHasRelatedIssues
public boolean isHasRelatedIssues(@NotNull String comment)Description copied from interface:IssueProviderReturns whether there are related issues in the specifiedcomment. The relation can be defined by a mention in the text (a mention means thatcommentcontains the substring that matches a certain pattern), or by any way the plugin chooses.- Specified by:
isHasRelatedIssuesin interfaceIssueProvider- Parameters:
comment- the comment- Returns:
- true if the comment has related issues
- See Also:
IssueProvider.getRelatedIssues(String)
-
getRelatedIssues
@NotNull public Collection<IssueMention> getRelatedIssues(@NotNull VcsModification modification)
Description copied from interface:IssueProviderReturns the collection of issues related to a modification. In most cases the relation is defined via mentioning the issue id in the modification comment, but could also be some extra field in VCS commit.- Specified by:
getRelatedIssuesin interfaceIssueProvider- Parameters:
modification- VCS modification- Returns:
- collection of related issues
- See Also:
IssueProvider.isHasRelatedIssues(jetbrains.buildServer.vcs.VcsModification)
-
isHasRelatedIssues
public boolean isHasRelatedIssues(@NotNull VcsModification modification)Description copied from interface:IssueProviderReturns whether there are related issues in the specifiedmodification. In most cases the relation is defined via mentioning the issue id in the modification comment, but could also be some extra field in VCS commit.- Specified by:
isHasRelatedIssuesin interfaceIssueProvider- Parameters:
modification- a VCS modification- Returns:
- true if the modification has related issues
- See Also:
IssueProvider.getRelatedIssues(jetbrains.buildServer.vcs.VcsModification)
-
isFetched
public boolean isFetched(@NotNull String id)Description copied from interface:SIssueProviderReturns whether the issue is fetched and can be efficiently returned usingIssueProvider.findIssueById(String)method.- Specified by:
isFetchedin interfaceSIssueProvider- Parameters:
id- the issue id- Returns:
- true if the issue is fetched
- See Also:
SIssueProvider.isFailedToFetch(String)
-
findPossiblyExpiredIssue
public IssueData findPossiblyExpiredIssue(@NotNull String id)
Description copied from interface:SIssueProviderReturns the issue data corresponding to theid.The main difference from
IssueProvider.findIssueById(String)method is that method must be always fast (should use only cached data) and the result data isn't expected to be up-to-date. So this method should return the issue data if by chance it can be retrieved fast, even if a provider considers it out-dated andIssueProvider.findIssueById(String)method would make an extra call to the issue-tracking system.The simplest (100% legal) implementation of this method:
public IssueData findPossiblyExpiredIssue(@NotNull String id) { return null; }This way TeamCity will always show 'Retrieving...' message, when the issue isn't fetched (seeSIssueProvider.isFetched(String)).- Specified by:
findPossiblyExpiredIssuein interfaceSIssueProvider- Parameters:
id- the issue id- Returns:
- issue data, or
nullif the it cannot be returned efficiently
-
isFailedToFetch
public boolean isFailedToFetch(@NotNull String id)Description copied from interface:SIssueProviderReturns whether the issue could not be fetched due to error.In case of
true, the issue data isn't in a cache (i.e.isFetched(id) == false), but the error is.- Specified by:
isFailedToFetchin interfaceSIssueProvider- Parameters:
id- the issue id- Returns:
- true if issue could not be fetched
- See Also:
SIssueProvider.isFetched(String)
-
findIssueById
@Nullable public IssueData findIssueById(@NotNull String id)
Description copied from interface:IssueProviderReturns the issue by the specified id. Returned data isn't expected to be up-to-date, i.e. fetched from the ITS at the moment of call.The implementors are encouraged to report retrieving errors by throwing
RetrieveIssueException, rather than simply returnnull:NotFoundExceptionwhen the issue cannot be found,UnsupportedExceptionwhen the issue tracker protocol is not supported, etc.- Specified by:
findIssueByIdin interfaceIssueProvider- Parameters:
id- issue id- Returns:
- the corresponding issue, or
nullif the issue cannot be retrieved
-
getAuthenticator
@NotNull protected IssueFetcherAuthenticator getAuthenticator()
-
isBatchFetchSupported
public boolean isBatchFetchSupported()
Description copied from interface:IssueBatchProviderSupportReturns whether the issue provider supports fetching in batch.Note: the method is always fast.
- Specified by:
isBatchFetchSupportedin interfaceIssueBatchProviderSupport- Returns:
- true if the issue provider supports fetching in batch
-
findIssuesByIds
@Nullable public Map<String,IssueData> findIssuesByIds(@NotNull Collection<String> ids)
Description copied from interface:IssueBatchProviderSupportFinds and returns the specified collection of issue ids. If current provider does not support batch fetching,nullis returned.Note: the method is not necessarily fast, and should be called in a separate issue.
- Specified by:
findIssuesByIdsin interfaceIssueBatchProviderSupport- Parameters:
ids- the collection of issue ids to fetch- Returns:
- the map
issue id -> issue data, ornull
-
getProperties
@NotNull public Map<String,String> getProperties()
Description copied from interface:IssueProviderReturns the map of provider properties. This map includes all fields that are configured in admin UI and stored in TeamCity config file (e.g. credentials used in all communications with remote server, server url, etc, but not the id or type).The keys should consist of alphanumeric characters and start with a letter.
- Specified by:
getPropertiesin interfaceIssueProvider- Returns:
- the properties map
-
setProperties
public void setProperties(@NotNull Map<String,String> map)Description copied from interface:IssueProviderSets the provider properties (seeIssueProvider.getProperties()method for the details).Few words about thread-safety: properties can be changed from the admin UI, or in config file. By any of these events this method is called (synchronously). Hence this method should lock any other API method.
- Specified by:
setPropertiesin interfaceIssueProvider- Parameters:
map- a properties map- See Also:
IssueProvider.getProperties()
-
getFetchHost
@NotNull protected String getFetchHost()
-
dispose
public void dispose()
Description copied from interface:IssueProviderDisposes the provider (releases all necessary resources, dumps caches on disk, etc). This method is called when the provider is deleted from the system, and on server shutdown.- Specified by:
disposein interfaceIssueProvider
-
getCommentTransformationHelper
public CommentTransformationHelper getCommentTransformationHelper()
Description copied from interface:IssueProviderReturns the instance of helper class to support comment transformation (i.e. automatic replacement of issues, mentioned in a comment, with a link and a popup).- Specified by:
getCommentTransformationHelperin interfaceIssueProvider- Returns:
- a helper, or null
-
getPropertiesProcessor
@NotNull public PropertiesProcessor getPropertiesProcessor()
Description copied from interface:SIssueProviderReturns the properties processor instance (validator).It is guaranteed that
IssueProvider.setProperties(java.util.Map)method is called only if the processor finds no errors.- Specified by:
getPropertiesProcessorin interfaceSIssueProvider- Returns:
- properties processor
-
getTestConnectionSupport
@NotNull public IssueTestConnectionSupport getTestConnectionSupport()
Description copied from interface:SIssueProviderReturns the test connection support.- Specified by:
getTestConnectionSupportin interfaceSIssueProvider- Returns:
- test connection support
-
getConfigurationSummary
public String getConfigurationSummary()
Description copied from interface:SIssueProviderReturns the basic summary of current configuration, for instance, "Jira" provider might return:"Projects: P1, P2".- Specified by:
getConfigurationSummaryin interfaceSIssueProvider- Returns:
- provider configuration summary, or null
-
quickCheck
protected boolean quickCheck(@NotNull String comment)Helper methods.
-
useIdPrefix
protected boolean useIdPrefix()
-
findIssuesByIdsImpl
@Nullable protected Map<String,IssueData> findIssuesByIdsImpl(@NotNull Collection<String> ids)
-
fixUrl
@Nullable protected IssueData fixUrl(@Nullable IssueData issueData, @NotNull String issueId)
Issue is fetched usingmyFetchHostthat is not the URL to be shown in UI. So we might need to change the URL inIssueDatatomyHostifmyFetchHostdiffers.
-
checkIssueIdBeforeTestConnection
@Nullable protected String checkIssueIdBeforeTestConnection(@NotNull String issueId)
-
compileDisjunction
@NotNull protected static Pattern compileDisjunction(@NotNull String prefixes, @NotNull String suffix)
Given a string containing the prefixes, composes the reg.exp pattern that accepts any of them plus suffix. Example:prefixes = "foo bar"; suffix = "-\\d+"; result = "(foo|bar)-\\d+"
Prefixes are separated by ' ', '\t', '\n', '\r', ',', ';' characters.
- Parameters:
prefixes- the prefixes (in one string)suffix- the suffix- Returns:
- disjunction pattern
-
safeCompile
@NotNull protected static Pattern safeCompile(@NotNull String pattern)
The same asPattern.compile(pattern), but returns an empty pattern if the provided pattern is incorrect. In this case the issue provider will be disabled.The pattern that matches empty string is considered incorrect.
- Parameters:
pattern- the pattern to compile- Returns:
- a compiled pattern
-
-