Skip to content

Commit

Permalink
ImageJUpdater: Do not update the updater separately
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
frauzufall authored and ctrueden committed Oct 19, 2024
1 parent 4f70b9a commit ff53573
Showing 1 changed file with 2 additions and 60 deletions.
62 changes: 2 additions & 60 deletions src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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"
Expand Down Expand Up @@ -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<URL> 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) {
Expand Down Expand Up @@ -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();
}

}

0 comments on commit ff53573

Please sign in to comment.