Class UrlRequester
java.lang.Object
org.codehaus.mojo.license.utils.UrlRequester
This class should be used to load the content from a URL.
Supported URL protocols are those standards plus classpath protocol.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondownloadList(String url) will download a external resource and read the content of the file that will then be translated into a new list.static StringfindProtocol(String url) Returns the protocol of the given URL as a string.static StringgetFromUrl(String url) Returns the content of the resource pointed by the given URL as a string.static StringgetFromUrl(String url, String encoding) Returns the content of the resource pointed by the given URL as a string.static booleanisExternalUrl(String url) Check if URL point to external resource.static booleanisStringUrl(String data) Checks if the given input is a URL value.static voidsetProxy(org.apache.maven.settings.Proxy proxy) Sets the proxy used by thehttpandhttpsrequests of this class.static URLConverts the given string to a URL.
-
Field Details
-
CLASSPATH_PROTOCOL
- See Also:
-
-
Constructor Details
-
UrlRequester
public UrlRequester()
-
-
Method Details
-
setProxy
public static void setProxy(org.apache.maven.settings.Proxy proxy) Sets the proxy used by thehttpandhttpsrequests of this class. The mojos set the active proxy ofsettings.xmlbefore they download anything.- Parameters:
proxy- the proxy, ornullto connect directly
-
isStringUrl
Checks if the given input is a URL value.- Parameters:
data- the license string or a URL- Returns:
- true if URL, false else
-
toUrl
Converts the given string to a URL.A
file:URL that is not a valid URI, such asfile:///${project.build.directory}/file.txtwith a Windows path, is built from its path instead: backslashes become slashes and characters such as spaces are quoted.java.net.URLaccepted these strings before 2.5.0.- Parameters:
url- the URL as a string- Returns:
- the URL
- Throws:
MalformedURLException- if the string is not a URLIllegalArgumentException- if the string is not a URI and not afile:URL
-
isExternalUrl
Check if URL point to external resource.- Parameters:
url- the URL as a string- Returns:
- true if URL use external protocol
-
getFromUrl
Returns the content of the resource pointed by the given URL as a string.- Parameters:
url- the resource destination that is expected to contain pure text- Returns:
- the string representation of the resource at the given URL
- Throws:
IOException- If an I/O error occurs when retrieve of the content URL
-
findProtocol
-
getFromUrl
Returns the content of the resource pointed by the given URL as a string.- Parameters:
url- the resource destination that is expected to contain pure textencoding- the resource content encoding- Returns:
- the string representation of the resource at the given URL
- Throws:
IOException- If an I/O error occurs when retrieve of the content URL
-
downloadList
public static List<String> downloadList(String url) throws org.apache.maven.plugin.MojoExecutionException will download a external resource and read the content of the file that will then be translated into a new list.
Lines starting with the character '#' will be omitted from the list
NOTE:
certificate checking for this request will be disabled because some resources might be present on some local servers in the internal network that do not use a safe connection- Parameters:
url- the URL to the external resource- Returns:
- a new list with all license entries from the remote resource
- Throws:
org.apache.maven.plugin.MojoExecutionException
-