Class Functions
An instance of this class is created for each request and made accessible from view pages via the variable 'h' (h stands for Hudson.)
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classURL decomposed for easier computation of relevant URLs.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanDeprecated, for removal: This API element is subject to removal in a future version.removed without replacement -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringAdds the proper suffix.static voidadvertiseHeaders(jakarta.servlet.http.HttpServletResponse rsp) Advertises the minimum set of HTTP headers that assist programmatic discovery of Jenkins.static voidadvertiseHeaders(javax.servlet.http.HttpServletResponse rsp) Deprecated.static StringappendIfNotNull(String text, String suffix, String nullText) static Stringstatic StringbreakableString(String plain) Get a string that can be safely broken to several lines when necessary.voidcalcCheckUrl(Map attributes, String userDefined, Object descriptor, String field) Determines the parameters that client-side needs for a form validation check.static Stringcapitalize(String s) Converts "abc" to "Abc".static voidcheckAnyPermission(AccessControlled ac, Permission[] permissions) Checks if the current security principal has one of the supplied permissions.static voidcheckAnyPermission(Object object, Permission[] permissions) This version is so that the 'checkAnyPermission' onlayout.jellydegrades gracefully if "it" is not anAccessControlledobject.static voidcheckPermission(AccessControlled object, Permission permission) static voidcheckPermission(Permission permission) static voidcheckPermission(Object object, Permission permission) This version is so that the 'checkPermission' onlayout.jellydegrades gracefully if "it" is not anAccessControlledobject.static voidconfigureAutoRefresh(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean noAutoRefresh) Deprecated.auto refresh has been removedstatic StringcreateRenderOnDemandProxy(org.apache.commons.jelly.JellyContext context, String attributesToCapture) Deprecated.static org.kohsuke.stapler.StaplerRequest2.RenderOnDemandParameterscreateRenderOnDemandProxyParameters(org.apache.commons.jelly.JellyContext context, String attributesToCapture) Called from renderOnDemand.jelly to generate the parameters for the proxy object generation.static Functions.RunUrldecompose(org.kohsuke.stapler.StaplerRequest req) Deprecated.static Functions.RunUrldecompose(org.kohsuke.stapler.StaplerRequest2 req) static <T> Tdefaulted(T value, T defaultValue) If the value exists, return that value.static booleanCan be used to check a checkbox by default.static intCounts the number of rows needed for textarea to fit the content.static Map<Thread, StackTraceElement[]> static Stringstatic <T> Collection<T> static StringPercent-encodes space and non-ASCII UTF-8 characters for use in URLs.static StringTransforms the input string so it renders as written in HTML output: newlines are converted to HTML line breaks, consecutive spaces are retained as&nbsp;, and HTML metacharacters are escaped.static StringextractPluginNameFromIconSrc(String iconSrc) Creates a sub map by using the given range (both ends inclusive).filterDescriptors(Object context, Iterable descriptors) filterExcludingFrom(SortedMap<Integer, V> map, String from, String to) Creates a sub map by using the given range (upper end inclusive).static StringformatMessage(String format, Object args) static StringGenerate a series of<script>tags to includescript.jsfromConsoleAnnotatorFactorys andConsoleAnnotationDescriptors.Generates an unique ID.static Stringstatic StringgetActionUrl(String itUrl, Action action) Computes the hyperlink to actions, to handle the situation when theAction.getUrlName()returns absolute URL.static List<TopLevelItem> getAllTopLevelItems(ItemGroup root) Gets all theTopLevelItems recursively in theItemGrouptree.static List<Descriptor<AuthorizationStrategy>> static StringReturns an avatar image URL for the specified user and preferred image sizestatic List<Descriptor<Builder>> getBuilderDescriptors(AbstractProject<?, ?> project) static List<Descriptor<BuildWrapper>> getBuildWrapperDescriptors(AbstractProject<?, ?> project) static List<Descriptor<CaptchaSupport>> getCheckUrl(String userDefined, Object descriptor, String field) static ArrayList<CLICommand> static List<Descriptor<Cloud>> static List<Descriptor<ComputerLauncher>> Deprecated.static ConsoleUrlProvidergetConsoleProviderFor(Run<?, ?> run) static StringgetConsoleUrl(WithConsoleUrl withConsoleUrl) Computes the link to the console for the run for the specified object, takingConsoleUrlProviderinto account.static jakarta.servlet.http.Cookiestatic Stringstatic javax.servlet.http.CookieDeprecated.static StringDeprecated.static StringgetCrumb(org.kohsuke.stapler.StaplerRequest req) Deprecated.static StringgetCrumb(org.kohsuke.stapler.StaplerRequest2 req) static List<Descriptor<CrumbIssuer>> static Stringstatic Stringstatic org.apache.commons.jelly.JellyContextWhen called from within JEXL expression evaluation, this method returns the currentJellyContextused to evaluate the script.static Localestatic Datestatic Map<DetailGroup, List<Detail>> getDetailsFor(Actionable object) Returns a grouped list of Detail objects for the given Actionable objectstatic StringgetDiffString(int i) Prints the integer as a string that represents difference, like "-5", "+/-0", "+3".static StringgetDiffString2(int i) getDiffString(int)that doesn't show anything for +/-0static StringgetDiffString2(String prefix, int i, String suffix) getDiffString2(int)that puts the result into prefix and suffix if there's something to printstatic Mapstatic StringReturns the link to be displayed in the footer of the UI.static List<NodePropertyDescriptor> Returns those node properties which can be configured as global node properties.static longstatic StringComputes the path to the icon of the given action from the context path.static booleanReturns true if we are running unit tests.static List<JobPropertyDescriptor> static List<JobPropertyDescriptor> getJobPropertyDescriptors(Class<? extends Job> clazz) Work around for bug 6935026.static List<Descriptor<MyViewsTabBar>> static StringgetNearestAncestorUrl(org.kohsuke.stapler.StaplerRequest2 req, Object it) Finds the given object in the ancestor list and returns its URL.static StringgetNearestAncestorUrl(org.kohsuke.stapler.StaplerRequest req, Object it) Deprecated.static Node.Mode[]static List<NodePropertyDescriptor> getNodePropertyDescriptors(Class<? extends Node> clazz) Deprecated.static List<PageDecorator> Gets all thePageDecorators.Used by<f:password/>so that we send an encrypted value to the client.static StringgetProjectListString(List<AbstractProject> projects) static List<Descriptor<Publisher>> getPublisherDescriptors(AbstractProject<?, ?> project) static StringGets the relative display name to the given item from the specified group.static StringComputes the relative path from the current page to the given item.static StringgetRelativeNameFrom(Item p, ItemGroup g) Gets the name to the given item relative to given group.static StringgetRelativeNameFrom(Item p, ItemGroup g, boolean useDisplayName) Gets the relative name or display name to the given item from the specified group.getRequestHeaders(String name) static StringResource path prefix.static List<Descriptor<RetentionStrategy<?>>> Deprecated.static List<SCMDescriptor<?>> getSCMDescriptors(AbstractProject<?, ?> project) static AreaIf we know the user's screen resolution, return it.static ExtensionList<SearchFactory> static StringFinds the inner-mostSearchableModelObjectin scope.static List<Descriptor<SecurityRealm>> Deprecated.static SimplePageDecoratorGets only oneSimplePageDecorator.static List<SimplePageDecorator> static Collection<Descriptor> getSortedDescriptorsForGlobalConfig(com.google.common.base.Predicate<GlobalConfigurationCategory> predicate) Deprecated.static Collection<Descriptor> LikegetSortedDescriptorsForGlobalConfigByDescriptor(Predicate)but with a constant truth predicate, to include all descriptors.static Collection<Descriptor> Gets all the descriptors sorted by their inheritance tree ofDescribableso that descriptors of similar types come nearby.static Collection<Descriptor> Deprecated.This is rather meaningless.static Collection<Descriptor> Descriptors in the global configuration form that users withJenkins.MANAGEpermission can configure.static Collection<Descriptor> Descriptors shown in the global configuration form to users withJenkins.SYSTEM_READpermission.static Mapstatic StringgetSystemProperty(String key) Gets the system property indicated by the specified key.static ThreadInfo[]static StringgetTimeSpanString(Date date) Returns a human-readable string describing the time difference between now and the specified date.static <B> ClassgetTypeParameter(Class<? extends B> c, Class<B> base, int n) Givenc=MyList (extends ArrayList<Foo>), base=List, compute the parameterization of 'base' that's assignable from 'c' (in this caseList<Foo>), and return its n-th type parameter (n=0 would returnFoo).getUserAvatar(User user, String avatarSize) Deprecated.as of 1.451 UsegetAvatar(hudson.model.User, java.lang.String)static Stringstatic StringgetUserTimeZonePostfix(Date date) static Stringstatic StringgetViewResource(Object it, String path) static List<Descriptor<ViewsTabBar>> static Stringstatic booleanhasAnyPermission(AccessControlled ac, Permission[] permissions) Checks if the current security principal has one of the supplied permissions.static booleanhasAnyPermission(Object object, Permission[] permissions) This version is so that the 'hasAnyPermission' degrades gracefully if "it" is not anAccessControlledobject.static booleanhasPermission(Permission permission) Returns true if the current user has the given permission.static booleanhasPermission(Object object, Permission permission) This version is so that the 'hasPermission' can degrade gracefully if "it" is not anAccessControlledobject.static booleanstatic StringhtmlAttributeEscape(String text) Escapes a string so it can be used in an HTML attribute value.static StringhumanReadableByteSize(long size) Returns human readable information about file sizebooleanIf the given href link is matching the current page, return true.static ObjectifThenElse(boolean cond, Object thenValue, Object elseValue) Deprecated.as of 1.294 JEXL now supports the real ternary operator "x?y:z", so this work around is no longer necessary.static StringinferHudsonURL(org.kohsuke.stapler.StaplerRequest req) Deprecated.static StringinferHudsonURL(org.kohsuke.stapler.StaplerRequest2 req) Infers the hudson installation URL from the given request.static voidinitPageVariables(org.apache.commons.jelly.JellyContext context) static booleanChecks if the current user is anonymous.static booleanstatic booleanisAutoRefresh(jakarta.servlet.http.HttpServletRequest request) Deprecated.static booleanisCollapsed(String paneId) static booleanstatic booleanDuring Jenkins start-up, beforeInitMilestone.PLUGINS_STARTEDthe extensions lists will be empty and they are not guaranteed to be fully populated until afterInitMilestone.EXTENSIONS_AUGMENTED, similarly, during termination afterJenkins.isTerminating()is set, it is no longer safe to access the extensions lists.static booleanstatic booleanDeprecated.static booleanstatic booleanstatic booleanstatic booleanstatic booleanDeprecated.Now always true.static Stringiso8601DateTime(Date date) static booleanstatic booleanstatic booleanstatic StringCombine path components via '/' while handling leading/trailing '/' to avoid duplicates.static StringEscape a string so variable values can be used in inline JavaScript in views.static StringReturns a localized string for the specified date, not including time.static StringnbspIndent(String size) One nbsp per 10 pixels in given size, which may be a plain number or "NxN" (like an iconSize).Prepend a prefix only when there's the specified body.static Stringstatic String[]printLogRecordHtml(LogRecord r, LogRecord prior) static voidprintStackTrace(Throwable t, PrintStream ps) LikeThrowable.printStackTrace(PrintStream)but usingprintThrowable(java.lang.Throwable)format.static voidprintStackTrace(Throwable t, PrintWriter pw) LikeThrowable.printStackTrace(PrintWriter)but usingprintThrowable(java.lang.Throwable)format.static StringPrints a stack trace from an exception into a readable form.static ObjectUsed for arguments to internationalized expressions to avoid escapestatic voidstatic <T> Iterable<T> reverse(Collection<T> collection) Reverses a collection so that it can be easily walked in reverse order.static Stringrfc822Date(Calendar cal) static StringrunScript(org.apache.commons.jelly.Script script) Evaluate a Jelly script and return output as a String.static Stringstatic booleanshowInPrimaryHeader(Action action) <T> List<T> singletonList(T t) Deprecated.From JEXL expressions (${…}) in*.jellyfiles you can use[obj]syntax to construct anObject[](which may be usable where aListis expected) rather thanh.singletonList(obj).static intWorks like JSTL build-in size(x) function, but handle null gracefully.static Functions.ThreadGroupMapsortThreadsAndGetGroupMap(ThreadInfo[] list) static <T> List<T> Returns a sub-list if the given list is bigger than the specifiedmaxSize.static StringtoCCStatus(Item i) Deprecated.This functionality has been moved to ccxml plugin.static StringtoEmailSafeString(String projectName) Escapes the character unsafe for e-mail address.static StringtranslateModifierKeysForUsersPlatform(String keyboardShortcut) static IcontryGetIcon(String iconGuess) static StringtryGetIconPath(String iconGuess, org.apache.commons.jelly.JellyContext context) static StringShortcut function for callingURLEncoder.encode(String,String)(with UTF-8 encoding).
Useful for encoding URL query parameters in jelly code (as in"...?param=${h.urlEncode(something)}").
For convenience in jelly code, it also accepts null parameter, and then returns an empty string.static booleanstatic StringvalidateIconSize(String iconSize) static StringEscapes XML unsafe charactersstatic Stringstatic String
-
Field Details
-
DEBUG_YUI
Deprecated, for removal: This API element is subject to removal in a future version.removed without replacementNo longer used, to be removed after enough plugins have adopted a version of the test harness with jenkins-test-harness/pull/874 in it.
-
-
Constructor Details
-
Functions
public Functions()
-
-
Method Details
-
generateId
Generates an unique ID. -
isModel
-
isModelWithContextMenu
-
isModelWithChildren
-
isMatrixProject
Deprecated. -
xsDate
-
iso8601DateTime
-
localDate
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String localDate(Date date) Returns a localized string for the specified date, not including time. -
rfc822Date
-
getTimeSpanString
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String getTimeSpanString(Date date) Returns a human-readable string describing the time difference between now and the specified date. -
isExtensionsAvailable
public static boolean isExtensionsAvailable()During Jenkins start-up, beforeInitMilestone.PLUGINS_STARTEDthe extensions lists will be empty and they are not guaranteed to be fully populated until afterInitMilestone.EXTENSIONS_AUGMENTED, similarly, during termination afterJenkins.isTerminating()is set, it is no longer safe to access the extensions lists. If you attempt to access the extensions list from a UI thread while the extensions are being loaded you will hit a big honking great monitor lock that will block until the effective extension list has been determined (as if a plugin fails to start, all of the failed plugin's extensions and any dependent plugins' extensions will have to be evicted from the list of extensions. In practical terms this only affects the "Jenkins is loading" screen, but as that screen uses the generic layouts we provide this utility method so that the generic layouts can avoid iterating extension lists while Jenkins is starting up. If you attempt to access the extensions list from a UI thread while Jenkins is being shut down, the extensions themselves may no longer be in a valid state and could attempt to revive themselves and block termination. In actual terms the termination only affects those views required to renderHudsonIsRestarting'sindex.jellywhich is the same set as theHudsonIsLoadingpages so it makes sense to use both checks here.- Returns:
trueif the extensions lists have been populated.- Since:
- 1.607
-
initPageVariables
public static void initPageVariables(org.apache.commons.jelly.JellyContext context) -
getTypeParameter
Givenc=MyList (extends ArrayList<Foo>), base=List, compute the parameterization of 'base' that's assignable from 'c' (in this caseList<Foo>), and return its n-th type parameter (n=0 would returnFoo).This method is useful for doing type arithmetic.
- Throws:
AssertionError- if c' is not parameterized.
-
getJDKDescriptor
-
getDiffString
Prints the integer as a string that represents difference, like "-5", "+/-0", "+3". -
getDiffString2
getDiffString(int)that doesn't show anything for +/-0 -
getDiffString2
getDiffString2(int)that puts the result into prefix and suffix if there's something to print -
addSuffix
Adds the proper suffix. -
decompose
- Since:
- 2.475
-
decompose
Deprecated. -
getScreenResolution
If we know the user's screen resolution, return it. Otherwise null.- Since:
- 1.213
-
useHidingPasswordFields
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean useHidingPasswordFields() -
getNodeModes
-
getProjectListString
-
ifThenElse
Deprecated.as of 1.294 JEXL now supports the real ternary operator "x?y:z", so this work around is no longer necessary. -
appendIfNotNull
-
getSystemProperties
-
getSystemProperty
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public static String getSystemProperty(String key) Gets the system property indicated by the specified key. Delegates toSystemProperties.getString(String). -
getEnvVars
-
isWindows
public static boolean isWindows() -
isGlibcSupported
public static boolean isGlibcSupported() -
getLogRecords
-
printLogRecord
-
printLogRecordHtml
-
reverse
Reverses a collection so that it can be easily walked in reverse order.- Since:
- 1.525
-
getCookie
public static jakarta.servlet.http.Cookie getCookie(jakarta.servlet.http.HttpServletRequest req, String name) - Since:
- 2.475
-
getCookie
@Deprecated public static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest req, String name) Deprecated. -
getCookie
public static String getCookie(jakarta.servlet.http.HttpServletRequest req, String name, String defaultValue) - Since:
- 2.475
-
getCookie
@Deprecated public static String getCookie(javax.servlet.http.HttpServletRequest req, String name, String defaultValue) Deprecated. -
validateIconSize
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String validateIconSize(String iconSize) throws SecurityException - Throws:
SecurityException
-
filter
Creates a sub map by using the given range (both ends inclusive). -
filterExcludingFrom
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static <V> SortedMap<Integer,V> filterExcludingFrom(SortedMap<Integer, V> map, String from, String to) Creates a sub map by using the given range (upper end inclusive). -
configureAutoRefresh
@Deprecated public static void configureAutoRefresh(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean noAutoRefresh) Deprecated.auto refresh has been removedNo longer used. -
isAutoRefresh
Deprecated. -
isCollapsed
-
isUserTimeZoneOverride
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean isUserTimeZoneOverride() -
getUserTimeZone
@CheckForNull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String getUserTimeZone() -
getUserTimeZonePostfix
-
getHourLocalTimezone
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static long getHourLocalTimezone() -
getNearestAncestorUrl
Finds the given object in the ancestor list and returns its URL. This is used to determine the "current" URL assigned to the given object, so that one can compute relative URLs from it.- Since:
- 2.475
-
getNearestAncestorUrl
@Deprecated public static String getNearestAncestorUrl(org.kohsuke.stapler.StaplerRequest req, Object it) Deprecated. -
getSearchURL
Finds the inner-mostSearchableModelObjectin scope. -
appendSpaceIfNotNull
-
nbspIndent
One nbsp per 10 pixels in given size, which may be a plain number or "NxN" (like an iconSize). Useful in a sortable table heading. -
getWin32ErrorMessage
-
isMultiline
-
encode
Percent-encodes space and non-ASCII UTF-8 characters for use in URLs.Input example 1: !"£$%^&*()_+}{:@~?><|¬`,./;'#[]- = Output example 1: !"%C2%A3$%^&*()_+}{:@~?><|%C2%AC`,./;'#[]-%20=Notes:- a blank space will render as %20
- this methods only escapes non-ASCII but leaves other URL-unsafe characters, such as '#'
Util.rawEncode(String)in theUtillibrary should generally be used instead (do check the documentation for that method)
-
urlEncode
Shortcut function for callingURLEncoder.encode(String,String)(with UTF-8 encoding).
Useful for encoding URL query parameters in jelly code (as in"...?param=${h.urlEncode(something)}").
For convenience in jelly code, it also accepts null parameter, and then returns an empty string.Input example 1: & " ' < > Output example 1: %26+%22+%27+%3C+%3E Input example 2: !"£$%^&*()_+}{:@~?><|¬`,./;'#[]-= Output example 2: %21%22%C2%A3%24%25%5E%26*%28%29_%2B%7D%7B%3A%40%7E%3F%3E%3C%7C%C2%AC%60%2C.%2F%3B%27%23%5B%5D-%3DNote: A blank space will render as + (You can see this in above examples)- Since:
- 2.200
-
escape
Transforms the input string so it renders as written in HTML output: newlines are converted to HTML line breaks, consecutive spaces are retained as&nbsp;, and HTML metacharacters are escaped.Input example 1: & " ' < > Output example 1: & " ' < > Input example 2: !"£$%^&*()_+}{:@~?><|¬`,./;'#[]-= Output example 2: !"£$%^&*()_+}{:@~?><|¬`,./;'#[]-=- See Also:
-
xmlEscape
Escapes XML unsafe charactersInput example 1: < > & Output example 1: < > & Input example 2: !"£$%^&*()_+}{:@~?><|¬`,./;'#[]-= Output example 2: !"£$%^&*()_+}{:@~?><|¬`,./;'#[]-=- See Also:
-
xmlUnescape
-
htmlAttributeEscape
Escapes a string so it can be used in an HTML attribute value.Input example 1: & " ' < > Output example 1: & " ' < > Input example 2: !"£$%^&*()_+}{:@~?><|¬`,./;'#[]-= Output example 2: !"£$%^&*()_+}{:@~?><|¬`,./;'#[]-=Note: 2 consecutive blank spaces will not render any special chars. -
checkPermission
-
checkPermission
-
checkPermission
This version is so that the 'checkPermission' onlayout.jellydegrades gracefully if "it" is not anAccessControlledobject. Otherwise it will perform no check and that problem is hard to notice. -
hasPermission
Returns true if the current user has the given permission.- Parameters:
permission- If null, returns true. This defaulting is convenient in making the use of this method terse.
-
hasPermission
This version is so that the 'hasPermission' can degrade gracefully if "it" is not anAccessControlledobject. -
inferHudsonURL
Infers the hudson installation URL from the given request.- Since:
- 2.475
-
inferHudsonURL
Deprecated. -
getJobPropertyDescriptors
-
getJobPropertyDescriptors
-
getBuildWrapperDescriptors
public static List<Descriptor<BuildWrapper>> getBuildWrapperDescriptors(AbstractProject<?, ?> project) -
getSecurityRealmDescriptors
-
getAuthorizationStrategyDescriptors
-
getBuilderDescriptors
-
getPublisherDescriptors
-
getSCMDescriptors
-
getComputerLauncherDescriptors
@Deprecated @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) @RestrictedSince("2.12") public static List<Descriptor<ComputerLauncher>> getComputerLauncherDescriptors()Deprecated.- Since:
- 2.12
-
getRetentionStrategyDescriptors
@Deprecated @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) @RestrictedSince("2.12") public static List<Descriptor<RetentionStrategy<?>>> getRetentionStrategyDescriptors()Deprecated.- Since:
- 2.12
-
getParameterDescriptors
-
getCaptchaSupportDescriptors
-
getViewsTabBarDescriptors
-
getMyViewsTabBarDescriptors
-
getNodePropertyDescriptors
@Deprecated @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) @RestrictedSince("2.12") public static List<NodePropertyDescriptor> getNodePropertyDescriptors(Class<? extends Node> clazz) Deprecated.- Since:
- 2.12
-
getGlobalNodePropertyDescriptors
Returns those node properties which can be configured as global node properties.- Since:
- 1.520
-
getSortedDescriptorsForGlobalConfig
@Deprecated @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static Collection<Descriptor> getSortedDescriptorsForGlobalConfig(com.google.common.base.Predicate<GlobalConfigurationCategory> predicate) Deprecated.Gets all the descriptors sorted by their inheritance tree ofDescribableso that descriptors of similar types come nearby.We sort them by
Extension.ordinal()but only forGlobalConfigurations, as the value is normally used to compare similar kinds of extensions, and we neededGlobalConfigurations to be able to position themselves in a layer above. This however creates some asymmetry between regularDescriptors andGlobalConfigurations. Perhaps it is better to introduce another annotation element? But then, extensions shouldn't normally concern themselves about ordering too much, and the only reason we needed this forGlobalConfigurations are for backward compatibility.- Parameters:
predicate- Filter the descriptors based on this predicate- Since:
- 1.494
-
getSortedDescriptorsForGlobalConfigByDescriptor
public static Collection<Descriptor> getSortedDescriptorsForGlobalConfigByDescriptor(Predicate<Descriptor> predicate) Gets all the descriptors sorted by their inheritance tree ofDescribableso that descriptors of similar types come nearby.We sort them by
Extension.ordinal()but only forGlobalConfigurations, as the value is normally used to compare similar kinds of extensions, and we neededGlobalConfigurations to be able to position themselves in a layer above. This however creates some asymmetry between regularDescriptors andGlobalConfigurations. Perhaps it is better to introduce another annotation element? But then, extensions shouldn't normally concern themselves about ordering too much, and the only reason we needed this forGlobalConfigurations are for backward compatibility.- Parameters:
predicate- Filter the descriptors based on this predicate- Since:
- 2.222
-
getSortedDescriptorsForGlobalConfigByDescriptor
LikegetSortedDescriptorsForGlobalConfigByDescriptor(Predicate)but with a constant truth predicate, to include all descriptors. -
getSortedDescriptorsForGlobalConfigNoSecurity
Deprecated.This is rather meaningless. -
getSortedDescriptorsForGlobalConfigUnclassified
Descriptors in the global configuration form that users withJenkins.MANAGEpermission can configure.- Since:
- 1.506
-
getSortedDescriptorsForGlobalConfigUnclassifiedReadable
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static Collection<Descriptor> getSortedDescriptorsForGlobalConfigUnclassifiedReadable()Descriptors shown in the global configuration form to users withJenkins.SYSTEM_READpermission.- Since:
- 2.222
-
hasAnyPermission
Checks if the current security principal has one of the supplied permissions.- Since:
- 2.238
-
hasAnyPermission
This version is so that the 'hasAnyPermission' degrades gracefully if "it" is not anAccessControlledobject. Otherwise it will perform no check and that problem is hard to notice.- Since:
- 2.238
-
checkAnyPermission
Checks if the current security principal has one of the supplied permissions.- Throws:
org.springframework.security.access.AccessDeniedException- if the user doesn't have the permission.- Since:
- 2.222
-
checkAnyPermission
This version is so that the 'checkAnyPermission' onlayout.jellydegrades gracefully if "it" is not anAccessControlledobject. Otherwise it will perform no check and that problem is hard to notice. -
getIconFilePath
Computes the path to the icon of the given action from the context path. -
size2
Works like JSTL build-in size(x) function, but handle null gracefully.- Throws:
Exception
-
getRelativeLinkTo
Computes the relative path from the current page to the given item. -
getAllTopLevelItems
Gets all theTopLevelItems recursively in theItemGrouptree.- Since:
- 1.512
-
getRelativeNameFrom
@Nullable public static String getRelativeNameFrom(@CheckForNull Item p, @CheckForNull ItemGroup g, boolean useDisplayName) Gets the relative name or display name to the given item from the specified group.- Parameters:
p- the Item we want the relative display name. Ifnull, anullwill be returned by the methodg- the ItemGroup used as point of reference for the item. If the group is not specified, item's path will be used.useDisplayName- if true, returns a display name, otherwise returns a name- Returns:
- String like "foo » bar".
nullif item is null or if one of its parents is not anItem. - Since:
- 1.515
-
getRelativeNameFrom
Gets the name to the given item relative to given group.- Parameters:
p- the Item we want the relative display name Ifnull, the method will immediately returnnull.g- the ItemGroup used as point of reference for the item- Returns:
- String like "foo/bar".
nullif the item isnullor if one of its parents is not anItem. - Since:
- 1.515
-
getRelativeDisplayNameFrom
@Nullable public static String getRelativeDisplayNameFrom(@CheckForNull Item p, @CheckForNull ItemGroup g) Gets the relative display name to the given item from the specified group.- Parameters:
p- the Item we want the relative display name. Ifnull, the method will immediately returnnull.g- the ItemGroup used as point of reference for the item- Returns:
- String like "Foo » Bar".
nullif the item isnullor if one of its parents is not anItem. - Since:
- 1.512
-
dumpAllThreads
-
getThreadInfos
-
sortThreadsAndGetGroupMap
-
isMustangOrAbove
Deprecated.Now always true. -
dumpThreadInfo
-
emptyList
-
jsStringEscape
Escape a string so variable values can be used in inline JavaScript in views. Note that inline JavaScript and especially passing variables is discouraged, see the documentation for alternatives.Input example : \ \\ ' " Output example: \\ \\\\ \' \"
- See Also:
-
capitalize
Converts "abc" to "Abc". -
getVersion
-
getResourcePath
Resource path prefix. -
getViewResource
-
hasView
- Throws:
IOException
-
defaultToTrue
Can be used to check a checkbox by default. Used from views likeh.defaultToTrue(scm.useUpdate). The expression will evaluate to true if scm is null. -
defaulted
public static <T> T defaulted(T value, T defaultValue) If the value exists, return that value. Otherwise return the default value.Starting 1.294, JEXL supports the elvis operator "x?:y" that supersedes this.
- Since:
- 1.150
-
printThrowable
Prints a stack trace from an exception into a readable form. UnlikeThrowable.printStackTrace(PrintWriter), this implementation follows the suggestion of JDK-6507809 to produce a linear trace even whenThrowable.getCause()is used.- Parameters:
t- InputThrowable- Returns:
- If
tis not null, generally a multiline string ending in a (platform-specific) newline; otherwise, the method returns a default "No exception details" string.
-
printStackTrace
LikeThrowable.printStackTrace(PrintWriter)but usingprintThrowable(java.lang.Throwable)format.- Parameters:
t- an exception to printpw- the log- Since:
- 2.43
-
printStackTrace
LikeThrowable.printStackTrace(PrintStream)but usingprintThrowable(java.lang.Throwable)format.- Parameters:
t- an exception to printps- the log- Since:
- 2.43
-
determineRows
Counts the number of rows needed for textarea to fit the content. Minimum 5 rows. -
toCCStatus
@Deprecated @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) @RestrictedSince("2.173") public static String toCCStatus(Item i) Deprecated.This functionality has been moved to ccxml plugin.Converts the Hudson build status to CruiseControl build status, which is either Success, Failure, Exception, or Unknown. -
isAnonymous
public static boolean isAnonymous()Checks if the current user is anonymous. -
getCurrentJellyContext
public static org.apache.commons.jelly.JellyContext getCurrentJellyContext()When called from within JEXL expression evaluation, this method returns the currentJellyContextused to evaluate the script.- Since:
- 1.164
-
runScript
public static String runScript(org.apache.commons.jelly.Script script) throws org.apache.commons.jelly.JellyTagException Evaluate a Jelly script and return output as a String.- Throws:
org.apache.commons.jelly.JellyTagException- Since:
- 1.267
-
subList
Returns a sub-list if the given list is bigger than the specifiedmaxSize. Warning: do not call this with aRunList, or you will break lazy loading! -
joinPath
Combine path components via '/' while handling leading/trailing '/' to avoid duplicates. -
getActionUrl
Computes the hyperlink to actions, to handle the situation when theAction.getUrlName()returns absolute URL.- Returns:
- null in case the action should not be presented to the user.
-
getConsoleUrl
Computes the link to the console for the run for the specified object, takingConsoleUrlProviderinto account.- Parameters:
withConsoleUrl- the object to compute a console url for (can beRun, aPlaceholderExecutable...)- Returns:
- the absolute URL for accessing the build console for the given object, or null if there is no console URL defined for the object.
- Since:
- 2.433
-
getConsoleProviderFor
- Parameters:
run- the run- Returns:
- the Console Provider for the given run, if null, the default Console Provider
-
toEmailSafeString
Escapes the character unsafe for e-mail address. See the Wikipedia page for the details, but here the vocabulary is even more restricted. -
getServerName
Deprecated.Obtains the host name of the Hudson server that clients can use to talk back to.This was primarily used in
jenkins-agent.jnlp.jellyto specify the destination that the agents talk to. -
getCheckUrl
Determines the form validation check URL. See textbox.jelly -
calcCheckUrl
Determines the parameters that client-side needs for a form validation check. See prepareDatabinding.jelly- Since:
- 1.528
-
hyperlinkMatchesCurrentPage
If the given href link is matching the current page, return true. Used intask.jellyto decide if the page should be highlighted. -
showInPrimaryHeader
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean showInPrimaryHeader(Action action) If the givenActionis aprimaryRootAction, or a parent of the current page, returntrue. Used inactions.jellyto decide if the action should shown in the main header or the hamburger. -
singletonList
Deprecated.From JEXL expressions (${…}) in*.jellyfiles you can use[obj]syntax to construct anObject[](which may be usable where aListis expected) rather thanh.singletonList(obj). -
getPageDecorators
Gets all thePageDecorators. -
getSimplePageDecorator
Gets only oneSimplePageDecorator.- Since:
- 2.128
-
getSimplePageDecorators
-
getCloudDescriptors
-
prepend
Prepend a prefix only when there's the specified body. -
getCrumbIssuerDescriptors
-
getCrumb
- Since:
- 2.475
-
getCrumb
Deprecated. -
getCrumbRequestField
-
getCurrentTime
-
getCurrentLocale
-
generateConsoleAnnotationScriptAndStylesheet
Generate a series of<script>tags to includescript.jsfromConsoleAnnotatorFactorys andConsoleAnnotationDescriptors.- See Also:
-
getLoggerNames
Work around for bug 6935026. -
getPasswordValue
Used by<f:password/>so that we send an encrypted value to the client. -
filterDescriptors
-
getIsUnitTest
public static boolean getIsUnitTest()Returns true if we are running unit tests. -
isArtifactsPermissionEnabled
public static boolean isArtifactsPermissionEnabled()Returnstrueif theRun.ARTIFACTSpermission is enabled,falseotherwise.When the
Run.ARTIFACTSpermission is not turned on using thehudson.security.ArtifactsPermissionsystem property, this permission must not be considered to be set tofalsefor every user. It must rather be like if the permission doesn't exist at all (which means that every user has to have an access to the artifacts but the permission can't be configured in the security screen). Got it? -
isWipeOutPermissionEnabled
public static boolean isWipeOutPermissionEnabled()Returnstrueif theItem.WIPEOUTpermission is enabled,falseotherwise.The "Wipe Out Workspace" action available on jobs is controlled by the
Item.BUILDpermission. For some specific projects, however, it is not acceptable to let users have this possibility, even it they can trigger builds. As such, when enabling thehudson.security.WipeOutPermissionsystem property, a new "WipeOut" permission will allow to have greater control on the "Wipe Out Workspace" action. -
createRenderOnDemandProxy
@Deprecated public static String createRenderOnDemandProxy(org.apache.commons.jelly.JellyContext context, String attributesToCapture) Deprecated. -
createRenderOnDemandProxyParameters
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static org.kohsuke.stapler.StaplerRequest2.RenderOnDemandParameters createRenderOnDemandProxyParameters(org.apache.commons.jelly.JellyContext context, String attributesToCapture) Called from renderOnDemand.jelly to generate the parameters for the proxy object generation.- Since:
- 2.475
-
getCurrentDescriptorByNameUrl
-
setCurrentDescriptorByNameUrl
-
restoreCurrentDescriptorByNameUrl
-
getRequestHeaders
-
rawHtml
Used for arguments to internationalized expressions to avoid escape -
getCLICommands
-
getAvatar
Returns an avatar image URL for the specified user and preferred image size- Parameters:
user- the useravatarSize- the preferred size of the avatar image- Returns:
- a URL string
- Since:
- 1.433
-
getUserAvatar
Deprecated.as of 1.451 UsegetAvatar(hudson.model.User, java.lang.String) -
humanReadableByteSize
Returns human readable information about file size- Parameters:
size- file size in bytes- Returns:
- file size in appropriate unit
-
breakableString
Get a string that can be safely broken to several lines when necessary. This implementation inserts<wbr>tags into string. It allows browsers to wrap line before any sequence of punctuation characters or anywhere in the middle of prolonged sequences of word characters.- Since:
- 1.517
-
advertiseHeaders
public static void advertiseHeaders(jakarta.servlet.http.HttpServletResponse rsp) Advertises the minimum set of HTTP headers that assist programmatic discovery of Jenkins. -
advertiseHeaders
Deprecated. -
isContextMenuVisible
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean isContextMenuVisible(Action a) -
tryGetIcon
-
extractPluginNameFromIconSrc
-
tryGetIconPath
-
generateItemId
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String generateItemId() -
getDetailsFor
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static Map<DetailGroup,List<Detail>> getDetailsFor(Actionable object) Returns a grouped list of Detail objects for the given Actionable object -
getSearchFactories
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static ExtensionList<SearchFactory> getSearchFactories() -
translateModifierKeysForUsersPlatform
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String translateModifierKeysForUsersPlatform(String keyboardShortcut) - Parameters:
keyboardShortcut- the shortcut to be translated- Returns:
- the translated shortcut, e.g. CMD+K to ⌘+K for macOS, CTRL+K for Windows
-
formatMessage
-