Skip to content

plugin.xml for eclipse bundle

Andrey Hihlovskiy edited this page Apr 25, 2014 · 56 revisions

Let's create eclipse bundle and program "plugin.xml" for it.

  1. Create folder "tutorials/MyEclipseplugin", create file "build.gradle" in it, insert code:
buildscript {
  repositories {
    mavenLocal()
    jcenter()
  }

  dependencies {
    classpath 'org.akhikhl.wuff:wuff-plugin:0.0.1'
  }
}

apply plugin: 'java'
apply plugin: 'eclipse-bundle'

repositories {
  mavenLocal()
  jcenter()
}
  1. Invoke on command line: build gradle

  2. Open file "tutorials/MyEclipsePlugin/build/libs/MyEclipsePlugin-1.0.0.0.jar" - it does not contain "plugin.xml". Explanation: Wuff skips default "plugin.xml" generation, because it does not "know" what to write there.

  3. Create folder "tutorials/MyEclipsePlugin/src/main/java/myeclipseplugin", create file "MyView.java" in it, insert code:

package myeclipseplugin;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

public class MyView extends ViewPart {

  @Override
  public void createPartControl(final Composite parent) {
  }

  @Override
  public void setFocus() {
  }
}
  1. Invoke on command line: build gradle

  2. Open file "tutorials/MyEclipsePlugin/build/libs/MyEclipsePlugin-1.0.0.0.jar" - it contains "plugin.xml" with the following code:

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

We see that Wuff recognized our file as view and that it automatically inserted extension-point for it. In general, Wuff recognizes any files matching to patterns '**/*View.groovy', '**/*View.java', '**/View*.groovy', '**/View*.java' as view files.

Explanation of attributes:

  • id="MyEclipsePlugin.MyView": synthesized from project name and view class name
  • name="MyEclipsePlugin MyView": synthesized from project name and view class name
  • class="myeclipseplugin.MyView": points to qualified class name of the view file.
  1. What should we do to change the view name or view id? Very simple: give our own view definition. Create folder "tutorials/MyEclipsePlugin/src/main/resources", create file "plugin.xml" in it, insert code:
<plugin>
  <extension point="org.eclipse.ui.views">
    <view id="myviewid" name="Very nice view" class="myeclipseplugin.MyView"/>
  </extension>
</plugin>

Invoke build gradle again and look into JAR/plugin.xml: it contains our view definition, not the generated one.

  1. Create file "tutorials/MyEclipsePlugin/src/main/java/myeclipseplugin/MyPerspective.java", insert code:
package myeclipseplugin;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class MyPerspective implements IPerspectiveFactory {

  public void createInitialLayout(IPageLayout layout) {
  }
}
  1. Invoke on command line: build gradle, then open JAR/plugin.xml, it contains:
<plugin>
  <extension point="org.eclipse.ui.views">
    <view id="myviewid" name="Very nice view" class="myeclipseplugin.MyView"/>
  </extension>
  <extension point="org.eclipse.ui.perspectives">
    <perspective id="MyEclipsePlugin.MyPerspective" name="MyEclipsePlugin MyPerspective" class="myeclipseplugin.MyPerspective"/>
  </extension>
  <extension point="org.eclipse.ui.perspectiveExtensions">
    <perspectiveExtension targetID="MyEclipsePlugin.MyPerspective">
      <view id="myviewid" standalone="true" minimized="false" relative="org.eclipse.ui.editorss" relationship="left"/>
    </perspectiveExtension>
  </extension>
</plugin>

We see that Wuff recognized "MyPerspective.java" file as perspective and that it automatically inserted extension-points for it. In general, Wuff recognizes any files matching to patterns '**/*Perspective.groovy', '**/*Perspective.java', '**/Perspective*.groovy', '**/Perspective*.java' as perspective files.

Explanation of attributes in "org.eclipse.ui.perspectives":

  • id="MyEclipsePlugin.MyPerspective": synthesized from project name and perspective class name.
  • name="MyEclipsePlugin MyPerspective": synthesized from project name and perspective class name.
  • class="myeclipseplugin.MyPerspective": points to qualified class name of the perspective file.

As we see, extension-point "org.eclipse.ui.perspectiveExtensions" links perspective and view. This is special case: our plugin contains exactly one perspective and one view, so Wuff decides that they must be linked to each other.

  1. Let's customize our perspective as well. Edit the file "tutorials/MyEclipsePlugin/src/main/resources/plugin.xml", insert code:
<plugin>
  <extension point="org.eclipse.ui.views">
    <view id="myviewid" name="Very nice view" class="myeclipseplugin.MyView"/>
  </extension>
  <extension point="org.eclipse.ui.perspectives">
    <perspective id="myperspectiveid" name="Very nice perspective" class="myeclipseplugin.MyPerspective"/>
  </extension>
</plugin>
  1. Invoke on command line: build gradle, then open JAR/plugin.xml, it contains:
<plugin>
  <extension point="org.eclipse.ui.views">
    <view id="myviewid" name="Very nice view" class="myeclipseplugin.MyView"/>
  </extension>
  <extension point="org.eclipse.ui.perspectives">
    <perspective id="myperspectiveid" name="Very nice perspective" class="myeclipseplugin.MyPerspective"/>
  </extension>
  <extension point="org.eclipse.ui.perspectiveExtensions">
    <perspectiveExtension targetID="myperspectiveid">
      <view id="myviewid" standalone="true" minimized="false" relative="org.eclipse.ui.editorss" relationship="left"/>
    </perspectiveExtension>
  </extension>
</plugin>

As we see, now Wuff recognizes that "plugin.xml" already contains extension-point for perspective and does not generate the default one. We also see that Wuff still links perspective and view, because it is a special case: one perspective and one view.

The example code for this page: tutorialExamples/PluginXml-1 and tutorialExamples/PluginXml-2.

Next page: plugin.xml for eclipse-equinox-app.

Clone this wiki locally