Search in sources :

Example 1 with ITopic

use of org.eclipse.help.ITopic in project linuxtools by eclipse.

the class CheckJavadoc method testHelpTopic.

/**
 * 	Create a valid topic file given the sample Javadoc files provided
 *  in the /javadoc_root directory.
 *  @throws IOException
 * 	@result  A valid topic will be created with the proper href and label.
 *           Additionally this topic will be enabled correctly and will
 *           contain no child topics (subtopics).
 */
@Test
public void testHelpTopic() throws IOException {
    // Get current directory and append our test doc directory to it.
    // Set plugin preferences to read/detect Javadocs from this directory
    // instead.
    String testDocLoc = "/javadoc_root";
    String dir = FileLocator.toFileURL(this.getClass().getResource(testDocLoc)).getPath();
    IPath wsRoot = new Path(dir);
    IPreferenceStore ps = JavaDocPlugin.getDefault().getPreferenceStore();
    ps.setValue(PreferenceConstants.JAVADOCS_DIRECTORY, wsRoot.toOSString());
    JavaDocToc toc = new JavaDocToc();
    // Get topics array
    ITopic[] topics = toc.getTopics();
    // Verify we have the test topic, in this case jnr-unixsocket
    assertTrue(topics.length > 0);
    assertTrue(topics.length == 1);
    // Set topics and check labels
    ITopic topicJnr = topics[0];
    // $NON-NLS-1$
    assertTrue(topicJnr.getLabel().startsWith("jnr-unixsocket"));
    // Get subtopics for each topic, should be 0 since
    // Javadocs directories are only one level deep
    ITopic[] subtopicsJnr = topicJnr.getSubtopics();
    assertTrue(subtopicsJnr.length == 0);
    IUAElement[] elementsJnr = topicJnr.getChildren();
    assertTrue(elementsJnr.length == 0);
    // Get hrefs and check for correctness according to Plugin-ID
    // relative path
    String hrefApache = topicJnr.getHref();
    assertEquals(hrefApache, // $NON-NLS-1$
    "org.eclipse.linuxtools.javadocs/jnr-unixsocket/index.html");
    // Check to make sure topics are enables (should always be true)
    // regardless of input
    assertTrue(topicJnr.isEnabled(null));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaDocToc(org.eclipse.linuxtools.internal.javadocs.ui.JavaDocToc) ITopic(org.eclipse.help.ITopic) IPath(org.eclipse.core.runtime.IPath) IUAElement(org.eclipse.help.IUAElement) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Test(org.junit.Test)

Example 2 with ITopic

use of org.eclipse.help.ITopic in project linuxtools by eclipse.

the class CheckDevhelp method testHelpTopic.

@Test
public void testHelpTopic() throws IOException {
    // We need to have a devhelp directory with contents to test.
    // Copy over the needed devhelp/html contents in this test plug-in,
    // test1.devhelp2 and index.html, to the workspace.
    ClassLoader cl = getClass().getClassLoader();
    Bundle bundle = null;
    if (cl instanceof BundleReference) {
        bundle = ((BundleReference) cl).getBundle();
    }
    IWorkspace ws = ResourcesPlugin.getWorkspace();
    IPath wslocpath = ws.getRoot().getLocation();
    // $NON-NLS-1$
    IPath outfilepath = wslocpath.append("devhelp/html/test1");
    File outfiledir = outfilepath.toFile();
    assertTrue(outfiledir.mkdirs());
    // $NON-NLS-1$
    outfilepath = outfilepath.append("test1.devhelp2");
    File outfile = outfilepath.toFile();
    // $NON-NLS-1$
    IPath outfilepath2 = wslocpath.append("devhelp/html/test1/index.html");
    File outfile2 = outfilepath2.toFile();
    outfile.createNewFile();
    outfile2.createNewFile();
    try (InputStream in = FileLocator.openStream(bundle, new Path("devhelp/html/test1/test1.devhelp2"), false)) {
        // $NON-NLS-1$
        Files.copy(in, Paths.get(outfile.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    try (InputStream in2 = FileLocator.openStream(bundle, new Path("devhelp/html/test1/index.html"), false)) {
        // $NON-NLS-1$
        Files.copy(in2, Paths.get(outfile2.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    // $NON-NLS-1$
    IPath x = wslocpath.append("devhelp/html");
    IPreferenceStore ps = DevHelpPlugin.getDefault().getPreferenceStore();
    ps.setValue(PreferenceConstants.DEVHELP_DIRECTORY, x.toOSString());
    DevHelpToc toc = new DevHelpToc();
    ITopic[] topics = toc.getTopics();
    // Verify we have the test1 topic
    assertTrue(topics.length > 0);
    ITopic topic = topics[0];
    // $NON-NLS-1$
    assertTrue(topic.getLabel().startsWith("test1"));
    ITopic[] subtopics = topic.getSubtopics();
    // Verify it has 4 or more sub-topics
    assertTrue(subtopics.length > 3);
    IUAElement[] elements = topic.getChildren();
    assertTrue(elements.length > 3);
    String href = topic.getHref();
    // Verify the topic href is the index.html file and that the topic is
    // enabled
    assertEquals(href, // $NON-NLS-1$
    "/org.eclipse.linuxtools.cdt.libhover.devhelp/test1/index.html");
    assertTrue(topic.isEnabled(null));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITopic(org.eclipse.help.ITopic) IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) BundleReference(org.osgi.framework.BundleReference) IUAElement(org.eclipse.help.IUAElement) IWorkspace(org.eclipse.core.resources.IWorkspace) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File) DevHelpToc(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.DevHelpToc) Test(org.junit.Test)

Example 3 with ITopic

use of org.eclipse.help.ITopic in project linuxtools by eclipse.

the class DevHelpToc method getTopics.

@Override
public ITopic[] getTopics() {
    try {
        ArrayList<ITopic> topics = new ArrayList<>();
        IPreferenceStore ps = DevHelpPlugin.getDefault().getPreferenceStore();
        IPath devhelpLocation = new Path(ps.getString(PreferenceConstants.DEVHELP_DIRECTORY));
        IFileSystem fs = EFS.getLocalFileSystem();
        IFileStore htmlDir = fs.getStore(devhelpLocation);
        IFileStore[] files = htmlDir.childStores(EFS.NONE, null);
        Arrays.sort(files, (arg0, arg1) -> (arg0.getName().compareToIgnoreCase(arg1.getName())));
        for (IFileStore file : files) {
            String name = file.fetchInfo().getName();
            if (fs.getStore(// $NON-NLS-1$
            devhelpLocation.append(name).append(name + ".devhelp2")).fetchInfo().exists()) {
                ITopic topic = new DevHelpTopic(name);
                topics.add(topic);
            }
        }
        ITopic[] retval = new ITopic[topics.size()];
        return topics.toArray(retval);
    } catch (CoreException e) {
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITopic(org.eclipse.help.ITopic) IPath(org.eclipse.core.runtime.IPath) IFileSystem(org.eclipse.core.filesystem.IFileSystem) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 4 with ITopic

use of org.eclipse.help.ITopic in project linuxtools by eclipse.

the class JavaDocToc method getTopics.

@Override
public ITopic[] getTopics() {
    try {
        // Finds the path to the javadoc directory from the preference
        // store, and gets all children directories.
        ArrayList<ITopic> topics = new ArrayList<>();
        IPreferenceStore ps = JavaDocPlugin.getDefault().getPreferenceStore();
        IPath javadocLocation = new Path(ps.getString(PreferenceConstants.JAVADOCS_DIRECTORY));
        IFileSystem fs = EFS.getLocalFileSystem();
        IFileStore htmlDir = fs.getStore(javadocLocation);
        IFileStore[] files = htmlDir.childStores(EFS.NONE, null);
        Arrays.sort(files, new Comparator<IFileStore>() {

            @Override
            public int compare(IFileStore arg0, IFileStore arg1) {
                return (arg0.getName().compareToIgnoreCase(arg1.getName()));
            }
        });
        // directory and generates topics for them.
        for (IFileStore file : files) {
            String name = file.fetchInfo().getName();
            if (fs.getStore(// $NON-NLS-1$
            javadocLocation.append(name)).fetchInfo().exists() && fs.getStore(// $NON-NLS-1$
            javadocLocation.append(name + "/index.html")).fetchInfo().exists()) {
                ITopic topic = new JavaDocTopic(name);
                topics.add(topic);
            }
        }
        // Returns an array of the generated topics
        ITopic[] retval = new ITopic[topics.size()];
        return topics.toArray(retval);
    } catch (CoreException e) {
    }
    // child directories present.
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITopic(org.eclipse.help.ITopic) IPath(org.eclipse.core.runtime.IPath) IFileSystem(org.eclipse.core.filesystem.IFileSystem) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

IPath (org.eclipse.core.runtime.IPath)4 Path (org.eclipse.core.runtime.Path)4 ITopic (org.eclipse.help.ITopic)4 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 ArrayList (java.util.ArrayList)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IFileSystem (org.eclipse.core.filesystem.IFileSystem)2 CoreException (org.eclipse.core.runtime.CoreException)2 IUAElement (org.eclipse.help.IUAElement)2 Test (org.junit.Test)2 File (java.io.File)1 InputStream (java.io.InputStream)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 DevHelpToc (org.eclipse.linuxtools.internal.cdt.libhover.devhelp.DevHelpToc)1 JavaDocToc (org.eclipse.linuxtools.internal.javadocs.ui.JavaDocToc)1 Bundle (org.osgi.framework.Bundle)1 BundleReference (org.osgi.framework.BundleReference)1