Skip to content

plugin.xml expression injection

Andrey Hihlovskiy edited this page Jul 2, 2014 · 10 revisions

We already programmed "plugin.xml" for IDE app. Now we can how to do "plugin.xml" expression injection.

Let's take an example Eclipse plugin we created in "plugin.xml" for Eclipse bundle.

Edit the file "tutorials/MyEclipsePlugin/src/main/resources/plugin.xml", change content to:

<plugin>
  <extension point="org.eclipse.ui.views">
    <view id="myviewid" name="${project.ext.myViewName}" class="myeclipseplugin.MyView"/>
  </extension>
</plugin>

Edit the file "tutorials/MyEclipsePlugin/build.gradle", insert code:

wuff {
  filterPluginXml = true
}

ext {
  myViewName = 'test123'
}

Invoke on command line: gradle build.

Open file "tutorials/MyBuildPlugin/build/libs/MyBuildPlugin-1.0.0.0.jar", open "plugin.xml", it should contain:

<plugin>
  <extension point="org.eclipse.ui.views">
    <view id="myviewid" name="test123" class="myeclipseplugin.MyView"/>
  </extension>
</plugin>

Note that expressions in "plugin.xml" are not expanded by default. We must set wuff.filterPluginXml=true to enable this feature.

Note that sometimes dollar sign, $, is used for Eclipse-specific expressions in "plugin.xml". Typical example is localized location of intro pages:

<extension point="org.eclipse.ui.intro.config">
  <config id="MyRcpApp.introConfigId" introId="MyRcpApp.intro" content="$nl$/intro/introContent.xml">
    <presentation home-page-id="homePageId" standby-page-id="homePageId">
      <implementation kind="html"/>
    </presentation>
  </config>
</extension>

Expression injection would produce errors with such Eclipse-specific expressions, because dollar sign has special meaning to it (see more information at Groovy templates documentation). To avoid the errors, we need to escape dollar sign:

<extension point="org.eclipse.ui.intro.config">
  <config id="MyRcpApp.introConfigId" introId="MyRcpApp.intro" content="\$nl\$/intro/introContent.xml">
    <presentation home-page-id="homePageId" standby-page-id="homePageId">
      <implementation kind="html"/>
    </presentation>
  </config>
</extension>

The example code for this page: examples/PluginXml-4.

We are done with programming "plugin.xml". Now we can go back to wiki home page and learn something else.

Clone this wiki locally