Package hudson.model
Class Items
java.lang.Object
hudson.model.Items
Convenience methods related to 
Item.- Author:
- Kohsuke Kawaguchi
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final Comparator<Item> A comparator ofIteminstances that uses a case-insensitive comparison ofItem.getFullName().static final Comparator<Item> A comparator ofIteminstances that uses a case-insensitive comparison ofItem.getName().static final List<TopLevelItemDescriptor> Deprecated.static final com.thoughtworks.xstream.XStreamUsed to load/save job configuration.static final XStream2
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionall()Returns all the registeredTopLevelItemDescriptors.static List<TopLevelItemDescriptor> Returns all the registeredTopLevelItemDescriptors that the current security principal is allowed to create within the specified item group.static List<TopLevelItemDescriptor> all(Authentication a, ItemGroup c) Deprecated.static List<TopLevelItemDescriptor> Returns all the registeredTopLevelItemDescriptors that the specified security principal is allowed to create within the specified item group.Gets a read-only view of all theItems recursively in theItemGrouptree visible toJenkins.getAuthentication2()without concern for the order in which items are returned.Gets a read-only view of all theItems recursively matching type and predicate in theItemGrouptree visible toJenkins.getAuthentication2()without concern for the order in which items are returned.allItems(Authentication authentication, ItemGroup root, Class<T> type) Deprecated.allItems(Authentication authentication, ItemGroup root, Class<T> type, Predicate<T> pred) Deprecated.allItems2(org.springframework.security.core.Authentication authentication, ItemGroup root, Class<T> type) allItems2(org.springframework.security.core.Authentication authentication, ItemGroup root, Class<T> type, Predicate<T> pred) static <V,T extends Throwable> 
 VcallWhileUpdatingByXml(ThrowingCallable<V, T> callable) Runs a block while makingcurrentlyUpdatingByXml()be temporarily true.static StringcomputeRelativeNamesAfterRenaming(String oldFullName, String newFullName, String relativeNames, ItemGroup context) Computes the relative name of list of items after a rename or move occurred.static booleanChecks whether we are in the middle of creating or configuring an item via XML.static <T extends Item>
 TfindNearest(Class<T> type, String name, ItemGroup context) Finds an item whose name (when referenced from the specified context) is closest to the given name.fromNameList(ItemGroup context, String list, Class<T> type) Does the opposite oftoNameList(Collection).fromNameList(String list, Class<T> type) Deprecated.as of 1.406 UsefromNameList(ItemGroup, String, Class)getAllItems(ItemGroup root, Class<T> type) getAllItems(ItemGroup root, Class<T> type, Predicate<T> pred) Similar togetAllItems(ItemGroup, Class)but with a predicate to pre-filter items to avoid checking ACLs unnecessarily and returning items not required by the callerstatic StringgetCanonicalName(ItemGroup context, String path) Computes the canonical full name of a relative path in anItemGroupcontext, handling relative positions ".." and "." as absolute path starting with "/".static XmlFilegetConfigFile(Item item) The file we save our configuration.static XmlFilegetConfigFile(File dir) The file we save our configuration.static TopLevelItemDescriptorgetDescriptor(String fqcn) Deprecated.Underspecified what the parameter is.static ItemLoads aItemfrom a config file.static <I extends AbstractItem & TopLevelItem>
 Imove(I item, DirectlyModifiableTopLevelItemGroup destination) Moves an item between folders (or top level).static <T extends Throwable>
 voidrunWhileUpdatingByXml(ThrowingRunnable<T> runnable) Runs a block while makingcurrentlyUpdatingByXml()be temporarily true.static StringtoNameList(Collection<? extends Item> items) Converts a list of items into a comma-separated list of full names.static <V,T extends Throwable> 
 VwhileUpdatingByXml(hudson.remoting.Callable<V, T> callable) 
- 
Field Details- 
LISTList of all installedTopLevelItemtypes.
- 
BY_NAMEA comparator ofIteminstances that uses a case-insensitive comparison ofItem.getName(). If you are replacinggetAllItems(ItemGroup, Class)withallItems(ItemGroup, Class)and need to restore the sort order of a further filtered result, you probably wantBY_FULL_NAME.- Since:
- 2.37
 
- 
BY_FULL_NAMEA comparator ofIteminstances that uses a case-insensitive comparison ofItem.getFullName().- Since:
- 2.37
 
- 
XSTREAMpublic static final com.thoughtworks.xstream.XStream XSTREAMUsed to load/save job configuration. When you extendJobin a plugin, try to put the alias so that it produces a reasonable XML.
- 
XSTREAM2
 
- 
- 
Constructor Details- 
Itemspublic Items()
 
