Package com.fathzer.plugin.loader.utils
Class AbstractPluginsDownloader
java.lang.Object
com.fathzer.plugin.loader.utils.AbstractPluginsDownloader
A class that downloads plugins from an Internet remote repository to a local folder.
WARNING: This class requires a Java 11+ JVM and is not available in java 8 distribution!
WARNING: This class requires a Java 11+ JVM and is not available in java 8 distribution!
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractPluginsDownloader(URI uri, Path localDirectory) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanclean()Deletes all files in local directory.Searches for plugin keys in remote repository, then downloads the corresponding jars.protected voiddownloadFile(URI uri, Path path) Downloads an URI to a file.protected PathgetDownloadTarget(URI uri) Gets the local path where a remote jar should be downloaded.protected java.net.http.HttpClientBuild the http client used to connect with the remote repository.protected java.net.http.HttpRequest.BuildergetJarRequestBuilder(URI uri) Gets the builder of the request used to download a jar.Gets the folder where plugins jar files are loaded.protected StringGets the wording of plugins.protected java.net.http.HttpRequest.BuilderGets the builder of the request used to query the repository.protected URIgetUri()Gets the remote plugin repository URI.Gets the content of the remote repository.getURIMap(InputStream in) Gets the map that links a plugin key to the URI of a remote jar file from an InputStreamvoidsetPluginTypeWording(String wording) Sets the wording of plugins.voidsetProxy(ProxySettings proxy) Sets the proxy used to connect with remote repository.protected booleanshouldLoad(URI uri, Path path) Tests whether a remote jar should be downloaded.
-
Constructor Details
-
AbstractPluginsDownloader
Constructor.- Parameters:
uri- The uri where to load the remote plugin .localDirectory- The folder where plugins jar files will be loaded.
-
-
Method Details
-
getUri
Gets the remote plugin repository URI.- Returns:
- The URI passed to the constructor.
-
getLocalDirectory
Gets the folder where plugins jar files are loaded.- Returns:
- The Path passed to the constructor.
-
setProxy
Sets the proxy used to connect with remote repository.- Parameters:
proxy- The proxy (null, which is the default, to use no proxy)
-
setPluginTypeWording
Sets the wording of plugins.
This information is used to generate human friendly error messages.- Parameters:
wording- The new wording (default is "plugin")
-
getPluginTypeWording
Gets the wording of plugins.
This information is used to generate human friendly error messages.- Returns:
- wording of the plugin (default is "plugin")
-
clean
Deletes all files in local directory.- Returns:
- true if loacalDirectory existed and is deleted.
- Throws:
IOException- If something went wrong
-
download
Searches for plugin keys in remote repository, then downloads the corresponding jars.- Parameters:
keys- The plugin's keys to search- Returns:
- The paths of files that contains the jars (including the ones for which
shouldLoad(URI, Path)returned false - Throws:
IOException- If something went wrong
-
getDownloadTarget
Gets the local path where a remote jar should be downloaded.- Parameters:
uri- The uri of a remote jar- Returns:
- a Path. Default value if a file in the local directory passed to the constructor, this the same filename as the uri.
-
shouldLoad
Tests whether a remote jar should be downloaded.- Parameters:
uri- The uri of a remote jarpath- The local path where the file should be downloaded (the one returned bygetDownloadTarget(URI)- Returns:
- true if the file should be loaded (default is the file is loaded if it does not exists in local directory.
-
downloadFile
Downloads an URI to a file.- Parameters:
uri- The uri to downloadpath- The local path where the file should be downloaded (the one returned bygetDownloadTarget(URI). There's no guarantee that the directory that contains path is created. If not, this method should create it.- Throws:
IOException- if something went wrong
-
getURIMap
Gets the content of the remote repository.
This method gets an input stream from the uri passed to this class constructor, then pass this input stream togetURIMap(InputStream)and return its result.- Returns:
- A key to uri map.
- Throws:
IOException- If something went wrong
-
getRepositoryRequestBuilder
protected java.net.http.HttpRequest.Builder getRepositoryRequestBuilder()Gets the builder of the request used to query the repository.
A sub-class can override this method to, for example, add headers to the request.- Returns:
- a request builder that build the request.
-
getJarRequestBuilder
Gets the builder of the request used to download a jar.
A sub-class can override this method to, for example, add headers to the request.- Parameters:
uri- The jar's uri.- Returns:
- a request builder that build the request.
-
getURIMap
Gets the map that links a plugin key to the URI of a remote jar file from an InputStream- Parameters:
in- An input stream on the remote repository URI- Returns:
- A map.
- Throws:
IOException- If something went wrong while reading the input stream
-
getHttpClient
protected java.net.http.HttpClient getHttpClient()Build the http client used to connect with the remote repository.- Returns:
- An HTTPClient
-