Sharing my experience on retrofitting a target platform based on Juno 3.8.2 to run JUnit plugin tests with Bundle-RequiredExecutionEnvironment
("BREE") JavaSE-1.8
:
Failed approach 1: Fragment
Creating a fragment to org.eclipse.osgi
with a Provide-Capability
header in the manifest:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: FrwJava8Support
Bundle-SymbolicName: frwJava8Support
Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.eclipse.osgi;bundle-version="3.8.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Provide-Capability: osgi.ee;osgi.ee="JavaSE";version:List="1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8"
This capability was never picked up.
Failed approach 2: Startup parameter
Using -Dorg.osgi.framework.system.capabilities
as outlined in Christian's answer.
First of all, the argument must be quoted correctly:
-Dorg.osgi.framework.system.capabilities="osgi.ee; osgi.ee=\"JavaSE\";version:List=\"1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8\""
This approach might have worked for any other use case other than pde.junit
. I still got this (slightly different) exception:
!MESSAGE Bundle com.XXX.tst.frw.common_1.0.0.qualifier [92] was not resolved.
!SUBENTRY 2 com.XXX.tst.frw.common 2 0 2015-04-18 13:43:55.336
!MESSAGE Missing Constraint: Bundle-RequiredExecutionEnvironment: JavaSE-1.8
!SUBENTRY 1 org.eclipse.osgi 2 0 2015-04-18 13:43:55.336
!MESSAGE Bundle com.XXX.tst.frw.common.test_1.0.0.qualifier [101] was not resolved.
!SUBENTRY 2 com.XXX.tst.frw.common.test 2 0 2015-04-18 13:43:55.336
!MESSAGE Missing host com.XXX.tst.frw.common_1.0.0.
!ENTRY org.eclipse.osgi 4 0 2015-04-18 13:43:55.336
!MESSAGE Application error
!STACK 1
java.lang.IllegalArgumentException: Bundle "com.XXX.tst.frw.common" 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)
Working approach 3: Patch Equinox
Patch the org.eclipse.osgi
bundle to include Luna's JavaSE-1.8.profile
.
Copy file <LUNA>\plugins\org.eclipse.osgi_3.10.1.v20140909-1633.jar\JavaSE-1.8.profile
to your target platform bundle pool's org.eclipse.osgi
bundle.
(e.g. <myworkspace>\.metadata\.plugins\org.eclipse.pde.core\.bundle_pool\plugins\org.eclipse.osgi_3.8.2.v20130124-134944.jar\JavaSE-1.8.profile
)
Reference profile in profile.list
(actually, this seems to be optional):
add JavaSE-1.8.profile,\
to .metadata\.plugins\org.eclipse.pde.core\.bundle_pool\plugins\org.eclipse.osgi_3.8.2.v20130124-134944.jar\profile.list
However, this solution requires hosting your own P2 repository containing the org.eclipse.osgi
bundle or applying a patch to every workspace's bundle pool.
Discussion
Still, there exists the possibility to keep BREE at "JavaSE-1.7" that is compatible with the existing org.eclipse.osgi
3.8.2 version.
I am currently aware of two drawbacks:
- Exporting plugins directly from Eclipse via PDE fails if Java 8 syntax is used in the code (e.g. lambda expressions).
- Log contains compiler errors and compiled result is actually of different size compared to a bundle compiled with JavaSE-1.8 BREE.
Presumably, PDE evaluates BREE and sets compiler source level accordingly which then results in "1.7" for Java 8 sources. It is possible that other PDE features (feature export, product export) might exhibit same problem.
Using Eclipse Tycho, it is possible to manually override the javac source level instead of evaluating a bundle's BREE (to select a JDK to compile with). However, also Tycho still matches the given source level vs. BREE and refuses to compile Java 8 code (tested with Tycho 0.22).
Also, approach 2 will most likely not work with PDE's bundle export, at least I am not aware of any possibility to pass VM arguments.
Update 29.05.2015
We went with approach 3 and successfully patched our target platform to use Java 8 together with Eclipse 3.8.
As we already maintain our own P2 repository with all 3.8-based Eclipse plugins, we needed to:
- create an updated copy of
org.eclipse.osgi
(needed to strip signing information from bundle as well)
- create a feature patch that patches
org.eclipse.rcp
feature with updated org.eclipse.osgi
bundle
- publish new 3.8-based P2 repository to be consumed by our workstations and build server.
Summary
If you maintain your own P2 repository to serve a custom target platform instead of using any Eclipse.org-based update site, it is possible to make Eclipse 3.8 work with Java 8.
References: Eclipse Bug to support osgi.ee