ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: Resource.getURL()
Date Thu, 21 Sep 2006 13:15:09 GMT
Antoine Levy-Lambert wrote:
> Hi,
> 
> I would like to add getURL() to Resource before Ant 1.7 ships.
> 
> I would add it to the Resource base class, and to ZipResource, FileResource.
> 
> I am not clear whether it is better to signal that a particular Resource does not provide
URL by throwing UnsupportedOperationException (as Matt suggested) or by returning null.
> 
> Concerning custom URLProtocolHandler (s), I am not clear how this works ?


first you provide something that lets you open connections

http://smartfrog.cvs.sourceforge.net/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/importing/classpath/ClasspathUrlStreamHandler.java?view=markup

and connections should be openable, or, as in this case, tell you off 
for trying to do so

http://smartfrog.cvs.sourceforge.net/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/importing/classpath/ClasspathUrlConnection.java?view=markup

The real problem is that to use URLs with URL.openConnection() you need 
to register the protocol in the top  classloader, or the URL class 
cannot open them. The alternative is to have a method in some class, 
openConnection(URL), which looks through its list of registered handlers 
and picks the right one:

http://smartfrog.cvs.sourceforge.net/smartfrog/core/extras/cdl/src/org/smartfrog/sfcore/languages/cdl/importing/classpath/UrlFactory.java?view=markup

To summarise: ***If you are going to play with URLs, you are going to 
discover problems with classloaders***

dont say I didnt warn you...

-steve

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message