in core/src/main/java/com/microsoft/alm/auth/oauth/helper/SwtJarLoader.java [80:124]
public static boolean tryGetSwtJar(final AtomicReference<File> swtJarReference) {
//precondition: swt runtime jar is not present on the system
final String swtJarUrl = BASE_URL + jarName;
logger.info("Downloading {}", swtJarUrl);
try {
final HttpURLConnection cloudSwtUrlConn = (HttpURLConnection) new URL(swtJarUrl).openConnection();
final int statusCode = cloudSwtUrlConn.getResponseCode();
if (statusCode != 200) {
throw new IOException(String.format("Failed to download SWT Runtime jar from %s. Server return code is " +
"%d", swtJarUrl, statusCode));
}
// Make sure the parent folder exists
final File parent = targetSwtJar.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
}
targetSwtJar.createNewFile();
final FileOutputStream fos = new FileOutputStream(targetSwtJar);
final InputStream is = cloudSwtUrlConn.getInputStream();
IOHelper.copyStream(is, fos);
IOHelper.closeQuietly(is);
IOHelper.closeQuietly(fos);
if (isValid(targetSwtJar)) {
swtJarReference.set(targetSwtJar);
return true;
} else {
// if target jar is corrupted, cleanup
cleanup(targetSwtJar);
}
} catch (IOException ioe) {
logger.warn("Failed to download SWT Runtime jar.", ioe);
// if we failed during downloading, remove partial file
cleanup(targetSwtJar);
}
swtJarReference.set(null);
return false;
}