Skip to content

Commit

Permalink
Closes #179
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed May 18, 2016
1 parent 6df2686 commit 726be6b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import org.protege.editor.core.update.PluginManager;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.UnknownHostException;
/*
* Copyright (C) 2007, University of Manchester
*
Expand All @@ -22,7 +25,21 @@ public class CheckPluginsAction extends ProtegeAction {


public void actionPerformed(ActionEvent event) {
PluginManager.getInstance().runCheckForPlugins();
try {
PluginManager.getInstance().runCheckForPlugins();
} catch (UnknownHostException e) {
JOptionPane.showMessageDialog(getWorkspace(),
"<html><body>" +
"<b>Protege could not connect to the plugin registry.</b><br><br> " +
"Please check your internet connection and try again." +
"</body></html>", "Unable to check for plugins", JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
JOptionPane.showMessageDialog(getWorkspace(),
"<html><body>" +
"<b>Protege could not connect to the plugin registry.</b><br><br> " +
"Reason: " + e.getMessage() +
"</body></html>", "Unable to check for plugins", JOptionPane.ERROR_MESSAGE);
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.protege.editor.core.ui.action.start;

import org.protege.editor.core.update.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.event.ActionEvent;
import java.io.IOException;

/**
* Author: drummond<br>
Expand All @@ -13,11 +16,15 @@
* Date: Nov 6, 2008<br><br>
*/
public class CheckPluginsAction extends AltStartupAction {
private static final long serialVersionUID = 1531046176436352912L;

private static final Logger logger = LoggerFactory.getLogger(CheckPluginsAction.class);

public void actionPerformed(ActionEvent event) {
PluginManager.getInstance().runCheckForPlugins();
try {
PluginManager.getInstance().runCheckForPlugins();
} catch (IOException e) {
logger.warn("A problem occurred whilst checking for plugin updates: {}", e.getMessage());
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import org.protege.editor.core.prefs.Preferences;
import org.protege.editor.core.prefs.PreferencesManager;
import org.protege.editor.core.ui.progress.BackgroundTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
Expand All @@ -17,7 +21,7 @@
* The University Of Manchester<br>
* Medical Informatics Group<br>
* Date: 25-Aug-2006<br><br>
* <p/>
* matthew.horridge@cs.man.ac.uk<br>
* www.cs.man.ac.uk/~horridgm<br><br>
*/
Expand All @@ -33,6 +37,8 @@ public class PluginManager {

public static final String DEFAULT_REGISTRY = "https://raw.githubusercontent.com/protegeproject/autoupdate/master/update-info/5.0.0/plugins.repository";

private final Logger logger = LoggerFactory.getLogger(PluginManager.class);

private static enum SearchType {
UPDATES_ONLY,
UPDATES_AND_INSTALLS
Expand Down Expand Up @@ -65,26 +71,26 @@ public boolean isAutoUpdateEnabled() {


public URL getPluginRegistryLocation() {
String pluginRegistryLoc = getPrefs().getString(PLUGIN_REGISTRY_KEY, DEFAULT_REGISTRY);
String pluginRegistryLoc = getPrefs().getString(PLUGIN_REGISTRY_KEY, DEFAULT_REGISTRY);
try {
return new URL(pluginRegistryLoc);
}
catch (MalformedURLException e) {
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}


public void setPluginRegistryLocation(URL url) {
String oldPluginRegistryLoc = getPrefs().getString(PLUGIN_REGISTRY_KEY, DEFAULT_REGISTRY);
String newPluginRegistryLoc = url.toString();
if (!newPluginRegistryLoc.equals(oldPluginRegistryLoc)) {
getPrefs().putString(PLUGIN_REGISTRY_KEY, newPluginRegistryLoc);
}
String oldPluginRegistryLoc = getPrefs().getString(PLUGIN_REGISTRY_KEY, DEFAULT_REGISTRY);
String newPluginRegistryLoc = url.toString();
if (!newPluginRegistryLoc.equals(oldPluginRegistryLoc)) {
getPrefs().putString(PLUGIN_REGISTRY_KEY, newPluginRegistryLoc);
}
}

/**
* Gets the date that auto-update was last run.
*
* @return The date which auto-update was last run. Not {@code null}.
*/
public Date getLastAutoUpdateDate() {
Expand All @@ -96,26 +102,33 @@ public void runAutoUpdate() {
runSearch(SearchType.UPDATES_ONLY);
}

public void runCheckForPlugins() {
public void runCheckForPlugins() throws IOException {
ensureConnectionToPluginRegistry();
runSearch(SearchType.UPDATES_AND_INSTALLS);
}

private void ensureConnectionToPluginRegistry() throws IOException {
URL registryLocation = getPluginRegistryLocation();
HttpURLConnection connection = (HttpURLConnection) registryLocation.openConnection();
connection.setRequestMethod("HEAD");
connection.getResponseCode();
}

private void runSearch(SearchType searchType) {
final BackgroundTask autoUpdateTask = ProtegeApplication.getBackgroundTaskManager().startTask("autoupdate");
Runnable runnable = () -> {
PluginRegistry registry = new PluginRegistryImpl(getPluginRegistryLocation());
try {
registry.reload();
getPrefs().putLong(LAST_RUN_PREFS_KEY, System.currentTimeMillis());
}
finally {
} finally {
ProtegeApplication.getBackgroundTaskManager().endTask(autoUpdateTask);
List<PluginInfo> availablePlugins = registry.getAvailablePlugins();
if (searchType == SearchType.UPDATES_AND_INSTALLS) {
showPluginsDialog(availablePlugins);
}
else {
if(!availablePlugins.isEmpty()) {
if (!availablePlugins.isEmpty()) {
showPluginsDialog(availablePlugins);
}
}
Expand All @@ -127,13 +140,13 @@ private void runSearch(SearchType searchType) {
}

private void showPluginsDialog(List<PluginInfo> pluginInfoList) {
SwingUtilities.invokeLater(() -> {
List<PluginInfo> selUpdates = PluginPanel.showDialog(pluginInfoList, null);
if (!selUpdates.isEmpty()){
PluginInstaller installer = new PluginInstaller(selUpdates);
installer.run();
}
});
SwingUtilities.invokeLater(() -> {
List<PluginInfo> selUpdates = PluginPanel.showDialog(pluginInfoList, null);
if (!selUpdates.isEmpty()) {
PluginInstaller installer = new PluginInstaller(selUpdates);
installer.run();
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.*;
/*
* Copyright (C) 2007, University of Manchester
Expand Down Expand Up @@ -175,8 +176,10 @@ private void readRegistry(URL node, int depth) {
}
}
reader.close();
} catch (UnknownHostException ex) {
logger.info(AUTO_UPDATE, "{} Cannot open remote plugin registry at {} (Unknown Host)", pad(depth), ex.getMessage());
} catch (IOException ex) {
logger.warn(AUTO_UPDATE, "{} Cannot open remote plugin registry at {}. Reason: {}", pad(depth), ex.getMessage(), ex);
logger.info(AUTO_UPDATE, "{} Cannot read plugin registry at {}. Reason: {}", pad(depth), node, ex.getMessage());
}
}
}
Expand Down

0 comments on commit 726be6b

Please sign in to comment.