Working with the Eclipse Tycho Plug-In
The Eclipse Tycho plug-in enables building Eclipse plug-ins with Maven. For more information, see Eclipse Tycho.
In Eclipse, when you create a plug-in project or a feature project, it is not created as a Maven project. Instead of using Maven, Eclipse PDE uses other metadata files such as manifest.mf
, build.properties
, plugin.xml
and feature.properties
. Tycho uses native metadata for Eclipse plug-ins and uses the pom.xml
file to configure and drive the build.Â
The support of Eclipse PDE makes it much easier to develop a plug-in for Eclipse. This not just a vanilla OSGi bundle, but a plug-in for Eclipse, so it should be possible to run and debug it using the Eclipse IDE. Therefore, you should create a plug-in project using the PDE. You can then convert it to a Maven project (only if you need to build automation with Maven).
Setting up the IDE
Download the Eclipse Luna SR2 Java EE version for your platform.
Install the latest Dev Studio Kernel to it (Help → install new software: point to p2 repo).
Creating an Eclipse Plugin
If you have previous experience in developing OSGi bundles with the maven-bundle-plugin and you plan to use Maven as the build tool for build automation of your plug-ins, we strongly suggest you have a good understanding of the following:
PomFirst vs ManifestFirst Development
Eclipse Tycho
Maven-bundle-plugin vs Tycho-maven-plugin
ManifestFirst Development is used since Eclipse PDE does not support PomFirst
Developing an Eclipse plug-in without PDE support
Include the Maven Tycho plug-in in your pom.xml
file.
<plugin> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <groupId>org.eclipse.tycho</groupId> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <artifactId>tycho-maven-plugin</artifactId> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <version>0.23.0</version> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <extensions>true</extensions> Â Â Â Â Â Â Â Â Â Â Â </plugin>
Include the target platform configuration as well, as shown below.
<plugin> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <groupId>org.eclipse.tycho</groupId> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <artifactId>target-platform-configuration</artifactId> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <version>0.23.0</version> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <configuration> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <resolver>p2</resolver> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <environments> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <os>linux</os> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <ws>gtk</ws> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <arch>x86</arch> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <os>linux</os> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <ws>gtk</ws> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <arch>x86_64</arch> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <os>win32</os> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <ws>win32</ws> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <arch>x86</arch> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <os>win32</os> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <ws>win32</ws> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <arch>x86_64</arch> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <os>macosx</os> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <ws>cocoa</ws> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <arch>x86</arch> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <os>macosx</os> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <ws>cocoa</ws> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <arch>x86_64</arch> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </environment> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </environments> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </configuration> Â Â Â Â Â Â Â Â Â Â Â </plugin>
Constraints when using Tycho
The artifactid in the pom.xml
must be equal to the bundle ID in the META-INF/manifest.mf
file.
The version in the pom.xml
must be equal to the bundle version in the META-INF/manifest.mf
file.
Resolving dependencies with Tycho
Instead of explicitly defining dependencies in your pom.xml
file, define all dependencies in the META-INF/manifest.mf
file (by defining the imported packages that are exported by other plug-ins/bundles).
P2 repositories that contain the dependent bundles (that export those imported packages), should be configured as repositories in the pom.xml
file (with the layout set as p2). For example, if you are using bundles provided by Developer Studio Kernel, you should add the Kernel p2 as a repository as shown below.
Â
<repository> Â Â Â Â Â Â Â <id>DevS-Deps-p2-Repository</id> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <url>http://builder1.us1.wso2.org/~developerstudio/developer-studio-kernel/4.0.0/p2/</url> Â Â Â Â Â Â Â <layout>p2</layout> </repository>
In addition, you need to add the Eclipse Luna p2 repo,
<repository> Â Â Â Â Â Â Â Â Â Â Â <id>Eclipse-p2-repo</id> Â Â Â Â Â Â Â Â Â Â Â <url>http://download.eclipse.org/releases/luna/</url> Â Â Â Â Â Â Â Â Â Â Â <layout>p2</layout> </repository>
In each p2 repo, you need to include a category.xml
file, which selects features for the p2 repository and specifies how to categorize them in the p2 installation dialog box. This file should be a single file per p2 repository. For example,
<?xml version="1.0" encoding="UTF-8"?> <site>   <feature id="feature.id" version="1.4.100.v2009"/>   <bundle id="bundle.id" version="1.3.1.v2013"/>   <iu id="unit.id"/>   <iu>     <query>       <expression type="match">         <![CDATA[           id == $0         ]]>       </expression>       <param>another.unit.id</param>     </query>   </iu>   <feature id="feature.in.category">      <category name="category.id"/>   </feature>   <category-def name="category.id" label="Category Label">      <description>Details on the category</description>   </category-def>   <!-- example for a dynamic category -->   <category-def name="javax" label="Bundles starting with javax."/>   <iu>      <category name="javax"/>      <query><expression type="match">id ~= /javax.*/</expression></query>   </iu> </site>
You also need to have the feature.xml
file in each and every feature you create to specify what plug-ins are included in this feature. For example, the API Manager feature's feature.xml
file looks like the following,
<?xml version="1.0" encoding="UTF-8"?> <feature      id="org.wso2.developerstudio.eclipse.apim.feature"      label="WSO2 API Manager Tooling Feature"      version="4.0.0.qualifier"      provider-name="%providerName">   <description url="http://wso2.com">      This feature will install plugins related WSO2 API Mangager Support.   </description>   <copyright url="%copyrightURL">      %copyright   </copyright>   <license url="%licenseURL">      %license   </license>   <requires>      <import feature="org.wso2.developerstudio.eclipse.esb.feature" version="4.0.0" match="greaterOrEqual"/>   </requires>   <plugin         id="org.wso2.developerstudio.eclipse.registry.apim.perspective"         download-size="0"         install-size="0"         version="0.0.0"         unpack="false"/> </feature>
The copyright and the license are included for all features from a common location to avoid duplication, using a feature common properties file. You can refer the API-M feature folder structure from the API-M tooling git repository. For more details on feature.xml
content, see Packaging and delivering Eclipse based products.
Using new third party dependencies
If you need to use a third party library, always try to get it from an existing p2 repository. In most cases, Eclipse P2 repository already provides common libraries such as Apache commons, gson, etc. However, if you cannot find such a p2 repo, we maintain our own dependencies p2 repo for those libraries here. You need to get your dependency converted into an OSGi bundle and get it published there. Contact the Developer Studio Kernel team who own this repository.
Tycko packaging types
According to the type of resource you want Tycho to build for you, you need to mention the packaging type. Tycho supports Eclipse plug-ins, Eclipse-test-plug-ins, features and p2 repos. By configuring the package type correctly in the pom.xml
file, you can specify Tycho to build your project accordingly.
For example, the minimum pom.xml
file for an Eclipse feature using Tycho should be as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" Â Â Â xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Â Â Â xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> Â <modelVersion>4.0.0</modelVersion> Â <groupId>some-group-id</groupId> Â <artifactId>feature id</artifactId> Â <version>feature version</version> Â <packaging>eclipse-feature</packaging> </project>
For more information on how the minimum pom.xml
file should look like for all project types, see Tycho/Packaging Types.Â