5

For my Eclipse plugin project, I have defined the following target platform:

<location includeAllPlatforms="true" includeMode="slicer" includeSource="true" type="InstallableUnit">
  <unit id="org.eclipse.equinox.executable.feature.group" version="3.5.0.v20110530-7P7NFUFFLWUl76mart"/>
  <unit id="org.eclipse.rcp.sdk.id" version="3.7.1.M20110909-1335"/>
  <unit id="org.eclipse.jdt.feature.group" version="3.7.1.r371_v20110810-0800-7z8gFcoFMLfTabvKsR5Qm9rBGEBK"/>
  <unit id="epp.package.java" version="1.4.1.20110909-1818"/>
...

My plugin has JUnit plugin tests (in the same plugin). If I try to run them with a JUnit launch config (org.eclipse.platform.ide), I get the following console messages about junit, and an exception:

!ENTRY org.eclipse.osgi 2 0 2011-12-16 13:00:35.206
!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:
!SUBENTRY 1 org.eclipse.osgi 2 0 2011-12-16 13:00:35.206
!MESSAGE Bundle reference:file:/Users/stolz/ws-bucky/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.jdt.junit4.runtime_1.1.200.v20110505-0800.jar was not resolved.
!SUBENTRY 2 org.eclipse.jdt.junit4.runtime 2 0 2011-12-16 13:00:35.206
!MESSAGE Missing required bundle org.junit_4.7.0.
!SUBENTRY 1 org.eclipse.osgi 2 0 2011-12-16 13:00:35.207
!MESSAGE Bundle reference:file:/Users/stolz/ws-bucky/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.junit4_4.8.1.v20100525/ was not resolved.
!SUBENTRY 2 org.junit4 2 0 2011-12-16 13:00:35.207
!MESSAGE Missing required bundle org.junit_4.8.1.

and

!SUBENTRY 1 org.eclipse.osgi 2 0 2011-12-16 13:00:35.234
!MESSAGE Bundle org.junit4_4.8.1.v20100525 [219] was not resolved.
!SUBENTRY 2 org.junit4 2 0 2011-12-16 13:00:35.235
!MESSAGE Missing required bundle org.junit_4.8.1.

!ENTRY org.eclipse.core.net 1 0 2011-12-16 13:00:39.889
!MESSAGE System property http.nonProxyHosts has been set to local|*.local|169.254/16|*.169.254/16 by an external source. This value will be overwritten using the values from the preferences
Exception in thread "Plug-in Tests Runner" java.lang.IllegalArgumentException: Bundle "org.eclipse.jdt.junit4.runtime" not found. Possible causes include missing dependencies, too restrictive version ranges, or a non-matching required execution environment.
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.getClassLoader(RemotePluginTestRunner.java:77)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.readPluginArgs(RemotePluginTestRunner.java:93)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.init(RemotePluginTestRunner.java:83)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:61)
    at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness$1.run(PlatformUITestHarness.java:47)
    at java.lang.Thread.run(Thread.java:680)

With the default JDT installation, the unit test runs fine, it's just that I want to define a proper target platform for a Hudson-build. Needless to say, I tried adding dependencies on the two offending platforms in various places, to no avail.

Update: Whoops, I confused this with another set of tests; these here are not headless but workbench-tests.

Another oddity is that sometimes I won't see this error when running the test for the first time after switching to the default Eclipse platform and back to mine. Odd.

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
Volker Stolz
  • 7,274
  • 1
  • 32
  • 50
  • 2
    What are you using for "them with a headless JUnit launch config"? Do you mean launching them headless from the command line or using "No application - HEADLESS mode"? – Paul Webster Dec 16 '11 at 13:19
  • @PaulWebster Got me there, the tests are not headless at all, but workbench tests. I've updated the question. – Volker Stolz Dec 16 '11 at 15:52
  • 2
    your target platform needs at least org.eclipse.rcp.feature.group, org.eclipse.platform.feature.group, and org.eclipse.jdt.feature.group, right? – Paul Webster Dec 16 '11 at 16:33
  • @PaulWebster I've added the rcp and platform feature group, but behaviour (and the total number of plugins) doesn't change. Also note the oddity I mentioned in the update. – Volker Stolz Dec 18 '11 at 03:15

2 Answers2

2

I don't like to blow my own horn here, but the only workaround I could come up with now (after another few hours of experimentation) is setting the launch-config to "all workspace and enabled target plugins" instead of either using a feature or plugin-based launch. I think this indicates that there is something fishy in the plugin-resolution process which Eclipse gets right by default, but not when you start restricting the available features/plugins.

With that change, it seems to reliably work both within Eclipse and Buckminster (leaving the target platform unchanged(!) from the problematic setup in the original question). So I conclude that the target platform is in principle correct, it must have been something about the launch.

Thanks for everyone's (@andrew-eisenberg, @PaulWebster at least) input!

Volker Stolz
  • 7,274
  • 1
  • 32
  • 50
0

How can you be compiling and launching your JUnit tests if JUnit is not part of the target platform? The first thing that you need to do is add org.junit and org.junit4 bundles to the target platform. Since it looks like you are doing a feature-based target platform, you may need to create a custom feature for these bundles.

Second, since it is unlikely that you want to ship your tests with your plugin, you probably want to follow the standard Eclipse practice of separating your tests into a *..tests plugin.

Typically, you simply do not include the tests in the final RCP app or update site.

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • JUnit comes as part of the JDT (which I depend on). So in principle it is there. But I am totally confused by the version numbers: Eclipse brings 4.8.2 with it, and the JDT seems to depend on 4.7.0. And I STILL haven't found out where the dependency on 4.8.1 comes from. – Volker Stolz Jan 06 '12 at 06:42
  • Another thing: since my project also defines a feature (which is used in the launch-config), I've tried adding the required plugins there, but to no avail, either. For a new feature just shipping JUnit, I'd expect to see the same. It's also worrying that it's not reliable reproducable, sometimes (after resetting the target platform/workspace) it will work. – Volker Stolz Jan 09 '12 at 06:55