Search in sources :

Example 1 with LibHoverLibrary

use of org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary in project linuxtools by eclipse.

the class CheckDevhelp method testParse.

@Test
public void testParse() throws IOException {
    ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser(// $NON-NLS-1$
    "/usr/share/gtk-doc/html");
    LibHoverInfo hover = p.parse(new NullProgressMonitor());
    assertNotNull(hover);
    Map<String, FunctionInfo> functions = hover.functions;
    assertNotNull(functions);
    assertFalse(functions.isEmpty());
    // Now, output the LibHoverInfo for caching later
    IPath location = LibhoverPlugin.getDefault().getStateLocation().append(// $NON-NLS-1$
    "C");
    File ldir = new File(location.toOSString());
    ldir.mkdir();
    // $NON-NLS-1$
    location = location.append("devhelp.libhover");
    try (FileOutputStream f = new FileOutputStream(location.toOSString());
        ObjectOutputStream out = new ObjectOutputStream(f)) {
        out.writeObject(hover);
    }
    IPreferenceStore ps = LibhoverPlugin.getDefault().getPreferenceStore();
    ps.setValue(CACHE_EXT_LIBHOVER, true);
    LibHover.getLibHoverDocs();
    Collection<LibHoverLibrary> c = LibHover.getLibraries();
    assertFalse(c.isEmpty());
    boolean found = false;
    for (LibHoverLibrary l : c) {
        if (l.getName().equals("devhelp")) {
            // $NON-NLS-1$
            found = true;
        }
    }
    assertTrue(found);
}
Also used : LibHoverLibrary(org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) ObjectOutputStream(java.io.ObjectOutputStream) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) ParseDevHelp(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp) FileOutputStream(java.io.FileOutputStream) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File) Test(org.junit.Test)

Example 2 with LibHoverLibrary

use of org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary in project linuxtools by eclipse.

the class LibHoverPreferencePage method regenerate.

private synchronized void regenerate() {
    generateButton.setEnabled(false);
    Job k = new Job(LibHoverMessages.getString(REGENERATE_MSG)) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IPreferenceStore ps = DevHelpPlugin.getDefault().getPreferenceStore();
            ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser(ps.getString(PreferenceConstants.DEVHELP_DIRECTORY));
            LibHoverInfo hover = p.parse(monitor);
            // Update the devhelp library info if it is on library list
            Collection<LibHoverLibrary> libs = LibHover.getLibraries();
            for (LibHoverLibrary l : libs) {
                if (l.getName().equals("devhelp")) {
                    // $NON-NLS-1$
                    l.setHoverinfo(hover);
                    break;
                }
            }
            try {
                // Now, output the LibHoverInfo for caching later
                // $NON-NLS-1$
                IPath location = LibhoverPlugin.getDefault().getStateLocation().append("C");
                File ldir = new File(location.toOSString());
                ldir.mkdir();
                // $NON-NLS-1$
                location = location.append("devhelp.libhover");
                try (FileOutputStream f = new FileOutputStream(location.toOSString());
                    ObjectOutputStream out = new ObjectOutputStream(f)) {
                    out.writeObject(hover);
                }
                monitor.done();
            } catch (IOException e) {
                monitor.done();
                return new Status(IStatus.ERROR, DevHelpPlugin.PLUGIN_ID, e.getLocalizedMessage(), e);
            }
            return Status.OK_STATUS;
        }
    };
    k.setUser(true);
    k.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            Display.getDefault().syncExec(() -> {
                if (generateButton != null)
                    generateButton.setEnabled(true);
            });
        }
    });
    k.schedule();
}
Also used : LibHoverLibrary(org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IOException(java.io.IOException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) ObjectOutputStream(java.io.ObjectOutputStream) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ParseDevHelp(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp) FileOutputStream(java.io.FileOutputStream) Job(org.eclipse.core.runtime.jobs.Job) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File)

Aggregations

File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 IPath (org.eclipse.core.runtime.IPath)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 LibHoverInfo (org.eclipse.linuxtools.cdt.libhover.LibHoverInfo)2 LibHoverLibrary (org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary)2 ParseDevHelp (org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp)2 IOException (java.io.IOException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 FunctionInfo (org.eclipse.linuxtools.cdt.libhover.FunctionInfo)1 Test (org.junit.Test)1