-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for Jakarta CDI #2970
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...essor/src/main/java/org/mapstruct/ap/internal/processor/JakartaCdiComponentProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct.ap.internal.processor; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import org.mapstruct.ap.internal.gem.MappingConstantsGem; | ||
| import org.mapstruct.ap.internal.model.Annotation; | ||
| import org.mapstruct.ap.internal.model.Mapper; | ||
|
|
||
| /** | ||
| * A {@link ModelElementProcessor} which converts the given {@link Mapper} | ||
| * object into an application-scoped Jakarta CDI bean in case Jakarta CDI | ||
| * is configured as the target component model for this mapper. | ||
| * | ||
| * @author Filip Hrisafov | ||
| */ | ||
| public class JakartaCdiComponentProcessor extends AnnotationBasedComponentModelProcessor { | ||
|
|
||
| @Override | ||
| protected String getComponentModelIdentifier() { | ||
| return MappingConstantsGem.ComponentModelGem.JAKARTA_CDI; | ||
| } | ||
|
|
||
| @Override | ||
| protected List<Annotation> getTypeAnnotations(Mapper mapper) { | ||
| return Collections.singletonList( | ||
| new Annotation( getTypeFactory().getType( "jakarta.enterprise.context.ApplicationScoped" ) ) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| protected List<Annotation> getMapperReferenceAnnotations() { | ||
| return Arrays.asList( new Annotation( getTypeFactory().getType( "jakarta.inject.Inject" ) ) ); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean requiresGenerationOfDecoratorClass() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean additionalPublicEmptyConstructor() { | ||
| return true; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...struct/ap/test/injectionstrategy/cdi/_default/CdiDefaultCompileOptionFieldMapperTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct.ap.test.injectionstrategy.cdi._default; | ||
|
|
||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.Gender; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; | ||
| import org.mapstruct.ap.testutil.IssueKey; | ||
| import org.mapstruct.ap.testutil.ProcessorTest; | ||
| import org.mapstruct.ap.testutil.WithCdi; | ||
| import org.mapstruct.ap.testutil.WithClasses; | ||
| import org.mapstruct.ap.testutil.runner.GeneratedSource; | ||
|
|
||
| import static java.lang.System.lineSeparator; | ||
|
|
||
| /** | ||
| * Test field injection for component model jakarta-cdi. | ||
| * Default value option mapstruct.defaultInjectionStrategy is "field" | ||
| * | ||
| * @author Filip Hrisafov | ||
| */ | ||
| @IssueKey("2950") | ||
| @WithClasses({ | ||
| CustomerDto.class, | ||
| CustomerEntity.class, | ||
| Gender.class, | ||
| GenderDto.class, | ||
| CustomerCdiDefaultCompileOptionFieldMapper.class, | ||
| GenderCdiDefaultCompileOptionFieldMapper.class | ||
| }) | ||
| @WithCdi | ||
| public class CdiDefaultCompileOptionFieldMapperTest { | ||
|
|
||
| @RegisterExtension | ||
| final GeneratedSource generatedSource = new GeneratedSource(); | ||
|
|
||
| @ProcessorTest | ||
| public void shouldHaveFieldInjection() { | ||
| generatedSource.forMapper( CustomerCdiDefaultCompileOptionFieldMapper.class ) | ||
| .content() | ||
| .contains( "import javax.enterprise.context.ApplicationScoped;" ) | ||
| .contains( "import javax.inject.Inject;" ) | ||
| .contains( "@Inject" + lineSeparator() + " private GenderCdiDefaultCompileOptionFieldMapper" ) | ||
| .contains( "@ApplicationScoped" + lineSeparator() + "public class" ) | ||
| .doesNotContain( "public CustomerCdiDefaultCompileOptionFieldMapperImpl(" ) | ||
| .doesNotContain( "jakarta.inject" ) | ||
| .doesNotContain( "jakarta.enterprise" ); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...ct/ap/test/injectionstrategy/cdi/_default/CustomerCdiDefaultCompileOptionFieldMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct.ap.test.injectionstrategy.cdi._default; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.MappingConstants; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| @Mapper(componentModel = MappingConstants.ComponentModel.CDI, | ||
| uses = GenderCdiDefaultCompileOptionFieldMapper.class) | ||
| public interface CustomerCdiDefaultCompileOptionFieldMapper { | ||
|
|
||
| CustomerDto asTarget(CustomerEntity customerEntity); | ||
| } |
26 changes: 26 additions & 0 deletions
26
...ruct/ap/test/injectionstrategy/cdi/_default/GenderCdiDefaultCompileOptionFieldMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct.ap.test.injectionstrategy.cdi._default; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.MappingConstants; | ||
| import org.mapstruct.ValueMapping; | ||
| import org.mapstruct.ValueMappings; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.Gender; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| @Mapper(componentModel = MappingConstants.ComponentModel.CDI) | ||
| public interface GenderCdiDefaultCompileOptionFieldMapper { | ||
|
|
||
| @ValueMappings({ | ||
| @ValueMapping(source = "MALE", target = "M"), | ||
| @ValueMapping(source = "FEMALE", target = "F") | ||
| }) | ||
| GenderDto mapToDto(Gender gender); | ||
| } |
21 changes: 21 additions & 0 deletions
21
...uct/ap/test/injectionstrategy/cdi/jakarta/CustomerCdiDefaultCompileOptionFieldMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct.ap.test.injectionstrategy.cdi.jakarta; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.MappingConstants; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| @Mapper(componentModel = MappingConstants.ComponentModel.CDI, | ||
| uses = GenderCdiDefaultCompileOptionFieldMapper.class) | ||
| public interface CustomerCdiDefaultCompileOptionFieldMapper { | ||
|
|
||
| CustomerDto asTarget(CustomerEntity customerEntity); | ||
| } |
26 changes: 26 additions & 0 deletions
26
...truct/ap/test/injectionstrategy/cdi/jakarta/GenderCdiDefaultCompileOptionFieldMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct.ap.test.injectionstrategy.cdi.jakarta; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.MappingConstants; | ||
| import org.mapstruct.ValueMapping; | ||
| import org.mapstruct.ValueMappings; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.Gender; | ||
| import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; | ||
|
|
||
| /** | ||
| * @author Filip Hrisafov | ||
| */ | ||
| @Mapper(componentModel = MappingConstants.ComponentModel.CDI) | ||
| public interface GenderCdiDefaultCompileOptionFieldMapper { | ||
|
|
||
| @ValueMappings({ | ||
| @ValueMapping(source = "MALE", target = "M"), | ||
| @ValueMapping(source = "FEMALE", target = "F") | ||
| }) | ||
| GenderDto mapToDto(Gender gender); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCDITypeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to complicate things. This also fetches the
@Injectfrom the inject package as well