Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple Spring DI support #563

Merged
merged 2 commits into from
Jan 21, 2019
Merged

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Jan 18, 2019

Support is provided my mapping Spring DI annotations to their CDI
counterparts leveraging the annotation transformation mechanism that
Arc provides

@geoand geoand force-pushed the basic-spring-di branch 3 times, most recently from c4426de to 2119ada Compare January 18, 2019 11:55
@geoand
Copy link
Contributor Author

geoand commented Jan 18, 2019

I can't see the logs of CI process unfortunately.
Also when I run the build on my machine it works just fine and the CI build seems to fail very quickly which seems fishy :)

private static final DotName VALUE_ANNOTATION
= DotName.createSimple("org.springframework.beans.factory.annotation.Value");

private static final DotName CDI_SINGLETON_ANNOTATION = DotName.createSimple(Singleton.class.getName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use org.jboss.protean.arc.processor.ScopeInfo#getDotName() and org.jboss.protean.arc.processor.DotNames.INJECT and friends instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@mkouba
Copy link
Contributor

mkouba commented Jan 18, 2019

I can see this:

2019-01-18T11:56:52.4616604Z [FATAL] Non-resolvable parent POM for org.jboss.shamrock:shamrock-spring-deployment:[unknown-version]: Could not find artifact org.jboss.shamrock:shamrock-spring:pom:1.0.0.Alpha1-SNAPSHOT in jboss-public-repository-group (http://repository.jboss.org/nexus/content/groups/developer/) and 'parent.relativePath' points at wrong local POM @ line 5, column 13
2019-01-18T11:56:52.4617877Z [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.jboss.shamrock:shamrock-arc-deployment:jar -> duplicate declaration of version (?) @ org.jboss.shamrock:shamrock-agroal-deployment:[unknown-version], /home/vsts/work/1/s/extensions/agroal/deployment/pom.xml, line 45, column 21

@geoand
Copy link
Contributor Author

geoand commented Jan 18, 2019

I can see this:

2019-01-18T11:56:52.4616604Z [FATAL] Non-resolvable parent POM for org.jboss.shamrock:shamrock-spring-deployment:[unknown-version]: Could not find artifact org.jboss.shamrock:shamrock-spring:pom:1.0.0.Alpha1-SNAPSHOT in jboss-public-repository-group (http://repository.jboss.org/nexus/content/groups/developer/) and 'parent.relativePath' points at wrong local POM @ line 5, column 13
2019-01-18T11:56:52.4617877Z [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.jboss.shamrock:shamrock-arc-deployment:jar -> duplicate declaration of version (?) @ org.jboss.shamrock:shamrock-agroal-deployment:[unknown-version], /home/vsts/work/1/s/extensions/agroal/deployment/pom.xml, line 45, column 21

Very helpful, thanks!

@geoand
Copy link
Contributor Author

geoand commented Jan 18, 2019

@mkouba Would be so kind as to paste the logs of the failed test?
Seems like something else failed this time.

Thanks a lot and sorry for the inconvenience!

@mkouba
Copy link
Contributor

mkouba commented Jan 18, 2019

@geoand No problem. The log should be visible here: https://dev.azure.com/protean-ci/Shamrock/_build/results?buildId=1267 (click on "1 errors / 0 warnings" link in the azure check detail)

2019-01-18T13:59:07.9251386Z [INFO] Running org.jboss.shamrock.spring.tests.InjectedSpringBeansResourceIT
2019-01-18T13:59:07.9814472Z [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.054 s <<< FAILURE! - in org.jboss.shamrock.spring.tests.InjectedSpringBeansResourceIT
2019-01-18T13:59:07.9815203Z [ERROR] initializationError(org.jboss.shamrock.spring.tests.InjectedSpringBeansResourceIT)  Time elapsed: 0.012 s  <<< ERROR!
2019-01-18T13:59:07.9815529Z java.lang.Exception: No runnable methods

@geoand
Copy link
Contributor Author

geoand commented Jan 18, 2019

@geoand No problem. The log should be visible here: https://dev.azure.com/protean-ci/Shamrock/_build/results?buildId=1267 (click on "1 errors / 0 warnings" link in the azure check detail)

2019-01-18T13:59:07.9251386Z [INFO] Running org.jboss.shamrock.spring.tests.InjectedSpringBeansResourceIT
2019-01-18T13:59:07.9814472Z [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.054 s <<< FAILURE! - in org.jboss.shamrock.spring.tests.InjectedSpringBeansResourceIT
2019-01-18T13:59:07.9815203Z [ERROR] initializationError(org.jboss.shamrock.spring.tests.InjectedSpringBeansResourceIT)  Time elapsed: 0.012 s  <<< ERROR!
2019-01-18T13:59:07.9815529Z java.lang.Exception: No runnable methods

Thanks!
Silly me, didn't write the substrate test correctly.
Should be fixed now

@@ -39,7 +39,7 @@

static InjectionPointInfo fromField(FieldInfo field, BeanDeployment beanDeployment) {
Set<AnnotationInstance> qualifiers = new HashSet<>();
for (AnnotationInstance annotation : field.annotations()) {
for (AnnotationInstance annotation : beanDeployment.getAnnotations(field)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should update fromMethod() as well, in order to support setter/constructor injection. I'd guess it is also supported by Spring DI, or?

In fact, AnnotationsTransformer method params support is not that good. We should improve this.

Copy link
Contributor Author

@geoand geoand Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken AnnotationTransformer doesn't currently support method parameters at all. Would you like me to address that with this PR?

And to answer you other question, yes Spring DI does allow annotations like (@Qualifier) on method params (and obviously this PR doesn't handle them)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the transformation of annotations method params should be disabled and only enabled by a config property than extension would set?
If you think we should have method param annotation handling, I will gladly add it with PR and update the Spring processor to handle such annotations

Copy link
Contributor Author

@geoand geoand Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around a little more with this and it turned out that adding support for method param qualifiers was fairly easy - so it was added in my latest commit

Support is provided my mapping Spring DI annotations to their CDI
counterparts leveraging the annotation transformation mechanism that
Arc provides
Copy link
Member

@stuartwdouglas stuartwdouglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extension should also be added to the bom, to make it easier for end users to consumer. Other than these issues I think it looks good, but I would like @mkouba to have the final say.

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.4.RELEASE</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be managed in the build parent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


private String determineName(AnnotationValue annotationValue) {
final String className = annotationValue.getClass().getName();
if (className.contains("ArrayValue")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use AnnotationValue.kind()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@mkouba mkouba merged commit e2b2c88 into quarkusio:master Jan 21, 2019
@geoand geoand deleted the basic-spring-di branch January 21, 2019 09:18
@geoand
Copy link
Contributor Author

geoand commented Jan 21, 2019

Should I perhaps create an issue for this and link it to this PR?
I mean just for the release notes

@stuartwdouglas stuartwdouglas added this to the 0.7.0 milestone Jan 21, 2019
@geoand geoand added the area/spring Issues relating to the Spring integration label Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/spring Issues relating to the Spring integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants