Class BaseBuildTypeIdentity
- java.lang.Object
-
- jetbrains.buildServer.serverSide.impl.BaseBuildTypeIdentity
-
- All Implemented Interfaces:
BuildTypeIdentity,BuildTypeIdentityEx,SPersistentEntity
- Direct Known Subclasses:
BuildTypeImpl,BuildTypeTemplateImpl
public abstract class BaseBuildTypeIdentity extends Object implements BuildTypeIdentityEx
Base class for build template and build configuration.Contains data and behaviour relates to the build template and build configurations identifiers and names.
- Since:
- 8.0
- Author:
- Leonid Bushuev from JetBrains
-
-
Field Summary
Fields Modifier and Type Field Description static StringIGNORE_BUILD_CONF_DEPENDENCIES_ON_MOVEprotected BuildTypeIdentityContextmyContextprotected EntityId<String>myEntityIdThe internal and external identifiers.protected ObjectmyExtIdChangeLockprotected StringmyFormerExternalIdThe former external identifier (when the new one has been assigned but not persisted yet).protected StringmyNameThe name of the identity.protected ProjectExmyProjectProject this identity belongs to.
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseBuildTypeIdentity(BuildTypeIdentityContext context, ProjectEx project, EntityId<String> entityId, String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidauditExternalIdChanged(ConfigAction cause, String oldExternalId, String newExternalId)protected voidbeforeModification()This method is called from methods that modify the state (the state that should be persisted).booleanbelongsTo(SProject project)Checks whether this build type or template belongs to the specified project or one of its subprojects, transitively.protected abstract voidcheckObsolete()ConfigActioncreateConfigAction(SUser user, String description)Creates a config action instance associated with this entity and having the specified description.protected abstract ConfigActioncreateExternalIdChangedConfigAction()protected voidcreateFirstConfigVersionIfHistoryIsEmpty()protected voiddoPersist(ConfigAction cause)protected voiddoPersist(BackgroundPersistTask task)FilegetConfigDirectory()Returns the directory where this configuration file is saved.protected abstract FileHistorygetConfigHistory()StringgetConfigId()Returns the entity's config identifier.FilegetConfigurationFile()Returns the configuration file.FilegetConfigurationFile(File projectsDir)Returns the configuration file where this entity is persisted in custom projects directoryEntityId<String>getEntityId()Returns the instance of the entity identifier.StringgetExternalId()Returns the external identifier.StringgetFullName()Name of the project and name of the identity.StringgetInternalId()Returns the internal identifier.StringgetName()The name of the identity.SPersistentEntitygetParent()The parent entity.ProjectExgetProject()Returns the project this build type entity belongs to.StringgetProjectId()PersistentEntityVersiongetVersion()Returns version of this entity which can be used to check if the entity was edited or persisted.protected abstract booleanisTemplate()protected abstract voidlogChangedConfigToAudit(ConfigAction cause, String description, int versionAfter)protected abstract voidlogRemovingToAudit(ConfigAction cause)protected voidmarkEdited()voidmarkPersisted(long expectedEditId)Marks entity as persistedvoidmarkUnedited()protected abstract voidnameChanged(String oldName, String newName)voidpersist()Persists this entity instance onto disk.voidpersist(ConfigAction cause)Persists this entity on disk.protected abstract voidpersistAuxiliaryData()protected abstract voidpersistInternal(ConfigAction cause)protected abstract voidpersistInternal(BackgroundPersistTask task)protected voidprocessConfigIfChanged(ConfigAction cause)voidremove()Removes this build template or configuration.voidremove(ConfigAction cause)BackgroundPersistTaskschedulePersisting(String reason)Schedules background persisting of this entity settings.BackgroundPersistTaskschedulePersisting(ConfigAction cause)Schedules background persisting of this project settings.voidschedulePersisting(BackgroundPersistTask task)PersistTaskscheduleRemove(ConfigAction cause)Schedules remove of this persistent entity.abstract voidsendExtIdChangedEvents(ConfigAction cause, String oldExternalId, String newExternalId)The method is called when the external identifier has been changed.protected voidsendPersistedEvents(ConfigAction cause)voidsetExternalId(String newExternalId)Changes the external id of this build template or build configuration.voidsetExternalId(ConfigAction cause, String newExternalId)Changes the external id of this build template or build configuration.voidsetExternalId(ConfigAction cause, String newExternalId, boolean sendEvents)Same as {BuildTypeIdentity.setExternalId(ConfigAction, String)} but provides control over events processing.voidsetName(String newName)Renames this build type identity.StringtoString()abstract voidunregister()Removes this object from project model.protected abstract voidwarnObsolete()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.serverSide.BuildTypeIdentityEx
getSettings
-
Methods inherited from interface jetbrains.buildServer.serverSide.SPersistentEntity
getReadOnlyReason, isReadOnly, isVirtual
-
-
-
-
Field Detail
-
IGNORE_BUILD_CONF_DEPENDENCIES_ON_MOVE
public static final String IGNORE_BUILD_CONF_DEPENDENCIES_ON_MOVE
- See Also:
- Constant Field Values
-
myContext
@NotNull protected final BuildTypeIdentityContext myContext
-
myProject
@NotNull protected volatile ProjectEx myProject
Project this identity belongs to.
-
myEntityId
@NotNull protected final EntityId<String> myEntityId
The internal and external identifiers.
-
myFormerExternalId
@NotNull protected volatile String myFormerExternalId
The former external identifier (when the new one has been assigned but not persisted yet).
-
myName
@NotNull protected String myName
The name of the identity.
-
myExtIdChangeLock
protected final Object myExtIdChangeLock
-
-
Constructor Detail
-
BaseBuildTypeIdentity
protected BaseBuildTypeIdentity(@NotNull BuildTypeIdentityContext context, @NotNull ProjectEx project, @NotNull EntityId<String> entityId, @NotNull String name)
-
-
Method Detail
-
beforeModification
protected void beforeModification()
This method is called from methods that modify the state (the state that should be persisted). All modification methods must call it before modifications are performed.- Since:
- 8.0
-
getProject
@NotNull public ProjectEx getProject()
Returns the project this build type entity belongs to.- Specified by:
getProjectin interfaceBuildTypeIdentity- Returns:
- the project this build type entity belongs to.
-
getParent
@Nullable public SPersistentEntity getParent()
Description copied from interface:SPersistentEntityThe parent entity.- Specified by:
getParentin interfaceSPersistentEntity- Returns:
- see above.
-
getProjectId
@NotNull public String getProjectId()
-
getEntityId
@NotNull public EntityId<String> getEntityId()
Description copied from interface:BuildTypeIdentityExReturns the instance of the entity identifier.This instance (not a copy!) that contains immutable internal id and modifiable external id. When one has changed the external id of this build template or configuration, the external id incide this class instance will be changed too.
- Specified by:
getEntityIdin interfaceBuildTypeIdentityEx- Returns:
- the instance of the entity identifier.
-
getInternalId
@NotNull public final String getInternalId()
Returns the internal identifier.- Specified by:
getInternalIdin interfaceBuildTypeIdentity- Returns:
- the internal identifier.
-
getConfigId
@NotNull public String getConfigId()
Description copied from interface:SPersistentEntityReturns the entity's config identifier. Config identifier uniquely identifies the entity across different TeamCity servers and can't be modified in contrast to external identifier.- Specified by:
getConfigIdin interfaceSPersistentEntity
-
getExternalId
@NotNull public final String getExternalId()
Returns the external identifier.- Specified by:
getExternalIdin interfaceBuildTypeIdentity- Specified by:
getExternalIdin interfaceSPersistentEntity- Returns:
- the external identifier.
-
getName
@NotNull public String getName()
Description copied from interface:BuildTypeIdentityThe name of the identity.- Specified by:
getNamein interfaceBuildTypeIdentity- Specified by:
getNamein interfaceSPersistentEntity- Returns:
- see above.
- See Also:
BuildTypeIdentity.getFullName(),BuildTypeIdentity.setName(String)
-
getFullName
@NotNull public String getFullName()
Description copied from interface:BuildTypeIdentityName of the project and name of the identity.- Specified by:
getFullNamein interfaceBuildTypeIdentity- See Also:
BuildTypeIdentity.getName()
-
belongsTo
public boolean belongsTo(@NotNull SProject project)Description copied from interface:BuildTypeIdentityChecks whether this build type or template belongs to the specified project or one of its subprojects, transitively.- Specified by:
belongsToin interfaceBuildTypeIdentity- Parameters:
project- the project to check this configuration to belongs to.- Returns:
- true if belongs.
-
setExternalId
public void setExternalId(@NotNull String newExternalId) throws InvalidIdentifierException, DuplicateExternalIdExceptionDescription copied from interface:BuildTypeIdentityChanges the external id of this build template or build configuration.This method persists the current entity, and can persist also dependent entities.
- Specified by:
setExternalIdin interfaceBuildTypeIdentity- Parameters:
newExternalId- new external identifier. Must be unique (case insensitively) in the scope of all build templates and build configurations (in other words, two projects with build configurations with same external id are not allowed).- Throws:
InvalidIdentifierException- wrong identifierDuplicateExternalIdException- a build template or a build configuration
-
setExternalId
public void setExternalId(@NotNull ConfigAction cause, @NotNull String newExternalId) throws InvalidIdentifierException, DuplicateExternalIdException, ObsoleteEntityExceptionDescription copied from interface:BuildTypeIdentityChanges the external id of this build template or build configuration.This method persists the current entity, and can persist also dependent entities.
- Specified by:
setExternalIdin interfaceBuildTypeIdentity- Parameters:
cause- configuration action caused the changenewExternalId- new external identifier. Must be unique (case insensitively) in the scope of all build templates and build configurations (in other words, two projects with build configurations with same external id are not allowed).- Throws:
InvalidIdentifierException- wrong identifierDuplicateExternalIdException- a build template or a build configurationObsoleteEntityException- when build type/template is not the same as the one in the project model (since 9.1.2)
-
setExternalId
public void setExternalId(@NotNull ConfigAction cause, @NotNull String newExternalId, boolean sendEvents) throws InvalidIdentifierException, DuplicateExternalIdException, ObsoleteEntityExceptionDescription copied from interface:BuildTypeIdentityExSame as {BuildTypeIdentity.setExternalId(ConfigAction, String)} but provides control over events processing. If parameter sendEvents is false, then no events about changing of the external id will be sent. This mode can be useful if the events will be sent later, for instance, in case of bulk edit ids operation.- Specified by:
setExternalIdin interfaceBuildTypeIdentityEx- Throws:
InvalidIdentifierExceptionDuplicateExternalIdExceptionObsoleteEntityException
-
checkObsolete
protected abstract void checkObsolete()
-
warnObsolete
protected abstract void warnObsolete()
-
sendExtIdChangedEvents
public abstract void sendExtIdChangedEvents(@NotNull ConfigAction cause, @NotNull String oldExternalId, @NotNull String newExternalId)The method is called when the external identifier has been changed.- Specified by:
sendExtIdChangedEventsin interfaceBuildTypeIdentityEx- Parameters:
oldExternalId- the old external identifier value.newExternalId- the new external identifier value.
-
createExternalIdChangedConfigAction
@NotNull protected abstract ConfigAction createExternalIdChangedConfigAction()
-
auditExternalIdChanged
protected abstract void auditExternalIdChanged(@NotNull ConfigAction cause, @NotNull String oldExternalId, @NotNull String newExternalId)
-
setName
public void setName(@NotNull String newName) throws DuplicateBuildTypeNameExceptionRenames this build type identity.- Specified by:
setNamein interfaceBuildTypeIdentity- Parameters:
newName- new name- Throws:
DuplicateBuildTypeNameException- See Also:
BuildTypeIdentity.getName(),BuildTypeIdentity.getFullName()
-
persist
public final void persist() throws PersistFailedExceptionDescription copied from interface:SPersistentEntityPersists this entity instance onto disk. Should be called each time when settings are changed, otherwise the changes will be lost after the server restart.- Specified by:
persistin interfaceSPersistentEntity- Throws:
PersistFailedException- if persisting failed
-
persist
public void persist(@NotNull ConfigAction cause) throws PersistFailedExceptionDescription copied from interface:SPersistentEntityPersists this entity on disk.- Specified by:
persistin interfaceSPersistentEntity- Parameters:
cause- an action which caused persisting- Throws:
PersistFailedException- if persisting failed
-
schedulePersisting
@NotNull public BackgroundPersistTask schedulePersisting(@NotNull String reason) throws PersistFailedException
Description copied from interface:SPersistentEntitySchedules background persisting of this entity settings.- Specified by:
schedulePersistingin interfaceSPersistentEntity- Parameters:
reason- provides a reason why persist operation was called- Returns:
- a task which can be used to track the operation progress or wait for the operation to complete
- Throws:
PersistFailedException- if failed to schedule the operation- See Also:
SPersistentEntity.schedulePersisting(ConfigAction)
-
schedulePersisting
@NotNull public BackgroundPersistTask schedulePersisting(@NotNull ConfigAction cause) throws PersistFailedException
Description copied from interface:SPersistentEntitySchedules background persisting of this project settings.- Specified by:
schedulePersistingin interfaceSPersistentEntity- Parameters:
cause- an action which caused persisting- Returns:
- a task which can be used to track the operation progress or wait for the operation to complete
- Throws:
PersistFailedException- if failed to schedule the operation- See Also:
SPersistentEntity.schedulePersisting(String)
-
schedulePersisting
public void schedulePersisting(@NotNull BackgroundPersistTask task) throws PersistFailedException- Throws:
PersistFailedException
-
sendPersistedEvents
protected void sendPersistedEvents(@NotNull ConfigAction cause)
-
persistInternal
protected abstract void persistInternal(@NotNull ConfigAction cause) throws PersistFailedException- Throws:
PersistFailedException
-
persistInternal
protected abstract void persistInternal(@NotNull BackgroundPersistTask task) throws PersistFailedException- Throws:
PersistFailedException
-
doPersist
protected void doPersist(@NotNull ConfigAction cause)
-
doPersist
protected void doPersist(@NotNull BackgroundPersistTask task)
-
persistAuxiliaryData
protected abstract void persistAuxiliaryData()
-
createFirstConfigVersionIfHistoryIsEmpty
protected void createFirstConfigVersionIfHistoryIsEmpty()
-
processConfigIfChanged
protected void processConfigIfChanged(@NotNull ConfigAction cause)
-
getConfigHistory
@NotNull protected abstract FileHistory getConfigHistory() throws IOException
- Throws:
IOException
-
logChangedConfigToAudit
protected abstract void logChangedConfigToAudit(@NotNull ConfigAction cause, @Nullable String description, int versionAfter)
-
getConfigDirectory
@NotNull public File getConfigDirectory()
Returns the directory where this configuration file is saved. If the project is in state when it's just changed external id is not persisted yet, the result of this function is based on the former project external id (in other words, it always points to the actual directory path).The directory can be not existent yet if no build templates or configurations were persisted.
- Returns:
- see above.
-
getConfigurationFile
@NotNull public File getConfigurationFile()
Returns the configuration file. If this build template/type or the project are in the state when it's just changed external id is not persisted yet, the result of this function is based on the former external id (in other words, it points to the actual file path).The file or underlying directory can be not existent yet if no project or build templates or configurations were persisted.
- Specified by:
getConfigurationFilein interfaceBuildTypeIdentity- Specified by:
getConfigurationFilein interfaceSPersistentEntity- Returns:
- see above.
-
getConfigurationFile
@NotNull public File getConfigurationFile(@NotNull File projectsDir)
Description copied from interface:SPersistentEntityReturns the configuration file where this entity is persisted in custom projects directory- Specified by:
getConfigurationFilein interfaceSPersistentEntity- Parameters:
projectsDir- path to teamcity projects directory- Returns:
- see above
-
remove
public void remove()
Removes this build template or configuration.This method also makes all changes on the disk and in the database, so calling persist() is not needed after this method.
- Specified by:
removein interfaceSPersistentEntity
-
remove
public void remove(@NotNull ConfigAction cause)
-
scheduleRemove
@NotNull public PersistTask scheduleRemove(@NotNull ConfigAction cause) throws PersistFailedException
Description copied from interface:SPersistentEntitySchedules remove of this persistent entity. Returns task which can be used to wait for the operation to complete.- Specified by:
scheduleRemovein interfaceSPersistentEntity- Parameters:
cause- reason of the remove- Returns:
- a task which can be used to track the operation progress or wait for the operation to complete
- Throws:
PersistFailedException- if failed to schedule the operation
-
isTemplate
protected abstract boolean isTemplate()
-
unregister
public abstract void unregister()
Description copied from interface:BuildTypeIdentityExRemoves this object from project model. No changes on disk are performed.- Specified by:
unregisterin interfaceBuildTypeIdentityEx
-
logRemovingToAudit
protected abstract void logRemovingToAudit(@NotNull ConfigAction cause)
-
markEdited
protected void markEdited()
-
markUnedited
public void markUnedited()
-
getVersion
@NotNull public PersistentEntityVersion getVersion()
Description copied from interface:SPersistentEntityReturns version of this entity which can be used to check if the entity was edited or persisted.- Specified by:
getVersionin interfaceSPersistentEntity- Returns:
- see above
-
markPersisted
public void markPersisted(long expectedEditId)
Description copied from interface:SPersistentEntityMarks entity as persisted- Specified by:
markPersistedin interfaceSPersistentEntity- Parameters:
expectedEditId- expected editId in the end of persist. The entity will be marked as unedited if expected editId is the same as actual, ie. the entity wasn't edited while persist was running
-
createConfigAction
@NotNull public ConfigAction createConfigAction(@Nullable SUser user, @NotNull String description)
Description copied from interface:SPersistentEntityCreates a config action instance associated with this entity and having the specified description. The config action object can be used inSPersistentEntity.schedulePersisting(ConfigAction)orSPersistentEntity.scheduleRemove(ConfigAction)methods to describe the performed action.- Specified by:
createConfigActionin interfaceSPersistentEntity- Parameters:
user- user who performs operation, or null if operation is performed by the systemdescription- description to set to the config action object- Returns:
- new config action
-
-