diff --git a/.github/workflows/close-inactive-issues.yml b/.github/workflows/close-inactive-issues.yml new file mode 100644 index 0000000..66742a9 --- /dev/null +++ b/.github/workflows/close-inactive-issues.yml @@ -0,0 +1,22 @@ +name: Close inactive issues +on: + schedule: + - cron: "30 1 * * *" + +jobs: + close-issues: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/stale@v5 + with: + days-before-issue-stale: 30 + days-before-issue-close: 14 + stale-issue-label: "stale" + stale-issue-message: "This issue is stale because it has been open for 30 days with no activity." + close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." + days-before-pr-stale: -1 + days-before-pr-close: -1 + repo-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 6398c7b..7682197 100644 --- a/docs/README.md +++ b/docs/README.md @@ -62,36 +62,31 @@ footer: io.github.linpeilie mapstruct-plus-spring-boot-starter - 1.3.5 + 1.3.6 ``` - gradle ```groovy -implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-starter', version: '1.3.5' +implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-starter', version: '1.3.6' ``` ## 更新日志 +### 1.3.6 + +- 兼容内部类转换 +- feature : AutoMapping 注解中的 targetClass 支持配置父类 +- [issue#I8QPRO](https://gitee.com/easii/mapstruct-plus/issues/I8QPRO) : 框架自动生成的 AutoMapperConfig 和 AutoMapMapper 包和类名支持配置 +- [issue#I8T7EF](https://gitee.com/easii/mapstruct-plus/issues/I8T7EF) : 支持在父类中配置的 AutoMapping 注解 + + ### 1.3.5 - AutoMapping、ReverseAutoMapping 支持配置在方法上面; - AutoMapping、ReverseAutoMapping 支持 defaultExpression 和 conditionExpression 属性 -### 1.3.4 - -……什么都没更新,腾讯云maven源同步的jar有问题,只能重新发个新包 - -### 1.3.3 - -- fixbug: 修复 win JDK8 编译报错问题 - -### 1.3.2 - -- 不可变对象支持,可以使用任意包下的 `Immutable` 标注类型为不可变类 -- 全面适配 IDEA 部分编译问题,使用更加流畅丝滑 - …… ## 代码仓库 diff --git a/docs/en/README.md b/docs/en/README.md index ec74f32..f2a03a2 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -58,32 +58,30 @@ fotter: io.github.linpeilie mapstruct-plus-spring-boot-starter - 1.3.5 + 1.3.6 ``` - gradle ```groovy -implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-starter', version: '1.3.5' +implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-starter', version: '1.3.6' ``` ## Change Log +### 1.3.6 + +- Compatible with internal class conversion. +- The targetClass in the AutoMapping annotation supports configuring the parent class. +- AutoMapperConfig and AutoMapMapperConfig package and class name generated automatically by the framework support configuration. +- Supports AutoMapping annotations configured in the parent class. + ### 1.3.5 - `@AutoMapping`、`@ReversedAutoMapping` support is configured on top of methods. - `@AutoMapping`、`@ReverseAutoMapping` support the defaultExpression and conditionExpression properties -### 1.3.3 - -- fixbug: fixed compilation error on win jdk8 - -### 1.3.2 - -- Support Immutable object, you can use the `@Immutable` annotation type under any package as an immutable class -- fully adapt the IDEA part of the compilation problem, use more smooth silky - …… ## Code Warehouse diff --git a/docs/en/guide/configuration.md b/docs/en/guide/configuration.md index dabd744..0eab172 100644 --- a/docs/en/guide/configuration.md +++ b/docs/en/guide/configuration.md @@ -163,4 +163,31 @@ eg: - **Description**:the class name of MapConvertMapperAdapter - **Type**:`String` - **Default**:MapConvertMapperAdapter -- **Compile Parameter**:`-Amapstruct.plus.mapAdapterClassName` \ No newline at end of file +- **Compile Parameter**:`-Amapstruct.plus.mapAdapterClassName` + +### autoConfigPackage + +> since `1.3.6` + +- **Description**:The package path of the automatically generated configuration class --- `AutoMapperConfig`/`AutoMapMapperConfig` --- from the MapStructPlus framework. +- **Type**:`String` +- **Default**:io.github.linpeilie +- **Compile Parameter**:`-Amapstruct.plus.autoConfigPackage` + +### autoMapperConfigClassName + +> since `1.3.6` + +- **Description**:MapStructPlus framework automatically generates the name of the configuration class(transformation between configuration objects) +- **Type**:`String` +- **Default**:AutoMapperConfig +- **Compile Parameter**:`-Amapstruct.plus.autoMapperConfigClassName` + +### autoMapMapperConfigClassName + +> since `1.3.6` + +- **Description**:MapStructPlus framework automatically generates the name of the configuration class(which configures the transformation between the Map and the object) +- **Type**:`String` +- **Default**:AutoMapMapperConfig +- **Compile Parameter**:`-Amapstruct.plus.autoMapMapperConfigClassName` diff --git a/docs/en/guide/multiple-class-convert.md b/docs/en/guide/multiple-class-convert.md index 831bd3a..1e80ca3 100644 --- a/docs/en/guide/multiple-class-convert.md +++ b/docs/en/guide/multiple-class-convert.md @@ -34,6 +34,12 @@ when using the `@AutoMapping` annotation, configure the `targetClass` attribute If `targetClass` is not specified when the `@AutoMapping` annotation is configured, the current rule applies to all class conversions. +:::info +`targetClass` also supports the configuration parent class, which applies to this rule when the target class is a subclass of the configured `targetClass`. + +> This feature is supported from 1.3.6 +::: + eg: ```java diff --git a/docs/en/release/log.md b/docs/en/release/log.md index 277c8ba..8b97ba6 100644 --- a/docs/en/release/log.md +++ b/docs/en/release/log.md @@ -6,6 +6,13 @@ category: description: MapStructPlus release log --- +### 1.3.6 + +- Compatible with internal class conversion. +- The targetClass in the AutoMapping annotation supports configuring the parent class. +- AutoMapperConfig and AutoMapMapperConfig package and class name generated automatically by the framework support configuration. +- Supports AutoMapping annotations configured in the parent class. + ### 1.3.5 - AutoMapping、ReverseAutoMapping 支持配置在方法上面; diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md index f350ccc..e24ee0e 100644 --- a/docs/guide/configuration.md +++ b/docs/guide/configuration.md @@ -160,4 +160,31 @@ public class MapStructPlusConfiguration { - **说明**:MapConvertMapperAdapter 类名 - **类型**:`String` - **默认值**:MapConvertMapperAdapter -- **对应编译参数**:`-Amapstruct.plus.mapAdapterClassName` \ No newline at end of file +- **对应编译参数**:`-Amapstruct.plus.mapAdapterClassName` + +### autoConfigPackage + +> since `1.3.6` + +- **说明**:MapStructPlus 框架自动生成的配置类 --- `AutoMapperConfig`/`AutoMapMapperConfig` 所在的包路径 +- **类型**:`String` +- **默认值**:io.github.linpeilie +- **对应编译参数**:`-Amapstruct.plus.autoConfigPackage` + +### autoMapperConfigClassName + +> since `1.3.6` + +- **说明**:MapStructPlus 框架自动生成的的配置类(配置对象之间的转换)类名 +- **类型**:`String` +- **默认值**:AutoMapperConfig +- **对应编译参数**:`-Amapstruct.plus.autoMapperConfigClassName` + +### autoMapMapperConfigClassName + +> since `1.3.6` + +- **说明**:MapStructPlus 框架自动生成的配置类(配置Map与对象之间的转换)类名 +- **类型**:`String` +- **默认值**:AutoMapMapperConfig +- **对应编译参数**:`-Amapstruct.plus.autoMapMapperConfigClassName` diff --git a/docs/guide/multiple-class-convert.md b/docs/guide/multiple-class-convert.md index 9739863..8eca0be 100644 --- a/docs/guide/multiple-class-convert.md +++ b/docs/guide/multiple-class-convert.md @@ -33,6 +33,13 @@ public class User { 如果在配置 `@AutoMapping` 注解时,没有指定 `targetClass` 时,则当前规则,会应用于与所有类转换。 +:::info +`targetClass` 同时支持配置父类,当目标类是所配置的 `targetClass` 的子类时,即可应用于该规则。 + +> 该特性从 1.3.6 开始支持 +::: + + 例如: ```java diff --git a/docs/release/log.md b/docs/release/log.md index 277c8ba..175f8fe 100644 --- a/docs/release/log.md +++ b/docs/release/log.md @@ -6,6 +6,13 @@ category: description: MapStructPlus release log --- +### 1.3.6 + +- 兼容内部类转换 +- feature : AutoMapping 注解中的 targetClass 支持配置父类 +- [issue#I8QPRO](https://gitee.com/easii/mapstruct-plus/issues/I8QPRO) : 框架自动生成的 AutoMapperConfig 和 AutoMapMapper 包和类名支持配置 +- [issue#I8T7EF](https://gitee.com/easii/mapstruct-plus/issues/I8T7EF) : 支持在父类中配置的 AutoMapping 注解 + ### 1.3.5 - AutoMapping、ReverseAutoMapping 支持配置在方法上面; diff --git a/example/pom.xml b/example/pom.xml index 385f8d9..0a89080 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -18,7 +18,7 @@ UTF-8 1.5.1.Final - 1.3.5 + 1.3.6 1.18.22 diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/MapStructPlusConfiguration.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/MapStructPlusConfiguration.java index f9f67ea..e9849a7 100644 --- a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/MapStructPlusConfiguration.java +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/MapStructPlusConfiguration.java @@ -4,6 +4,9 @@ import io.github.linpeilie.annotations.MapperConfig; @MapperConfig(adapterClassName = "DemoConvertMapperAdapter", adapterPackage = "io.github.linpeilie.adapter", - mapAdapterClassName = "DemoMapConvertMapperAdapter") + mapAdapterClassName = "DemoMapConvertMapperAdapter", + autoConfigPackage = "cn.easii", + autoMapperConfigClassName = "EasiiAutoMapperConfig", + autoMapMapperConfigClassName = "EasiiAutoMapMapperConfig") public class MapStructPlusConfiguration { } diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/A.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/A.java new file mode 100644 index 0000000..885d82a --- /dev/null +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/A.java @@ -0,0 +1,12 @@ +package io.github.linpeilie.model; + +import io.github.linpeilie.annotations.AutoMapping; +import lombok.Data; + +@Data +public class A { + + @AutoMapping(target = "createBy.id") + private Long createBy; + +} diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/AA.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/AA.java new file mode 100644 index 0000000..0473775 --- /dev/null +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/AA.java @@ -0,0 +1,13 @@ +package io.github.linpeilie.model; + +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import lombok.Data; + +@AutoMapper(target = BB.class) +@Data +public class AA extends A { + + private String name; + +} diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/B.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/B.java new file mode 100644 index 0000000..e7d3c97 --- /dev/null +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/B.java @@ -0,0 +1,10 @@ +package io.github.linpeilie.model; + +import lombok.Data; + +@Data +public class B { + + private C createBy; + +} diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BB.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BB.java new file mode 100644 index 0000000..d4a1383 --- /dev/null +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BB.java @@ -0,0 +1,10 @@ +package io.github.linpeilie.model; + +import lombok.Data; + +@Data +public class BB extends B { + + private String name; + +} diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BaseDTO.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BaseDTO.java new file mode 100644 index 0000000..6519f89 --- /dev/null +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BaseDTO.java @@ -0,0 +1,12 @@ +package io.github.linpeilie.model; + +import io.github.linpeilie.annotations.AutoMapping; +import lombok.Data; + +@Data +public class BaseDTO { + + @AutoMapping(target = "success", targetClass = BaseVO.class, ignore = true) + private Boolean success; + +} diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BaseVO.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BaseVO.java new file mode 100644 index 0000000..177ec2c --- /dev/null +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/BaseVO.java @@ -0,0 +1,12 @@ +package io.github.linpeilie.model; + +import io.github.linpeilie.annotations.AutoMapping; +import lombok.Data; + +@Data +public class BaseVO { + + @AutoMapping(target = "success", targetClass = BaseDTO.class, ignore = true) + private Integer success; + +} diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/C.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/C.java new file mode 100644 index 0000000..962ec03 --- /dev/null +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/C.java @@ -0,0 +1,10 @@ +package io.github.linpeilie.model; + +import lombok.Data; + +@Data +public class C { + + private Long id; + +} diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/Car.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/Car.java index 8e37150..23aba5f 100644 --- a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/Car.java +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/Car.java @@ -17,4 +17,9 @@ public class Car { @AutoMapping(target = "wheels", ignore = true) private Wheels wheels; + @Data + public static class InnerClass { + private String f; + } + } diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/GoodsDto.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/GoodsDto.java index 0418d7d..7e9c50e 100644 --- a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/GoodsDto.java +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/GoodsDto.java @@ -1,18 +1,22 @@ package io.github.linpeilie.model; import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMappers; import io.github.linpeilie.annotations.AutoMapping; import java.util.Date; import lombok.Data; @Data -@AutoMapper(target = Goods.class) -public class GoodsDto { +@AutoMappers({ + @AutoMapper(target = Goods.class), + @AutoMapper(target = GoodsVo.class) +}) +public class GoodsDto extends BaseDTO { - @AutoMapping(target = "takeDownTime", dateFormat = "yyyy-MM-dd HH:mm:ss") + @AutoMapping(targetClass = Goods.class, target = "takeDownTime", dateFormat = "yyyy-MM-dd HH:mm:ss") private Date takeDownTime; - @AutoMapping(target = "price", numberFormat = "$#.00") + @AutoMapping(targetClass = Goods.class, target = "price", numberFormat = "$#.00") private int price; private Integer state; diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/GoodsVo.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/GoodsVo.java index e411eea..deb4910 100644 --- a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/GoodsVo.java +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/GoodsVo.java @@ -1,9 +1,11 @@ package io.github.linpeilie.model; +import io.github.linpeilie.annotations.AutoMapper; import lombok.Data; @Data -public class GoodsVo { +@AutoMapper(target = GoodsDto.class) +public class GoodsVo extends BaseVO { private Integer price; diff --git a/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/InnerClassTarget.java b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/InnerClassTarget.java new file mode 100644 index 0000000..c425fba --- /dev/null +++ b/example/spring-boot-with-lombok/src/main/java/io/github/linpeilie/model/InnerClassTarget.java @@ -0,0 +1,12 @@ +package io.github.linpeilie.model; + +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +@Data +@AutoMapper(target = Car.InnerClass.class) +public class InnerClassTarget { + + private String f; + +} diff --git a/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/AutoMapperProcessor.java b/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/AutoMapperProcessor.java index 988f9ee..be2d558 100644 --- a/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/AutoMapperProcessor.java +++ b/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/AutoMapperProcessor.java @@ -399,6 +399,15 @@ public class AutoMapperProcessor extends AbstractProcessor { if (StrUtil.isNotEmpty(mapperConfig.mapAdapterClassName())) { AutoMapperProperties.setMapAdapterClassName(mapperConfig.mapAdapterClassName()); } + if (StrUtil.isNotEmpty(mapperConfig.autoConfigPackage())) { + AutoMapperProperties.setAutoConfigPackage(mapperConfig.autoConfigPackage()); + } + if (StrUtil.isNotEmpty(mapperConfig.autoMapperConfigClassName())) { + AutoMapperProperties.setAutoMapperConfigClassName(mapperConfig.autoMapperConfigClassName()); + } + if (StrUtil.isNotEmpty(mapperConfig.autoMapMapperConfigClassName())) { + AutoMapperProperties.setAutoMapMapperConfigClassName(mapperConfig.autoMapMapperConfigClassName()); + } } private void refreshProperties(final Set annotations, final RoundEnvironment roundEnv) { @@ -621,7 +630,24 @@ public class AutoMapperProcessor extends AbstractProcessor { if (target.reflectionName().contentEquals(mappingMetadata.getTargetClass().reflectionName())) { return true; } - return false; + TypeElement targetTypeElement = classNameToTypeElement(target); + Optional superClass = getSuperClass(targetTypeElement); + return superClass.filter(typeElement -> isTargetFieldMapping(ClassName.get(typeElement), mappingMetadata)) + .isPresent(); + } + + private Optional getSuperClass(TypeElement ele) { + TypeMirror superclass = ele.getSuperclass(); + if (superclass == null) { + return Optional.empty(); + } + if ("java.lang.Object".equals(superclass.toString())) { + return Optional.empty(); + } + if (ele.getQualifiedName().contentEquals(superclass.toString())) { + return Optional.empty(); + } + return Optional.of((TypeElement) processingEnv.getTypeUtils().asElement(superclass)); } private AutoMapperMetadata buildAutoMapperMetadata(final AutoMapper autoMapper, final Element ele) { @@ -672,6 +698,11 @@ public class AutoMapperProcessor extends AbstractProcessor { } } } + + // super class + getSuperClass(ele) + .ifPresent(superClass -> list.addAll(buildFieldReverseMappingMetadata(superClass))); + list.removeIf(Objects::isNull); return list; } @@ -738,6 +769,10 @@ public class AutoMapperProcessor extends AbstractProcessor { } } + // add super class AutoMappings + getSuperClass(autoMapperEle) + .ifPresent(superClass -> list.addAll(buildFieldMappingMetadata(superClass))); + list.removeIf(Objects::isNull); return list; } @@ -801,6 +836,11 @@ public class AutoMapperProcessor extends AbstractProcessor { .collect(Collectors.toList()); } + private TypeElement classNameToTypeElement(ClassName className) { + String classNameString = className.toString(); + return processingEnv.getElementUtils().getTypeElement(classNameString); + } + @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported(); diff --git a/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/AutoMapperProperties.java b/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/AutoMapperProperties.java index 1346394..1a72ec8 100644 --- a/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/AutoMapperProperties.java +++ b/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/AutoMapperProperties.java @@ -31,6 +31,12 @@ public class AutoMapperProperties { private static String mapAdapterClassName = DEFAULT_MAP_ADAPTER_CLASS_NAME; + private static String autoConfigPackage = DEFAULT_BASE_PACKAGE; + + private static String autoMapperConfigClassName = AUTO_MAPPER_CONFIG_CLASS_NAME; + + private static String autoMapMapperConfigClassName = AUTO_MAP_MAPPER_CONFIG_CLASS_NAME; + public static String getMapperPackage() { return mapperPackage; } @@ -60,15 +66,27 @@ public class AutoMapperProperties { } public static String getConfigPackage() { - return DEFAULT_BASE_PACKAGE; + return autoConfigPackage; + } + + public static void setAutoConfigPackage(String autoConfigPackage) { + AutoMapperProperties.autoConfigPackage = autoConfigPackage; } public static String getConfigClassName() { - return AUTO_MAPPER_CONFIG_CLASS_NAME; + return autoMapperConfigClassName; + } + + public static void setAutoMapperConfigClassName(String autoMapperConfigClassName) { + AutoMapperProperties.autoMapperConfigClassName = autoMapperConfigClassName; } public static String getMapConfigClassName() { - return AUTO_MAP_MAPPER_CONFIG_CLASS_NAME; + return autoMapMapperConfigClassName; + } + + public static void setAutoMapMapperConfigClassName(String autoMapMapperConfigClassName) { + AutoMapperProperties.autoMapMapperConfigClassName = autoMapMapperConfigClassName; } public static String getComponentModel() { diff --git a/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/ProcessorOptions.java b/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/ProcessorOptions.java index d19e226..9451c99 100644 --- a/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/ProcessorOptions.java +++ b/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/ProcessorOptions.java @@ -33,6 +33,12 @@ public class ProcessorOptions { public static final String MAP_ADAPTER_CLASS_NAME = "mapstruct.plus.mapAdapterClassName"; + public static final String AUTO_CONFIG_PACKAGE = "mapstruct.plus.autoConfigPackage"; + + public static final String AUTO_MAPPER_CONFIG_CLASS_NAME = "mapstruct.plus.autoMapperConfigClassName"; + + public static final String AUTO_MAP_MAPPER_CONFIG_CLASS_NAME = "mapstruct.plus.autoMapMapperConfigClassName"; + public static Map> optionConsumers() { final Map> consumerMap = new HashMap<>(); @@ -53,6 +59,9 @@ public class ProcessorOptions { consumerMap.put(ADAPTER_PACKAGE, AutoMapperProperties::setAdapterPackage); consumerMap.put(ADAPTER_CLASS_NAME, AutoMapperProperties::setAdapterClassName); consumerMap.put(MAP_ADAPTER_CLASS_NAME, AutoMapperProperties::setMapAdapterClassName); + consumerMap.put(AUTO_CONFIG_PACKAGE, AutoMapperProperties::setAutoConfigPackage); + consumerMap.put(AUTO_MAPPER_CONFIG_CLASS_NAME, AutoMapperProperties::setAutoMapperConfigClassName); + consumerMap.put(AUTO_MAP_MAPPER_CONFIG_CLASS_NAME, AutoMapperProperties::setAutoMapMapperConfigClassName); return consumerMap; } diff --git a/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/generator/AutoMapperGenerator.java b/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/generator/AutoMapperGenerator.java index 2051b74..893054b 100644 --- a/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/generator/AutoMapperGenerator.java +++ b/mapstruct-plus-processor/src/main/java/io/github/linpeilie/processor/generator/AutoMapperGenerator.java @@ -26,6 +26,7 @@ import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; import org.apache.commons.lang3.StringUtils; import static io.github.linpeilie.processor.Constants.*; @@ -90,7 +91,7 @@ public class AutoMapperGenerator { private boolean classIsImmutable(ProcessingEnvironment processingEnv, ClassName className) { final TypeElement targetElement = processingEnv.getElementUtils() - .getTypeElement(className.packageName() + "." + className.simpleName()); + .getTypeElement(className.reflectionName().replaceAll("\\$", ".")); final List annotationMirrors = targetElement.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { if (annotationMirror.getAnnotationType().asElement().getSimpleName().contentEquals("Immutable")) { diff --git a/mapstruct-plus/src/main/java/io/github/linpeilie/annotations/MapperConfig.java b/mapstruct-plus/src/main/java/io/github/linpeilie/annotations/MapperConfig.java index be66a36..9b5cd79 100644 --- a/mapstruct-plus/src/main/java/io/github/linpeilie/annotations/MapperConfig.java +++ b/mapstruct-plus/src/main/java/io/github/linpeilie/annotations/MapperConfig.java @@ -74,4 +74,28 @@ public @interface MapperConfig { */ String mapAdapterClassName() default ""; + /** + * MapStructPlus 所生成的配置类(AutoMapperConfig/AutoMapMapperConfig)包路径 + *
+ * 默认包路径为 io.github.linpeilie + * @return AutoMapperConfig / AutoMapMapperConfig 包路径 + */ + String autoConfigPackage() default ""; + + /** + * MapStructPlus 所生成的配置类转换的配置类名 + *
+ * 默认类名为 AutoMapperConfig + * @return AutoMapperConfig 类名 + */ + String autoMapperConfigClassName() default ""; + + /** + * MapStructPlus 所生成的配置 Map 与对象转换的配置类名 + *
+ * 默认类名为 AutoMapMapperConfig + * @return AutoMapMapperConfig 类名 + */ + String autoMapMapperConfigClassName() default ""; + } diff --git a/pom.xml b/pom.xml index f05ac5f..c908be3 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ - 1.3.5 + 1.3.6 8 8 UTF-8