IntelliJ Plugin 开发之 plugin.xml 配置文件详解(四)

前面几篇文章,我们一起了解了 Plugin 的项目创建和运行效果。接下来我们开始静下心来深入了解插件的内容了。

从 plugin .xml 核心配置文件开始。

更消息的内容,请参考官方文档:

http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_configuration_file.html

plugin.xml 文件是核心配置文件,你可以理解成 Java web 开发中的 web.xml 文件,Android 开发中的 AndroidManifest.xml 文件。所有的组件的注册都需要在此文件中进行配置,否则该组件不会生效。

plugin.xml 文件所在位置为 /ProjectRoot/resources/META-INF/plugin.xml。如图:

配置文件内容 + 注释描述:

<!-- url="" specifies the URL of the plugin homepage (displayed in the Welcome Screen and in "Plugins" settings dialog) -->
<idea-plugin url="http://www.jetbrains.com/idea">

  <!-- Plugin name -->
  <name>插件的名称,显示在 IDEA 已安装插件列表中(抱歉,之前的文章截图说明中可能有误)</name>

  <!-- Unique identifier of the plugin.
       Cannot be changed between the plugin versions.
       If not specified, assumed to be equal to <name>. -->
  <id>插件 ID,用于在插件市场中唯一确定身份的标示,在不同版本中,必须保持一致。
建议设置值为:包名 + 插件名称</id>

  <!-- Description of the plugin. -->
  <description>插件功能说明,显示在插件市场当前插件的副标题位置。</description>

  <!-- Description of changes in the latest version of the plugin.
       Displayed in the "Plugins" settings dialog and in the
       plugin repository Web interface. -->
  <change-notes>插件版本更新内容说明</change-notes>

  <!-- Plugin version -->
  <version>插件版本号</version>

  <!-- The vendor of the plugin.
       The optional "url" attribute specifies the URL of the vendor homepage.
       The optional "email" attribute specifies the e-mail address of the vendor.-->
  <vendor url="http://www.jetbrains.com" email="[email protected]" />

  <!-- The unique identifiers of the plugins on which this plugin depends. -->
  <depends>当前插件依赖的其他插件的id,本人没用过</depends>

  <!-- Optional dependency on another plugin.
       If the plugin with the "MySecondPlugin" ID is installed,
       the contents of mysecondplugin.xml (the format of this file
       conforms to the format of plugin.xml) will be loaded. -->
  <depends optional="true" config-file="mysecondplugin.xml">MySecondPlugin</depends>

  <!-- Allows a plugin to integrate its help system (in JavaHelp format)
       with the IDEA help system. The "file" attribute specifies the name
       of the JAR file in the "help" subdirectory of the plugin directory.
       The "path" attribute specifies the name of the helpset file within
       the JAR file.-->
  <helpset file="myhelp.jar" path="/Help.hs" />

  <!-- Minimum and maximum build of IDEA compatible with the plugin -->
  当前插件的起止 IDE 版本支持
  <idea-version since-build="3000" until-build="3999"/>

  <!-- Resource bundle from which the text of plugin descriptions,
       action names and etc. will be loaded -->
  国际化资源文件
  <resource-bundle>messages.MyPluginBundle</resource-bundle>

  <!-- Plugin's application components -->
  ApplicationComponent 注册,已过时。
  <application-components>
    <component>
      <!-- Component's interface class -->
      <interface-class>com.foo.Component1Interface</interface-class>

      <!-- Component's implementation class -->
      <implementation-class>com.foo.impl.Component1Impl</implementation-class>
    </component>
  </application-components>

  <!-- Plugin's project components -->
  ProjectComponent 组件注册,已过时。
  <project-components>
    <component>
      <!-- Interface and implementation classes are the same -->
      <interface-class>com.foo.Component2</interface-class>

      <!-- If the "workspace" option is set "true", the component
           saves its state to the .iws file instead of the .ipr file.
           Note that the <option> element is used only if the component
           implements the JDOMExternalizable interface. Otherwise, the
           use of the <option> element takes no effect.  -->
      <option name="workspace" value="true" />

      <!-- If the "loadForDefaultProject" tag is present, the project component is instantiated also for the default project. -->
      <loadForDefaultProject>
    </component>
  </project-components>

  <!-- Plugin's module components -->
  ModuleComponent 组件注册,已过时。
  <module-components>
    <component>
      <interface-class>com.foo.Component3</interface-class>
    </component>
  </module-components>

  <!-- Actions -->
  Action 组件注册
  <actions>
    <action id="VssIntegration.GarbageCollection" class="com.foo.impl.CollectGarbage" text="Collect _Garbage" description="Run garbage collector">
      <keyboard-shortcut first-keystroke="control alt G" second-keystroke="C" keymap="$default"/>
    </action>
  </actions>

  <!-- Extension points defined by the plugin.
       Extension points are registered by a plugin so that other
       plugins can provide this plugin with certain data. The
       "beanClass" attribute specifies the class the implementations
       of which can be used for the extension point. -->
  扩展点,即定义当前插件某功能可扩展的点,便于被其他插件依赖,并扩展当前插件不完善的功能
  <extensionPoints>
    <extensionPoint name="testExtensionPoint" beanClass="com.foo.impl.MyExtensionBean"/>
  </extensionPoints>

  <!-- Extensions which the plugin adds to extension points
       defined by the IDEA core or by other plugins.
       The "defaultExtensionNs " attribute must be set to the
       ID of the plugin defining the extension point, or to 
       "com.intellij" if the extension point is defined by the
       IDEA core. The name of the tag within the <extensions>
       tag matches the name of the extension point, and the
       "implementation" class specifies the name of the class
       added to the extension point. -->
  扩展,定义具体某类型扩展的实现,扩展其他插件或者 Plugin Platform 默认提供的扩展功能。
  <extensions xmlns="VssIntegration">
    <testExtensionPoint implementation="com.foo.impl.MyExtensionImpl"/>
  </extensions>
