From ff53573fa87c157da6d20244f41a6d2227bd4563 Mon Sep 17 00:00:00 2001 From: Deborah Schmidt Date: Mon, 19 Aug 2019 12:01:23 +0200 Subject: [PATCH] ImageJUpdater: Do not update the updater separately The removed code does the following: * check if the updater can be updated * if yes, download updater and it's dependencies and install it, do not ask for approval * try to restart the updater in place * if that does not work, ask for restart of Fiji This is why it should be removed: * if other components depend on the updater, this can break the installation because the other component will not get updated at the same time as the updater * the updater will be updated without the users approval CTR: I asked Johannes why this logic was introduced. Here is what he said: > The reason was dependency hell. If you don't update the updater first, > then create a new class loader, then re-load the updater and run it, > it really can break everything, especially when imagej-ui-swing is > updated (and not necessarily the updater). CTR: So really, there are things that can go wrong either way. In the interest of simplicity, we remove the logic. If all hell breaks loose, we can put it back, and deal with the fallout as best we can. But I expect that removing this logic will fix more problems than it causes. Closes #83. Signed-off-by: Curtis Rueden --- .../ui/swing/updater/ImageJUpdater.java | 62 +------------------ 1 file changed, 2 insertions(+), 60 deletions(-) diff --git a/src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java b/src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java index fb0bdf8..959c283 100644 --- a/src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java +++ b/src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java @@ -80,11 +80,6 @@ public class ImageJUpdater implements UpdaterUI { @Parameter(required = false) private UploaderService uploaderService; - @Parameter(required = false) - private CommandService commandService; - - private final static String UPDATER_UPDATING_THREAD_NAME = "Updating the Updater itself!"; - @Override public void run() { @@ -103,7 +98,7 @@ public void run() { UpdaterUserInterface.set(new SwingUserInterface(log, statusService)); - if (!areWeUpdatingTheUpdater() && new File(imagejRoot, "update").exists()) { + if (new File(imagejRoot, "update").exists()) { if (!UpdaterUserInterface.get().promptYesNo("It is suggested that you restart ImageJ, then continue the update.\n" + "Alternately, you can attempt to continue the upgrade without\n" + "restarting, but ImageJ might crash.\n\n" @@ -165,56 +160,6 @@ protected void updateConflictList() { return; } - if (!areWeUpdatingTheUpdater() && Installer.isTheUpdaterUpdateable(files, commandService)) { - try { - // download just the updater - Installer.updateTheUpdater(files, main.getProgress("Installing the updater..."), commandService); - } - catch (final UpdateCanceledException e) { - main.error("Canceled"); - return; - } - catch (final IOException e) { - main.error("Installer failed: " + e); - return; - } - - // make a class path using the updated files - final List classPath = new ArrayList<>(); - for (FileObject component : Installer.getUpdaterFiles(files, commandService, false)) { - final File updated = files.prefixUpdate(component.getFilename(false)); - if (updated.exists()) try { - classPath.add(updated.toURI().toURL()); - continue; - } catch (MalformedURLException e) { - log.error(e); - } - final String name = component.getLocalFilename(false); - File file = files.prefix(name); - try { - classPath.add(file.toURI().toURL()); - } catch (MalformedURLException e) { - log.error(e); - } - } - try { - log.info("Trying to install and execute the new updater"); - final URL[] urls = classPath.toArray(new URL[classPath.size()]); - URLClassLoader remoteClassLoader = new URLClassLoader(urls, getClass().getClassLoader().getParent()); - Class runnable = remoteClassLoader.loadClass(ImageJUpdater.class.getName()); - final Thread thread = new Thread((Runnable)runnable.newInstance()); - thread.setName(UPDATER_UPDATING_THREAD_NAME); - thread.start(); - thread.join(); - return; - } catch (Throwable t) { - log.error(t); - } - - main.info("Please restart ImageJ and call Help>Update to continue with the update"); - return; - } - try { final String missingUploaders = main.files.protocolsMissingUploaders(main.getUploaderService(), main.getProgress(null)); if (missingUploaders != null) { @@ -411,11 +356,8 @@ protected static boolean moveOutOfTheWay(final File file) { return file.renameTo(backup); } - private boolean areWeUpdatingTheUpdater() { - return UPDATER_UPDATING_THREAD_NAME.equals(Thread.currentThread().getName()); - } - public static void main(String[] args) { new ImageJUpdater().run(); } + }