- 
- 
Method Details- 
runWhileUpdatingByXmlpublic static <T extends Throwable> void runWhileUpdatingByXml(ThrowingRunnable<T> runnable) throws T Runs a block while makingcurrentlyUpdatingByXml()be temporarily true. Use this when you are creating or changing an item.- Type Parameters:
- T- an error type (may be- Error)
- Parameters:
- runnable- a block, typically running- load(hudson.model.ItemGroup, java.io.File)or- Item.onLoad(hudson.model.ItemGroup<? extends hudson.model.Item>, java.lang.String)
- Throws:
- T- anything- runnablethrows
- Since:
- TODO
 
- 
callWhileUpdatingByXmlpublic static <V,T extends Throwable> V callWhileUpdatingByXml(ThrowingCallable<V, T> callable) throws TRuns a block while makingcurrentlyUpdatingByXml()be temporarily true. Use this when you are creating or changing an item.- Type Parameters:
- V- a return value type (may be- Void)
- T- an error type (may be- Error)
- Parameters:
- callable- a block, typically running- load(hudson.model.ItemGroup, java.io.File)or- Item.onLoad(hudson.model.ItemGroup<? extends hudson.model.Item>, java.lang.String)
- Returns:
- whatever callablereturned
- Throws:
- T- anything- callablethrows
- Since:
- TODO
 
- 
whileUpdatingByXmlpublic static <V,T extends Throwable> V whileUpdatingByXml(hudson.remoting.Callable<V, T> callable) throws TPreferrunWhileUpdatingByXml(jenkins.util.ThrowingRunnable<T>)orcallWhileUpdatingByXml(jenkins.util.ThrowingCallable<V, T>).- Throws:
- T
- Since:
- 1.546
 
- 
currentlyUpdatingByXmlpublic static boolean currentlyUpdatingByXml()Checks whether we are in the middle of creating or configuring an item via XML. Used to determine thenewInstanceparameter forTrigger.start(J, boolean).- Returns:
- true if runWhileUpdatingByXml(jenkins.util.ThrowingRunnable<T>)orcallWhileUpdatingByXml(jenkins.util.ThrowingCallable<V, T>)is currently being called, false for example when merely starting Jenkins or reloading from disk
- Since:
- 1.546
 
- 
allReturns all the registeredTopLevelItemDescriptors.
- 
allReturns all the registeredTopLevelItemDescriptors that the current security principal is allowed to create within the specified item group.- Since:
- 1.607
 
- 
all2public static List<TopLevelItemDescriptor> all2(org.springframework.security.core.Authentication a, ItemGroup c) Returns all the registeredTopLevelItemDescriptors that the specified security principal is allowed to create within the specified item group.- Since:
- 2.266
 
- 
allDeprecated.- Since:
- 1.607
 
- 
getDescriptorDeprecated.Underspecified what the parameter is.Descriptor.getId()? ADescribableclass name?
- 
toNameListConverts a list of items into a comma-separated list of full names.
- 
fromNameListDeprecated.as of 1.406 UsefromNameList(ItemGroup, String, Class)
- 
fromNameListpublic static <T extends Item> List<T> fromNameList(ItemGroup context, @NonNull String list, @NonNull Class<T> type) Does the opposite oftoNameList(Collection).
- 
getCanonicalNameComputes the canonical full name of a relative path in anItemGroupcontext, handling relative positions ".." and "." as absolute path starting with "/". The resulting name is the item fullName from Jenkins root.
- 
computeRelativeNamesAfterRenamingpublic static String computeRelativeNamesAfterRenaming(String oldFullName, String newFullName, String relativeNames, ItemGroup context) Computes the relative name of list of items after a rename or move occurred. Used to manage job references as names in plugins to supportItemListener.onLocationChanged(hudson.model.Item, java.lang.String, java.lang.String).In a hierarchical context, when a plugin has a reference to a job as ../foo/barthis method will handle the relative path as "foo" is renamed to "zot" to compute../zot/bar- Parameters:
- oldFullName- the old full name of the item
- newFullName- the new full name of the item
- relativeNames- coma separated list of Item relative names
- context- the {link ItemGroup} relative names refer to
- Returns:
- relative name for the renamed item, based on the same ItemGroup context
 
- 
loadLoads aItemfrom a config file.- Parameters:
- dir- The directory that contains the config file, not the config file itself.
- Throws:
- IOException
 
- 
getConfigFileThe file we save our configuration.
- 
getConfigFileThe file we save our configuration.
- 
getAllItemsGets all theItems recursively in theItemGrouptree and filter them by the given type. The returned list will represent a snapshot view of the items present at some time during the call. If items are moved during the call, depending on the move, it may be possible for some items to escape the snapshot entirely.If you do not need to iterate all items, or if the order of the items is not required, consider using allItems(ItemGroup, Class)instead.- Parameters:
- root- Root node to start searching from
- type- Given type of of items being searched for
- Returns:
- List of items matching given criteria
- Since:
- 1.512
 