</idea-plugin>

在上述代码中都有注释,大概搂了一遍各项配置的含义。下面,针对某几项核心、常用的配置进行更详细的说明:

<id>插件 ID,唯一表示。用户在插件市场众多插件当中唯一确定你的插件。一旦插件 ID 定义好并启用后,后续不可再更改,否则会成为新的插件。</id>

<name>插件名称,显示的位置如下图:</name>

<description>插件功能说明,如上图中 插件名称下方的描述</description>

<change-notes>插件更新日志描述,建议保留所有版本的更新说明。书写时,建议写上每个版本的版本号,以及内容。内容支持 html 标签,比喻ul,li</change-notes>

<version>插件版本号,如:1.0</version>

<vendor url="http://www.jetbrains.com" email="[email protected]" />

vendor 标签为作者主站网址和邮箱配置。便于用户有疑问时联系你。

<actions></actions>

actions 标签之间可以配置多个 action 标签。

<action 
        id="包名 + 插件名称 + 类名"
        class="com.duke.demo.HelloAction"
        text="HelloActionMenu"
        description="当前插件菜单功能说明" 
        icon="插件图标" 
        keymap="未知" 
        popup="" 
        project-type=""
        use-shortcut-of=""/>
最核心的标签。每一个 action 标签代表一个菜单项或工具栏中的一个按钮。在 action 标签中间,还可以配置 keyboard-shortcut 标签,用来设置快捷键。

<keyboard-shortcut first-keystroke="control alt G" second-keystroke="C" keymap="$default"/>

action 的快捷键标签。

first-keystroke:首选快捷键

second-keystroke:备选快捷键

keymap:默认快捷键

至此,常用的核心配置项介绍完毕。

猜你喜欢

转载自blog.csdn.net/fesdgasdgasdg/article/details/85948666