Bug 36174 - Consider enabling java.net.useSystemProxies by default
Summary: Consider enabling java.net.useSystemProxies by default
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.6.2
Hardware: Other other
: P2 enhancement (vote)
Target Milestone: 1.7.0
Assignee: Ant Notifications List
Depends on:
Reported: 2005-08-12 23:46 UTC by Kohsuke Kawaguchi
Modified: 2008-02-22 12:18 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Kohsuke Kawaguchi 2005-08-12 23:46:45 UTC
Today, to use Ant with a proxy, you either have to use <setproxy> task or use
the ANT_OPTS with a long sequence of system properties.

The former is horrible, because a proxy setting is by nature different from a
person to person. Doing this as a task requires you to either hard-code a proxy
name, or put the burden on the build script writer to externalize the property
definitions, and ask users to configure them individually.

ANT_OPTS is little better, but the proxy string is very lengthy.

In both cases, the user who wishs to move between different network environments
(such as between home and office) need to spend a lot of effort changing proxy
settings in many places.

This situation can be improved by using the system property
"java.net.useSystemProxies", a new addition in JDK 5.0.

When enabled, unless a proxy is configured specifically, URL class
will automatically consult the platform default proxy setting. On
Windows, this is a connection setting of IE, and on Unix this is
a setting of Gnome.

Unfortunately, this property is designed to read only once when
the proxy related code is initialized for the first time. So for
this to be usable, Ant has to set this property to true at the very
beginning, perhaps like this:

try {
} catch (SecurityException e) {
    ; // failing to set this property isn't fatal

In earlier JVMs this takes no effect, which is a resonable behavior.

Please consider doing this in the future.
Comment 1 Steve Loughran 2005-08-15 15:11:06 UTC
As the author of setproxy, I am somewhat disappointed by the use of "horrible"
as an adjective. Unsatisfactory, would be more appropriate :) It does at least
let you write build files that use <isreachable> (ant1.7) to check for proxies
being there before trying to connect to them, which is something that laptop
users will appreciate. 

Returning to the system property, yes, this does seem a good idea by default.


-we need a way of turning it off, a --noproxy option. 

-I wonder what the effects of running Ant under an IDE will be. If it is only
read at the start of the JVM URL classes, then by the time that it gets to Ant
it is probably too late. does this mean that we shouldnt do it? No. I just dont
want to break the IDE itself by unexpectedly fidding with proxy settings.

-we turn this on in ant main
-the --noproxy option will skip this. 
-we document proxy setup in ant properly; that is, how to use ANT_OPTS,  the
--noproxy command and the java1.5 stuff
-ant diagnostics adds proxy configuration diagnostics.

Comment 2 Steve Loughran 2005-08-17 16:01:27 UTC
Test CVS_HEAD to see if it works. 

This does not seem to work on my java1.5.01 runtime on Linux...there may be gulf
between what is intended and what is implemented. 
Comment 3 Steve Loughran 2005-08-22 16:29:53 UTC
see this bug here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092063

it looks like Java1.5 proxy server handles laptops badly as it always tries to
do RDNS lookup, even when handed an ipaddr to connect to.

we may need to provide our own ProxySelector, one that assumes that whenever you
give an absolute IPAddress, that means you want to bypass the proxy.