stempler / bnd-platform

Build OSGi bundles and Eclipse Update Sites from existing JARs, e.g. from Maven repositories (Plugin for Gradle)
Apache License 2.0
79 stars 30 forks source link

Generated updatesite not working due to missing filters #67

Closed stefan-ka closed 4 years ago

stefan-ka commented 4 years ago

Hi there

I'm having a problem in a project where I want to use your plugin and I was wondering if you have any ideas how to fix this.

A few of my Gradle dependencies are already bundles containing an MANIFEST.MF file. And they conain a Eclipse-PlatformFilter:

Eclipse-PlatformFilter: (& (osgi.ws=gtk)(osgi.os=linux)(osgi.arch=x86_64
 ))

These are the dependencies (available through maven central):

com.eclipsesource.j2v8:j2v8_macosx_x86_64:4.6.0
com.eclipsesource.j2v8:j2v8_linux_x86_64:4.6.0
com.eclipsesource.j2v8:j2v8_win32_x86_64:4.6.0
com.eclipsesource.j2v8:j2v8_win32_x86:4.6.0

Now, the problem is that the filter is respected in the corresponding units in the updatesite, but not in the feature bundle (content.xml). An example:

The unit for one of the libs contains the correct filter in the update site:

<unit id='com.eclipsesource.j2v8.linux_x86_64' version='4.6.0.20191106024042' singleton='false'>
      <update id='com.eclipsesource.j2v8.linux_x86_64' range='[0.0.0,4.6.0.20191106024042)' severity='0'/>
      <properties size='2'>
        <property name='org.eclipse.equinox.p2.name' value='j2v8_linux_x86_64'/>
        <property name='org.eclipse.equinox.p2.description' value='J2V8 is a set of Java bindings for V8'/>
      </properties>
      <provides size='8'>
        <provided namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.linux_x86_64' version='4.6.0.20191106024042'/>
        <provided namespace='osgi.bundle' name='com.eclipsesource.j2v8.linux_x86_64' version='4.6.0.20191106024042'/>
        <provided namespace='java.package' name='com.eclipsesource.v8' version='4.6.0'/>
        <provided namespace='java.package' name='com.eclipsesource.v8.debug' version='4.6.0'/>
        <provided namespace='java.package' name='com.eclipsesource.v8.debug.mirror' version='4.6.0'/>
        <provided namespace='java.package' name='com.eclipsesource.v8.utils' version='4.6.0'/>
        <provided namespace='java.package' name='com.eclipsesource.v8.utils.typedarrays' version='4.6.0'/>
        <provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/>
      </provides>
      <requires size='4'>
        <required namespace='java.package' name='com.eclipsesource.v8' range='[4.6.0,5.0.0)'/>
        <required namespace='java.package' name='com.eclipsesource.v8.debug.mirror' range='[4.6.0,5.0.0)'/>
        <required namespace='java.package' name='com.eclipsesource.v8.utils' range='[4.6.0,5.0.0)'/>
        <required namespace='java.package' name='com.eclipsesource.v8.utils.typedarrays' range='[4.6.0,5.0.0)'/>
      </requires>
      <filter>
        (&amp;(osgi.arch=x86_64)(osgi.os=linux)(osgi.ws=gtk))
      </filter>
      <artifacts size='1'>
        <artifact classifier='osgi.bundle' id='com.eclipsesource.j2v8.linux_x86_64' version='4.6.0.20191106024042'/>
      </artifacts>
      <touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/>
      <touchpointData size='1'>
        <instructions size='1'>
          <instruction key='manifest'>
            Bundle-SymbolicName: com.eclipsesource.j2v8.linux_x86_64&#xA;Bundle-Version: 4.6.0.20191106024042
          </instruction>
        </instructions>
      </touchpointData>
    </unit>

The feature group unit on the other hand lists all the libs as required without the filter:

