Class AbstractItem
- java.lang.Object
-
- hudson.model.AbstractModelObject
-
- hudson.model.Actionable
-
- hudson.model.AbstractItem
-
- All Implemented Interfaces:
DescriptorByNameOwner,Item,ModelObject,PersistenceRoot,Saveable,SearchableModelObject,SearchItem,AccessControlled,Loadable,ModelObjectWithContextMenu,OnMaster,org.kohsuke.stapler.HttpDeletable,org.kohsuke.stapler.StaplerProxy
- Direct Known Subclasses:
AbstractTopLevelItem,Job
@ExportedBean public abstract class AbstractItem extends Actionable implements Loadable, Item, org.kohsuke.stapler.HttpDeletable, AccessControlled, DescriptorByNameOwner, org.kohsuke.stapler.StaplerProxy
Partial default implementation ofItem.- Author:
- Kohsuke Kawaguchi
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jenkins.model.ModelObjectWithContextMenu
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem, ModelObjectWithContextMenu.MenuItemType
-
-
Field Summary
Fields Modifier and Type Field Description protected StringdescriptionProject description.protected StringdisplayNameprotected StringnameProject name.static AlternativeUiTextProvider.Message<AbstractItem>PRONOUNReplaceable pronoun of that points to a job.static booleanSKIP_PERMISSION_CHECKEscape hatch for StaplerProxy-based access controlstatic AlternativeUiTextProvider.Message<AbstractItem>TASK_NOUNReplaceable noun for describing the kind of task that this item represents.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractItem(ItemGroup parent, String name)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidcheckRename(String newName)Allows subclasses to block renames for domain-specific reasons.voiddelete()Deletes this item.voiddelete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)FormValidationdoCheckNewName(String newName)Called bydoConfirmRename(java.lang.String)andrename.jellyto validate renames.voiddoConfigDotXml(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)Acceptsconfig.xmlsubmission, as well as serve it.org.kohsuke.stapler.HttpResponsedoConfirmRename(String newName)Renames this itemvoiddoDoDelete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)Deletes this item.voiddoReload()Reloads this job from the disk.protected voiddoSetName(String name)Just updatenamewithout performing the rename operation, which would involve copying files and etc.voiddoSubmitDescription(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)Accepts the new description.StringgetAbsoluteUrl()Returns the absolute URL of this item.ACLgetACL()Returns theACLfor this object.abstract Collection<? extends Job>getAllJobs()Gets all the jobs that thisItemcontains as descendants.ApigetApi()Remote API access.XmlFilegetConfigFile()StringgetDescription()Gets the project description HTML.StringgetDisplayName()Gets the human readable short name of this item.StringgetDisplayNameOrNull()This is intended to be used by the Job configuration pages where we want to return null if the display name is not set.StringgetFullDisplayName()Works likeItem.getDisplayName()but return the full path that includes all the display names of the ancestors.StringgetFullName()Gets the full name of this item, like "abc/def/ghi".StringgetName()Gets the name of the item.ItemGroupgetParent()This bridge method is to maintain binary compatibility withItem.getParent().StringgetPronoun()Get the term used in the UI to represent this kind ofItem.StringgetRelativeDisplayNameFrom(ItemGroup p)Gets the display name of the current item relative to the given group.StringgetRelativeNameFromGroup(ItemGroup p)This method only exists to disambiguateItem.getRelativeNameFrom(ItemGroup)andItem.getRelativeNameFrom(Item)FilegetRootDir()Gets the root directory on the file system that thisItemcan use freely for storing the configuration data.StringgetSearchName()Default implementation that returns the display name.StringgetSearchUrl()Returns the URL of this item relative to the parentSearchItem.StringgetShortUrl()Returns the URL of this item relative to the parentItemGroup.ObjectgetTarget()StringgetTaskNoun()Gets the term used in the UI to represent the kind ofQueue.Taskassociated with this kind ofItem.StringgetUrl()Returns the URL of this item relative to the context root of the application.booleanisNameEditable()Controls whether the default rename action is available for this item.voidload()Loads the state of this object from disk.voidmovedTo(DirectlyModifiableTopLevelItemGroup destination, AbstractItem newItem, File destDir)Notify this item it's been moved to another location, replaced by newItem (might be the same object, but not guaranteed).voidonCopiedFrom(Item src)When aItemis copied from existing one, the files are first copied on the file system, then it will be loaded, then this method will be invoked to perform any implementation-specific work.voidonLoad(ItemGroup<? extends Item> parent, String name)Called right after when aItemis loaded from disk.protected voidperformDelete()Does the real job of deleting the item.protected voidrenameTo(String newName)Renames this item.static AbstractItemresolveForCLI(String name)Used for CLI binding.voidsave()Save the settings to a file.voidsetDescription(String description)Sets the project description HTML.voidsetDisplayName(String displayName)voidsetDisplayNameOrNull(String displayName)This method exists so that the Job configuration pages can use getDisplayNameOrNull so that nothing is shown in the display name text box if the display name is not set.StringtoString()voidupdateByXml(Source source)Updates an Item by its XML definition.voidupdateByXml(StreamSource source)Deprecated.as of 1.473 UseupdateByXml(Source)voidwriteConfigDotXml(OutputStream os)Writesconfig.xmlto the specified output stream.protected ObjectwriteReplace()-
Methods inherited from class hudson.model.Actionable
addAction, addOrReplaceAction, doContextMenu, getAction, getAction, getActions, getActions, getAllActions, getDynamic, removeAction, removeActions, replaceAction, replaceActions
-
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface hudson.security.AccessControlled
checkAnyPermission, checkPermission, hasAnyPermission, hasPermission, hasPermission, hasPermission2
-
Methods inherited from interface hudson.model.DescriptorByNameOwner
getDescriptorByName
-
Methods inherited from interface hudson.model.Item
getRelativeNameFrom, getRelativeNameFrom, onCreatedFromScratch
-
Methods inherited from interface hudson.search.SearchableModelObject
getSearch
-
Methods inherited from interface hudson.search.SearchItem
getSearchIndex
-
-
-
-
Field Detail
-
name
protected transient String name
Project name.
-
description
protected volatile String description
Project description. Can be HTML.
-
displayName
protected String displayName
-
SKIP_PERMISSION_CHECK
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean SKIP_PERMISSION_CHECK
Escape hatch for StaplerProxy-based access control
-
PRONOUN
public static final AlternativeUiTextProvider.Message<AbstractItem> PRONOUN
Replaceable pronoun of that points to a job. Defaults to "Job"/"Project" depending on the context.
-
TASK_NOUN
public static final AlternativeUiTextProvider.Message<AbstractItem> TASK_NOUN
Replaceable noun for describing the kind of task that this item represents. Defaults to "Build".
-
-
Method Detail
-
getName
@Exported(visibility=999) public String getName()
Description copied from interface:ItemGets the name of the item.The name must be unique among other
Items that belong to the same parent.This name is also used for directory name, so it cannot contain any character that's not allowed on the file system.
- Specified by:
getNamein interfaceItem- See Also:
Item.getFullName()
-
getPronoun
public String getPronoun()
Get the term used in the UI to represent this kind ofItem. Must start with a capital letter.
-
getTaskNoun
public String getTaskNoun()
Gets the term used in the UI to represent the kind ofQueue.Taskassociated with this kind ofItem. Must start with a capital letter. Defaults to "Build".- Since:
- 2.50
-
getDisplayName
@Exported public String getDisplayName()
Description copied from interface:ItemGets the human readable short name of this item.This method should try to return a short concise human readable string that describes this item. The string need not be unique.
The returned string should not include the display names of
ancestor items.- Specified by:
getDisplayNamein interfaceItem- Specified by:
getDisplayNamein interfaceModelObject- Returns:
- The display name of this object, or if it is not set, the name of the object.
-
getDisplayNameOrNull
@Exported public String getDisplayNameOrNull()
This is intended to be used by the Job configuration pages where we want to return null if the display name is not set.- Returns:
- The display name of this object or null if the display name is not set
-
setDisplayNameOrNull
public void setDisplayNameOrNull(String displayName) throws IOException
This method exists so that the Job configuration pages can use getDisplayNameOrNull so that nothing is shown in the display name text box if the display name is not set.- Throws:
IOException
-
setDisplayName
public void setDisplayName(String displayName) throws IOException
- Throws:
IOException
-
getRootDir
public File getRootDir()
Description copied from interface:PersistenceRootGets the root directory on the file system that thisItemcan use freely for storing the configuration data.This parameter is given by the
ItemGroupwhenItemis loaded from memory.- Specified by:
getRootDirin interfacePersistenceRoot
-
getParent
@WithBridgeMethods(value=Jenkins.class, castRequired=true) @NonNull public ItemGroup getParent()
This bridge method is to maintain binary compatibility withItem.getParent().
-
getDescription
@Exported public String getDescription()
Gets the project description HTML.
-
setDescription
public void setDescription(String description) throws IOException
Sets the project description HTML.- Throws:
IOException
-
doSetName
protected void doSetName(String name)
Just updatenamewithout performing the rename operation, which would involve copying files and etc.
-
isNameEditable
public boolean isNameEditable()
Controls whether the default rename action is available for this item.- Returns:
- whether
namecan be modified by a user - Since:
- 2.110
- See Also:
checkRename(java.lang.String),renameTo(java.lang.String)
-
doConfirmRename
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public org.kohsuke.stapler.HttpResponse doConfirmRename(@QueryParameter String newName) throws IOExceptionRenames this item- Throws:
IOException
-
doCheckNewName
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @NonNull public FormValidation doCheckNewName(@QueryParameter String newName)
Called bydoConfirmRename(java.lang.String)andrename.jellyto validate renames.- Returns:
FormValidation.ok(java.lang.String)if this item can be renamed as specified, otherwiseFormValidation.error(java.lang.String)with a message explaining the problem.
-
checkRename
protected void checkRename(@NonNull String newName) throws FailureAllows subclasses to block renames for domain-specific reasons. Generic validation of the new name (e.g., null checking, checking for illegal characters, and checking that the name is not in use) always happens prior to calling this method.- Parameters:
newName- the new name for the item- Throws:
Failure- if the rename should be blocked- Since:
- 2.110
- See Also:
Job.checkRename(java.lang.String)
-
renameTo
protected void renameTo(String newName) throws IOException
Renames this item. Not all the Items need to support this operation, but if you decide to do so, you can use this method.- Throws:
IOException
-
movedTo
public void movedTo(DirectlyModifiableTopLevelItemGroup destination, AbstractItem newItem, File destDir) throws IOException
Notify this item it's been moved to another location, replaced by newItem (might be the same object, but not guaranteed). This method is executed after the item root directory has been moved to it's new location.Derived classes can override this method to add some specific behavior on move, but have to call parent method so the item is actually setup within it's new parent.
-
getAllJobs
public abstract Collection<? extends Job> getAllJobs()
Gets all the jobs that thisItemcontains as descendants.- Specified by:
getAllJobsin interfaceItem
-
getFullName
@Exported public final String getFullName()
Description copied from interface:ItemGets the full name of this item, like "abc/def/ghi".Full name consists of
names ofItems that lead from the rootJenkinsto thisItem, separated by '/'. This is the unique name that identifies thisIteminside the wholeJenkins.- Specified by:
getFullNamein interfaceItem- See Also:
Jenkins.getItemByFullName(String,Class)
-
getFullDisplayName
@Exported public final String getFullDisplayName()
Description copied from interface:ItemWorks likeItem.getDisplayName()but return the full path that includes all the display names of the ancestors.- Specified by:
getFullDisplayNamein interfaceItem
-
getRelativeDisplayNameFrom
public String getRelativeDisplayNameFrom(ItemGroup p)
Gets the display name of the current item relative to the given group.- Parameters:
p- the ItemGroup used as point of reference for the item- Returns:
- String like "foo ยป bar"
- Since:
- 1.515
-
getRelativeNameFromGroup
public String getRelativeNameFromGroup(ItemGroup p)
This method only exists to disambiguateItem.getRelativeNameFrom(ItemGroup)andItem.getRelativeNameFrom(Item)- Since:
- 1.512
- See Also:
Item.getRelativeNameFrom(ItemGroup)
-
onLoad
public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException
Called right after when aItemis loaded from disk. This is an opportunity to do a post load processing.- Specified by:
onLoadin interfaceItemname- Name of the directory (not a path --- just the name portion) from which the configuration was loaded. This usually becomes thenameof this item.- Throws:
IOException
-
onCopiedFrom
public void onCopiedFrom(Item src)
When aItemis copied from existing one, the files are first copied on the file system, then it will be loaded, then this method will be invoked to perform any implementation-specific work.- Specified by:
onCopiedFromin interfaceItem- Parameters:
src- Item from which it's copied from. The same type asthis. Never null.
-
getUrl
public final String getUrl()
Description copied from interface:ItemReturns the URL of this item relative to the context root of the application.- Specified by:
getUrlin interfaceItem- Returns:
- URL that ends with '/'.
- See Also:
for how to implement this.
-
getShortUrl
public String getShortUrl()
Description copied from interface:ItemReturns the URL of this item relative to the parentItemGroup.- Specified by:
getShortUrlin interfaceItem- Returns:
- URL that ends with '/'.
- See Also:
for how to implement this.
-
getSearchUrl
public String getSearchUrl()
Description copied from interface:SearchItemReturns the URL of this item relative to the parentSearchItem.- Specified by:
getSearchUrlin interfaceSearchItem- Returns:
- URL like "foo" or "foo/bar". The path can end with '/'. The path that starts with '/' will be interpreted as the absolute path (within the context path of Jenkins.)
-
getAbsoluteUrl
@Exported(visibility=999, name="url") public final String getAbsoluteUrl()Description copied from interface:ItemReturns the absolute URL of this item. This relies on the currentStaplerRequestto figure out what the host name is, so can be used only during processing client requests.- Specified by:
getAbsoluteUrlin interfaceItem- Returns:
- absolute URL.
-
getApi
public final Api getApi()
Remote API access.
-
getACL
@NonNull public ACL getACL()
Returns theACLfor this object.- Specified by:
getACLin interfaceAccessControlled- Returns:
- never null.
-
save
public void save() throws IOExceptionSave the settings to a file.- Specified by:
savein interfaceItem- Specified by:
savein interfaceSaveable- Throws:
IOException- if the persistence failed.
-
getConfigFile
public final XmlFile getConfigFile()
-
writeReplace
protected Object writeReplace()
-
doSubmitDescription
public void doSubmitDescription(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletExceptionAccepts the new description.- Throws:
IOExceptionjavax.servlet.ServletException
-
doDoDelete
public void doDoDelete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException, InterruptedExceptionDeletes this item. Note on the funny name: for reasons of historical compatibility, this URL is/doDeletesince it predates<l:confirmationLink>./deletegoes to a Jelly page which should now be unused by core but is left in case plugins are still using it.- Throws:
IOExceptionjavax.servlet.ServletExceptionInterruptedException
-
delete
public void delete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException- Specified by:
deletein interfaceorg.kohsuke.stapler.HttpDeletable- Throws:
IOExceptionjavax.servlet.ServletException
-
delete
public void delete() throws IOException, InterruptedExceptionDeletes this item.Any exception indicates the deletion has failed, but
AbortExceptionwould prevent the caller from showing the stack trace. This- Specified by:
deletein interfaceItem- Throws:
IOExceptionInterruptedException
-
performDelete
protected void performDelete() throws IOException, InterruptedExceptionDoes the real job of deleting the item.- Throws:
IOExceptionInterruptedException
-
doConfigDotXml
@WebMethod(name="config.xml") public void doConfigDotXml(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOExceptionAcceptsconfig.xmlsubmission, as well as serve it.- Throws:
IOException
-
writeConfigDotXml
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void writeConfigDotXml(OutputStream os) throws IOException
Writesconfig.xmlto the specified output stream. The user must have at leastItem.EXTENDED_READ. If he lacksItem.CONFIGURE, then anySecrets detected will be masked out.- Throws:
IOException
-
updateByXml
@Deprecated public void updateByXml(StreamSource source) throws IOException
Deprecated.as of 1.473 UseupdateByXml(Source)- Throws:
IOException
-
updateByXml
public void updateByXml(Source source) throws IOException
Updates an Item by its XML definition.- Parameters:
source- source of the Item's new definition. The source should be either aStreamSourceor aSAXSource, other sources may not be handled.- Throws:
IOException- Since:
- 1.473
-
doReload
public void doReload() throws IOExceptionReloads this job from the disk. Exposed through CLI as well. TODO: think about exposing this to UI- Throws:
IOException- Since:
- 1.556
-
load
public void load() throws IOExceptionDescription copied from interface:LoadableLoads the state of this object from disk.- Specified by:
loadin interfaceLoadable- Throws:
IOException- The state could not be loaded.
-
getSearchName
public String getSearchName()
Description copied from class:AbstractModelObjectDefault implementation that returns the display name.- Specified by:
getSearchNamein interfaceSearchItem- Overrides:
getSearchNamein classAbstractModelObject
-
getTarget
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public Object getTarget()
- Specified by:
getTargetin interfaceorg.kohsuke.stapler.StaplerProxy
-
resolveForCLI
@CLIResolver public static AbstractItem resolveForCLI(String name) throws org.kohsuke.args4j.CmdLineException
Used for CLI binding.- Throws:
org.kohsuke.args4j.CmdLineException
-
-