Class LicenseDownloader
java.lang.Object
org.codehaus.mojo.license.download.LicenseDownloader
- All Implemented Interfaces:
AutoCloseable
Utilities for downloading remote license files.
- Since:
- 1.0
- Author:
- pgier
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA result of a license download operation. -
Constructor Summary
ConstructorsConstructorDescriptionLicenseDownloader(org.apache.maven.settings.Proxy proxy, int connectTimeout, int socketTimeout, int connectionRequestTimeout, Map<String, SpdxLicenseList.Attachments.ContentSanitizer> contentSanitizers, Charset charset) Creates a newLicenseDownloaderwithout authentication.LicenseDownloader(org.apache.maven.settings.Proxy proxy, int connectTimeout, int socketTimeout, int connectionRequestTimeout, Map<String, SpdxLicenseList.Attachments.ContentSanitizer> contentSanitizers, Charset charset, String userName, String password, String serverUrl, Map<String, String> httpHeaders) Creates a newLicenseDownloaderwith optional authentication. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcalculateStringChecksum(String contentString) voidclose()downloadLicense(String licenseUrlString, FileNameEntry fileNameEntry) Downloads a license file from the givenlicenseUrlStringstores it locally and returns the local path where the license file was stored.intvoidsetBasedir(Path basedir) Sets the directory against which a relativefile:license URL is resolved.voidSets which well-known license URLs are answered from a text bundled with the plugin instead of a request.voidsetLicenseCache(PersistentLicenseCache licenseCache) Sets the persistent cache of downloaded license texts; none by default.voidsetRejectHtml(boolean rejectHtml) Sets whether a response that is an HTML page, by Content-Type or by its first bytes, is rejected instead of being saved as a license text; off by default, because many licenses are published only as HTML pages.
-
Constructor Details
-
LicenseDownloader
public LicenseDownloader(org.apache.maven.settings.Proxy proxy, int connectTimeout, int socketTimeout, int connectionRequestTimeout, Map<String, SpdxLicenseList.Attachments.ContentSanitizer> contentSanitizers, Charset charset) Creates a newLicenseDownloaderwithout authentication. Proxy settings and timeouts are still applied. -
LicenseDownloader
public LicenseDownloader(org.apache.maven.settings.Proxy proxy, int connectTimeout, int socketTimeout, int connectionRequestTimeout, Map<String, SpdxLicenseList.Attachments.ContentSanitizer> contentSanitizers, Charset charset, String userName, String password, String serverUrl, Map<String, String> httpHeaders) Creates a newLicenseDownloaderwith optional authentication.Credentials (
userName/password) andhttpHeadersare sent only to URLs that start withserverUrl, preventing credential leakage to third-party license servers.- Parameters:
proxy- optional proxy configuration fromsettings.xmlconnectTimeout- HTTP connection timeout in millisecondssocketTimeout- HTTP socket (read) timeout in millisecondsconnectionRequestTimeout- HTTP connection-pool request timeout in millisecondscontentSanitizers- optional content sanitizers keyed by an id stringcharset- charset used when reading text license contentuserName- username for preemptive Basic Authentication, ornull/empty to disablepassword- password for preemptive Basic Authentication, ornull/empty to disableserverUrl- URL prefix that a license URL must start with in order to receive credentials;nulldisables authentication for all URLshttpHeaders- additional HTTP headers sent only to matching URLs (e.g.Authorization: Bearer)
-
-
Method Details
-
setBasedir
Sets the directory against which a relativefile:license URL is resolved. Without it, such a URL is resolved against the working directory.- Parameters:
basedir- the directory, usually the basedir of the project- Since:
- 2.8.1
-
setBundledTextsMode
Sets which well-known license URLs are answered from a text bundled with the plugin instead of a request. The default isBundledLicenseTexts.Mode.none, which keeps the behavior of this class unchanged.- Parameters:
mode- the mode- Since:
- 2.8.0
-
setRejectHtml
public void setRejectHtml(boolean rejectHtml) Sets whether a response that is an HTML page, by Content-Type or by its first bytes, is rejected instead of being saved as a license text; off by default, because many licenses are published only as HTML pages.- Parameters:
rejectHtml- whether HTML responses are rejected- Since:
- 2.8.1
-
setLicenseCache
Sets the persistent cache of downloaded license texts; none by default. Onlyhttpandhttpsdownloads that carry no credentials go through it.- Parameters:
licenseCache- the cache, ornullfor none- Since:
- 2.8.0
-
getBundledTextsServed
public int getBundledTextsServed()- Returns:
- the number of downloads that were answered from a bundled text
- Since:
- 2.8.0
-
downloadLicense
public LicenseDownloader.LicenseDownloadResult downloadLicense(String licenseUrlString, FileNameEntry fileNameEntry) throws IOException, URISyntaxException, org.apache.maven.plugin.MojoFailureException Downloads a license file from the givenlicenseUrlStringstores it locally and returns the local path where the license file was stored. Note that theoutputFilename can be further modified by this method, esp. the file extension can be adjusted based on the mime type of the HTTP response.- Parameters:
licenseUrlString- the URLfileNameEntry- a hint where to store the license file- Returns:
- the path to the file where the downloaded license file was stored
- Throws:
IOExceptionURISyntaxExceptionorg.apache.maven.plugin.MojoFailureException
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
calculateStringChecksum
-