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

#2399 Add OSGi Declarative Services as Component Model #2400

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ktor
Copy link

@ktor ktor commented Apr 1, 2021

It is work in progress. I've created the pull request to collaborate on the code. It is missing tests but otherwise generates OSGi DS annotations correctly, at least for my use case.

I have a trouble creating OSGi container in the test so it could check if references are properly binded as it is done for Spring Component Model implementation. Maybe it is too much trouble anyways and there is a better / simpler way to test if it is correctly generated. Please advise.

Example of usage

Factory

@Component(immediate = true, property = {}, service = CompanyMapperFactory.class)
public class CompanyMapperFactory {

    @Reference
    private CustomerCompanyLocalService CustomerCompanyLocalService;

    public CustomerCompany createDbCustomerCompany() {
        return CustomerCompanyLocalService.createCustomerCompany(DEFAULT_ID_WILL_BE_IGNORED);
    }

Mapper

@Mapper(componentModel = "osgi_ds", uses = {CompanyMapperFactory.class})
public interface CompanyMapper {

    CustomerCompany map(Company company);

MapperImpl

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2020-12-30T11:14:32+0000",
    comments = "version: 1.4.0.Beta4-SNAPSHOT, compiler: IncrementalProcessingEnvironment from gradle-language-java-5.6.4.jar, environment: Java 1.8.0_272 (Oracle Corporation)"
)
@Component
public class CompanyMapperImpl implements CompanyMapper {

    @Reference
    private CompanyMapperFactory companyMapperFactory;

    @Override
    public CustomerCompany map(Company company) {
        if ( company == null ) {
            return null;
        }

        CustomerCompany customerCompany = companyMapperFactory.createCustomerCompany();

@ktor ktor changed the title #2399 Add OSGi Declarative Services as Componen Model #2399 Add OSGi Declarative Services as Component Model Apr 1, 2021
@ktor ktor changed the title #2399 Add OSGi Declarative Services as Component Model #2400 Add OSGi Declarative Services as Component Model Apr 1, 2021
@ktor ktor changed the title #2400 Add OSGi Declarative Services as Component Model #2399 Add OSGi Declarative Services as Component Model Apr 1, 2021
Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @ktor. I have extremely limited knowledge with OSGi, so I would trust your judgement here.

I've left some comments, which I think need addressing.

I have a trouble creating OSGi container in the test so it could check if references are properly binded as it is done for Spring Component Model implementation. Maybe it is too much trouble anyways and there is a better / simpler way to test if it is correctly generated. Please advise.

Before merging this we should have tests for this. Otherwise, we won't be able to maintain this. I don't know what kind of troubles you had. I guess it is something with our custom test harness and our custom class loaders. I would suggest checking CompilingStatement, most likely you'll need to add the reference to the jar in the same way it is done for spring-beans.

@ktor
Copy link
Author

ktor commented Apr 9, 2021

Thank you for code review @filiphr. I've made the changes you've proposed and added simple test to confirm that generated mappers contain required annotations.

So far I had no luck with integration test where junit would invoke simple osgi container that would confirm that components are initialized and bind correctly but the DS annotations are pretty simple.

I believe the simple test could suffice if maintained: would only change once OSGi DS specification changes (very rare).

@ktor
Copy link
Author

ktor commented Apr 9, 2021

Changed to draft because after changes in OsgiDsComponentProcessor my DS supplied factory that is references in uses attribute of @Mapper annotation does not get needed @Reference annotation. I will update the test for the usecase.

@filiphr
Copy link
Member

filiphr commented Apr 9, 2021

I believe the simple test could suffice if maintained: would only change once OSGi DS specification changes (very rare).

Can you please show me an example test case that I can look into, to see why it isn't working in our test setup. We do have some complex setup of course 😄

@ktor ktor force-pushed the master branch 3 times, most recently from 80ecb53 to 9387774 Compare April 15, 2021 13:27
…sgi-ds component mode annotation generation, what is missing are injection tests with some king of osgi runtime that would be invoked from the tests as it is done for spring, all places where that is missing are annotated with "TODO osgi" comment
@ktor
Copy link
Author

ktor commented Apr 15, 2021

Can you please show me an example test case that I can look into

Hi @filiphr, I've finished the "simple" tests, meaning I've copied all the tests from spring decorator and injection strategy to osgi_ds packages and adjusted the "simple" tests to checkup on expected, generated OSGi DS result.

All places that I've failed to test are now commented with TODO osgi. Those are methods like osgiUp, osgiDown and test methods that require some kind of osgi runtime or mock suite. Those methods should be responsible for spinning up a local osgi container in junit test runtime or to run some kind of osgi mocks. Tried following without success:

  1. https://bnd.bndtools.org/chapters/315-launchpad-testing.html and failed to provide "remote workspace" for it to use
  2. https://sling.apache.org/documentation/development/osgi-mock.html failed to apply completely, it was some time ago and don't remember exactly what was not working, maybe I'll give it another chance

@ktor
Copy link
Author

ktor commented Apr 15, 2021

Hello @cschneider,

Thank you for your presentation: https://www.youtube.com/watch?v=9WGbnfa2BaM. I write to you in hope that you could help me to implement OSGi DS test for services generated with mapstruct mapper generator.

I would be very grateful if you could take a look at one particular test: https://github.com/mapstruct/mapstruct/pull/2400/files#diff-54dfa14bd76fc710acc684c990077482d0fc184f6b440d4e5b05b1d8d22666ccR56 and suggest a way to test if OSGi DS annotations generated with the mapstruct tooling would work in osgi container supporting OSGi R7.

Classes generated with mvn clean test that should somehow be included in the test and activated with the osgi runtime / test suite are prepared in the directory processor/target/compilation-tests/org.mapstruct.ap.test.decorator.osgi_ds.constructor.OsgiDsDecoratorTest/{{name_of_a_test_method}}_eclipse/classes

Thank you!

@ktor ktor marked this pull request as ready for review April 15, 2021 14:23
@ktor ktor requested a review from filiphr April 15, 2021 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants