Class 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
Item
.- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.kohsuke.stapler.HttpDeletable
org.kohsuke.stapler.HttpDeletable.HttpDeletableDispatcher
Nested classes/interfaces inherited from interface jenkins.model.ModelObjectWithContextMenu
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem, ModelObjectWithContextMenu.MenuItemType
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
Project description.protected String
protected String
Project name.static final AlternativeUiTextProvider.Message<AbstractItem>
Replaceable pronoun of that points to a job.static boolean
Escape hatch for StaplerProxy-based access controlstatic final AlternativeUiTextProvider.Message<AbstractItem>
Replaceable noun for describing the kind of task that this item represents. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkRename
(String newName) Allows subclasses to block renames for domain-specific reasons.void
delete()
Deletes this item.void
delete
(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) void
delete
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Deprecated.doCheckNewName
(String newName) Called bydoConfirmRename(java.lang.String)
andrename.jelly
to validate renames.void
doConfigDotXml
(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Acceptsconfig.xml
submission, as well as serve it.void
doConfigDotXml
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Deprecated.org.kohsuke.stapler.HttpResponse
doConfirmRename
(String newName) Renames this itemvoid
doDoDelete
(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Deletes this item.void
doDoDelete
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Deprecated.void
doReload()
Reloads this job from the disk.protected void
Just updatename
without performing the rename operation, which would involve copying files and etc.void
doSubmitDescription
(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Accepts the new description.void
doSubmitDescription
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Deprecated.final String
Returns the absolute URL of this item.getACL()
Returns theACL
for this object.abstract Collection<? extends Job>
Gets all the jobs that thisItem
contains as descendants.final Api
getApi()
Remote API access.final XmlFile
Gets the project description HTML.Gets the human readable short name of this item.This is intended to be used by the Job configuration pages where we want to return null if the display name is not set.final String
Works likeItem.getDisplayName()
but return the full path that includes all the display names of the ancestors.final String
Gets the full name of this item, like "abc/def/ghi".getName()
Gets the name of the item.This bridge method is to maintain binary compatibility withItem.getParent()
.Get the term used in the UI to represent this kind ofItem
.Gets the display name of the current item relative to the given group.This method only exists to disambiguateItem.getRelativeNameFrom(ItemGroup)
andItem.getRelativeNameFrom(Item)
Gets the root directory on the file system that thisItem
can use freely for storing the configuration data.Default implementation that returns the display name.Returns the URL of this item relative to the parentSearchItem
.Returns the URL of this item relative to the parentItemGroup
.Gets the term used in the UI to represent the kind ofQueue.Task
associated with this kind ofItem
.final String
getUrl()
Returns the URL of this item relative to the context root of the application.boolean
Controls whether the default rename action is available for this item.void
load()
Loads the state of this object from disk.void
movedTo
(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).void
onCopiedFrom
(Item src) When aItem
is 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.void
Called right after when aItem
is loaded from disk.protected void
Does the real job of deleting the item.protected void
Renames this item.static AbstractItem
resolveForCLI
(String name) Used for CLI binding.void
save()
Save the settings to a file.void
setDescription
(String description) Sets the project description HTML.void
setDisplayName
(String displayName) void
setDisplayNameOrNull
(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.toString()
void
updateByXml
(Source source) Updates an Item by its XML definition.void
updateByXml
(StreamSource source) Deprecated.as of 1.473 UseupdateByXml(Source)
void
Writesconfig.xml
to the specified output stream.protected Object
Methods inherited from class hudson.model.Actionable
addAction, addOrReplaceAction, doContextMenu, doContextMenu, getAction, getAction, getActions, getActions, getAllActions, getDynamic, getDynamic, removeAction, removeActions, replaceAction, replaceActions
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, makeSearchIndex, requirePOST, sendError, sendError, sendError, 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 Details
-
name
Project name. -
description
Project description. Can be HTML. -
displayName
-
SKIP_PERMISSION_CHECK
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean SKIP_PERMISSION_CHECKEscape hatch for StaplerProxy-based access control -
PRONOUN
Replaceable pronoun of that points to a job. Defaults to "Job"/"Project" depending on the context. -
TASK_NOUN
Replaceable noun for describing the kind of task that this item represents. Defaults to "Build".
-
-
Constructor Details
-
AbstractItem
-
-
Method Details
-
getName
Description copied from interface:Item
Gets the name of the item.The name must be unique among other
Item
s 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.
-
getPronoun
Get the term used in the UI to represent this kind ofItem
. Must start with a capital letter. -
getTaskNoun
Gets the term used in the UI to represent the kind ofQueue.Task
associated with this kind ofItem
. Must start with a capital letter. Defaults to "Build".- Since:
- 2.50
-
getDisplayName
Description copied from interface:Item
Gets 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:
getDisplayName
in interfaceItem
- Specified by:
getDisplayName
in interfaceModelObject
- Returns:
- The display name of this object, or if it is not set, the name of the object.
-
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
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
- Throws:
IOException
-
getRootDir
Description copied from interface:PersistenceRoot
Gets the root directory on the file system that thisItem
can use freely for storing the configuration data.This parameter is given by the
ItemGroup
whenItem
is loaded from memory.- Specified by:
getRootDir
in interfacePersistenceRoot
-
getParent
This bridge method is to maintain binary compatibility withItem.getParent()
. -
getDescription
Gets the project description HTML. -
setDescription
Sets the project description HTML.- Throws:
IOException
-
doSetName
Just updatename
without 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
name
can be modified by a user - Since:
- 2.110
- See Also:
-
doConfirmRename
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public org.kohsuke.stapler.HttpResponse doConfirmRename(@QueryParameter String newName) throws IOException Renames 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.jelly
to 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
Allows 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:
-
renameTo
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
Gets all the jobs that thisItem
contains as descendants.- Specified by:
getAllJobs
in interfaceItem
-
getFullName
Description copied from interface:Item
Gets the full name of this item, like "abc/def/ghi".Full name consists of
name
s ofItem
s that lead from the rootJenkins
to thisItem
, separated by '/'. This is the unique name that identifies thisItem
inside the wholeJenkins
.- Specified by:
getFullName
in interfaceItem
- See Also:
-
getFullDisplayName
Description copied from interface:Item
Works likeItem.getDisplayName()
but return the full path that includes all the display names of the ancestors.- Specified by:
getFullDisplayName
in interfaceItem
-
getRelativeDisplayNameFrom
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
This method only exists to disambiguateItem.getRelativeNameFrom(ItemGroup)
andItem.getRelativeNameFrom(Item)
- Since:
- 1.512
- See Also:
-
onLoad
Called right after when aItem
is loaded from disk. This is an opportunity to do a post load processing.- Specified by:
onLoad
in interfaceItem
name
- Name of the directory (not a path --- just the name portion) from which the configuration was loaded. This usually becomes thename
of this item.- Throws:
IOException
-
onCopiedFrom
When aItem
is 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:
onCopiedFrom
in interfaceItem
- Parameters:
src
- Item from which it's copied from. The same type asthis
. Never null.
-
getUrl
Description copied from interface:Item
Returns the URL of this item relative to the context root of the application. -
getShortUrl
Description copied from interface:Item
Returns the URL of this item relative to the parentItemGroup
.- Specified by:
getShortUrl
in interfaceItem
- Returns:
- URL that ends with '/'.
- See Also:
-
getSearchUrl
Description copied from interface:SearchItem
Returns the URL of this item relative to the parentSearchItem
.- Specified by:
getSearchUrl
in 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
Description copied from interface:Item
Returns the absolute URL of this item. This relies on the currentStaplerRequest2
to figure out what the host name is, so can be used only during processing client requests.- Specified by:
getAbsoluteUrl
in interfaceItem
- Returns:
- absolute URL.
-
getApi
Remote API access. -
getACL
Returns theACL
for this object.- Specified by:
getACL
in interfaceAccessControlled
- Returns:
- never null.
-
save
Save the settings to a file.- Specified by:
save
in interfaceItem
- Specified by:
save
in interfaceSaveable
- Throws:
IOException
- if the persistence failed.
-
getConfigFile
-
writeReplace
-
doSubmitDescription
public void doSubmitDescription(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException Accepts the new description.- Throws:
IOException
jakarta.servlet.ServletException
- Since:
- 2.475
-
doSubmitDescription
@Deprecated @StaplerNotDispatchable public void doSubmitDescription(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException Deprecated.- Throws:
IOException
javax.servlet.ServletException
-
doDoDelete
public void doDoDelete(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException, InterruptedException Deletes this item. Note on the funny name: for reasons of historical compatibility, this URL is/doDelete
since it predates<l:confirmationLink>
./delete
goes to a Jelly page which should now be unused by core but is left in case plugins are still using it.- Throws:
IOException
jakarta.servlet.ServletException
InterruptedException
- Since:
- 2.475
-
doDoDelete
@Deprecated @StaplerNotDispatchable public void doDoDelete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException, InterruptedException Deprecated.- Throws:
IOException
javax.servlet.ServletException
InterruptedException
-
delete
public void delete(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException - Specified by:
delete
in interfaceorg.kohsuke.stapler.HttpDeletable
- Throws:
IOException
jakarta.servlet.ServletException
- Since:
- 2.475
-
delete
@Deprecated public void delete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException Deprecated.- Specified by:
delete
in interfaceorg.kohsuke.stapler.HttpDeletable
- Throws:
IOException
javax.servlet.ServletException
-
delete
Deletes this item.Any exception indicates the deletion has failed, but
AbortException
would prevent the caller from showing the stack trace.- Specified by:
delete
in interfaceItem
- Throws:
IOException
InterruptedException
- See Also:
-
performDelete
Does the real job of deleting the item.- Throws:
IOException
InterruptedException
-
doConfigDotXml
@WebMethod(name="config.xml") public void doConfigDotXml(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException Acceptsconfig.xml
submission, as well as serve it.- Throws:
IOException
- Since:
- 2.475
-
doConfigDotXml
@Deprecated @StaplerNotDispatchable public void doConfigDotXml(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException Deprecated.- Throws:
IOException
-
writeConfigDotXml
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void writeConfigDotXml(OutputStream os) throws IOException Writesconfig.xml
to the specified output stream. The user must have at leastItem.EXTENDED_READ
. If he lacksItem.CONFIGURE
, then anySecret
s or other sensitive information detected will be masked out.- Throws:
IOException
- See Also:
-
updateByXml
Deprecated.as of 1.473 UseupdateByXml(Source)
- Throws:
IOException
-
updateByXml
Updates an Item by its XML definition.- Parameters:
source
- source of the Item's new definition. The source should be either aStreamSource
or aSAXSource
, other sources may not be handled.- Throws:
IOException
- Since:
- 1.473
-
doReload
Reloads this job from the disk. Exposed through CLI as well. TODO: think about exposing this to UI- Throws:
IOException
- Since:
- 1.556
-
load
Description copied from interface:Loadable
Loads the state of this object from disk.- Specified by:
load
in interfaceLoadable
- Throws:
IOException
- The state could not be loaded.
-
getSearchName
Description copied from class:AbstractModelObject
Default implementation that returns the display name.- Specified by:
getSearchName
in interfaceSearchItem
- Overrides:
getSearchName
in classAbstractModelObject
-
toString
-
getTarget
- Specified by:
getTarget
in 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
-
delete(StaplerRequest2, StaplerResponse2)