PageRenderTime 129ms CodeModel.GetById 118ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms


HTML | 52 lines | 52 code | 0 blank | 0 comment | 0 complexity | 8e67606d2a5d645c761b9e2703312108 MD5 | raw file
 1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>How Plugins are Loaded</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="jEdit 4.3 User's Guide"><link rel="up" href="plugin-implement.html" title="Chapter 18. Implementing a Simple Plugin"><link rel="prev" href="plugin-implement.html" title="Chapter 18. Implementing a Simple Plugin"><link rel="next" href="plugin-implement-quicknotepadplugin.html" title="The QuickNotepadPlugin Class"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"> How Plugins are Loaded</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="plugin-implement.html">Prev</a> </td><th width="60%" align="center">Chapter 18. Implementing a Simple Plugin</th><td width="20%" align="right"> <a accesskey="n" href="plugin-implement-quicknotepadplugin.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="plugin-load"></a><a class="indexterm" name="id2606910"></a> How Plugins are Loaded</h2></div></div></div><p>We will discuss the implementation of the
 2        <span class="application">QuickNotepad</span> plugin, along with the jEdit
 3        APIs it makes use of. But first, we describe how plugins are
 4        loaded.</p><p>As part of its startup routine, jEdit's <code class="function">main</code>
 5        method calls various methods to load and initialize plugins.</p><p>Additionally, plugins using the jEdit 4.2 plugin API can be loaded
 6        and unloaded at any time. This is a great help when developing your own
 7        plugins -- there is no need to restart the editor after making changes
 8        (see <a class="xref" href="plugin-implement-reloading.html" title="Reloading the Plugin">the section called &#8220;Reloading the Plugin&#8221;</a> ).</p><p>Plugins are loaded from files with the <code class="filename">.jar</code>
 9        filename extension located in the <code class="filename">jars</code>
10        subdirectories of the jEdit installation and user settings directories
11        (see <a class="xref" href="settings-directory.html" title="The jEdit Settings Directory">the section called &#8220;The jEdit Settings Directory&#8221;</a>).</p><p>For each JAR archive file it finds, jEdit scans its entries and
12        performs the following tasks:</p><div class="itemizedlist"><ul type="disc"><li><p>Adds to a collection maintained by jEdit a new object of
13                type <a class="ulink" href="../api/org/gjt/sp/jedit/PluginJAR.html" target="_top">
14                <code class="classname">PluginJAR</code></a>. This is a data
15                structure holding the name of the JAR archive file, a reference
16                to the <a class="ulink" href="../api/org/gjt/sp/jedit/JARClassLoader.html" target="_top">
17                <code class="classname">JARClassLoader</code></a>, and a collection
18                of plugins found in the archive file.</p></li><li><p>Loads any properties defined in files ending with the
19                extension <code class="filename">.props</code> that are contained in the
20                archive. See <a class="xref" href="plugin-implement-properties.html" title="The Property File">the section called &#8220;The Property File&#8221;</a>.</p></li><li><p>Reads action definitions from any file named
21                <code class="filename">actions.xml</code> in the archive (the file need
22                not be at the top level). See <a class="xref" href="plugin-implement-actions.html" title="The Actions Catalog">the section called &#8220;The Actions Catalog&#8221;</a>.</p></li><li><p>Parses and loads the contents of any file named
23                <code class="filename">dockables.xml</code> in the archive (the file need
24                not be at the top level). This file contains BeanShell code for
25                creating docking or floating windows that will contain the
26                visible components of the plugin. Not all plugins define
27                dockable windows, but those that do need a
28                <code class="filename">dockables.xml</code> file. See <a class="xref" href="plugin-implement-dockables.html" title="The dockables.xml Window Catalog">the section called &#8220;The dockables.xml Window Catalog&#8221;</a>.</p></li><li><p>Checks for a class name with a name ending with
29                <code class="filename">Plugin.class</code>.</p><p>Such a class is known as a <em class="firstterm">plugin core
30                class</em> and must extend jEdit's abstract <a class="ulink" href="../api/org/gjt/sp/jedit/EditPlugin.html" target="_top">
31                <code class="classname">EditPlugin</code></a> class.</p><p>The initialization routine checks the plugin's properties
32                to see if it is subject to any dependencies. For example, a
33                plugin may require that the version of the Java runtime
34                environment or of jEdit itself be equal to or above some
35                threshold version. A plugin can also require the presence of
36                another plugin.</p><p>If any dependency is not satisfied, the loader marks the
37                plugin as &#8220;<span class="quote">broken</span>&#8221; and logs an error
38                message.</p></li></ul></div><p>After scanning the plugin JAR file and loading any resources, a
39        new instance of the plugin core class is created and added to the
40        collection maintained by the appropriate <a class="ulink" href="../api/org/gjt/sp/jedit/PluginJAR.html" target="_top">
41        <code class="classname">PluginJAR</code></a>. jEdit then calls the
42        <code class="function">start()</code> method of the plugin core class. The
43        <code class="function">start()</code> method can perform initialization of the
44        object's data members. Because this method is defined as an empty
45        &#8220;<span class="quote">no-op</span>&#8221; in the <a class="ulink" href="../api/org/gjt/sp/jedit/EditPlugin.html" target="_top">
46        <code class="classname">EditPlugin</code></a> abstract class, a plugin need
47        not provide an implementation if no unique initialization is
48        required.</p><div class="sidebar"><p class="title"><b>Updating 4.1 plugins</b></p><p>Note that while jEdit 4.1 plugins were only loaded on startup,
49            jEdit 4.2 plugins can be loaded at any time. As a result, the
50            <code class="function">start()</code> method needs to cope with being called
51            at any time, and <code class="function">stop()</code> needs to fully clean up
52            after the plugin.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="plugin-implement.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="plugin-implement.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="plugin-implement-quicknotepadplugin.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 18. Implementing a Simple Plugin </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> The QuickNotepadPlugin Class</td></tr></table></div></body></html>