Permalink
Browse files

fixed to launth for Arena Version 7.0

  • Loading branch information...
shogo82148 committed Oct 19, 2012
1 parent 24f105e commit 2589aab5d8d495ece1cf07de6472a45e6d692cd0
Showing with 79 additions and 47 deletions.
  1. +79 −47 src/net/fornwall/eclipsecoder/actions/LaunchTopCoderAppletJob.java
@@ -29,8 +29,21 @@
*/
public class LaunchTopCoderAppletJob extends Job {
private static final String APPLET_URL = "http://www.topcoder.com/contest/classes/ContestApplet.jar";
private static final String APPLET_BASE_URL = "http://www.topcoder.com/contest/classes/7.0/";
private static final String[] APPLET_JARS = {
"arena-client-7.0.0.jar",

This comment has been minimized.

Show comment
Hide comment
@ahmedfarag

ahmedfarag Feb 23, 2013

this needs to be edited to be "arena-client-7.0.2.jar" to keep up with topcoder latest update.

@ahmedfarag

ahmedfarag Feb 23, 2013

this needs to be edited to be "arena-client-7.0.2.jar" to keep up with topcoder latest update.

"basic_type_serialization-1.0.1.jar",
"client-socket-SNAPSHOT.jar",
"concurrent-SNAPSHOT.jar",
"encoder-SNAPSHOT.jar",
"arena-shared-SNAPSHOT.jar",
"client-common-SNAPSHOT.jar",
"compeng-common-SNAPSHOT.jar",
"custom-serialization-SNAPSHOT.jar",
"http-tunnel-client-SNAPSHOT.jar",
"log4j-1.2.13.jar"
};
private static final int ESTIMATED_APPLET_SIZE = 2000000;
private static boolean classLoaderWorks(ClassLoader loader) {
@@ -41,45 +54,45 @@ private static boolean classLoaderWorks(ClassLoader loader) {
return false;
}
}
private static File getLocalAppletJar() {
private static File getLocalAppletJar(String jarname) {
File userHome = new File(System.getProperty("user.home"));
File eclipsecoderDir = new File(userHome, ".eclipsecoder");
if (((eclipsecoderDir.exists() && eclipsecoderDir.isDirectory()) || eclipsecoderDir.mkdir())
&& (eclipsecoderDir.canRead() && eclipsecoderDir.canWrite())) {
// try with global jar location outside workspace
return new File(eclipsecoderDir, "ContestApplet.jar");
return new File(eclipsecoderDir, jarname);
}
IPath stateLocation = EclipseCoderPlugin.getDefault().getStateLocation();
IPath jarLocation = stateLocation.append("ContestApplet.jar");
IPath jarLocation = stateLocation.append(jarname);
return jarLocation.toFile();
}
public LaunchTopCoderAppletJob(String name) {
super(name);
}
private IStatus download(IProgressMonitor monitor) {
private IStatus download(IProgressMonitor monitor, String jarname) {
File jar = getLocalAppletJar(jarname);
InputStream in = null;
OutputStream out = null;
try {
URLConnection connection = new URL(APPLET_URL).openConnection();
URLConnection connection = new URL(APPLET_BASE_URL + jarname).openConnection();
int jarSize = (connection.getContentLength() == -1) ? ESTIMATED_APPLET_SIZE : connection.getContentLength();
monitor.beginTask("Downloading applet", jarSize);
monitor.beginTask("Downloading applet: " + jarname, jarSize);
in = connection.getInputStream();
out = new FileOutputStream(getLocalAppletJar());
out = new FileOutputStream(jar);
byte[] buffer = new byte[2048];
int i;
while ((i = in.read(buffer)) != -1) {
if (monitor.isCanceled()) {
Utilities.close(out);
if (getLocalAppletJar().exists()) {
if (!getLocalAppletJar().delete()) {
if (jar.exists()) {
if (!jar.delete()) {
Utilities.showMessageDialog("Cannot delete file", "Cannot delete applet file:\n"
+ getLocalAppletJar().getAbsolutePath()
+ jar.getAbsolutePath()
+ "\n\nCheck permissions if problem persists.", true);
}
}
@@ -91,14 +104,14 @@ private IStatus download(IProgressMonitor monitor) {
}
} catch (MalformedURLException e) {
// should never happen as APPLET_URL is a valid URL
if (getLocalAppletJar().exists()) {
getLocalAppletJar().delete();
if (jar.exists()) {
jar.delete();
}
StartTopCoderAppletAction.getAction().setEnabled(true);
Utilities.showException(e);
} catch (IOException e) {
if (getLocalAppletJar().exists()) {
getLocalAppletJar().delete();
if (jar.exists()) {
jar.delete();
}
StartTopCoderAppletAction.getAction().setEnabled(true);
return new Status(IStatus.ERROR, EclipseCoderPlugin.PLUGIN_ID, IStatus.OK, e.getMessage(), e);
@@ -112,59 +125,78 @@ private IStatus download(IProgressMonitor monitor) {
@Override
protected IStatus run(IProgressMonitor monitor) {
File localAppletJar = getLocalAppletJar();
if (!localAppletJar.exists()) {
IStatus status = download(monitor);
if (status != null)
return status;
for(String jarname : APPLET_JARS) {
File localAppletJar = getLocalAppletJar(jarname);
if (!localAppletJar.exists()) {
IStatus status = download(monitor, jarname);
if (status != null)
return status;
}
}
if (!localAppletJar.exists()) {
// should have been downloaded above
return new Status(IStatus.ERROR, EclipseCoderPlugin.PLUGIN_ID, IStatus.OK, "Applet does not exist at "
+ localAppletJar.getAbsolutePath(), null);
for(String jarname : APPLET_JARS) {
File localAppletJar = getLocalAppletJar(jarname);
if (!localAppletJar.exists()) {
// should have been downloaded above
return new Status(IStatus.ERROR, EclipseCoderPlugin.PLUGIN_ID, IStatus.OK, "Applet does not exist at "
+ localAppletJar.getAbsolutePath(), null);
}
}
try {
long lastModifiedLocal = localAppletJar.lastModified();
URLConnection connection = new URL(APPLET_URL).openConnection();
long lastModifiedRemote = connection.getLastModified();
if (lastModifiedRemote > lastModifiedLocal) {
IStatus status = download(monitor);
if (status != null)
return status;
for(String jarname : APPLET_JARS) {
File localAppletJar = getLocalAppletJar(jarname);
long lastModifiedLocal = localAppletJar.lastModified();
URLConnection connection = new URL(APPLET_BASE_URL + jarname).openConnection();
long lastModifiedRemote = connection.getLastModified();
if (lastModifiedRemote > lastModifiedLocal) {
IStatus status = download(monitor, jarname);
if (status != null)
return status;
}
}
URL[] urls = new URL[APPLET_JARS.length + 1];
for(int i = 0; i < APPLET_JARS.length; i++) {
urls[i] = getLocalAppletJar(APPLET_JARS[i]).toURI().toURL();
}
URL appletURL = getLocalAppletJar().toURI().toURL();
Bundle bundle = EclipseCoderPlugin.getDefault().getBundle();
Path path = new Path("arenaplugin.jar");
URL pluginURL = FileLocator.find(bundle, path, null);
urls[APPLET_JARS.length] = FileLocator.find(bundle, path, null);
ClassLoader parent = Thread.currentThread().getContextClassLoader();
ClassLoader loader = new URLClassLoader(new URL[] { appletURL, pluginURL }, parent);
ClassLoader loader = new URLClassLoader(urls, parent);
if (classLoaderWorks(loader)) {
TopCoderAppletLauncher.run(loader);
} else {
StartTopCoderAppletAction.getAction().setEnabled(true);
String message;
if (getLocalAppletJar().delete()) {
String paths = "";
boolean flag = true;
for(String jarname : APPLET_JARS) {
File localAppletJar = getLocalAppletJar(jarname);
if(!localAppletJar.delete()) {
paths += "," + localAppletJar.getAbsolutePath();
flag = false;
}
}
if (flag) {
message = "The downloaded applet jar could not be used and has been deleted. Try to start again.";
// Utilities
// .showMessageDialog(
// "Error starting applet",
// "The downloaded applet jar could not be used and has
// been deleted. Try to start again.",
// true);
} else {
// Utilities.showMessageDialog("Error starting applet",
// "The downloaded applet jar could not be used and cannot
// be removed - please check the file "
// + getLocalAppletJar().getAbsolutePath(), true);
message = "The downloaded applet jar could not be used and cannot be removed - please check the file"
+ paths;
}
// Utilities.showMessageDialog("Error starting applet",
// "The downloaded applet jar could not be used and cannot
// be removed - please check the file "
// + getLocalAppletJar().getAbsolutePath(), true);
message = "The downloaded applet jar could not be used and cannot be removed - please check the file "
+ getLocalAppletJar().getAbsolutePath();
return new Status(IStatus.ERROR, EclipseCoderPlugin.PLUGIN_ID, IStatus.OK, message, null);
}

2 comments on commit 2589aab

@fornwall

This comment has been minimized.

Show comment
Hide comment
@fornwall

fornwall Oct 27, 2012

This has now been merged and released in version 0.3.9 of the net.fornwall.eclipsecoder plugin.

Great work, thanks!

fornwall replied Oct 27, 2012

This has now been merged and released in version 0.3.9 of the net.fornwall.eclipsecoder plugin.

Great work, thanks!

@shogo82148

This comment has been minimized.

Show comment
Hide comment
@shogo82148

shogo82148 Oct 28, 2012

Owner

It's my pleasure.

Owner

shogo82148 replied Oct 28, 2012

It's my pleasure.

Please sign in to comment.