/*
* @see IInstallableRuntime#install(IPath, IProgressMonitor)
*/
public void install(IPath path, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 1000);
URL url = null;
File temp = null;
try {
url = new URL(getArchiveUrl());
temp = File.createTempFile("runtime", ""); //$NON-NLS-1$ //$NON-NLS-2$
temp.deleteOnExit();
} catch (IOException e) {
if (monitor != null)
monitor.done();
// if (Trace.WARNING) {
// Trace.trace(Trace.STRING_WARNING, "Error creating url and temp file", e);
// }
throw new CoreException(new Status(IStatus.ERROR, PEXServerPlugin.PLUGIN_ID, 0,
NLS.bind(Messages.InstallableRuntime2_ErrorInstallingServer, e.getLocalizedMessage()), e));
}
String name = url.getQuery();
// int slashIdx = name.lastIndexOf('/');
// if (slashIdx >= 0)
// name = name.substring(slashIdx + 1);
int archiveSize = getArchiveSize();
// download
FileOutputStream fout = null;
try {
InputStream in = url.openStream();
fout = new FileOutputStream(temp);
download(in, fout, progress.newChild(500), name, archiveSize);
progress.setWorkRemaining(500);
} catch (Exception e) {
if (monitor != null)
monitor.done();
// if (Trace.WARNING) {
// Trace.trace(Trace.STRING_WARNING, "Error downloading runtime", e);
// }
throw new CoreException(new Status(IStatus.ERROR, PEXServerPlugin.PLUGIN_ID, 0,
NLS.bind(Messages.InstallableRuntime2_ErrorInstallingServer, e.getLocalizedMessage()), e));
} finally {
try {
if (fout != null)
fout.close();
} catch (IOException e) {
// ignore
}
}
if (progress.isCanceled())
throw new CoreException(Status.CANCEL_STATUS);
FileInputStream in = null;
try {
in = new FileInputStream(temp);
if (name.endsWith("zip")) //$NON-NLS-1$
unzip(in, path, progress.newChild(500));
else if (name.endsWith("tar")) //$NON-NLS-1$
untar(in, path, progress.newChild(500));
else if (name.endsWith("tar.gz")) { //$NON-NLS-1$
File tarFile = File.createTempFile("runtime", ".tar"); //$NON-NLS-1$ //$NON-NLS-2$
tarFile.deleteOnExit();
String tarName = name;
progress.subTask(NLS.bind(Messages.InstallableRuntime2_TaskUncompressing, tarName));
int tempSize = Integer.MAX_VALUE;
if (temp.length() < Integer.MAX_VALUE)
tempSize = (int)temp.length();
ungzip(in, tarFile, progress.newChild(250), tempSize);
progress.setWorkRemaining(250);
if (!progress.isCanceled()) {
in = new FileInputStream(tarFile);
untar(in, path, progress.newChild(250));
}
}
} catch (Exception e) {
// if (Trace.SEVERE) {
// Trace.trace(Trace.STRING_SEVERE, "Error uncompressing runtime", e);
// }
throw new CoreException(new Status(IStatus.ERROR, PEXServerPlugin.PLUGIN_ID, 0,
NLS.bind(Messages.InstallableRuntime2_ErrorInstallingServer, e.getLocalizedMessage()), e));
} finally {
try {
if (in != null)
in.close();
} catch (IOException e) {
// ignore
}
progress.done();
}
}