Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Setting IEclipsePreferences in headless build(@Preference annotation does not work when running plug-in tests with Tycho)
Setting IEclipsePreferences in headless build [message #1207881] Sun, 24 November 2013 20:41 Go to next message
Thorsten Beck is currently offline Thorsten BeckFriend
Messages: 4
Registered: November 2013
Junior Member
In my pure-e4 application I have a class that accesses preference values via the @Preference annotation:
@Inject @Preference(nodePath = "my.application.bundle.id", value = "FOO") String fooName;

This works fine. I also have a JUnit plug-in test for this class where I want to set the Preference to a certain value:
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("my.application.bundle.id");
prefs.put("FOO", "bar");

This also works fine when running the test in Eclipse. However, when running a headless build (Tycho) I get the following error for the test:
Unable to process "ClassUnderTest.fooName": no actual value was found for the argument "String[@org.eclipse.e4.core.di.extensions.Preference(nodePath=my.application.bundle.id, value=FOO)]".

Normal injections via @Inject work fine in Tycho plug-in tests. So there seems to be a problem with the @Preference annotation. I tried several things, e.g. adding prefs to an IEclipseContext in my test and injecting it into ClassUnderTest:
IEclipseContext context = EclipseContextFactory.create();
context.set(IEclipsePreferences.class, prefs);
ContextInjectionFactory.make(ClassUnderTest.class, context);

but that didn't change anything. I suspect the problem lies in the fact that "Preference values are not stored directly in the IEclipseContext but contributed by an ExtendedObjectSupplier" [vogella.com]

How can I create a Preference Value in my JUnit plug-in test so it can be injected and accessed by ClassUnderTest when running the test with Tycho?
Re: Setting IEclipsePreferences in headless build [message #1209437 is a reply to message #1207881] Mon, 25 November 2013 14:14 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Do you maybe miss equinox.ds or is it started at the wrong start level?
ExtendedObjectSuppliers are contribute through DS.

Tom

On 25.11.13 15:07, Thorsten Beck wrote:
> In my pure-e4 application I have a class that accesses preference values
> via the @Preference annotation:
>
> @Inject @Preference(nodePath = "my.application.bundle.id", value =
> "FOO") String fooName;
>
> This works fine. I also have a JUnit plug-in test for this class where I
> want to set the Preference to a certain value:
>
> IEclipsePreferences prefs =
> InstanceScope.INSTANCE.getNode("my.application.bundle.id");
> prefs.put("FOO", "bar");
>
> This also works fine when running the test in Eclipse. However, when
> running a headless build (Tycho) I get the following error for the test:
>
> Unable to process "ClassUnderTest.fooName": no actual value was found
> for the argument
> "String[@org.eclipse.e4.core.di.extensions.Preference(nodePath=my.application.bundle.id,
> value=FOO)]".
>
> Normal injections via @Inject work fine in Tycho plug-in tests. So there
> seems to be a problem with the @Preference annotation. I tried several
> things, e.g. adding prefs to an IEclipseContext in my test and injecting
> it into ClassUnderTest:
>
> IEclipseContext context = EclipseContextFactory.create();
> context.set(IEclipsePreferences.class, prefs);
> ContextInjectionFactory.make(ClassUnderTest.class, context);
>
> but that didn't change anything. I suspect the problem lies in the fact
> that "Preference values are not stored directly in the IEclipseContext
> but contributed by an ExtendedObjectSupplier" [vogella.com]
>
> How can I create a Preference Value in my JUnit plug-in test so it can
> be injected and accessed by ClassUnderTest when running the test with
> Tycho?
Re: Setting IEclipsePreferences in headless build [message #1209769 is a reply to message #1209437] Mon, 25 November 2013 17:50 Go to previous message
Thorsten Beck is currently offline Thorsten BeckFriend
Messages: 4
Registered: November 2013
Junior Member
In fact, I was missing equinox.ds since I wasn't aware of its relation to ExtendedObjectSuppliers.
I added the following to my plugin-test's pom file
<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>tycho-surefire-plugin</artifactId>
  <configuration>
    <dependencies>
      <dependency>
        <type>p2-installable-unit</type>
        <artifactId>org.eclipse.equinox.ds</artifactId>
      </dependency>
    </dependencies>
  </configuration>
</plugin>

and now everything works fine.
Awesome! Thanks for the quick reply!
Thorsten
Previous Topic:Hot to get access to an OSGi service in a bundle Activator (e4)?
Next Topic:Howto add a closelistener to a MPart?
Goto Forum:
  


Current Time: Thu Apr 25 23:34:41 GMT 2024

Powered by FUDForum. Page generated in 0.03052 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top