<unit id='org.contextmapper.contextmap.generator.feature.feature.group' version='0.1.0.20191106024042' singleton='false'>
      <update id='org.contextmapper.contextmap.generator.feature.feature.group' range='[0.0.0,0.1.0.20191106024042)' severity='0'/>
      <properties size='3'>
        <property name='org.eclipse.equinox.p2.name' value='ContextMappers Context Map Generator'/>
        <property name='org.eclipse.equinox.p2.provider' value='Context Mapper'/>
        <property name='org.eclipse.equinox.p2.type.group' value='true'/>
      </properties>
      <provides size='1'>
        <provided namespace='org.eclipse.equinox.p2.iu' name='org.contextmapper.contextmap.generator.feature.feature.group' version='0.1.0.20191106024042'/>
      </provides>
      <requires size='34'>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.linux_x86_64' range='[4.6.0.20191106024042,4.6.0.20191106024042]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.linux_x86_64.source' range='[4.6.0.20191106024042,4.6.0.20191106024042]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.macosx_x86_64' range='[4.6.0,4.6.0]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.macosx_x86_64.source' range='[4.6.0,4.6.0]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.win32_x86' range='[4.6.0,4.6.0]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.win32_x86.source' range='[4.6.0,4.6.0]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.win32_x86_64' range='[4.6.0,4.6.0]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.win32_x86_64.source' range='[4.6.0,4.6.0]'/>
    <!-- removed others to save space here ... -->
        <required namespace='org.eclipse.equinox.p2.iu' name='org.contextmapper.contextmap.generator.feature.feature.jar' range='[0.1.0.20191106024042,0.1.0.20191106024042]'>
          <filter>
            (org.eclipse.update.install.features=true)
          </filter>
        </required>
      </requires>
      <touchpoint id='null' version='0.0.0'/>
    </unit>

With the generated updatesite it is not possible to install the feature, since the feature requires all of the bundles (no filter defined), but the Eclipse installer cannot find the bundles due to the generated filters in the individual bundles:

Problems occurred while resolving the target contents
    Cannot complete the install because one or more required items could not be found.
        Missing requirement: ContextMappers Context Map Generator 0.1.0.20191105183722 (org.contextmapper.contextmap.generator.feature.feature.group 0.1.0.20191105183722) requires 'org.eclipse.equinox.p2.iu; com.eclipsesource.j2v8.macosx_x86_64 [4.6.0,4.6.0]' but it could not be found
        Software being installed: ContextMappers Context Map Generator 0.1.0.20191105183722 (org.contextmapper.contextmap.generator.feature.feature.group 0.1.0.20191105183722)

From my manual tests, I would say that the problem would be solved if the filters would be generated into the feature group unit as well:

        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.linux_x86_64' range='[4.6.0.20191106024042,4.6.0.20191106024042]'>
          <filter>
            (&amp;(osgi.arch=x86_64)(osgi.os=linux)(osgi.ws=gtk))
          </filter>
        </required>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.linux_x86_64.source' range='[4.6.0.20191106024042,4.6.0.20191106024042]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.macosx_x86_64' range='[4.6.0,4.6.0]'>
          <filter>
            (&amp;(osgi.arch=x86_64)(osgi.os=macosx)(osgi.ws=cocoa))
          </filter>
        </required>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.macosx_x86_64.source' range='[4.6.0,4.6.0]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.win32_x86' range='[4.6.0,4.6.0]'>
          <filter>
            (&amp;(osgi.arch=x86)(osgi.os=win32)(osgi.ws=win32))
          </filter>
        </required>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.win32_x86.source' range='[4.6.0,4.6.0]'/>
        <required namespace='org.eclipse.equinox.p2.iu' name='com.eclipsesource.j2v8.win32_x86_64' range='[4.6.0,4.6.0]'>
          <filter>
            (&amp;(osgi.arch=x86_64)(osgi.os=win32)(osgi.ws=win32))
          </filter>
        </required>

However, I don't know how to produce this output with your plugin.

Any ideas how to fix this? Is there maybe a way to specify the filters if I configure the feature in my Gradle build manually? I'm grateful for any inputs how to work around this issue...

stefan-ka commented 4 years ago

Is there any way to define the "os", "ws", and "arch" attribute on the "plugin" tags of the generated feature.xml?? This would fix the generated updatesite...

stefan-ka commented 4 years ago

Found a solution. For some reason you have to create an empty bnd configuration, then it works.

Example:

bundle "com.eclipsesource.j2v8:j2v8_macosx_x86_64:4.6.0", {
    bnd {}
}