/** * Convenience constructor. * @param u holds the URL to expose. */ public URLResource(URLProvider u) { setURL(u.getURL()); }
public void execute() { for (Resource r : resources) { URLProvider up = r.as(URLProvider.class); if (up != null) { URL u = up.getURL(); try { FileUtils.close(u.openConnection()); } catch (IOException ex) { // ignore } } } } }
/** * Parse the given URL as an antlib descriptor and return the * content as something that can be turned into an Antlib task. * * <p>simply delegates to {@link #parseUnknownElement * parseUnknownElement} if the resource provides an URL and throws * an exception otherwise.</p> * * @since Ant 1.8.0 */ @Override public UnknownElement parseAntlibDescriptor(Project containingProject, Resource resource) { URLProvider up = resource.as(URLProvider.class); if (up == null) { throw new BuildException("Unsupported resource type: " + resource); } return parseUnknownElement(containingProject, up.getURL()); }
private boolean isOneOf(Object o, Resource importedResource, File importedFile, URL importedURL) { if (o.equals(importedResource) || o.equals(importedFile) || o.equals(importedURL)) { return true; } if (o instanceof Resource) { if (importedFile != null) { FileProvider fp = ((Resource) o).as(FileProvider.class); if (fp != null && fp.getFile().equals(importedFile)) { return true; } } if (importedURL != null) { URLProvider up = ((Resource) o).as(URLProvider.class); return up != null && up.getURL().equals(importedURL); } } return false; }
private String resourceToURI(final Resource resource) { final FileProvider fp = resource.as(FileProvider.class); if (fp != null) { return FILE_UTILS.toURI(fp.getFile().getAbsolutePath()); } final URLProvider up = resource.as(URLProvider.class); if (up != null) { final URL u = up.getURL(); return String.valueOf(u); } else { return resource.getName(); } }
/** * make a get request, with the supplied progress and logging info. * All the other config parameters are set at the task level, * source, dest, ignoreErrors, etc. * @param logLevel level to log at, see {@link Project#log(String, int)} * @param progress progress callback; null for no-callbacks * @return true for a successful download, false otherwise. * The return value is only relevant when {@link #ignoreErrors} is true, as * when false all failures raise BuildExceptions. * @throws IOException for network trouble * @throws BuildException for argument errors, or other trouble when ignoreErrors * is false. * @deprecated only gets the first configured resource */ @Deprecated public boolean doGet(final int logLevel, final DownloadProgress progress) throws IOException { checkAttributes(); return doGet(sources.iterator().next().as(URLProvider.class).getURL(), destination, logLevel, progress); }
final URL source = up.getURL();
URLProvider up = ((Resource) source).as(URLProvider.class); if (up != null) { url = up.getURL();
element instanceof URLProvider ? ((URLProvider) element).getURL().toString() : element instanceof Resource ? ((Resource) element).getName() : element.toString()