Search code examples
eclipse-plugineclipse-rcptychop2

How to make Eclipse unpack bundles without Eclipse-BundleShape header


I have a large number of bundles from a legacy Eclipse RCP application that I want to be able to use in a Tycho build. There is no p2 repository with these bundles yet, so I created one. This already works pretty well, except that the bundles which need to be unpacked in the installation are still installed as JARs.

My first approach to create the p2 repository was to deploy the bundles to a Maven repository and then use pomDependency=consider to include them in an eclipse-feature and eclipse-repository. However, Tycho ignores the unpack attributes in the feature.xml so this doesn't work (cf. this documentation). The recommended solution for this problem is to add Eclipse-BundleShape: dir in the manifests of the included bundles. I could do that - but since I have hundreds of bundles, this would be quite a large effort.

Then, I was given the tip to use the "Features and Bundles Publisher Application": With this application, the feature and bundle artifacts are created in the p2 repository at the same time, so the information about the bundle shape can be copied over from the feature.xml into the respective bundles.

However this still doesn't work: Although I have set unpack="true" for one of the bundles being published, the bundle doesn't have the

<instruction key='zipped'>
  true
</instruction>

in the content.xml in the p2 repository and hence is not unpacked when installing it. Any ideas what I could be doing wrong? Any other ideas how to get this working?


This is my pom.xml for the p2 repository creation:

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycorp.xyz.expose</groupId>
    <artifactId>com.mycorp.xyz.expose.orbit</artifactId>
    <version>1.0.0</version>

    <dependencies>
        <dependency>
            <groupId>com.mycorp.xyz.expose</groupId>
            <artifactId>com.mycorp.somelib</artifactId>
            <version>6.40.0</version>
        </dependency>
        <!-- and many more... -->
    </dependencies>

    <build>
        <outputDirectory>${project.build.directory}/artifacts</outputDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.9</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/artifacts/plugins</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho.extras</groupId>
                <artifactId>tycho-p2-extras-plugin</artifactId>
                <version>0.21.0</version>
                <executions>
                    <execution>
                        <id>publish-features-and-bundles</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>publish-features-and-bundles</goal>
                        </goals>
                        <configuration>
                            <sourceLocation>${project.build.directory}/artifacts</sourceLocation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-repository-plugin</artifactId>
                <version>0.21.0</version>
                <executions>
                    <execution>
                        <id>assemble</id>
                        <phase>package</phase>
                        <goals>
                            <goal>verify-repository</goal>
                            <goal>archive-repository</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project> 

The only other file in the project is the following feature.xml in src/main/resources/features`:

<?xml version="1.0" encoding="UTF-8"?>
<feature
      id="com.mycorp.xyz.expose.orbit"
      label="..."
      version="1.0.0">

   <plugin
         id="com.mycorp.somelib"
         download-size="0"
         install-size="0"
         version="0.0.0"
         unpack="true"/>

   <!-- and many more... -->

</feature>

Solution

  • I've debugged the Features and Bundles Publisher Application that is running in the described setup, and it turns out that the publisher doesn't associate the unpack="true" from the feature.xml with the bundles because the versions don't match.

    So you'll need to provide the actual OSGi versions of the referenced bundles instead of 0.0.0 in the feature.xml. There is no automatic replacement like in a normal Tycho build. So the feature.xml would e.g. look like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <feature
          id="com.mycorp.xyz.expose.orbit"
          label="..."
          version="1.0.0">
    
       <plugin
             id="com.mycorp.somelib"
             download-size="0"
             install-size="0"
             version="6.40.0.140829051758"
             unpack="true"/>
    
    </feature>
    

    Then, the bundle is unpacked at installation time as expected.