Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not update the updater separately #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ branches:
install: true
services:
- xvfb
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
script: ".travis/build.sh"
env:
global:
Expand Down
101 changes: 23 additions & 78 deletions src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,21 @@

package net.imagej.ui.swing.updater;

import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import net.imagej.ui.swing.updater.ViewOptions.Option;
import net.imagej.updater.*;
import net.imagej.updater.Conflicts.Conflict;
import net.imagej.updater.util.*;

import net.imagej.updater.FileObject;
import net.imagej.updater.FilesCollection;
import net.imagej.updater.Installer;
import net.imagej.updater.URLChange;
import net.imagej.updater.UpdaterUI;
import net.imagej.updater.UploaderService;
import net.imagej.updater.util.AvailableSites;
import net.imagej.updater.util.HTTPSUtil;
import net.imagej.updater.util.Progress;
import net.imagej.updater.util.UpdateCanceledException;
import net.imagej.updater.util.UpdaterUserInterface;
import net.imagej.updater.util.UpdaterUtil;
import org.scijava.app.StatusService;
import org.scijava.command.CommandService;
import org.scijava.event.ContextDisposingEvent;
import org.scijava.event.EventHandler;
import org.scijava.log.LogService;
Expand All @@ -61,6 +55,16 @@
import org.scijava.util.AppUtils;

import javax.swing.*;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.util.List;

/**
* The Updater. As a command.
Expand All @@ -84,11 +88,6 @@ public class ImageJUpdater implements UpdaterUI {
@Parameter
private UploaderService uploaderService;

@Parameter
private CommandService commandService;

private final static String UPDATER_UPDATING_THREAD_NAME = "Updating the Updater itself!";

@Override
public void run() {

Expand All @@ -107,7 +106,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 @@ -173,56 +172,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 @@ -419,10 +368,6 @@ 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();
}
Expand Down