* @throws ApplicationException if the download service is not available.
*/
private void startDownload(boolean forceDownload)
throws IOException, ApplicationException
{
DownloadService ds;
try
{
ds =
(DownloadService) ServiceManager.lookup(Utils.JNLP_SERVICE_NAME);
} catch (UnavailableServiceException e)
{
LOG.log(Level.SEVERE, "Could not find service: "+
Utils.JNLP_SERVICE_NAME, e);
String setupFile;
if (Utils.isWindows())
{
setupFile = Installation.WINDOWS_SETUP_FILE_NAME;
}
else
{
setupFile = Installation.UNIX_SETUP_FILE_NAME;
}
throw new ApplicationException(
ReturnCode.DOWNLOAD_ERROR,
getThrowableMsg(INFO_DOWNLOADING_ERROR_NO_SERVICE_FOUND.get(
Utils.JNLP_SERVICE_NAME, setupFile),
e), e);
}
String[] urls = getJarUrls();
String[] versions = getJarVersions();
/*
* Calculate the percentages that correspond to each file.
* TODO ideally this should be done dynamically, but as this is just
* to provide progress, updating this information from time to time can
* be enough and does not complexify the build process.
*/
int[] percentageMax = new int[urls.length];
int[] ratios = new int[urls.length];
int totalRatios = 0;
for (int i=0; i<percentageMax.length; i++)
{
int ratio;
if (urls[i].endsWith("NasuTekDS.jar"))
{
ratio = 23;
}
else if (urls[i].endsWith("je.jar"))
{
ratio = 11;
}
else if (urls[i].endsWith("zipped.jar"))
{
ratio = 110;
}
else if (urls[i].endsWith("aspectjrt.jar"))
{
ratio = 10;
}
else
{
ratio = (100 / urls.length);
}
ratios[i] = ratio;
totalRatios += ratio;
}
for (int i=0; i<percentageMax.length; i++)
{
int r = 0;
for (int j=0; j<=i; j++)
{
r += ratios[j];
}
percentageMax[i] = (100 * r)/totalRatios;
}
for (int i = 0; i < urls.length && (getException() == null); i++)
{
if (i == 0)
{
currentPercMin = 0;
}
else {
currentPercMin = percentageMax[i-1];
}
currentPercMax = percentageMax[i];
// determine if a particular resource is cached
String sUrl = urls[i];
String version = versions[i];
URL url = new URL(sUrl);
boolean cached = ds.isResourceCached(url, version);
if (cached && forceDownload)
{
try
{
ds.removeResource(url, version);
} catch (IOException ioe)
{
}
cached = false;
}
if (!cached)
{
// if not in the cache load the resource into the cache
ds.loadResource(url, version, this);
}
downloadPercentage = currentPercMax;
}
isFinished = true;
}