Package hudson.model
Class DownloadService.Downloadable
- java.lang.Object
-
- hudson.model.DownloadService.Downloadable
-
- All Implemented Interfaces:
ExtensionPoint
- Enclosing class:
- DownloadService
public static class DownloadService.Downloadable extends Object implements ExtensionPoint
Represents a periodically updated JSON data file obtained from a remote URL.This mechanism is one of the basis of the update center, which involves fetching up-to-date data file.
- Since:
- 1.305
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Constructor Description Downloadable()
Creates a new downloadable.Downloadable(Class<?> clazz)
Creates a new downloadable.Downloadable(String id)
Creates a new downloadable with a specific ID.Downloadable(String id, String url)
Creates a new downloadable with a specific ID and URL.Downloadable(String id, String url, long interval)
Creates a new downloadable.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ExtensionList<DownloadService.Downloadable>
all()
Returns all the registeredDownloadService.Downloadable
s.static DownloadService.Downloadable
get(Class<?> clazz)
Returns theDownloadService.Downloadable
that has an ID associated with the specified class (as computed viaidFor(Class)
).static DownloadService.Downloadable
get(String id)
Returns theDownloadService.Downloadable
that has the given ID.net.sf.json.JSONObject
getData()
Loads the current file into JSON and returns it, or null if no data exists.TextFile
getDataFile()
This is where the retrieved file will be stored.long
getDue()
When shall we retrieve this file next time?String
getId()
long
getInterval()
How often do we retrieve the new image?String
getUrl()
URL to download.List<String>
getUrls()
URLs to download from.static <T> boolean
hasDuplicates(List<T> genericList, String comparator)
check if the list of update center entries has duplicatesstatic String
idFor(Class<?> clazz)
Generates an ID based on a class.net.sf.json.JSONObject
reduce(List<net.sf.json.JSONObject> jsonList)
Function that takes multiple JSONObjects and returns a single one.FormValidation
updateNow()
-
-
-
Constructor Detail
-
Downloadable
public Downloadable(@NonNull String id, @NonNull String url, long interval)
Creates a new downloadable.- Parameters:
id
- The ID to use.url
- URL relative toUpdateCenter.getDefaultBaseUrl()
. So if this string is "foo.json", the ultimate URL will be something like "http://updates.jenkins-ci.org/updates/foo.json" For security and privacy reasons, we don't allow the retrieval from random locations.interval
- The interval, in milliseconds, between attempts to update this downloadable's data.
-
Downloadable
public Downloadable()
Creates a new downloadable. This will generate an ID based on this downloadable's class (usingidFor(Class)
. The URL will be set to that ID, with an added.json
extension, and the default interval will be used.
-
Downloadable
public Downloadable(@NonNull Class<?> clazz)
Creates a new downloadable. This will generate an ID based on the specified class (usingidFor(Class)
. The URL will be set to that ID, with an added.json
extension, and the default interval will be used.- Parameters:
clazz
- The class to use to generate the ID.
-
Downloadable
public Downloadable(@NonNull String id)
Creates a new downloadable with a specific ID. The URL will be set to that ID, with an added.json
extension, and the default interval will be used.- Parameters:
id
- The ID to use.
-
Downloadable
public Downloadable(@NonNull String id, @NonNull String url)
Creates a new downloadable with a specific ID and URL. The default interval will be used.- Parameters:
id
- The ID to use.url
- URL relative toUpdateCenter.getDefaultBaseUrl()
. So if this string is "foo.json", the ultimate URL will be something like "http://updates.jenkins-ci.org/updates/foo.json".For security and privacy reasons, we don't allow the retrieval from random locations.
-
-
Method Detail
-
getId
@NonNull public String getId()
-
idFor
@NonNull public static String idFor(@NonNull Class<?> clazz)
Generates an ID based on a class.- Parameters:
clazz
- The class to use to generate an ID.- Returns:
- The ID generated based on the specified class.
- Since:
- 2.244
-
getUrl
public String getUrl()
URL to download.
-
getInterval
public long getInterval()
How often do we retrieve the new image?- Returns:
- number of milliseconds between retrieval.
-
getDataFile
public TextFile getDataFile()
This is where the retrieved file will be stored.
-
getDue
public long getDue()
When shall we retrieve this file next time?
-
getData
public net.sf.json.JSONObject getData() throws IOException
Loads the current file into JSON and returns it, or null if no data exists.- Throws:
IOException
-
updateNow
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public FormValidation updateNow() throws IOException
- Throws:
IOException
-
reduce
public net.sf.json.JSONObject reduce(List<net.sf.json.JSONObject> jsonList)
Function that takes multiple JSONObjects and returns a single one.- Parameters:
jsonList
- to be processed- Returns:
- a single JSONObject
-
hasDuplicates
public static <T> boolean hasDuplicates(List<T> genericList, String comparator)
check if the list of update center entries has duplicates- Type Parameters:
T
- the generic class- Parameters:
genericList
- list of entries coming from multiple update centerscomparator
- the unique ID of an entry- Returns:
- true if the list has duplicates, false otherwise
-
all
@NonNull public static ExtensionList<DownloadService.Downloadable> all()
Returns all the registeredDownloadService.Downloadable
s.
-
get
@CheckForNull public static DownloadService.Downloadable get(@NonNull Class<?> clazz)
Returns theDownloadService.Downloadable
that has an ID associated with the specified class (as computed viaidFor(Class)
).- Parameters:
clazz
- The class to use to determine the downloadable's ID.- Since:
- 2.244
-
get
@CheckForNull public static DownloadService.Downloadable get(String id)
Returns theDownloadService.Downloadable
that has the given ID.- Parameters:
id
- The ID to look for.
-
-