Lines 15-21
Link Here
|
15 |
|
15 |
|
16 |
import java.io.*; |
16 |
import java.io.*; |
17 |
import java.net.URLConnection; |
17 |
import java.net.URLConnection; |
|
|
18 |
import java.net.UnknownHostException; |
18 |
import java.text.MessageFormat; |
19 |
import java.text.MessageFormat; |
|
|
20 |
import java.util.Properties; |
19 |
import java.util.jar.*; |
21 |
import java.util.jar.*; |
20 |
import java.util.Iterator; |
22 |
import java.util.Iterator; |
21 |
import java.util.List; |
23 |
import java.util.List; |
Lines 168-174
Link Here
|
168 |
|
170 |
|
169 |
URLConnection distrConnection = null; |
171 |
URLConnection distrConnection = null; |
170 |
distrConnection = moduleUpdate.getDistribution().openConnection(); |
172 |
distrConnection = moduleUpdate.getDistribution().openConnection(); |
171 |
flen = distrConnection.getContentLength(); |
|
|
172 |
moduleUpdate.setRemoteDistributionFilename(distrConnection); |
173 |
moduleUpdate.setRemoteDistributionFilename(distrConnection); |
173 |
|
174 |
|
174 |
if ( downloadCanceled ) |
175 |
if ( downloadCanceled ) |
Lines 176-190
Link Here
|
176 |
|
177 |
|
177 |
moduleDownloaded = 0; |
178 |
moduleDownloaded = 0; |
178 |
|
179 |
|
179 |
progressDialog.setGaugeBounds( ProgressDialog.PARTIAL_GAUGE, 0, flen / 1024 ); |
|
|
180 |
|
181 |
moduleUpdate.setDownloadStarted( true ); |
180 |
moduleUpdate.setDownloadStarted( true ); |
182 |
|
181 |
|
183 |
destFile = getNBM( moduleUpdate ); |
182 |
destFile = getNBM( moduleUpdate ); |
184 |
|
183 |
|
185 |
BufferedInputStream bsrc = new BufferedInputStream( distrConnection.getInputStream() ); |
184 |
BufferedInputStream bsrc = null; |
186 |
BufferedOutputStream bdest = new BufferedOutputStream( new FileOutputStream( destFile ) ); |
185 |
BufferedOutputStream bdest = null; |
|
|
186 |
try { |
187 |
bsrc = new BufferedInputStream( distrConnection.getInputStream() ); |
188 |
bdest = new BufferedOutputStream( new FileOutputStream( destFile ) ); |
189 |
} catch (UnknownHostException uhe) { // thrown on jdk1.5 |
190 |
// connect via proxy fails, try system proxy |
191 |
readSystemProxy (); |
192 |
distrConnection = moduleUpdate.getDistribution().openConnection(); |
193 |
bsrc = new BufferedInputStream( distrConnection.getInputStream() ); |
194 |
bdest = new BufferedOutputStream( new FileOutputStream( destFile ) ); |
195 |
} catch (IOException ioe) { // thrown on jdk1.4 |
196 |
// connect via proxy fails, try system proxy |
197 |
readSystemProxy (); |
198 |
distrConnection = moduleUpdate.getDistribution().openConnection(); |
199 |
bsrc = new BufferedInputStream( distrConnection.getInputStream() ); |
200 |
bdest = new BufferedOutputStream( new FileOutputStream( destFile ) ); |
201 |
} finally { |
202 |
// unset proxy back after download |
203 |
unsetSystemProxy (); |
204 |
} |
187 |
|
205 |
|
|
|
206 |
flen = distrConnection.getContentLength(); |
207 |
progressDialog.setGaugeBounds( ProgressDialog.PARTIAL_GAUGE, 0, flen / 1024 ); |
208 |
|
188 |
int c; |
209 |
int c; |
189 |
int i = 0; |
210 |
int i = 0; |
190 |
|
211 |
|
Lines 424-428
Link Here
|
424 |
|
445 |
|
425 |
private String getBundle( String key ) { |
446 |
private String getBundle( String key ) { |
426 |
return NbBundle.getMessage( Downloader.class, key ); |
447 |
return NbBundle.getMessage( Downloader.class, key ); |
|
|
448 |
} |
449 |
|
450 |
static private String oldProxyHost = null; |
451 |
static private String oldProxyPort = null; |
452 |
static private boolean isSystemProxy = false; |
453 |
|
454 |
// helper method for handling system proxy |
455 |
static void readSystemProxy () { |
456 |
String systemProxy = System.getProperty("netbeans.system_http_proxy"); // NOI18N |
457 |
if (systemProxy == null) { |
458 |
return; |
459 |
} |
460 |
|
461 |
int i = systemProxy.indexOf(":"); // NOI18N |
462 |
if (i <= 0 || i >= systemProxy.length() - 1) { |
463 |
return; |
464 |
} |
465 |
|
466 |
String systemProxyHost= systemProxy.substring(0, i); |
467 |
String systemProxyPort = systemProxy.substring(i+1); |
468 |
|
469 |
oldProxyHost = System.getProperty("http.proxyHost"); // NOI18N |
470 |
oldProxyPort = System.getProperty("http.proxyPort"); // NOI18N |
471 |
|
472 |
System.setProperty("http.proxyHost", systemProxyHost); // NOI18N |
473 |
System.setProperty("http.proxyPort", systemProxyPort); // NOI18N |
474 |
|
475 |
isSystemProxy = true; |
476 |
} |
477 |
|
478 |
static void unsetSystemProxy () { |
479 |
if (isSystemProxy) { |
480 |
isSystemProxy = false; |
481 |
} else { |
482 |
// no system proxy set => no job |
483 |
return ; |
484 |
} |
485 |
|
486 |
Properties props = System.getProperties(); |
487 |
|
488 |
if (oldProxyHost == null) { |
489 |
props.remove("http.proxyHost"); // NOI18N |
490 |
} else { |
491 |
props.put("http.proxyHost", oldProxyHost); // NOI18N |
492 |
} |
493 |
|
494 |
if (oldProxyPort == null) { |
495 |
props.remove("http.proxyPort"); // NOI18N |
496 |
} else { |
497 |
props.put("http.proxyPort", oldProxyPort); // NOI18N |
498 |
} |
499 |
|
500 |
System.setProperties(props); |
427 |
} |
501 |
} |
428 |
} |
502 |
} |