Removing root files in a RCP built with Tycho

I have recently introduced the use of Tycho to build a RCP application in my company.
Formerly, I was using PDE to export it manually. In the meantime, I also changed the underlying platform, passing from Galileo to Helios.

One thing to know is that the product is based on features, and that one of them includes the Eclipse RCP feature. I do not know what caused this change, but now, root files that are contributed by the RCP feature (like notice.html, epl-v10.html, .eclipseproduct and the readme directory) are also present in my resulting application. They were not in the previous builds.

This change is a little bit problematic for me, even if it is not a crucial problem.
However, unlike what notice.html says, it is not the Eclipse Foundation that makes the product available, but my company. And if all the plug-ins we install are licensed under the EPL, we have had an all-in-one file with the user agreement and a link to the license (which is now EPL but who knows the future… we could use dual-licensing then…).

So, I had to find a way to keep the same file structure than before, that is to say, remove these new root files.
I first tried by configuring the Tycho plug-ins, but that was not supported. I tried to remove the inclusion of the RCP feature. My target platform declares an install unit for the RCP feature group. But that’s not enough, Tycho complains in the build then. I have to keep the feature included. I tried to look at the PDE root file properties, but only file addition is supported. I also went for ANT tasks and scripting to run during the build process. But it was a quite heavy solution because it means unzipping the products, removing the files and zipping again. Eventually, I found a very elegant solution to this issue.

In fact, the product is located in a dedicated Maven module that uses the eclipse-repository packaging.
This packaging was added in Tycho as a replacement for update-site. One of its properties is to be based on p2 to build the Eclipse repository. So, all I had to do to remove these files was to add p2 instructions that would be forwarded by Tycho.

The p2.inf file must be placed in the Maven module of the product. It should even be named <product-id>.p2.inf. However, when there is only one built product, I noticed that the ID did not have to be the right one (I changed the product ID but did not rename the p2.inf and it worked anyway). I guess the ID becomes important only when there are several built products.

So, here is the content of my p2.inf file:

##
# Remove root files
# Define repositories
##
instructions.configure=\
    org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/readme);\
    org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/notice.html);\
    org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/epl-v10.html);\
    org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/.eclipseproduct);\
    org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/plugin_customization.ini,target:\
    ${installFolder}/configuration/plugin_customization.ini);\
    org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/plugin_customization.ini);\
    addRepository(type:0,name:Eclipse Helios,location:http${#58}//download.eclipse.org/releases/helios/);\
    addRepository(type:1,name:Eclipse Helios,location:http${#58}//download.eclipse.org/releases/helios/);\
    addRepository(type:0,name:FindBugs,location:http${#58}//findbugs.cs.umd.edu/eclipse/);\
    addRepository(type:1,name:FindBugs,location:http${#58}//findbugs.cs.umd.edu/eclipse/);\
    addRepository(type:0,name:PMD,location:http${#58}//pmd.sf.net/eclipse/);\
    addRepository(type:1,name:PMD,location:http${#58}//pmd.sf.net/eclipse/);\
    addRepository(type:0,name:Subclipse,location:http${#58}//subclipse.tigris.org/update_1.6.x);\
    addRepository(type:1,name:Subclipse,location:http${#58}//subclipse.tigris.org/update_1.6.x);\
    addRepository(type:0,name:CheckStyle,location:http${#58}//eclipse-cs.sf.net/update/);\
    addRepository(type:1,name:CheckStyle,location:http${#58}//eclipse-cs.sf.net/update/);\
    addRepository(type:0,name:JIRA,location:http${#58}//update.atlassian.com/atlassian-eclipse-plugin/e3.5/);\
    addRepository(type:1,name:JIRA,location:http${#58}//update.atlassian.com/atlassian-eclipse-plugin/e3.5/);

What is important here is the use of native touch points.
${installFolder} represents the root of the product directory. This directory is the one that will be archived by Tycho. Thus, the files are removed before the ZIP operation and this is much more efficient than updating the ZIP files after. This file is also used to register the URL of predefined Eclipse repositories.

You can also use this solution to add files at the root.
However, it is better to use root features for this use case. Tycho supports most of them or will soon (root works, but root.folder does not work yet).


About this entry