Class VersionHandler
- java.lang.Object
-
- hudson.plugins.project_inheritance.projects.versioning.VersionHandler
-
public class VersionHandler extends Object
This class offers utility functions to encode and decode versioning information in various ways.Since Jenkins lacks the concept of a persistent user-connection across several HTTP interactions, the information about what versions a user has requested needs to be stored in and retrieved from a number of different communication paths.
Different situations need different kinds of storage:
- In the StaplerRequest, when dealing with Web GUI interactions
- In the URL parameters, when dealing with Web GUI redirects
- In the thread, once execution of a build starts
- Author:
- mhschroe
-
-
Field Summary
Fields Modifier and Type Field Description static Map<String,Map<String,Long>>
decodedVersionMaps
static String
SINGLE_VERSION_KEY
This field name is used as an URL parameter, to select the version of the job encoded in the lead-up to the URL.static String
VERSIONING_KEY
This field name is used as an URL parameter, so select versions of arbitrary subprojects.
-
Constructor Summary
Constructors Constructor Description VersionHandler()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Map<String,Long>
addVersions(Map<String,Long> map)
Will merge the currently configured versions (if any) with the given map.static void
clearVersions()
static void
clearVersionsPartial()
Same asclearVersions()
, but only clears "permanent" storage areas, that might leak into subsequent runs.static Map<String,Long>
decodeUrlParameter(String in)
static String
encodeUrlParameter(InheritanceProject root)
static String
encodeUrlParameter(Map<String,Long> in)
static Map<String,Long>
getFromFormRequest(org.kohsuke.stapler.StaplerRequest req)
Decodes the versions stored in the form-part of the given request.static Map<String,Long>
getFromProject(AbstractProject<?,?> root)
This method loads the map of versions from the parameters passed in via the current StaperRequest's URL.static Map<String,Long>
getFromRequest()
Attempts to read the active versions from the current request, no matter if stored as inside the URL parameters or the form part of the request.static Map<String,Long>
getFromUrlParameter()
This method loads the map of versions from the parameters passed in via the current StaperRequest's URL.static String
getFullUrlParameter(String value)
static String
getFullUrlParameter(Map<String,Long> vMap)
static Long
getVersion(InheritanceProject root)
static Map<String,Long>
getVersions()
Tries to fetch pre-initialised versioning information.static Map<String,Long>
initVersions(AbstractProject<?,?> root)
Will initialise the versioning information and distribute it across the various avenues of saving it.static Map<String,Long>
initVersions(Map<String,Long> map)
Will initialise the versioning information and distribute it across the various avenues of saving it.static InheritanceProject
resolve(String name)
Wrapper aroundInheritanceProject.getProjectByName(String)
static Map<InheritanceProject,Long>
resolve(Map<String,Long> in)
-
-
-
Field Detail
-
SINGLE_VERSION_KEY
public static final String SINGLE_VERSION_KEY
This field name is used as an URL parameter, to select the version of the job encoded in the lead-up to the URL.- See Also:
- Constant Field Values
-
VERSIONING_KEY
public static final String VERSIONING_KEY
This field name is used as an URL parameter, so select versions of arbitrary subprojects.- See Also:
- Constant Field Values
-
-
Method Detail
-
resolve
public static InheritanceProject resolve(String name)
Wrapper aroundInheritanceProject.getProjectByName(String)
- Parameters:
name
- the full name of the prefix. Namespaces separated by '/'- Returns:
- the project with that name, may be null if project or prefix namespaces do not exist.
-
getVersions
public static Map<String,Long> getVersions()
Tries to fetch pre-initialised versioning information.If no values have been pre-initialised via
initVersions(AbstractProject)
orsetVersions(Map)
, the map will be empty.- Returns:
- may be empty, but never null. If empty, the caller should use the most recent stable versions, but this function will not actually return those.
-
getVersion
public static Long getVersion(InheritanceProject root)
-
initVersions
public static Map<String,Long> initVersions(AbstractProject<?,?> root)
Will initialise the versioning information and distribute it across the various avenues of saving it.It will first attempt to read the values from the environment via
getVersions()
. It will then combine that map with the defaults from the given projects, with the former one overwriting values of the latter one.- Parameters:
root
- the project to initialize the environment for- Returns:
- all versions for the given project
-
initVersions
public static Map<String,Long> initVersions(Map<String,Long> map)
Will initialise the versioning information and distribute it across the various avenues of saving it.It will take the information as given in the passed-in map.
- Parameters:
map
- the map to set in the current environment- Returns:
- all versions for the given project
-
addVersions
public static Map<String,Long> addVersions(Map<String,Long> map)
Will merge the currently configured versions (if any) with the given map.- Parameters:
map
- the map to overwrite/add values with.- Returns:
- the joined map.
-
clearVersions
public static void clearVersions()
-
clearVersionsPartial
public static void clearVersionsPartial()
Same asclearVersions()
, but only clears "permanent" storage areas, that might leak into subsequent runs.For example, it clears data saved inside the current Thread, but does not purge data from the
StaplerRequest
, which does not exist across invocations.
-
getFromProject
public static Map<String,Long> getFromProject(AbstractProject<?,?> root)
This method loads the map of versions from the parameters passed in via the current StaperRequest's URL.- Parameters:
root
- the project to retrieve versions for- Returns:
- a map, may be empty, but never null
-
getFromUrlParameter
public static Map<String,Long> getFromUrlParameter()
This method loads the map of versions from the parameters passed in via the current StaperRequest's URL.- Returns:
- a map, may be empty, but never nulll
-
encodeUrlParameter
public static String encodeUrlParameter(InheritanceProject root)
-
getFromRequest
public static Map<String,Long> getFromRequest()
Attempts to read the active versions from the current request, no matter if stored as inside the URL parameters or the form part of the request.This is safer than calling
getFromFormRequest(StaplerRequest)
, since it will only do that, if the project/version parameter are set in the request.- Returns:
- a map, may be empty, but never null
-
getFromFormRequest
public static Map<String,Long> getFromFormRequest(org.kohsuke.stapler.StaplerRequest req)
Decodes the versions stored in the form-part of the given request.Avoid calling this, if the request has no form, as it can lead to a HTTP error being send to the remote client.
- Parameters:
req
- the request to check- Returns:
- a map, may be empty, but never null
-
-