diff options
author | Jeff Johnston | 2015-07-29 20:15:05 +0000 |
---|---|---|
committer | Jeff Johnston | 2015-07-29 21:14:23 +0000 |
commit | e2ec4d2e95bdbb0f51c80d292ad46215a4dc3ff6 (patch) | |
tree | ad0eaeafb515a6e89406f4cfc6bdd0407cbb2c61 | |
parent | f8dc49363d1a312a48c743856c3a84eb0095d251 (diff) | |
download | org.eclipse.linuxtools-e2ec4d2e95bdbb0f51c80d292ad46215a4dc3ff6.tar.gz org.eclipse.linuxtools-e2ec4d2e95bdbb0f51c80d292ad46215a4dc3ff6.tar.xz org.eclipse.linuxtools-e2ec4d2e95bdbb0f51c80d292ad46215a4dc3ff6.zip |
Make sure Libhover Devhelp plugin initializes at startup
- add org.eclipse.ui.startup extension to Libhover Devhelp plug-in
- split out DevHelp initialization job from DevHelpPlugin and
put it into new DevHelpStartup class which implements IStartup
- remove IStartup stuff from DevHelpPlugin
Change-Id: I363ed667792700dc348e28156db4180e9f92d0c0
Reviewed-on: https://git.eclipse.org/r/52822
Tested-by: Hudson CI
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
3 files changed, 152 insertions, 122 deletions
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/plugin.xml b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/plugin.xml index f9cd5a22b3..d519e5fb83 100644 --- a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/plugin.xml +++ b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/plugin.xml @@ -39,4 +39,10 @@ producer="org.eclipse.linuxtools.internal.cdt.libhover.devhelp.DevHelpContentProducer"> </contentProducer> </extension> + <extension + point="org.eclipse.ui.startup"> + <startup + class="org.eclipse.linuxtools.internal.cdt.libhover.devhelp.DevHelpStartup"> + </startup> + </extension> </plugin> diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpPlugin.java b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpPlugin.java index 29819d3eb0..44bc0ea3c7 100644 --- a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpPlugin.java +++ b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpPlugin.java @@ -10,37 +10,17 @@ *******************************************************************************/ package org.eclipse.linuxtools.internal.cdt.libhover.devhelp; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.util.Collection; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.linuxtools.cdt.libhover.LibHoverInfo; -import org.eclipse.linuxtools.cdt.libhover.LibhoverPlugin; -import org.eclipse.linuxtools.internal.cdt.libhover.LibHover; -import org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary; -import org.eclipse.linuxtools.internal.cdt.libhover.devhelp.preferences.LibHoverMessages; -import org.eclipse.linuxtools.internal.cdt.libhover.devhelp.preferences.PreferenceConstants; -import org.eclipse.ui.IStartup; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle. */ -public class DevHelpPlugin extends AbstractUIPlugin implements IStartup { +public class DevHelpPlugin extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "org.eclipse.linuxtools.cdt.libhover.devhelp"; //$NON-NLS-1$ - private static final String REGENERATE_MSG = "Libhover.Devhelp.Regenerate.msg"; //$NON-NLS-1$ // The shared instance private static DevHelpPlugin plugin; @@ -52,17 +32,20 @@ public class DevHelpPlugin extends AbstractUIPlugin implements IStartup { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - k = new DevhelpStartupJob(LibHoverMessages.getString(REGENERATE_MSG)) ; - k.schedule(); } @Override public void stop(BundleContext context) throws Exception { - k.cancel(); + if (k != null) + k.cancel(); plugin = null; super.stop(context); } + public void setJob(Job j) { + k = j; + } + /** * Returns the shared instance * @@ -72,102 +55,4 @@ public class DevHelpPlugin extends AbstractUIPlugin implements IStartup { return plugin; } - @Override - public void earlyStartup() { - // do nothing...we just want start to get called and reparse the devhelp - // directory - } - - /** - * Job used to load devhelp data on startup. - * - */ - private static class DevhelpStartupJob extends Job { - - private IProgressMonitor runMonitor; - - public DevhelpStartupJob(String name) { - super(name); - } - - @Override - protected void canceling() { - if (runMonitor != null) - runMonitor.setCanceled(true); - }; - - @Override - protected IStatus run(IProgressMonitor monitor) { - runMonitor = monitor; - if (monitor.isCanceled()) - return Status.CANCEL_STATUS; - IPreferenceStore ps = DevHelpPlugin.getDefault() - .getPreferenceStore(); - String devhelpDir = ps.getString(PreferenceConstants.DEVHELP_DIRECTORY); - IPath devhelpPath = new Path(devhelpDir); - File devhelp = devhelpPath.toFile(); - if (!devhelp.exists()) { - // No input data to process so quit now - monitor.done(); - return Status.OK_STATUS; - } - long ltime = devhelp.lastModified(); - IPath libhoverPath = LibhoverPlugin.getDefault() - .getStateLocation().append("C").append("devhelp.libhover"); //$NON-NLS-1$ //$NON-NLS-2$ - File libhoverDir = new File(libhoverPath.toOSString()); - if (libhoverDir.exists()) { - long ltime2 = libhoverDir.lastModified(); - // Check the last modified time of the devhelp libhover file compared to the - // devhelp directory we use to parse the data - if (ltime < ltime2) { - // Our devhelp info is up to date and is older than the last modification to - // the devhelp input data so stop now - monitor.done(); - return Status.OK_STATUS; - } - } - ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser( - ps.getString(PreferenceConstants.DEVHELP_DIRECTORY)); - LibHoverInfo hover = p.parse(monitor); - if (monitor.isCanceled()) - return Status.CANCEL_STATUS; - // Update the devhelp library info if it is on library list - Collection<LibHoverLibrary> libs = LibHover.getLibraries(); - for (LibHoverLibrary l : libs) { - if (monitor.isCanceled()) - return Status.CANCEL_STATUS; - if (l.getName().equals("devhelp")) { //$NON-NLS-1$ - l.setHoverinfo(hover); - break; - } - } - try { - if (monitor.isCanceled()) - return Status.CANCEL_STATUS; - // Now, output the LibHoverInfo for caching later - IPath location = LibhoverPlugin.getDefault() - .getStateLocation().append("C"); //$NON-NLS-1$ - File ldir = new File(location.toOSString()); - ldir.mkdir(); - location = location.append("devhelp.libhover"); //$NON-NLS-1$ - try (FileOutputStream f = new FileOutputStream( - location.toOSString()); - ObjectOutputStream out = new ObjectOutputStream(f)) { - out.writeObject(hover); - } - monitor.done(); - } catch (NullPointerException e) { - monitor.done(); - return Status.CANCEL_STATUS; - } catch (IOException e) { - monitor.done(); - return new Status(IStatus.ERROR, DevHelpPlugin.PLUGIN_ID, - e.getLocalizedMessage(), e); - } - - return Status.OK_STATUS; - } - - }; - }
\ No newline at end of file diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpStartup.java b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpStartup.java new file mode 100644 index 0000000000..0d0c2ed2c4 --- /dev/null +++ b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpStartup.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2015 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat Inc. - Initial implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.cdt.libhover.devhelp; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.Collection; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.cdt.libhover.LibHoverInfo; +import org.eclipse.linuxtools.cdt.libhover.LibhoverPlugin; +import org.eclipse.linuxtools.internal.cdt.libhover.LibHover; +import org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary; +import org.eclipse.linuxtools.internal.cdt.libhover.devhelp.preferences.LibHoverMessages; +import org.eclipse.linuxtools.internal.cdt.libhover.devhelp.preferences.PreferenceConstants; +import org.eclipse.ui.IStartup; + +public class DevHelpStartup implements IStartup { + + private static final String REGENERATE_MSG = "Libhover.Devhelp.Regenerate.msg"; //$NON-NLS-1$ + + private Job k; + + @Override + public void earlyStartup() { + k = new DevhelpStartupJob(LibHoverMessages.getString(REGENERATE_MSG)) ; + k.schedule(); + DevHelpPlugin.getDefault().setJob(k); + } + + /** + * Job used to load devhelp data on startup. + * + */ + private static class DevhelpStartupJob extends Job { + + private IProgressMonitor runMonitor; + + public DevhelpStartupJob(String name) { + super(name); + } + + @Override + protected void canceling() { + if (runMonitor != null) + runMonitor.setCanceled(true); + }; + + @Override + protected IStatus run(IProgressMonitor monitor) { + runMonitor = monitor; + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + IPreferenceStore ps = DevHelpPlugin.getDefault() + .getPreferenceStore(); + String devhelpDir = ps.getString(PreferenceConstants.DEVHELP_DIRECTORY); + IPath devhelpPath = new Path(devhelpDir); + File devhelp = devhelpPath.toFile(); + if (!devhelp.exists()) { + // No input data to process so quit now + monitor.done(); + return Status.OK_STATUS; + } + long ltime = devhelp.lastModified(); + IPath libhoverPath = LibhoverPlugin.getDefault() + .getStateLocation().append("C").append("devhelp.libhover"); //$NON-NLS-1$ //$NON-NLS-2$ + File libhoverDir = new File(libhoverPath.toOSString()); + if (libhoverDir.exists()) { + long ltime2 = libhoverDir.lastModified(); + // Check the last modified time of the devhelp libhover file compared to the + // devhelp directory we use to parse the data + if (ltime < ltime2) { + // Our devhelp info is up to date and is older than the last modification to + // the devhelp input data so stop now + monitor.done(); + return Status.OK_STATUS; + } + } + ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser( + ps.getString(PreferenceConstants.DEVHELP_DIRECTORY)); + LibHoverInfo hover = p.parse(monitor); + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + // Update the devhelp library info if it is on library list + Collection<LibHoverLibrary> libs = LibHover.getLibraries(); + for (LibHoverLibrary l : libs) { + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + if (l.getName().equals("devhelp")) { //$NON-NLS-1$ + l.setHoverinfo(hover); + break; + } + } + try { + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + // Now, output the LibHoverInfo for caching later + IPath location = LibhoverPlugin.getDefault() + .getStateLocation().append("C"); //$NON-NLS-1$ + File ldir = new File(location.toOSString()); + ldir.mkdir(); + location = location.append("devhelp.libhover"); //$NON-NLS-1$ + try (FileOutputStream f = new FileOutputStream( + location.toOSString()); + ObjectOutputStream out = new ObjectOutputStream(f)) { + out.writeObject(hover); + } + monitor.done(); + } catch (NullPointerException e) { + monitor.done(); + return Status.CANCEL_STATUS; + } catch (IOException e) { + monitor.done(); + return new Status(IStatus.ERROR, DevHelpPlugin.PLUGIN_ID, + e.getLocalizedMessage(), e); + } + + return Status.OK_STATUS; + } + + }; + +} |