You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2016/10/24 07:03:47 UTC
[6/6] incubator-taverna-workbench git commit: some event stuff..
(incomplete?)
some event stuff.. (incomplete?)
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/commit/fff5de51
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/tree/fff5de51
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/diff/fff5de51
Branch: refs/heads/master
Commit: fff5de51c19adfcf83b4dab3973ff6c846bbcdc7
Parents: a3483f5
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 21 13:09:44 2016 +0200
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 21 13:09:44 2016 +0200
----------------------------------------------------------------------
.../spring/perspective-results-context-osgi.xml | 2 +-
.../plugins/ui/CheckForUpdatesStartupHook.java | 62 ++++++++++++--------
.../spring/plugins-gui-context-osgi.xml | 11 +++-
.../META-INF/spring/plugins-gui-context.xml | 6 +-
4 files changed, 55 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/fff5de51/taverna-perspective-results/src/main/resources/META-INF/spring/perspective-results-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-perspective-results/src/main/resources/META-INF/spring/perspective-results-context-osgi.xml b/taverna-perspective-results/src/main/resources/META-INF/spring/perspective-results-context-osgi.xml
index d6ec0be..41ccc36 100644
--- a/taverna-perspective-results/src/main/resources/META-INF/spring/perspective-results-context-osgi.xml
+++ b/taverna-perspective-results/src/main/resources/META-INF/spring/perspective-results-context-osgi.xml
@@ -27,7 +27,7 @@
<service ref="ResultsPerspective" auto-export="interfaces">
<service-properties value-type="java.lang.String[]">
<beans:entry key="event.topics"
- value="uk/org/taverna/platform/run/RunService/*" />
+ value="org/apache/taverna/platform/run/api/RunService/*" />
</service-properties>
</service>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/fff5de51/taverna-plugins-gui/src/main/java/org/apache/taverna/raven/plugins/ui/CheckForUpdatesStartupHook.java
----------------------------------------------------------------------
diff --git a/taverna-plugins-gui/src/main/java/org/apache/taverna/raven/plugins/ui/CheckForUpdatesStartupHook.java b/taverna-plugins-gui/src/main/java/org/apache/taverna/raven/plugins/ui/CheckForUpdatesStartupHook.java
index 725f789..75d8424 100644
--- a/taverna-plugins-gui/src/main/java/org/apache/taverna/raven/plugins/ui/CheckForUpdatesStartupHook.java
+++ b/taverna-plugins-gui/src/main/java/org/apache/taverna/raven/plugins/ui/CheckForUpdatesStartupHook.java
@@ -19,10 +19,14 @@ package org.apache.taverna.raven.plugins.ui;
import java.io.File;
import java.util.Date;
-import uk.org.taverna.commons.plugin.PluginManager;
-import uk.org.taverna.configuration.app.ApplicationConfiguration;
-
+import org.apache.log4j.Logger;
+import org.apache.taverna.configuration.app.ApplicationConfiguration;
+import org.apache.taverna.plugin.PluginException;
+import org.apache.taverna.plugin.PluginManager;
import org.apache.taverna.workbench.StartupSPI;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventHandler;
/**
* Startup hook for checking if there are available updates for Taverna plugins.
@@ -31,24 +35,31 @@ import org.apache.taverna.workbench.StartupSPI;
* @author Stian Soiland-Reyes
*
*/
-public class CheckForUpdatesStartupHook implements StartupSPI {
+public class CheckForUpdatesStartupHook implements StartupSPI, EventHandler {
+
+ public void setPluginManager(PluginManager pluginManager) {
+ this.pluginManager = pluginManager;
+ }
+
+ public void setApplicationConfiguration(ApplicationConfiguration applicationConfiguration) {
+ this.applicationConfiguration = applicationConfiguration;
+ }
public static final String CHECK_FOR_UPDATES_DIRECTORY_NAME = "updates";
public static final String LAST_UPDATE_CHECK_FILE_NAME = "last_update_check";
+ private EventAdmin eventAdmin;
private PluginManager pluginManager;
private ApplicationConfiguration applicationConfiguration;
-
- public static File checkForUpdatesDirectory = getCheckForUpdatesDirectory();
- public static File lastUpdateCheckFile = new File(checkForUpdatesDirectory,
- LAST_UPDATE_CHECK_FILE_NAME);
+ private Logger logger = Logger.getLogger(CheckForUpdatesStartupHook.class);
public int positionHint() {
return 90;
}
public boolean startup() {
-
+ File lastUpdateCheckFile = new File(getCheckForUpdatesDirectory(),
+ LAST_UPDATE_CHECK_FILE_NAME);
// Check if more than 2 weeks passed since we checked for updates.
if (lastUpdateCheckFile.exists()) {
long lastModified = lastUpdateCheckFile.lastModified();
@@ -56,30 +67,26 @@ public class CheckForUpdatesStartupHook implements StartupSPI {
if (now - lastModified < 14 * 24 * 3600 * 1000) { // 2 weeks have not passed since we
// last asked
+ // No need to check for updates yet
return true;
- } else { // Check again for updates
- if (pluginManager.checkForUpdates()) {
- CheckForUpdatesDialog dialog = new CheckForUpdatesDialog();
- dialog.setVisible(true);
- }
- return true;
- }
- } else {
- // If we are here - then this is the first time to check for updates
- if (pluginManager.checkForUpdates()) {
- CheckForUpdatesDialog dialog = new CheckForUpdatesDialog();
- dialog.setVisible(true);
}
- return true;
}
+ try {
+ pluginManager.checkForUpdates();
+ } catch (PluginException e) {
+ logger.error("Can't check for updates", e);
+ return false;
+ }
+ return true;
}
+
/**
* Gets the registration directory where info about registration will be saved to.
*/
public File getCheckForUpdatesDirectory() {
- File home = applicationConfiguration.getApplicationHomeDir();
+ File home = applicationConfiguration.getApplicationHomeDir().toFile();
File registrationDirectory = new File(home, CHECK_FOR_UPDATES_DIRECTORY_NAME);
if (!registrationDirectory.exists()) {
@@ -87,4 +94,13 @@ public class CheckForUpdatesStartupHook implements StartupSPI {
}
return registrationDirectory;
}
+
+ @Override
+ public void handleEvent(Event event) {
+ // TODO: Handle Plug
+ if (event.getTopic().equals(PluginManager.UPDATES_AVAILABLE) {
+ CheckForUpdatesDialog dialog = new CheckForUpdatesDialog();
+ dialog.setVisible(true);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/fff5de51/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context-osgi.xml b/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context-osgi.xml
index e10ffa6..566a170 100644
--- a/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context-osgi.xml
+++ b/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context-osgi.xml
@@ -24,6 +24,15 @@
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
- <service ref="CheckForUpdatesStartupHook" interface="org.apache.taverna.workbench.StartupSPI" />
+ <service ref="CheckForUpdatesStartupHook" auto-export="interfaces">
+ <service-properties value-type="java.lang.String[]">
+ <beans:entry key="event.topics"
+ value="org/apache/taverna/platform/run/api/RunService/*" />
+ </service-properties>
+ </service>
+ <reference id="eventAdmin" interface="org.osgi.service.event.EventAdmin" />
+ <reference id="pluginManager" interface="org.apache.taverna.plugin.PluginManager" />
+ <reference id="applicationConfiguration" interface="org.apache.taverna.configuration.app.ApplicationConfiguration" />
+
</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/fff5de51/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context.xml
----------------------------------------------------------------------
diff --git a/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context.xml b/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context.xml
index 7610e16..7900c3f 100644
--- a/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context.xml
+++ b/taverna-plugins-gui/src/main/resources/META-INF/spring/plugins-gui-context.xml
@@ -21,6 +21,10 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
- <bean id="CheckForUpdatesStartupHook" class="net.sf.taverna.raven.plugins.ui.CheckForUpdatesStartupHook" />
+ <bean id="CheckForUpdatesStartupHook" class="net.sf.taverna.raven.plugins.ui.CheckForUpdatesStartupHook">
+ <property name="eventAdmin" ref="eventAdmin" />
+ <property name="pluginManager" ref="pluginManager" />
+ <property name="applicationConfiguration" ref="applicationConfiguration" />
+ </bean>
</beans>