- 
getAllItemspublic static <T extends Item> List<T> getAllItems(ItemGroup root, Class<T> type, Predicate<T> pred) Similar togetAllItems(ItemGroup, Class)but with a predicate to pre-filter items to avoid checking ACLs unnecessarily and returning items not required by the caller- Parameters:
- root- Root node to start searching from
- type- Given type of of items being searched for
- pred- Predicate condition to filter items
- Returns:
- List of items matching given criteria
- Since:
- 2.221
 
- 
allItemsGets a read-only view of all theItems recursively in theItemGrouptree visible toJenkins.getAuthentication2()without concern for the order in which items are returned. Each iteration of the view will be "live" reflecting the items available between the time the iteration was started and the time the iteration was completed, however if items are moved during an iteration - depending on the move - it may be possible for such items to escape the entire iteration.- Type Parameters:
- T- the type.
- Parameters:
- root- the root.
- type- the type.
- Returns:
- An Iterablefor all items.
- Since:
- 2.37
 
- 
allItemspublic static <T extends Item> Iterable<T> allItems(ItemGroup root, Class<T> type, Predicate<T> pred) Gets a read-only view of all theItems recursively matching type and predicate in theItemGrouptree visible toJenkins.getAuthentication2()without concern for the order in which items are returned. Each iteration of the view will be "live" reflecting the items available between the time the iteration was started and the time the iteration was completed, however if items are moved during an iteration - depending on the move - it may be possible for such items to escape the entire iteration.- Type Parameters:
- T- the type.
- Parameters:
- root- the root.
- type- the type.
- pred- the predicate.
- Returns:
- An Iterablefor all items.
- Since:
- 2.221
 
- 
allItems2public static <T extends Item> Iterable<T> allItems2(org.springframework.security.core.Authentication authentication, ItemGroup root, Class<T> type) Gets a read-only view all theItems recursively in theItemGrouptree visible to the supplied authentication without concern for the order in which items are returned. Each iteration of the view will be "live" reflecting the items available between the time the iteration was started and the time the iteration was completed, however if items are moved during an iteration - depending on the move - it may be possible for such items to escape the entire iteration.- Type Parameters:
- T- the type.
- Parameters:
- root- the root.
- type- the type.
- Returns:
- An Iterablefor all items.
- Since:
- 2.266
 
- 
allItems@Deprecated public static <T extends Item> Iterable<T> allItems(Authentication authentication, ItemGroup root, Class<T> type) Deprecated.- Since:
- 2.37
 
- 
allItems2public static <T extends Item> Iterable<T> allItems2(org.springframework.security.core.Authentication authentication, ItemGroup root, Class<T> type, Predicate<T> pred) Gets a read-only view all theItems recursively matching supplied type and predicate conditions in theItemGrouptree visible to the supplied authentication without concern for the order in which items are returned. Each iteration of the view will be "live" reflecting the items available between the time the iteration was started and the time the iteration was completed, however if items are moved during an iteration - depending on the move - it may be possible for such items to escape the entire iteration.- Type Parameters:
- T- the type.
- Parameters:
- root- the root.
- type- the type.
- pred- the predicate.
- Returns:
- An Iterablefor all items.
- Since:
- 2.266
 
- 
allItems@Deprecated public static <T extends Item> Iterable<T> allItems(Authentication authentication, ItemGroup root, Class<T> type, Predicate<T> pred) Deprecated.- Since:
- 2.221
 
- 
findNearest@CheckForNull public static <T extends Item> T findNearest(Class<T> type, String name, ItemGroup context) Finds an item whose name (when referenced from the specified context) is closest to the given name.- Type Parameters:
- T- the type of item being considered
- Parameters:
- type- same as- T
- name- the supplied name
- context- a context to start from (used to compute relative names)
- Returns:
- the closest available item
- Since:
- 1.538
 
- 
movepublic static <I extends AbstractItem & TopLevelItem> I move(I item, DirectlyModifiableTopLevelItemGroup destination) throws IOException, IllegalArgumentException Moves an item between folders (or top level). Fires all relevant events but does not verify that the item’s directory is not currently being used in some way (for example by a running build). Does not check any permissions.- Parameters:
- item- some item (job or folder)
- destination- the destination of the move (a folder or- Jenkins); not the current parent (or you could just call- AbstractItem.renameTo(java.lang.String))
- Returns:
- the new item (usually the same object as item)
- Throws:
- IOException- if the move fails, or some subsequent step fails (directory might have already been moved)
- IllegalArgumentException- if the move would really be a rename, or the destination cannot accept the item, or the destination already has an item of that name
- Since:
- 1.548
 
 
- 
all()for read access andExtensionfor registration.