Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Setup to include for @ContextValue annotation
Setup to include for @ContextValue annotation [message #1504958] Tue, 09 December 2014 18:17 Go to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Hello guys,
following this very good blog post link I am thinking to include the e(fx)clipse Dependency Injection features in my project.

I tried to look here, but I could not find the info I wanted. What steps do I need to take in order to include it in my .product/pom.xml ? Maybe I have not looked hard enough, but I could not find a way. Basically I would like to use the @ContextValue annotation in my product (which now supports back to Kepler).

Thanks!
Re: Setup to include for @ContextValue annotation [message #1505073 is a reply to message #1504958] Tue, 09 December 2014 20:25 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

To make use of the @ContextValue you need the following bundles in your
runtime env:
* org.eclipse.fx.core
* org.eclipse.fx.core.di
* org.eclipse.fx.core.di.context

The best update site to point to in your tycho build is
http://download.eclipse.org/efxclipse/runtime-released/1.1.0/site

Tom

On 09.12.14 19:17, Andrea Richiardi wrote:
> Hello guys,
> following this very good blog post
> http://tomsondev.bestsolution.at/2013/11/21/writing-ieclipsecontext-less-code/
> I am thinking to include the e(fx)clipse Dependency Injection features
> in my project.
>
> I tried to look here, but I could not find the info I wanted. What steps
> do I need to take in order to include it in my .product/pom.xml ? Maybe
> I have not looked hard enough, but I could not find a way. Basically I
> would like to use the @ContextValue annotation in my product (which now
> supports back to Kepler).
>
> Thanks!
Re: Setup to include for @ContextValue annotation [message #1505884 is a reply to message #1505073] Wed, 10 December 2014 11:43 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
I added the repo and the bundles to my MANIFEST.MF, but I still cannot see it. Maybe I am doing something wrong...
mvn clean install
of my product does not complete as well. Maybe I need to add
org.eclipse.fx.runtime.feature
in my .product file?

[Updated on: Wed, 10 December 2014 11:50]

Report message to a moderator

Re: Setup to include for @ContextValue annotation [message #1505900 is a reply to message #1505884] Wed, 10 December 2014 11:57 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
So is your product built with features? I don't think fx.runtime.feature
is appropriate for your usecase (assumeing that the application is based
upon SWT?)

I'm not sure what you mean by: "I still cannot see it". What can you not
see? You need to have "org.eclipse.fx.core.di" as a dependency which
holds the annotation.

Tom

On 10.12.14 12:43, Andrea Richiardi wrote:
> I added the repo and the bundles to my MANIFEST.MF, but I still cannot
> see it. Maybe I am doing something wrong...mvn clean install of my
> product does not complete as well. Maybe I need to add
> org.eclipse.fx.runtime.feature in my .product file?
Re: Setup to include for @ContextValue annotation [message #1505932 is a reply to message #1505900] Wed, 10 December 2014 12:29 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Hello Tom thank you first of all and yes, feature and SWT based.
What I meant is that I added
<feature id="org.eclipse.fx.runtime.feature"/>
and now Maven downloads all the dependencies, but in my MANIFEST I have big red crosses in the Require-Bundle section.
But as I said, maybe I am doing something wrong and still investigating, probably a runtime dependency is different from what I think it is and I need to put it somwhere else.

For instance now I add the following to the .product and trying:
<plugins>
     <plugin id="org.eclipse.fx.core" autoStart="true" startLevel="3" />
      <plugin id="org.eclipse.fx.core.di" autoStart="true" startLevel="3" />
      <plugin id="org.eclipse.fx.core.di.context" autoStart="true" startLevel="3" />
</plugins>
Re: Setup to include for @ContextValue annotation [message #1506008 is a reply to message #1505932] Wed, 10 December 2014 13:52 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
To make eclipse happy you need to add this feature to your target platform setting in your IDE!
Re: Setup to include for @ContextValue annotation [message #1506023 is a reply to message #1506008] Wed, 10 December 2014 14:09 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Yes, you are right, but this does not explain the failure with mvn, now I am trying to specify version 1.1.0 in my .product.

And something is moving, I now have (I am still using kepler):
Cannot complete the install because of a conflicting dependency.
  Software being installed: e(fx)clipse core Feature 1.1.0.201411050703 (org.eclipse.fx.core.feature.feature.group 1.1.0.201411050703)
  Software currently installed: Equinox Target Components 3.9.0.v20140221-1852 (org.eclipse.equinox.sdk.feature.group 3.9.0.v20140221-1852)
  Only one of the following can be installed at once: 
    OSGi System Bundle 3.10.100.v20141020-1414 (org.eclipse.osgi 3.10.100.v20141020-1414)
    OSGi System Bundle 3.9.0.v20130529-1710 (org.eclipse.osgi 3.9.0.v20130529-1710)
    OSGi System Bundle 3.9.1.v20130814-1242 (org.eclipse.osgi 3.9.1.v20130814-1242)
    OSGi System Bundle 3.10.1.v20140909-1633 (org.eclipse.osgi 3.10.1.v20140909-1633)
    OSGi System Bundle 3.8.2.v20130124-134944 (org.eclipse.osgi 3.8.2.v20130124-134944)
    OSGi System Bundle 3.9.1.v20140110-1610 (org.eclipse.osgi 3.9.1.v20140110-1610)
  Cannot satisfy dependency:
    From: Equinox Core SDK 3.8.0.v20140114-1344 (org.eclipse.equinox.core.sdk.feature.group 3.8.0.v20140114-1344)
    To: org.eclipse.osgi [3.9.1.v20140110-1610]
  Cannot satisfy dependency:
    From: Equinox Target Components 3.9.0.v20140221-1852 (org.eclipse.equinox.sdk.feature.group 3.9.0.v20140221-1852)
    To: org.eclipse.equinox.core.sdk.feature.group [3.8.0.v20140114-1344]
  Cannot satisfy dependency:
    From: e(fx)clipse core Feature 1.1.0.201411050703 (org.eclipse.fx.core.feature.feature.group 1.1.0.201411050703)
    To: org.eclipse.fx.osgi [1.1.0.201411050602]
  Cannot satisfy dependency:
    From: OSGi integration for JavaFX 1.1.0.201411050602 (org.eclipse.fx.osgi 1.1.0.201411050602)
    To: bundle org.eclipse.osgi 3.10.0

Re: Setup to include for @ContextValue annotation [message #1506075 is a reply to message #1506023] Wed, 10 December 2014 15:03 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I repeat including our feature is NOT a good idea it comes with too many things you don't - we only support luna because we also require java8!!! You'd have to backport our code yourself to run on Java7 or use our code as a blueprint and implement something similar.
Re: Setup to include for @ContextValue annotation [message #1506243 is a reply to message #1506075] Wed, 10 December 2014 17:54 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Ok I think I think I backported the three bundles successfully using RetroLambda, I am now trying to execute some code, I will keep you posted.
Re: Setup to include for @ContextValue annotation [message #1506274 is a reply to message #1506243] Wed, 10 December 2014 18:29 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I'm not sure this is enough - we might use jdk8 stream APIs as well and
we use type annotations for null checks!

Tom

On 10.12.14 18:54, Andrea Richiardi wrote:
> Ok I think I think I backported the three bundles successfully using
> RetroLambda, I am now trying to execute some code, I will keep you posted.
Re: Setup to include for @ContextValue annotation [message #1506324 is a reply to message #1506274] Wed, 10 December 2014 19:27 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Yes, I removed every type annotation and used org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0) for classical return types and method parameters.
It builds with Maven without issues, I just need to verify that retrolamba generates Java 7 bytecode for the two, three lamdas I have seen.

EDIT: still some work to do the tests all fail with:
org.eclipse.e4.core.di.InjectionException: Unable to process "EventBroker.logger": no actual value was found for the argument "Logger".
	at org.eclipse.e4.core.internal.di.InjectorImpl.reportUnresolvedArgument(InjectorImpl.java:412)
	at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:403)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:108)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:333)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:254)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
	at org.eclipse.e4.ui.services.events.EventBrokerFactory.compute(EventBrokerFactory.java:29)

[Updated on: Wed, 10 December 2014 19:52]

Report message to a moderator

Re: Setup to include for @ContextValue annotation [message #1507152 is a reply to message #1506324] Thu, 11 December 2014 11:06 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Hello Tom, would like to have an opinion on my refactoring, and if you want to help me testing it (especially the new org...di.javafx).
Would it make sense to have a separate repo with these bundles just for DI?

https://github.com/arichiardi/efxclipse-di-context
Re: Setup to include for @ContextValue annotation [message #1507161 is a reply to message #1507152] Thu, 11 December 2014 11:19 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

It's good you managed to get it working but for e(fx)clipse it does not
make sense to host those forked bundles - e(fx)clipse requires Java8 in
all areas so downgrading to Java6/7 is not really useful to our main
user group who are JavaFX-Application devs.

Feel free to keep them at github and sync them from time to time when we
move forward ;-)

Tom

On 11.12.14 12:06, Andrea Richiardi wrote:
> Hello Tom, would like to have an opinion on my refactoring, and if you
> want to help me testing it (especially the new org...di.javafx).
> Would it make sense to have a separate repo with these bundles just for DI?
>
> https://github.com/arichiardi/efxclipse-di-context
Re: Setup to include for @ContextValue annotation [message #1507320 is a reply to message #1507161] Thu, 11 December 2014 14:18 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
I understand it is not your use case at all, nonetheless I would not feel very comfortable in putting my name on some Maven artifact as it was not at all my merit Smile
You are not even interested in putting these modified packages under a *.j7 package on eclipse.org/github and delegating the maintenance to me?
Re: Setup to include for @ContextValue annotation [message #1507678 is a reply to message #1507320] Thu, 11 December 2014 21:10 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 11.12.14 15:18, Andrea Richiardi wrote:
> I understand it is not your use case at all, nonetheless I would not
> feel very comfortable in putting my name on some Maven artifact as it
> was not at all my merit :)

As long as you keep all the copyright and attribution in place and
follow the EPL you are free to do anything with the work. That's the
nature of OpenSource when released under EPL ;-)

> You are not even interested in putting these modified packages under a
> *.j7 package on eclipse.org/github and delegating the maintenance to me?
>

This would require me to make you a committer on the project and I'd
like to keep the focus on e(fx)clipse which is enough work already. If
you add features in future I'd appreciate if you file upstream requests.

Tom
Re: Setup to include for @ContextValue annotation [message #1508233 is a reply to message #1507678] Fri, 12 December 2014 08:17 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
I'll do for sure, thank you very much, I will maybe ask you some question every now and then Smile
Re: Setup to include for @ContextValue annotation [message #1512400 is a reply to message #1508233] Mon, 15 December 2014 18:17 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Hi Tom, as I told you, I have a question Embarrassed
I am trying to make your tests working but I keep receiving the error:

testSimpleInjection(....addons.di.context.tests.ContextBoundValueTestCase)  Time elapsed: 0.006 sec  <<< ERROR!
org.eclipse.e4.core.di.InjectionException: Could not find satisfiable constructor in .....di.context.internal.EclipseContextBoundValue


I debugged using the JUnit Plugin Test launch configuration and it looks like it cannot find AdapterService, during the injection of:

@Inject
	public EclipseContextBoundValue(@NonNull IEclipseContext context, @NonNull AdapterService adapterService) {
		this.context = context;
		this.adapterService = adapterService;
	}


Any hint on why it failes?

EDIT: Never mind, I forgot to import .core.adapter.internal when I refactored.

[Updated on: Mon, 15 December 2014 20:21]

Report message to a moderator

Re: Setup to include for @ContextValue annotation [message #1512633 is a reply to message #1512400] Mon, 15 December 2014 22:52 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Is the DS-Bundle loaded?

Tom

On 15.12.14 19:17, Andrea Richiardi wrote:
> Hi Tom, as I told you, I have a question :blush: I am trying to make
> your tests working but I keep receiving the error:
>
> testSimpleInjection(....addons.di.context.tests.ContextBoundValueTestCase)
> Time elapsed: 0.006 sec <<< ERROR!
> org.eclipse.e4.core.di.InjectionException: Could not find satisfiable
> constructor in .....di.context.internal.EclipseContextBoundValue
>
> I debugged from using the JUnit Plugin Test launch cofiguration and it
> looks like it cannot find AdapterService, during the injection of:
>
> @Inject
> public EclipseContextBoundValue(@NonNull IEclipseContext context,
> @NonNull AdapterService adapterService) {
> this.context = context;
> this.adapterService = adapterService;
> }
>
>
> Any hint on why it failes?
Re: Setup to include for @ContextValue annotation [message #1513390 is a reply to message #1512633] Tue, 16 December 2014 13:41 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Thanks for answering Tom, I now have your tests with ContextValue working!
As you suggested in another Eclipse's forum thread, I also had to set a Logger in the context or the IEventBroker was not getting its dependencies filled.

I have another problem on the othe test case, the one with @Adapt. It throws:
testAdapt(com.andrearichiardi.eclipse.addons.di.context.AdaptSupplierTestCase)  Time elapsed: 0.078 sec  <<< ERROR!
org.eclipse.e4.core.di.InjectionException: Unable to process "Bean.integerValue": no actual value was found for the argument "Integer[@com.andrearichiardi.eclipse.addons.adapter.Adapt(),@javax.inject.Named(value=test)]".


I checked that both Providers and di.context.internal.AdaptValueSupplier are present but still it fails in
    private Object[] InjectorImpl.resolveArgs(...) {
...
                // 6) post process
		for (int i = 0; i < descriptors.length; i++) {
			// check that values are of a correct type
                       ...
                       if (!descriptorsClass.isAssignableFrom(actualArgs[i].getClass()))
			   it gets here -->	actualArgs[i] = IInjector.NOT_A_VALUE;
			}
                 }


Basically it finds the value "test" but never converts it to the desired type, so for instance here descriptorsClass is Integer but actualArgs[i].getClass() returns a String and of course the check fails. I think both tests can be fixed in e(fx)clipse as well, that is why I am trying to make them work.

Here is what services are running:
Components in bundle com.andrearichiardi.eclipse.addons: 
ID	State			Component Name			Located in bundle
1	Registered		com.andrearichiardi.eclipse.addons.jlogger			com.andrearichiardi.eclipse.addons(bid=8)
2	Registered		com.andrearichiardi.eclipse.addons.adapter.adapterservice			com.andrearichiardi.eclipse.addons(bid=8)
3	Registered		com.andrearichiardi.eclipse.addons.di.context.loggersupplier			com.andrearichiardi.eclipse.addons(bid=8)
4	Registered		com.andrearichiardi.eclipse.addons.di.context.observableadapter			com.andrearichiardi.eclipse.addons(bid=8)
5	Active		com.andrearichiardi.eclipse.addons.di.context.dateformatter			com.andrearichiardi.eclipse.addons(bid=8)
6	Registered		com.andrearichiardi.eclipse.addons.di.context.valuesupplier			com.andrearichiardi.eclipse.addons(bid=8)
7	Active		com.andrearichiardi.eclipse.addons.di.context.localeprovider			com.andrearichiardi.eclipse.addons(bid=8)
8	Active		com.andrearichiardi.eclipse.addons.di.context.numberformatter			com.andrearichiardi.eclipse.addons(bid=8)
9	Registered		com.andrearichiardi.eclipse.addons.di.context.adaptsupplier			com.andrearichiardi.eclipse.addons(bid=8)
10	Active		com.andrearichiardi.eclipse.addons.di.context.temporalaccessformatter			com.andrearichiardi.eclipse.addons(bid=8)
11	Active		com.andrearichiardi.eclipse.addons.di.context.scopedobjectfactoryfunction			com.andrearichiardi.eclipse.addons(bid=8)
12	Active		com.andrearichiardi.eclipse.addons.tests.stringDoubleProvider			com.andrearichiardi.eclipse.addons.tests(bid=9)
13	Active		com.andrearichiardi.eclipse.addons.tests.stringIntegerProvider			com.andrearichiardi.eclipse.addons.tests(bid=9)


[Updated on: Tue, 16 December 2014 17:30]

Report message to a moderator

Re: Setup to include for @ContextValue annotation [message #1513628 is a reply to message #1513390] Tue, 16 December 2014 17:57 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
It looks like the primary supplier used for the object is org.eclipse.e4.core.internal.contexts.ContextObjectSupplier, shouldn't it be AdaptValueSupplier ? I cannot understand why it gets the other one...

EDIT:
I found it.. somehow the Named annotation takes precedence over Adapt.

It is evident when putting a breakpoint in AdaptValueSupplier, removing the Named annotation.
static class Bean {
		@Inject
		@Adapt
		
		Integer integerValue;


As you can see, now the code enters in the AdaptValueSupplier.get.

You can also see this in InjectorImpl.resolveArgs where the step 3) use the primary supplier will fill up the dependency, leaving no space to other suppliers.

[Updated on: Tue, 16 December 2014 18:26]

Report message to a moderator

Re: Setup to include for @ContextValue annotation [message #1513815 is a reply to message #1513628] Tue, 16 December 2014 21:39 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Yes it should be "AdaptValueSupplier" and my test suite runs fine!

Tom

On 16.12.14 18:57, Andrea Richiardi wrote:
> It looks like the primary supplier used for the object is
> org.eclipse.e4.core.internal.contexts.ContextObjectSupplier, shouldn't
> it be AdaptValueSupplier ? I cannot understand why it gets the other one...
Re: Setup to include for @ContextValue annotation [message #1542030 is a reply to message #1513815] Fri, 02 January 2015 11:30 Go to previous messageGo to next message
Andrea Richiardi is currently offline Andrea RichiardiFriend
Messages: 64
Registered: August 2012
Member
Hi Tom,
now everything works! I leave the link here in case someone is interested, I also split the tests in two by applying some maven magic, for kepler and > e4.
I hope everything is fine with license and credits and you give me your blessing Embarrassed
Thanks!

Eclipse Addons 1.0.0

[Updated on: Sat, 03 January 2015 16:53]

Report message to a moderator

Re: Setup to include for @ContextValue annotation [message #1542613 is a reply to message #1542030] Fri, 02 January 2015 19:20 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Good job!

Tom

On 02.01.15 12:30, Andrea Richiardi wrote:
> Hi Tom,
> now everything works! I live the link here in case someone is
> interested, I also split the tests in two applying some maven magic, for
> kepler and > e4.
> I hope everything is fine with license and credits and you give me your
> blessing :blush: Thanks!
>
> https://github.com/arichiardi/eclipse-addons
Previous Topic:Problem with the "ambitious" installation
Next Topic:Unsatisfied 'org.eclipse.fx.osgi.util' when exporting osgi/javafx app
Goto Forum:
  


Current Time: Tue Sep 24 00:01:53 GMT 2024

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

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

Back to the top