From a306656827f41467162831f3cab52cf3e2704465 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 7 May 2017 14:05:10 +0200 Subject: [PATCH 01/13] protobuf example --- .../example/mapper/CustomerMapper.java | 4 +- .../example/mapper/OrderItemMapper.java | 4 +- .../example/{dto => protobuf}/Customer.java | 2 +- .../{dto => protobuf}/CustomerDto.java | 2 +- .../example/{dto => protobuf}/OrderItem.java | 2 +- .../{dto => protobuf}/OrderItemDto.java | 2 +- .../mapstruct/example/CustomerMapperTest.java | 16 +-- .../example/mapper/EmployeeMapper.java | 4 +- .../example/{dto => protobuf}/Employee.java | 2 +- .../{dto => protobuf}/EmployeeDto.java | 2 +- .../mapstruct/example/EmployeeMapperTest.java | 12 +- .../example/mapper/FishTankMapper.java | 2 +- .../mapper/FishTankMapperConstant.java | 2 +- .../mapper/FishTankMapperExpression.java | 2 +- .../mapper/FishTankMapperWithDocument.java | 2 +- .../example/{dto => protobuf}/FishDto.java | 2 +- .../{dto => protobuf}/FishTankDto.java | 2 +- .../FishTankWithNestedDocumentDto.java | 2 +- .../{dto => protobuf}/MaterialDto.java | 2 +- .../{dto => protobuf}/MaterialTypeDto.java | 2 +- .../{dto => protobuf}/OrnamentDto.java | 2 +- .../{dto => protobuf}/WaterPlantDto.java | 2 +- .../{dto => protobuf}/WaterQualityDto.java | 2 +- .../WaterQualityOrganisationDto.java | 2 +- .../WaterQualityReportDto.java | 2 +- .../WaterQualityWithDocumentDto.java | 2 +- .../example/FishTanksMappersTest.java | 4 +- mapstruct-protobuf3/pom.xml | 75 ++++++++++++ mapstruct-protobuf3/spi-impl/pom.xml | 41 +++++++ .../ProtobufAccessorNamingStrategy.java | 30 +++++ ...rg.mapstruct.ap.spi.AccessorNamingStrategy | 1 + mapstruct-protobuf3/usage/pom.xml | 114 ++++++++++++++++++ .../mapstruct/example/mapper/UserMapper.java | 56 +++++++++ .../example/protobuf/Permission.java | 11 ++ .../org/mapstruct/example/protobuf/User.java | 38 ++++++ .../usage/src/main/proto/User.proto | 17 +++ .../java/org/mapstruct/example/SpiTest.java | 46 +++++++ .../example/mapper/SourceTargetMapper.java | 4 +- .../example/{dto => protobuf}/Source.java | 2 +- .../example/{dto => protobuf}/Target.java | 2 +- .../example/SourceTargetMapperTest.java | 10 +- .../example/mapper/GolfPlayerMapper.java | 4 +- .../example/{dto => protobuf}/GolfPlayer.java | 2 +- .../{dto => protobuf}/GolfPlayerDto.java | 2 +- .../java/org/mapstruct/example/SpiTest.java | 4 +- .../example/mapper/SourceTargetMapper.java | 4 +- .../example/{dto => protobuf}/MammalDto.java | 4 +- .../{dto => protobuf}/MammalEntity.java | 2 +- .../example/SourceTargetMapperTest.java | 9 +- .../example/SourceTargetTestMapperTest.java | 4 +- .../mapper/SourceTargetTestMapper.java | 4 +- pom.xml | 1 + 52 files changed, 502 insertions(+), 71 deletions(-) rename mapstruct-field-mapping/src/main/java/org/mapstruct/example/{dto => protobuf}/Customer.java (97%) rename mapstruct-field-mapping/src/main/java/org/mapstruct/example/{dto => protobuf}/CustomerDto.java (96%) rename mapstruct-field-mapping/src/main/java/org/mapstruct/example/{dto => protobuf}/OrderItem.java (90%) rename mapstruct-field-mapping/src/main/java/org/mapstruct/example/{dto => protobuf}/OrderItemDto.java (74%) rename mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/{dto => protobuf}/Employee.java (97%) rename mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/{dto => protobuf}/EmployeeDto.java (97%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/FishDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/FishTankDto.java (98%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/FishTankWithNestedDocumentDto.java (98%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/MaterialDto.java (97%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/MaterialTypeDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/OrnamentDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/WaterPlantDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/WaterQualityDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/WaterQualityOrganisationDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/WaterQualityReportDto.java (97%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{dto => protobuf}/WaterQualityWithDocumentDto.java (96%) create mode 100644 mapstruct-protobuf3/pom.xml create mode 100644 mapstruct-protobuf3/spi-impl/pom.xml create mode 100644 mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java create mode 100644 mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy create mode 100644 mapstruct-protobuf3/usage/pom.xml create mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java create mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java create mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java create mode 100644 mapstruct-protobuf3/usage/src/main/proto/User.proto create mode 100644 mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java rename mapstruct-rounding/src/main/java/org/mapstruct/example/{dto => protobuf}/Source.java (97%) rename mapstruct-rounding/src/main/java/org/mapstruct/example/{dto => protobuf}/Target.java (97%) rename mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/{dto => protobuf}/GolfPlayer.java (96%) rename mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/{dto => protobuf}/GolfPlayerDto.java (96%) rename mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/{dto => protobuf}/MammalDto.java (94%) rename mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/{dto => protobuf}/MammalEntity.java (97%) diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java index a939057..3a674a3 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java @@ -22,8 +22,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import org.mapstruct.example.dto.Customer; -import org.mapstruct.example.dto.CustomerDto; +import org.mapstruct.example.protobuf.Customer; +import org.mapstruct.example.protobuf.CustomerDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java index 43868eb..e9839a4 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java @@ -21,8 +21,8 @@ import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; -import org.mapstruct.example.dto.OrderItem; -import org.mapstruct.example.dto.OrderItemDto; +import org.mapstruct.example.protobuf.OrderItem; +import org.mapstruct.example.protobuf.OrderItemDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/Customer.java similarity index 97% rename from mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java rename to mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/Customer.java index 9295570..789d087 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/Customer.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; import java.util.Collection; diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/CustomerDto.java similarity index 96% rename from mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java rename to mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/CustomerDto.java index 7537a61..a5940a2 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/CustomerDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; import java.util.List; diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItem.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItem.java similarity index 90% rename from mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItem.java rename to mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItem.java index 384f6d6..5bcdeb9 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItem.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItem.java @@ -1,4 +1,4 @@ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * @author Filip Hrisafov diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItemDto.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItemDto.java similarity index 74% rename from mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItemDto.java rename to mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItemDto.java index 3ad7457..b8c65ae 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItemDto.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItemDto.java @@ -1,4 +1,4 @@ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * @author Filip Hrisafov diff --git a/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java b/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java index 5aaf5f1..c3e19ce 100644 --- a/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java +++ b/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java @@ -18,18 +18,18 @@ */ package org.mapstruct.example; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; +import org.junit.Test; +import org.mapstruct.example.mapper.CustomerMapper; +import org.mapstruct.example.protobuf.Customer; +import org.mapstruct.example.protobuf.CustomerDto; +import org.mapstruct.example.protobuf.OrderItem; +import org.mapstruct.example.protobuf.OrderItemDto; import java.util.ArrayList; import java.util.Collections; -import org.junit.Test; -import org.mapstruct.example.dto.Customer; -import org.mapstruct.example.dto.CustomerDto; -import org.mapstruct.example.dto.OrderItem; -import org.mapstruct.example.dto.OrderItemDto; -import org.mapstruct.example.mapper.CustomerMapper; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; /** * diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java index 11fc87b..3bbc39f 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java @@ -22,8 +22,8 @@ import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.example.dto.Employee; -import org.mapstruct.example.dto.EmployeeDto; +import org.mapstruct.example.protobuf.Employee; +import org.mapstruct.example.protobuf.EmployeeDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/Employee.java similarity index 97% rename from mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java rename to mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/Employee.java index 64fc4b7..2cc92c9 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/Employee.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; import java.util.List; diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/EmployeeDto.java similarity index 97% rename from mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java rename to mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/EmployeeDto.java index 5d5fd64..3e4b43b 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/EmployeeDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; import java.util.List; diff --git a/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java b/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java index b4a87e2..054b56b 100644 --- a/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java +++ b/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java @@ -18,16 +18,16 @@ */ package org.mapstruct.example; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; +import org.mapstruct.example.mapper.CycleAvoidingMappingContext; +import org.mapstruct.example.mapper.EmployeeMapper; +import org.mapstruct.example.protobuf.Employee; +import org.mapstruct.example.protobuf.EmployeeDto; import java.util.Arrays; import java.util.List; -import org.junit.Test; -import org.mapstruct.example.dto.Employee; -import org.mapstruct.example.dto.EmployeeDto; -import org.mapstruct.example.mapper.CycleAvoidingMappingContext; -import org.mapstruct.example.mapper.EmployeeMapper; +import static org.assertj.core.api.Assertions.assertThat; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java index 995927f..700c130 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java @@ -22,8 +22,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; +import org.mapstruct.example.protobuf.FishTankDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java index bf7ed73..2b77ff7 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java @@ -21,8 +21,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; +import org.mapstruct.example.protobuf.FishTankDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java index 681a347..7bbdc68 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java @@ -21,8 +21,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; +import org.mapstruct.example.protobuf.FishTankDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java index 81d1fac..fba2a22 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java @@ -21,8 +21,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import org.mapstruct.example.dto.FishTankWithNestedDocumentDto; import org.mapstruct.example.model.FishTank; +import org.mapstruct.example.protobuf.FishTankWithNestedDocumentDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishDto.java index 7df7735..6b615c5 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankDto.java similarity index 98% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankDto.java index 02f60e7..1cc41af 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankWithNestedDocumentDto.java similarity index 98% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankWithNestedDocumentDto.java index 093ded0..2a2ba4d 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankWithNestedDocumentDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialDto.java similarity index 97% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialDto.java index cecc43c..f34ac45 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialTypeDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialTypeDto.java index 22d5f0a..d917b30 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialTypeDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/OrnamentDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/OrnamentDto.java index 3e6d40f..067e269 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/OrnamentDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterPlantDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterPlantDto.java index bbf06de..09091ee 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterPlantDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityDto.java index 5012a57..8bf7f68 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityOrganisationDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityOrganisationDto.java index fba834a..6787c46 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityOrganisationDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityReportDto.java similarity index 97% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityReportDto.java index 4c8b957..fbe7296 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityReportDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityWithDocumentDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityWithDocumentDto.java index c332bc1..462fab4 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityWithDocumentDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java b/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java index 3ef79fc..6f0437f 100644 --- a/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java +++ b/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java @@ -19,8 +19,6 @@ package org.mapstruct.example; import org.junit.Test; -import org.mapstruct.example.dto.FishTankDto; -import org.mapstruct.example.dto.FishTankWithNestedDocumentDto; import org.mapstruct.example.mapper.FishTankMapper; import org.mapstruct.example.mapper.FishTankMapperConstant; import org.mapstruct.example.mapper.FishTankMapperExpression; @@ -33,6 +31,8 @@ import org.mapstruct.example.model.WaterPlant; import org.mapstruct.example.model.WaterQuality; import org.mapstruct.example.model.WaterQualityReport; +import org.mapstruct.example.protobuf.FishTankDto; +import org.mapstruct.example.protobuf.FishTankWithNestedDocumentDto; import static org.assertj.core.api.Assertions.assertThat; diff --git a/mapstruct-protobuf3/pom.xml b/mapstruct-protobuf3/pom.xml new file mode 100644 index 0000000..7de5ced --- /dev/null +++ b/mapstruct-protobuf3/pom.xml @@ -0,0 +1,75 @@ + + + + 4.0.0 + + org.mapstruct.examples.spi + protobuf-parent + 1.0.0 + pom + + + 1.2.0.Beta1 + 1.8 + 1.8 + + + + spi-impl + usage + + + + + + org.mapstruct + mapstruct-jdk8 + ${org.mapstruct.version} + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + junit + junit + 4.12 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + + + + diff --git a/mapstruct-protobuf3/spi-impl/pom.xml b/mapstruct-protobuf3/spi-impl/pom.xml new file mode 100644 index 0000000..7bfd7d5 --- /dev/null +++ b/mapstruct-protobuf3/spi-impl/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.mapstruct.examples.spi + protobuf-parent + 1.0.0 + + + protobuf-spi-impl + 1.0.0 + + + + org.mapstruct + mapstruct-processor + + + diff --git a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java new file mode 100644 index 0000000..a61f8f6 --- /dev/null +++ b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java @@ -0,0 +1,30 @@ +package org.mapstruct.example.protobuf; + +import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; + +public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrategy { + + @Override + public String getElementName(ExecutableElement adderMethod) { + + String methodName = super.getPropertyName(adderMethod); + Element receiver = adderMethod.getEnclosingElement(); + if (receiver != null) { + TypeElement type = (TypeElement) ((DeclaredType) receiver).asElement(); + if (type != null) { + TypeMirror superType = type.getSuperclass(); + if ("com.google.protobuf.GeneratedMessageV3".equals(superType.toString())) { + methodName += "List"; + } + } + } + return methodName; + } + +} \ No newline at end of file diff --git a/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy b/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy new file mode 100644 index 0000000..93e2eb3 --- /dev/null +++ b/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy @@ -0,0 +1 @@ +org.mapstruct.example.protobuf.ProtobufAccessorNamingStrategy diff --git a/mapstruct-protobuf3/usage/pom.xml b/mapstruct-protobuf3/usage/pom.xml new file mode 100644 index 0000000..d4e351a --- /dev/null +++ b/mapstruct-protobuf3/usage/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + + org.mapstruct.examples.spi + protobuf-parent + 1.0.0 + + + protobuf-usage + 1.0.0-SNAPSHOT + + + + org.mapstruct + mapstruct-jdk8 + + + com.google.protobuf + protobuf-java + 3.2.0 + + + junit + junit + 4.12 + test + + + + + + + kr.motd.maven + os-maven-plugin + 1.4.0.Final + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.5.0 + + + generate-sources + + compile + compile-custom + + + com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier} + + grpc-java + io.grpc:protoc-gen-grpc-java:1.2.0:exe:${os.detected.classifier} + + + + + + + maven-compiler-plugin + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + org.mapstruct.examples.spi + protobuf-spi-impl + 1.0.0 + + + + + + + + diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java new file mode 100644 index 0000000..2d1a9ad --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java @@ -0,0 +1,56 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.example.mapper; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.example.mapper.UserMapper.BuilderFactory; +import org.mapstruct.example.protobuf.Permission; +import org.mapstruct.example.protobuf.User; +import org.mapstruct.example.protobuf.UserProtos.PermissionDTO; +import org.mapstruct.example.protobuf.UserProtos.UserDTO; +import org.mapstruct.factory.Mappers; + +@Mapper(uses = BuilderFactory.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface UserMapper { + + UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); + + + @Mapping(source = "permissions", target = "permissionsList") + UserDTO.Builder map(User user); + + @Mapping(source = "permissionsList", target = "permissions") + User map(UserDTO userDTO); + + @ValueMapping(source = "UNRECOGNIZED", target = MappingConstants.NULL) + Permission map(PermissionDTO permissionDTO); + + PermissionDTO map(Permission perm); + + + class BuilderFactory { + UserDTO.Builder builder() { + return UserDTO.newBuilder(); + } + } +} diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java new file mode 100644 index 0000000..fd75a2b --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java @@ -0,0 +1,11 @@ +package org.mapstruct.example.protobuf; + +/** + * Created by thomas on 07.05.17. + */ +public enum Permission { + + ADMIN, + USER, + NONE +} diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java new file mode 100644 index 0000000..957659a --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java @@ -0,0 +1,38 @@ +package org.mapstruct.example.protobuf; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by thomas on 07.05.17. + */ +public class User { + + private String id; + private String email; + private List permissions = new ArrayList<>(); + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public List getPermissions() { + return permissions; + } + + public void setPermissions(List permissions) { + this.permissions = permissions; + } +} diff --git a/mapstruct-protobuf3/usage/src/main/proto/User.proto b/mapstruct-protobuf3/usage/src/main/proto/User.proto new file mode 100644 index 0000000..bcb8652 --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/proto/User.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + + +option java_package = "org.mapstruct.example.protobuf"; +option java_outer_classname = "UserProtos"; + +message UserDTO { + string id = 1; + string email = 2; + repeated PermissionDTO permissions = 3; +} + +enum PermissionDTO { + NONE = 0; + USER = 1; + ADMIN = 2; +} \ No newline at end of file diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java new file mode 100644 index 0000000..3d86125 --- /dev/null +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.example; + +import org.junit.Assert; +import org.junit.Test; +import org.mapstruct.example.mapper.UserMapper; +import org.mapstruct.example.protobuf.GolfPlayer; +import org.mapstruct.example.protobuf.GolfPlayerDto; + +/** + * @author Sjaak Derksen + */ +public class SpiTest { + /** + * Test if everything is working when sources are present + */ + @Test + public void test() { + GolfPlayer golfPlayer1 = new GolfPlayer(); + golfPlayer1.withName("Tiger Woods").withHandicap(12); + + GolfPlayerDto dto = UserMapper.INSTANCE.toDto(golfPlayer1); + + GolfPlayer golfPlayer2 = UserMapper.INSTANCE.toPlayer(dto); + + Assert.assertEquals("Tiger Woods", golfPlayer2.name()); + Assert.assertEquals(12L, golfPlayer2.handicap(), 0); + } +} diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java index 69e5da1..9f397c3 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java @@ -22,11 +22,11 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import org.mapstruct.example.dto.Source; -import org.mapstruct.example.dto.Target; import org.mapstruct.example.mapper.util.RoundingUtil; import org.mapstruct.example.mapper.util.RoundingUtil.Fraction2; import org.mapstruct.example.mapper.util.RoundingUtil.Fraction3; +import org.mapstruct.example.protobuf.Source; +import org.mapstruct.example.protobuf.Target; import org.mapstruct.factory.Mappers; diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Source.java similarity index 97% rename from mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java rename to mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Source.java index d088133..7b8d66c 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Source.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; import java.math.BigDecimal; diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Target.java similarity index 97% rename from mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java rename to mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Target.java index 4e791f0..4c59bea 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Target.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; import java.math.BigDecimal; diff --git a/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java b/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java index 81a3098..fa991f3 100644 --- a/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java +++ b/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java @@ -18,12 +18,14 @@ */ package org.mapstruct.example; -import java.math.BigDecimal; -import org.mapstruct.example.mapper.SourceTargetMapper; import org.junit.Test; +import org.mapstruct.example.mapper.SourceTargetMapper; +import org.mapstruct.example.protobuf.Source; +import org.mapstruct.example.protobuf.Target; + +import java.math.BigDecimal; + import static org.junit.Assert.assertEquals; -import org.mapstruct.example.dto.Source; -import org.mapstruct.example.dto.Target; /** * diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java index 421d579..9821060 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java @@ -18,9 +18,9 @@ */ package org.mapstruct.example.mapper; -import org.mapstruct.example.dto.GolfPlayerDto; -import org.mapstruct.example.dto.GolfPlayer; import org.mapstruct.Mapper; +import org.mapstruct.example.protobuf.GolfPlayer; +import org.mapstruct.example.protobuf.GolfPlayerDto; import org.mapstruct.factory.Mappers; @Mapper diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayer.java similarity index 96% rename from mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java rename to mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayer.java index 0eecd31..234f921 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayer.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * @author Gunnar Morling diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayerDto.java similarity index 96% rename from mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java rename to mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayerDto.java index 197ae36..321bc06 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayerDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** * @author Gunnar Morling diff --git a/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java index 999bcb5..b51f95b 100644 --- a/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java +++ b/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java @@ -20,9 +20,9 @@ import org.junit.Assert; import org.junit.Test; -import org.mapstruct.example.dto.GolfPlayer; -import org.mapstruct.example.dto.GolfPlayerDto; import org.mapstruct.example.mapper.GolfPlayerMapper; +import org.mapstruct.example.protobuf.GolfPlayer; +import org.mapstruct.example.protobuf.GolfPlayerDto; /** * @author Sjaak Derksen diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java index e63b966..7cbca28 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java @@ -23,8 +23,8 @@ import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; -import org.mapstruct.example.dto.MammalDto; -import org.mapstruct.example.dto.MammalEntity; +import org.mapstruct.example.protobuf.MammalDto; +import org.mapstruct.example.protobuf.MammalEntity; import org.mapstruct.factory.Mappers; diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalDto.java similarity index 94% rename from mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java rename to mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalDto.java index e2f8cb2..be6cb68 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalDto.java @@ -16,9 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; - -import java.math.BigDecimal; +package org.mapstruct.example.protobuf; /** * diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalEntity.java similarity index 97% rename from mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java rename to mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalEntity.java index 3a6f118..77ac222 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalEntity.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.dto; +package org.mapstruct.example.protobuf; /** diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java index 56911aa..a3d4c99 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java @@ -18,11 +18,12 @@ */ package org.mapstruct.example; -import static org.fest.assertions.Assertions.assertThat; -import org.mapstruct.example.mapper.SourceTargetMapper; import org.junit.Test; -import org.mapstruct.example.dto.MammalDto; -import org.mapstruct.example.dto.MammalEntity; +import org.mapstruct.example.mapper.SourceTargetMapper; +import org.mapstruct.example.protobuf.MammalDto; +import org.mapstruct.example.protobuf.MammalEntity; + +import static org.fest.assertions.Assertions.assertThat; /** diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java index 52bb77d..235aef4 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java @@ -19,9 +19,9 @@ package org.mapstruct.example; import org.junit.Test; -import org.mapstruct.example.dto.MammalDto; -import org.mapstruct.example.dto.MammalEntity; import org.mapstruct.example.mapper.SourceTargetTestMapper; +import org.mapstruct.example.protobuf.MammalDto; +import org.mapstruct.example.protobuf.MammalEntity; import static org.fest.assertions.Assertions.assertThat; diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java index 990e350..907feb0 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java @@ -23,8 +23,8 @@ import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; -import org.mapstruct.example.dto.MammalDto; -import org.mapstruct.example.dto.MammalEntity; +import org.mapstruct.example.protobuf.MammalDto; +import org.mapstruct.example.protobuf.MammalEntity; import org.mapstruct.factory.Mappers; /** diff --git a/pom.xml b/pom.xml index ee97813..e216551 100644 --- a/pom.xml +++ b/pom.xml @@ -36,5 +36,6 @@ mapstruct-rounding mapstruct-spi-accessor-naming mapstruct-updatemethods-1 + mapstruct-protobuf3 From 56d5242f590a081048e0eeda7bdc2088eb985f1d Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 7 May 2017 14:10:19 +0200 Subject: [PATCH 02/13] Revert "protobuf example" This reverts commit a306656827f41467162831f3cab52cf3e2704465. --- .../example/{protobuf => dto}/Customer.java | 2 +- .../{protobuf => dto}/CustomerDto.java | 2 +- .../example/{protobuf => dto}/OrderItem.java | 2 +- .../{protobuf => dto}/OrderItemDto.java | 2 +- .../example/mapper/CustomerMapper.java | 4 +- .../example/mapper/OrderItemMapper.java | 4 +- .../mapstruct/example/CustomerMapperTest.java | 16 +-- .../example/{protobuf => dto}/Employee.java | 2 +- .../{protobuf => dto}/EmployeeDto.java | 2 +- .../example/mapper/EmployeeMapper.java | 4 +- .../mapstruct/example/EmployeeMapperTest.java | 12 +- .../example/{protobuf => dto}/FishDto.java | 2 +- .../{protobuf => dto}/FishTankDto.java | 2 +- .../FishTankWithNestedDocumentDto.java | 2 +- .../{protobuf => dto}/MaterialDto.java | 2 +- .../{protobuf => dto}/MaterialTypeDto.java | 2 +- .../{protobuf => dto}/OrnamentDto.java | 2 +- .../{protobuf => dto}/WaterPlantDto.java | 2 +- .../{protobuf => dto}/WaterQualityDto.java | 2 +- .../WaterQualityOrganisationDto.java | 2 +- .../WaterQualityReportDto.java | 2 +- .../WaterQualityWithDocumentDto.java | 2 +- .../example/mapper/FishTankMapper.java | 2 +- .../mapper/FishTankMapperConstant.java | 2 +- .../mapper/FishTankMapperExpression.java | 2 +- .../mapper/FishTankMapperWithDocument.java | 2 +- .../example/FishTanksMappersTest.java | 4 +- mapstruct-protobuf3/pom.xml | 75 ------------ mapstruct-protobuf3/spi-impl/pom.xml | 41 ------- .../ProtobufAccessorNamingStrategy.java | 30 ----- ...rg.mapstruct.ap.spi.AccessorNamingStrategy | 1 - mapstruct-protobuf3/usage/pom.xml | 114 ------------------ .../mapstruct/example/mapper/UserMapper.java | 56 --------- .../example/protobuf/Permission.java | 11 -- .../org/mapstruct/example/protobuf/User.java | 38 ------ .../usage/src/main/proto/User.proto | 17 --- .../java/org/mapstruct/example/SpiTest.java | 46 ------- .../example/{protobuf => dto}/Source.java | 2 +- .../example/{protobuf => dto}/Target.java | 2 +- .../example/mapper/SourceTargetMapper.java | 4 +- .../example/SourceTargetMapperTest.java | 10 +- .../example/{protobuf => dto}/GolfPlayer.java | 2 +- .../{protobuf => dto}/GolfPlayerDto.java | 2 +- .../example/mapper/GolfPlayerMapper.java | 4 +- .../java/org/mapstruct/example/SpiTest.java | 4 +- .../example/{protobuf => dto}/MammalDto.java | 4 +- .../{protobuf => dto}/MammalEntity.java | 2 +- .../example/mapper/SourceTargetMapper.java | 4 +- .../example/SourceTargetMapperTest.java | 9 +- .../example/SourceTargetTestMapperTest.java | 4 +- .../mapper/SourceTargetTestMapper.java | 4 +- pom.xml | 1 - 52 files changed, 71 insertions(+), 502 deletions(-) rename mapstruct-field-mapping/src/main/java/org/mapstruct/example/{protobuf => dto}/Customer.java (97%) rename mapstruct-field-mapping/src/main/java/org/mapstruct/example/{protobuf => dto}/CustomerDto.java (96%) rename mapstruct-field-mapping/src/main/java/org/mapstruct/example/{protobuf => dto}/OrderItem.java (90%) rename mapstruct-field-mapping/src/main/java/org/mapstruct/example/{protobuf => dto}/OrderItemDto.java (74%) rename mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/{protobuf => dto}/Employee.java (97%) rename mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/{protobuf => dto}/EmployeeDto.java (97%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/FishDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/FishTankDto.java (98%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/FishTankWithNestedDocumentDto.java (98%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/MaterialDto.java (97%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/MaterialTypeDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/OrnamentDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/WaterPlantDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/WaterQualityDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/WaterQualityOrganisationDto.java (96%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/WaterQualityReportDto.java (97%) rename mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/{protobuf => dto}/WaterQualityWithDocumentDto.java (96%) delete mode 100644 mapstruct-protobuf3/pom.xml delete mode 100644 mapstruct-protobuf3/spi-impl/pom.xml delete mode 100644 mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java delete mode 100644 mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy delete mode 100644 mapstruct-protobuf3/usage/pom.xml delete mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java delete mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java delete mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java delete mode 100644 mapstruct-protobuf3/usage/src/main/proto/User.proto delete mode 100644 mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java rename mapstruct-rounding/src/main/java/org/mapstruct/example/{protobuf => dto}/Source.java (97%) rename mapstruct-rounding/src/main/java/org/mapstruct/example/{protobuf => dto}/Target.java (97%) rename mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/{protobuf => dto}/GolfPlayer.java (96%) rename mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/{protobuf => dto}/GolfPlayerDto.java (96%) rename mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/{protobuf => dto}/MammalDto.java (94%) rename mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/{protobuf => dto}/MammalEntity.java (97%) diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/Customer.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java similarity index 97% rename from mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/Customer.java rename to mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java index 789d087..9295570 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/Customer.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; import java.util.Collection; diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/CustomerDto.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java similarity index 96% rename from mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/CustomerDto.java rename to mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java index a5940a2..7537a61 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/CustomerDto.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; import java.util.List; diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItem.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItem.java similarity index 90% rename from mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItem.java rename to mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItem.java index 5bcdeb9..384f6d6 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItem.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItem.java @@ -1,4 +1,4 @@ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * @author Filip Hrisafov diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItemDto.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItemDto.java similarity index 74% rename from mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItemDto.java rename to mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItemDto.java index b8c65ae..3ad7457 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/protobuf/OrderItemDto.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/OrderItemDto.java @@ -1,4 +1,4 @@ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * @author Filip Hrisafov diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java index 3a674a3..a939057 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java @@ -22,8 +22,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import org.mapstruct.example.protobuf.Customer; -import org.mapstruct.example.protobuf.CustomerDto; +import org.mapstruct.example.dto.Customer; +import org.mapstruct.example.dto.CustomerDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java index e9839a4..43868eb 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java @@ -21,8 +21,8 @@ import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; -import org.mapstruct.example.protobuf.OrderItem; -import org.mapstruct.example.protobuf.OrderItemDto; +import org.mapstruct.example.dto.OrderItem; +import org.mapstruct.example.dto.OrderItemDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java b/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java index c3e19ce..5aaf5f1 100644 --- a/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java +++ b/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java @@ -18,18 +18,18 @@ */ package org.mapstruct.example; -import org.junit.Test; -import org.mapstruct.example.mapper.CustomerMapper; -import org.mapstruct.example.protobuf.Customer; -import org.mapstruct.example.protobuf.CustomerDto; -import org.mapstruct.example.protobuf.OrderItem; -import org.mapstruct.example.protobuf.OrderItemDto; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; import java.util.ArrayList; import java.util.Collections; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; +import org.junit.Test; +import org.mapstruct.example.dto.Customer; +import org.mapstruct.example.dto.CustomerDto; +import org.mapstruct.example.dto.OrderItem; +import org.mapstruct.example.dto.OrderItemDto; +import org.mapstruct.example.mapper.CustomerMapper; /** * diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/Employee.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java similarity index 97% rename from mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/Employee.java rename to mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java index 2cc92c9..64fc4b7 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/Employee.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; import java.util.List; diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/EmployeeDto.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java similarity index 97% rename from mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/EmployeeDto.java rename to mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java index 3e4b43b..5d5fd64 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/protobuf/EmployeeDto.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; import java.util.List; diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java index 3bbc39f..11fc87b 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java @@ -22,8 +22,8 @@ import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.example.protobuf.Employee; -import org.mapstruct.example.protobuf.EmployeeDto; +import org.mapstruct.example.dto.Employee; +import org.mapstruct.example.dto.EmployeeDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java b/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java index 054b56b..b4a87e2 100644 --- a/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java +++ b/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java @@ -18,16 +18,16 @@ */ package org.mapstruct.example; -import org.junit.Test; -import org.mapstruct.example.mapper.CycleAvoidingMappingContext; -import org.mapstruct.example.mapper.EmployeeMapper; -import org.mapstruct.example.protobuf.Employee; -import org.mapstruct.example.protobuf.EmployeeDto; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; +import org.mapstruct.example.dto.Employee; +import org.mapstruct.example.dto.EmployeeDto; +import org.mapstruct.example.mapper.CycleAvoidingMappingContext; +import org.mapstruct.example.mapper.EmployeeMapper; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java index 6b615c5..7df7735 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java similarity index 98% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java index 1cc41af..02f60e7 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankWithNestedDocumentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java similarity index 98% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankWithNestedDocumentDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java index 2a2ba4d..093ded0 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/FishTankWithNestedDocumentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java similarity index 97% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java index f34ac45..cecc43c 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialTypeDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialTypeDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java index d917b30..22d5f0a 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/MaterialTypeDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/OrnamentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/OrnamentDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java index 067e269..3e6d40f 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/OrnamentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterPlantDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterPlantDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java index 09091ee..bbf06de 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterPlantDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java index 8bf7f68..5012a57 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityOrganisationDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityOrganisationDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java index 6787c46..fba834a 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityOrganisationDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityReportDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java similarity index 97% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityReportDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java index fbe7296..4c8b957 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityReportDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityWithDocumentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java similarity index 96% rename from mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityWithDocumentDto.java rename to mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java index 462fab4..c332bc1 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/protobuf/WaterQualityWithDocumentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java index 700c130..995927f 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java @@ -22,8 +22,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; -import org.mapstruct.example.protobuf.FishTankDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java index 2b77ff7..bf7ed73 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java @@ -21,8 +21,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; -import org.mapstruct.example.protobuf.FishTankDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java index 7bbdc68..681a347 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java @@ -21,8 +21,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; -import org.mapstruct.example.protobuf.FishTankDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java index fba2a22..81d1fac 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java @@ -21,8 +21,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.example.dto.FishTankWithNestedDocumentDto; import org.mapstruct.example.model.FishTank; -import org.mapstruct.example.protobuf.FishTankWithNestedDocumentDto; import org.mapstruct.factory.Mappers; /** diff --git a/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java b/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java index 6f0437f..3ef79fc 100644 --- a/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java +++ b/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java @@ -19,6 +19,8 @@ package org.mapstruct.example; import org.junit.Test; +import org.mapstruct.example.dto.FishTankDto; +import org.mapstruct.example.dto.FishTankWithNestedDocumentDto; import org.mapstruct.example.mapper.FishTankMapper; import org.mapstruct.example.mapper.FishTankMapperConstant; import org.mapstruct.example.mapper.FishTankMapperExpression; @@ -31,8 +33,6 @@ import org.mapstruct.example.model.WaterPlant; import org.mapstruct.example.model.WaterQuality; import org.mapstruct.example.model.WaterQualityReport; -import org.mapstruct.example.protobuf.FishTankDto; -import org.mapstruct.example.protobuf.FishTankWithNestedDocumentDto; import static org.assertj.core.api.Assertions.assertThat; diff --git a/mapstruct-protobuf3/pom.xml b/mapstruct-protobuf3/pom.xml deleted file mode 100644 index 7de5ced..0000000 --- a/mapstruct-protobuf3/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - 4.0.0 - - org.mapstruct.examples.spi - protobuf-parent - 1.0.0 - pom - - - 1.2.0.Beta1 - 1.8 - 1.8 - - - - spi-impl - usage - - - - - - org.mapstruct - mapstruct-jdk8 - ${org.mapstruct.version} - - - - org.mapstruct - mapstruct-processor - ${org.mapstruct.version} - - - - junit - junit - 4.12 - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - - - - diff --git a/mapstruct-protobuf3/spi-impl/pom.xml b/mapstruct-protobuf3/spi-impl/pom.xml deleted file mode 100644 index 7bfd7d5..0000000 --- a/mapstruct-protobuf3/spi-impl/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - 4.0.0 - - - org.mapstruct.examples.spi - protobuf-parent - 1.0.0 - - - protobuf-spi-impl - 1.0.0 - - - - org.mapstruct - mapstruct-processor - - - diff --git a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java deleted file mode 100644 index a61f8f6..0000000 --- a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.mapstruct.example.protobuf; - -import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; - -public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrategy { - - @Override - public String getElementName(ExecutableElement adderMethod) { - - String methodName = super.getPropertyName(adderMethod); - Element receiver = adderMethod.getEnclosingElement(); - if (receiver != null) { - TypeElement type = (TypeElement) ((DeclaredType) receiver).asElement(); - if (type != null) { - TypeMirror superType = type.getSuperclass(); - if ("com.google.protobuf.GeneratedMessageV3".equals(superType.toString())) { - methodName += "List"; - } - } - } - return methodName; - } - -} \ No newline at end of file diff --git a/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy b/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy deleted file mode 100644 index 93e2eb3..0000000 --- a/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy +++ /dev/null @@ -1 +0,0 @@ -org.mapstruct.example.protobuf.ProtobufAccessorNamingStrategy diff --git a/mapstruct-protobuf3/usage/pom.xml b/mapstruct-protobuf3/usage/pom.xml deleted file mode 100644 index d4e351a..0000000 --- a/mapstruct-protobuf3/usage/pom.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - - 4.0.0 - - - org.mapstruct.examples.spi - protobuf-parent - 1.0.0 - - - protobuf-usage - 1.0.0-SNAPSHOT - - - - org.mapstruct - mapstruct-jdk8 - - - com.google.protobuf - protobuf-java - 3.2.0 - - - junit - junit - 4.12 - test - - - - - - - kr.motd.maven - os-maven-plugin - 1.4.0.Final - - - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.5.0 - - - generate-sources - - compile - compile-custom - - - com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier} - - grpc-java - io.grpc:protoc-gen-grpc-java:1.2.0:exe:${os.detected.classifier} - - - - - - - maven-compiler-plugin - - - - org.mapstruct - mapstruct-processor - ${org.mapstruct.version} - - - - org.mapstruct.examples.spi - protobuf-spi-impl - 1.0.0 - - - - - - - - diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java deleted file mode 100644 index 2d1a9ad..0000000 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.example.mapper; - -import org.mapstruct.CollectionMappingStrategy; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.MappingConstants; -import org.mapstruct.ValueMapping; -import org.mapstruct.example.mapper.UserMapper.BuilderFactory; -import org.mapstruct.example.protobuf.Permission; -import org.mapstruct.example.protobuf.User; -import org.mapstruct.example.protobuf.UserProtos.PermissionDTO; -import org.mapstruct.example.protobuf.UserProtos.UserDTO; -import org.mapstruct.factory.Mappers; - -@Mapper(uses = BuilderFactory.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) -public interface UserMapper { - - UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); - - - @Mapping(source = "permissions", target = "permissionsList") - UserDTO.Builder map(User user); - - @Mapping(source = "permissionsList", target = "permissions") - User map(UserDTO userDTO); - - @ValueMapping(source = "UNRECOGNIZED", target = MappingConstants.NULL) - Permission map(PermissionDTO permissionDTO); - - PermissionDTO map(Permission perm); - - - class BuilderFactory { - UserDTO.Builder builder() { - return UserDTO.newBuilder(); - } - } -} diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java deleted file mode 100644 index fd75a2b..0000000 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.mapstruct.example.protobuf; - -/** - * Created by thomas on 07.05.17. - */ -public enum Permission { - - ADMIN, - USER, - NONE -} diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java deleted file mode 100644 index 957659a..0000000 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.mapstruct.example.protobuf; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by thomas on 07.05.17. - */ -public class User { - - private String id; - private String email; - private List permissions = new ArrayList<>(); - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public List getPermissions() { - return permissions; - } - - public void setPermissions(List permissions) { - this.permissions = permissions; - } -} diff --git a/mapstruct-protobuf3/usage/src/main/proto/User.proto b/mapstruct-protobuf3/usage/src/main/proto/User.proto deleted file mode 100644 index bcb8652..0000000 --- a/mapstruct-protobuf3/usage/src/main/proto/User.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - - -option java_package = "org.mapstruct.example.protobuf"; -option java_outer_classname = "UserProtos"; - -message UserDTO { - string id = 1; - string email = 2; - repeated PermissionDTO permissions = 3; -} - -enum PermissionDTO { - NONE = 0; - USER = 1; - ADMIN = 2; -} \ No newline at end of file diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java deleted file mode 100644 index 3d86125..0000000 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.example; - -import org.junit.Assert; -import org.junit.Test; -import org.mapstruct.example.mapper.UserMapper; -import org.mapstruct.example.protobuf.GolfPlayer; -import org.mapstruct.example.protobuf.GolfPlayerDto; - -/** - * @author Sjaak Derksen - */ -public class SpiTest { - /** - * Test if everything is working when sources are present - */ - @Test - public void test() { - GolfPlayer golfPlayer1 = new GolfPlayer(); - golfPlayer1.withName("Tiger Woods").withHandicap(12); - - GolfPlayerDto dto = UserMapper.INSTANCE.toDto(golfPlayer1); - - GolfPlayer golfPlayer2 = UserMapper.INSTANCE.toPlayer(dto); - - Assert.assertEquals("Tiger Woods", golfPlayer2.name()); - Assert.assertEquals(12L, golfPlayer2.handicap(), 0); - } -} diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Source.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java similarity index 97% rename from mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Source.java rename to mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java index 7b8d66c..d088133 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Source.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; import java.math.BigDecimal; diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Target.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java similarity index 97% rename from mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Target.java rename to mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java index 4c59bea..4e791f0 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/protobuf/Target.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; import java.math.BigDecimal; diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java index 9f397c3..69e5da1 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java @@ -22,11 +22,11 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.example.dto.Source; +import org.mapstruct.example.dto.Target; import org.mapstruct.example.mapper.util.RoundingUtil; import org.mapstruct.example.mapper.util.RoundingUtil.Fraction2; import org.mapstruct.example.mapper.util.RoundingUtil.Fraction3; -import org.mapstruct.example.protobuf.Source; -import org.mapstruct.example.protobuf.Target; import org.mapstruct.factory.Mappers; diff --git a/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java b/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java index fa991f3..81a3098 100644 --- a/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java +++ b/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java @@ -18,14 +18,12 @@ */ package org.mapstruct.example; -import org.junit.Test; -import org.mapstruct.example.mapper.SourceTargetMapper; -import org.mapstruct.example.protobuf.Source; -import org.mapstruct.example.protobuf.Target; - import java.math.BigDecimal; - +import org.mapstruct.example.mapper.SourceTargetMapper; +import org.junit.Test; import static org.junit.Assert.assertEquals; +import org.mapstruct.example.dto.Source; +import org.mapstruct.example.dto.Target; /** * diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayer.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java similarity index 96% rename from mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayer.java rename to mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java index 234f921..0eecd31 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayer.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * @author Gunnar Morling diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayerDto.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java similarity index 96% rename from mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayerDto.java rename to mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java index 321bc06..197ae36 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/protobuf/GolfPlayerDto.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** * @author Gunnar Morling diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java index 9821060..421d579 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java @@ -18,9 +18,9 @@ */ package org.mapstruct.example.mapper; +import org.mapstruct.example.dto.GolfPlayerDto; +import org.mapstruct.example.dto.GolfPlayer; import org.mapstruct.Mapper; -import org.mapstruct.example.protobuf.GolfPlayer; -import org.mapstruct.example.protobuf.GolfPlayerDto; import org.mapstruct.factory.Mappers; @Mapper diff --git a/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java index b51f95b..999bcb5 100644 --- a/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java +++ b/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java @@ -20,9 +20,9 @@ import org.junit.Assert; import org.junit.Test; +import org.mapstruct.example.dto.GolfPlayer; +import org.mapstruct.example.dto.GolfPlayerDto; import org.mapstruct.example.mapper.GolfPlayerMapper; -import org.mapstruct.example.protobuf.GolfPlayer; -import org.mapstruct.example.protobuf.GolfPlayerDto; /** * @author Sjaak Derksen diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalDto.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java similarity index 94% rename from mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalDto.java rename to mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java index be6cb68..e2f8cb2 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalDto.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java @@ -16,7 +16,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; + +import java.math.BigDecimal; /** * diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalEntity.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java similarity index 97% rename from mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalEntity.java rename to mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java index 77ac222..3a6f118 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/protobuf/MammalEntity.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.example.protobuf; +package org.mapstruct.example.dto; /** diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java index 7cbca28..e63b966 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java @@ -23,8 +23,8 @@ import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; -import org.mapstruct.example.protobuf.MammalDto; -import org.mapstruct.example.protobuf.MammalEntity; +import org.mapstruct.example.dto.MammalDto; +import org.mapstruct.example.dto.MammalEntity; import org.mapstruct.factory.Mappers; diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java index a3d4c99..56911aa 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java @@ -18,12 +18,11 @@ */ package org.mapstruct.example; -import org.junit.Test; -import org.mapstruct.example.mapper.SourceTargetMapper; -import org.mapstruct.example.protobuf.MammalDto; -import org.mapstruct.example.protobuf.MammalEntity; - import static org.fest.assertions.Assertions.assertThat; +import org.mapstruct.example.mapper.SourceTargetMapper; +import org.junit.Test; +import org.mapstruct.example.dto.MammalDto; +import org.mapstruct.example.dto.MammalEntity; /** diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java index 235aef4..52bb77d 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java @@ -19,9 +19,9 @@ package org.mapstruct.example; import org.junit.Test; +import org.mapstruct.example.dto.MammalDto; +import org.mapstruct.example.dto.MammalEntity; import org.mapstruct.example.mapper.SourceTargetTestMapper; -import org.mapstruct.example.protobuf.MammalDto; -import org.mapstruct.example.protobuf.MammalEntity; import static org.fest.assertions.Assertions.assertThat; diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java index 907feb0..990e350 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java @@ -23,8 +23,8 @@ import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; -import org.mapstruct.example.protobuf.MammalDto; -import org.mapstruct.example.protobuf.MammalEntity; +import org.mapstruct.example.dto.MammalDto; +import org.mapstruct.example.dto.MammalEntity; import org.mapstruct.factory.Mappers; /** diff --git a/pom.xml b/pom.xml index e216551..ee97813 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,5 @@ mapstruct-rounding mapstruct-spi-accessor-naming mapstruct-updatemethods-1 - mapstruct-protobuf3 From 788d0bd3f23a5a622dbf09ad4acf61054c119b0b Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 7 May 2017 14:14:40 +0200 Subject: [PATCH 03/13] proto3 example --- mapstruct-protobuf3/pom.xml | 75 ++++++++++++ mapstruct-protobuf3/spi-impl/pom.xml | 41 +++++++ .../ProtobufAccessorNamingStrategy.java | 30 +++++ ...rg.mapstruct.ap.spi.AccessorNamingStrategy | 1 + mapstruct-protobuf3/usage/pom.xml | 114 ++++++++++++++++++ .../mapstruct/example/mapper/UserMapper.java | 56 +++++++++ .../example/protobuf/Permission.java | 11 ++ .../org/mapstruct/example/protobuf/User.java | 38 ++++++ .../usage/src/main/proto/User.proto | 17 +++ .../java/org/mapstruct/example/SpiTest.java | 46 +++++++ pom.xml | 1 + 11 files changed, 430 insertions(+) create mode 100644 mapstruct-protobuf3/pom.xml create mode 100644 mapstruct-protobuf3/spi-impl/pom.xml create mode 100644 mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java create mode 100644 mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy create mode 100644 mapstruct-protobuf3/usage/pom.xml create mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java create mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java create mode 100644 mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java create mode 100644 mapstruct-protobuf3/usage/src/main/proto/User.proto create mode 100644 mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java diff --git a/mapstruct-protobuf3/pom.xml b/mapstruct-protobuf3/pom.xml new file mode 100644 index 0000000..7de5ced --- /dev/null +++ b/mapstruct-protobuf3/pom.xml @@ -0,0 +1,75 @@ + + + + 4.0.0 + + org.mapstruct.examples.spi + protobuf-parent + 1.0.0 + pom + + + 1.2.0.Beta1 + 1.8 + 1.8 + + + + spi-impl + usage + + + + + + org.mapstruct + mapstruct-jdk8 + ${org.mapstruct.version} + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + junit + junit + 4.12 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + + + + diff --git a/mapstruct-protobuf3/spi-impl/pom.xml b/mapstruct-protobuf3/spi-impl/pom.xml new file mode 100644 index 0000000..7bfd7d5 --- /dev/null +++ b/mapstruct-protobuf3/spi-impl/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.mapstruct.examples.spi + protobuf-parent + 1.0.0 + + + protobuf-spi-impl + 1.0.0 + + + + org.mapstruct + mapstruct-processor + + + diff --git a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java new file mode 100644 index 0000000..a61f8f6 --- /dev/null +++ b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java @@ -0,0 +1,30 @@ +package org.mapstruct.example.protobuf; + +import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; + +public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrategy { + + @Override + public String getElementName(ExecutableElement adderMethod) { + + String methodName = super.getPropertyName(adderMethod); + Element receiver = adderMethod.getEnclosingElement(); + if (receiver != null) { + TypeElement type = (TypeElement) ((DeclaredType) receiver).asElement(); + if (type != null) { + TypeMirror superType = type.getSuperclass(); + if ("com.google.protobuf.GeneratedMessageV3".equals(superType.toString())) { + methodName += "List"; + } + } + } + return methodName; + } + +} \ No newline at end of file diff --git a/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy b/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy new file mode 100644 index 0000000..93e2eb3 --- /dev/null +++ b/mapstruct-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy @@ -0,0 +1 @@ +org.mapstruct.example.protobuf.ProtobufAccessorNamingStrategy diff --git a/mapstruct-protobuf3/usage/pom.xml b/mapstruct-protobuf3/usage/pom.xml new file mode 100644 index 0000000..d4e351a --- /dev/null +++ b/mapstruct-protobuf3/usage/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + + org.mapstruct.examples.spi + protobuf-parent + 1.0.0 + + + protobuf-usage + 1.0.0-SNAPSHOT + + + + org.mapstruct + mapstruct-jdk8 + + + com.google.protobuf + protobuf-java + 3.2.0 + + + junit + junit + 4.12 + test + + + + + + + kr.motd.maven + os-maven-plugin + 1.4.0.Final + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.5.0 + + + generate-sources + + compile + compile-custom + + + com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier} + + grpc-java + io.grpc:protoc-gen-grpc-java:1.2.0:exe:${os.detected.classifier} + + + + + + + maven-compiler-plugin + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + org.mapstruct.examples.spi + protobuf-spi-impl + 1.0.0 + + + + + + + + diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java new file mode 100644 index 0000000..2d1a9ad --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java @@ -0,0 +1,56 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.example.mapper; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.example.mapper.UserMapper.BuilderFactory; +import org.mapstruct.example.protobuf.Permission; +import org.mapstruct.example.protobuf.User; +import org.mapstruct.example.protobuf.UserProtos.PermissionDTO; +import org.mapstruct.example.protobuf.UserProtos.UserDTO; +import org.mapstruct.factory.Mappers; + +@Mapper(uses = BuilderFactory.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface UserMapper { + + UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); + + + @Mapping(source = "permissions", target = "permissionsList") + UserDTO.Builder map(User user); + + @Mapping(source = "permissionsList", target = "permissions") + User map(UserDTO userDTO); + + @ValueMapping(source = "UNRECOGNIZED", target = MappingConstants.NULL) + Permission map(PermissionDTO permissionDTO); + + PermissionDTO map(Permission perm); + + + class BuilderFactory { + UserDTO.Builder builder() { + return UserDTO.newBuilder(); + } + } +} diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java new file mode 100644 index 0000000..fd75a2b --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java @@ -0,0 +1,11 @@ +package org.mapstruct.example.protobuf; + +/** + * Created by thomas on 07.05.17. + */ +public enum Permission { + + ADMIN, + USER, + NONE +} diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java new file mode 100644 index 0000000..957659a --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java @@ -0,0 +1,38 @@ +package org.mapstruct.example.protobuf; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by thomas on 07.05.17. + */ +public class User { + + private String id; + private String email; + private List permissions = new ArrayList<>(); + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public List getPermissions() { + return permissions; + } + + public void setPermissions(List permissions) { + this.permissions = permissions; + } +} diff --git a/mapstruct-protobuf3/usage/src/main/proto/User.proto b/mapstruct-protobuf3/usage/src/main/proto/User.proto new file mode 100644 index 0000000..bcb8652 --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/proto/User.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + + +option java_package = "org.mapstruct.example.protobuf"; +option java_outer_classname = "UserProtos"; + +message UserDTO { + string id = 1; + string email = 2; + repeated PermissionDTO permissions = 3; +} + +enum PermissionDTO { + NONE = 0; + USER = 1; + ADMIN = 2; +} \ No newline at end of file diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java new file mode 100644 index 0000000..3d86125 --- /dev/null +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.example; + +import org.junit.Assert; +import org.junit.Test; +import org.mapstruct.example.mapper.UserMapper; +import org.mapstruct.example.protobuf.GolfPlayer; +import org.mapstruct.example.protobuf.GolfPlayerDto; + +/** + * @author Sjaak Derksen + */ +public class SpiTest { + /** + * Test if everything is working when sources are present + */ + @Test + public void test() { + GolfPlayer golfPlayer1 = new GolfPlayer(); + golfPlayer1.withName("Tiger Woods").withHandicap(12); + + GolfPlayerDto dto = UserMapper.INSTANCE.toDto(golfPlayer1); + + GolfPlayer golfPlayer2 = UserMapper.INSTANCE.toPlayer(dto); + + Assert.assertEquals("Tiger Woods", golfPlayer2.name()); + Assert.assertEquals(12L, golfPlayer2.handicap(), 0); + } +} diff --git a/pom.xml b/pom.xml index ee97813..0dd0ebe 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ mapstruct-nested-bean-mappings mapstruct-rounding mapstruct-spi-accessor-naming + mapstruct-protobuf3 mapstruct-updatemethods-1 From cd8905247b16a3a4e9751344492cbd33f7524bbd Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 7 May 2017 14:19:06 +0200 Subject: [PATCH 04/13] proto3 example test (fails) --- .../java/org/mapstruct/example/SpiTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java index 3d86125..952edef 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java @@ -21,8 +21,9 @@ import org.junit.Assert; import org.junit.Test; import org.mapstruct.example.mapper.UserMapper; -import org.mapstruct.example.protobuf.GolfPlayer; -import org.mapstruct.example.protobuf.GolfPlayerDto; +import org.mapstruct.example.protobuf.Permission; +import org.mapstruct.example.protobuf.User; +import org.mapstruct.example.protobuf.UserProtos.UserDTO; /** * @author Sjaak Derksen @@ -33,14 +34,15 @@ public class SpiTest { */ @Test public void test() { - GolfPlayer golfPlayer1 = new GolfPlayer(); - golfPlayer1.withName("Tiger Woods").withHandicap(12); + User user = new User(); + user.setEmail("test"); + user.getPermissions().add(Permission.ADMIN); - GolfPlayerDto dto = UserMapper.INSTANCE.toDto(golfPlayer1); + UserDTO.Builder dto = UserMapper.INSTANCE.map(user); - GolfPlayer golfPlayer2 = UserMapper.INSTANCE.toPlayer(dto); + User back = UserMapper.INSTANCE.map(dto.build()); - Assert.assertEquals("Tiger Woods", golfPlayer2.name()); - Assert.assertEquals(12L, golfPlayer2.handicap(), 0); + Assert.assertEquals("test", back.getEmail()); + Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); } } From ffb9615d449606d6d291c798abd10a008d42bb57 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 7 May 2017 14:25:27 +0200 Subject: [PATCH 05/13] proto3 example test (fails) --- .../usage/src/test/java/org/mapstruct/example/SpiTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java index 952edef..cb3536b 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java @@ -42,6 +42,7 @@ public void test() { User back = UserMapper.INSTANCE.map(dto.build()); + Assert.assertNull(back.getId()); Assert.assertEquals("test", back.getEmail()); Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); } From 70987ed5ae2138b4f09a25836b40ee969f22a2b2 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 7 May 2017 14:27:48 +0200 Subject: [PATCH 06/13] author tags --- .../example/protobuf/ProtobufAccessorNamingStrategy.java | 3 +++ .../main/java/org/mapstruct/example/mapper/UserMapper.java | 4 +++- .../main/java/org/mapstruct/example/protobuf/Permission.java | 2 +- .../src/main/java/org/mapstruct/example/protobuf/User.java | 2 +- .../usage/src/test/java/org/mapstruct/example/SpiTest.java | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java index a61f8f6..2668857 100644 --- a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java +++ b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java @@ -8,6 +8,9 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; +/** + * @author Thomas Kratz + */ public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrategy { @Override diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java index 2d1a9ad..4dc52f6 100644 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java @@ -29,7 +29,9 @@ import org.mapstruct.example.protobuf.UserProtos.PermissionDTO; import org.mapstruct.example.protobuf.UserProtos.UserDTO; import org.mapstruct.factory.Mappers; - +/** + * @author Thomas Kratz + */ @Mapper(uses = BuilderFactory.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) public interface UserMapper { diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java index fd75a2b..d0085a4 100644 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java @@ -1,7 +1,7 @@ package org.mapstruct.example.protobuf; /** - * Created by thomas on 07.05.17. + * @author Thomas Kratz */ public enum Permission { diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java index 957659a..b95dd9e 100644 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java @@ -4,7 +4,7 @@ import java.util.List; /** - * Created by thomas on 07.05.17. + * @author Thomas Kratz */ public class User { diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java index cb3536b..61ed0c6 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java @@ -26,7 +26,7 @@ import org.mapstruct.example.protobuf.UserProtos.UserDTO; /** - * @author Sjaak Derksen + * @author Thomas Kratz */ public class SpiTest { /** From 5e9c3f2ce3967867c4aa96607e33d40ce2669355 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 7 May 2017 14:34:53 +0200 Subject: [PATCH 07/13] we do not map nulls yet --- .../mapstruct/example/{SpiTest.java => ProtobufTest.java} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/{SpiTest.java => ProtobufTest.java} (90%) diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java similarity index 90% rename from mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java rename to mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java index 61ed0c6..4b415c2 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/SpiTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java @@ -28,13 +28,14 @@ /** * @author Thomas Kratz */ -public class SpiTest { +public class ProtobufTest { /** * Test if everything is working when sources are present */ @Test public void test() { User user = new User(); + user.setId(""); // this is not exisiting in the proto. we don't know how to handle nulls yet user.setEmail("test"); user.getPermissions().add(Permission.ADMIN); @@ -42,7 +43,7 @@ public void test() { User back = UserMapper.INSTANCE.map(dto.build()); - Assert.assertNull(back.getId()); + Assert.assertEquals("",back.getId()); Assert.assertEquals("test", back.getEmail()); Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); } From 19aa9e6946a767354152f13e235d200350f30fde Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 7 May 2017 14:36:07 +0200 Subject: [PATCH 08/13] we do not map nulls yet --- .../java/org/mapstruct/example/ProtobufTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java index 4b415c2..53e2514 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java @@ -47,4 +47,20 @@ public void test() { Assert.assertEquals("test", back.getEmail()); Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); } + + @Test(expected = NullPointerException.class) + public void testNulls() { + User user = new User(); + // if id is null everything is broken + user.setEmail("test"); + user.getPermissions().add(Permission.ADMIN); + + UserDTO.Builder dto = UserMapper.INSTANCE.map(user); + +// User back = UserMapper.INSTANCE.map(dto.build()); +// +// Assert.assertEquals("",back.getId()); +// Assert.assertEquals("test", back.getEmail()); +// Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); + } } From 36697dde8be43c63e700cb2af27eaa2a53f5a45c Mon Sep 17 00:00:00 2001 From: thomas Date: Mon, 8 May 2017 09:14:04 +0200 Subject: [PATCH 09/13] NullValueCheckStrategy --- .../mapstruct/example/mapper/UserMapper.java | 6 +++++- .../org/mapstruct/example/ProtobufTest.java | 17 +++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java index 4dc52f6..5e17fe6 100644 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java @@ -22,6 +22,7 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingConstants; +import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.ValueMapping; import org.mapstruct.example.mapper.UserMapper.BuilderFactory; import org.mapstruct.example.protobuf.Permission; @@ -29,10 +30,13 @@ import org.mapstruct.example.protobuf.UserProtos.PermissionDTO; import org.mapstruct.example.protobuf.UserProtos.UserDTO; import org.mapstruct.factory.Mappers; + /** * @author Thomas Kratz */ -@Mapper(uses = BuilderFactory.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +@Mapper(uses = BuilderFactory.class, + collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) public interface UserMapper { UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java index 53e2514..862aaa1 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java @@ -35,7 +35,7 @@ public class ProtobufTest { @Test public void test() { User user = new User(); - user.setId(""); // this is not exisiting in the proto. we don't know how to handle nulls yet + user.setId(""); user.setEmail("test"); user.getPermissions().add(Permission.ADMIN); @@ -48,19 +48,20 @@ public void test() { Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); } - @Test(expected = NullPointerException.class) + + @Test public void testNulls() { User user = new User(); - // if id is null everything is broken + // if id is null we should get the default empty string user.setEmail("test"); user.getPermissions().add(Permission.ADMIN); UserDTO.Builder dto = UserMapper.INSTANCE.map(user); -// User back = UserMapper.INSTANCE.map(dto.build()); -// -// Assert.assertEquals("",back.getId()); -// Assert.assertEquals("test", back.getEmail()); -// Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); + User back = UserMapper.INSTANCE.map(dto.build()); + + Assert.assertEquals("", back.getId()); + Assert.assertEquals("test", back.getEmail()); + Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); } } From d0f6c95ca11e632d4ffe64eb27b1b0a60a774b4b Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 9 May 2017 08:34:24 +0200 Subject: [PATCH 10/13] feedback from pr #25 --- mapstruct-protobuf3/pom.xml | 3 +++ .../ProtobufAccessorNamingStrategy.java | 20 ++++++++++--------- mapstruct-protobuf3/usage/pom.xml | 6 +++--- .../org/mapstruct/example/ProtobufTest.java | 13 ++++++++---- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/mapstruct-protobuf3/pom.xml b/mapstruct-protobuf3/pom.xml index 7de5ced..6b259ab 100644 --- a/mapstruct-protobuf3/pom.xml +++ b/mapstruct-protobuf3/pom.xml @@ -29,6 +29,9 @@ pom + 1.4.0.Final + 0.5.0 + 3.2.0 1.2.0.Beta1 1.8 1.8 diff --git a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java index 2668857..d861312 100644 --- a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java +++ b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java @@ -3,9 +3,9 @@ import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; -import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; /** @@ -13,19 +13,21 @@ */ public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrategy { + public static final String PROTOBUF_GENERATED_MESSAGE_V3 = "com.google.protobuf.GeneratedMessageV3"; + public static final String LIST_SUFFIX = "List"; + @Override public String getElementName(ExecutableElement adderMethod) { - String methodName = super.getPropertyName(adderMethod); + String methodName = getPropertyName(adderMethod); Element receiver = adderMethod.getEnclosingElement(); - if (receiver != null) { - TypeElement type = (TypeElement) ((DeclaredType) receiver).asElement(); - if (type != null) { - TypeMirror superType = type.getSuperclass(); - if ("com.google.protobuf.GeneratedMessageV3".equals(superType.toString())) { - methodName += "List"; - } + if (receiver != null && receiver.getKind() == ElementKind.CLASS) { + TypeElement type = (TypeElement) receiver; + TypeMirror superType = type.getSuperclass(); + if (superType != null && PROTOBUF_GENERATED_MESSAGE_V3.equals(superType.toString())) { + methodName += LIST_SUFFIX; } + } return methodName; } diff --git a/mapstruct-protobuf3/usage/pom.xml b/mapstruct-protobuf3/usage/pom.xml index d4e351a..f910099 100644 --- a/mapstruct-protobuf3/usage/pom.xml +++ b/mapstruct-protobuf3/usage/pom.xml @@ -40,7 +40,7 @@ com.google.protobuf protobuf-java - 3.2.0 + ${protobuf.java.version} junit @@ -55,7 +55,7 @@ kr.motd.maven os-maven-plugin - 1.4.0.Final + ${os.mavenplugin.version} @@ -63,7 +63,7 @@ org.xolstice.maven.plugins protobuf-maven-plugin - 0.5.0 + ${protobuf.plugin.version} generate-sources diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java index 862aaa1..ccf92c7 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java @@ -18,6 +18,7 @@ */ package org.mapstruct.example; +import com.google.protobuf.InvalidProtocolBufferException; import org.junit.Assert; import org.junit.Test; import org.mapstruct.example.mapper.UserMapper; @@ -33,7 +34,7 @@ public class ProtobufTest { * Test if everything is working when sources are present */ @Test - public void test() { + public void test() throws InvalidProtocolBufferException { User user = new User(); user.setId(""); user.setEmail("test"); @@ -41,7 +42,9 @@ public void test() { UserDTO.Builder dto = UserMapper.INSTANCE.map(user); - User back = UserMapper.INSTANCE.map(dto.build()); + UserDTO deserialized = UserDTO.parseFrom(dto.build().toByteArray()); + + User back = UserMapper.INSTANCE.map(deserialized); Assert.assertEquals("",back.getId()); Assert.assertEquals("test", back.getEmail()); @@ -50,7 +53,7 @@ public void test() { @Test - public void testNulls() { + public void testNulls() throws InvalidProtocolBufferException { User user = new User(); // if id is null we should get the default empty string user.setEmail("test"); @@ -58,7 +61,9 @@ public void testNulls() { UserDTO.Builder dto = UserMapper.INSTANCE.map(user); - User back = UserMapper.INSTANCE.map(dto.build()); + UserDTO deserialized = UserDTO.parseFrom(dto.build().toByteArray()); + + User back = UserMapper.INSTANCE.map(deserialized); Assert.assertEquals("", back.getId()); Assert.assertEquals("test", back.getEmail()); From 8412efc8c76af4838fd467e857eec21b9592efae Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 9 May 2017 08:36:25 +0200 Subject: [PATCH 11/13] cleanup --- .../example/protobuf/ProtobufAccessorNamingStrategy.java | 1 - .../src/test/java/org/mapstruct/example/ProtobufTest.java | 4 ---- 2 files changed, 5 deletions(-) diff --git a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java index d861312..1765ef5 100644 --- a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java +++ b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java @@ -27,7 +27,6 @@ public String getElementName(ExecutableElement adderMethod) { if (superType != null && PROTOBUF_GENERATED_MESSAGE_V3.equals(superType.toString())) { methodName += LIST_SUFFIX; } - } return methodName; } diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java index ccf92c7..fa0a0d1 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java @@ -41,9 +41,7 @@ public void test() throws InvalidProtocolBufferException { user.getPermissions().add(Permission.ADMIN); UserDTO.Builder dto = UserMapper.INSTANCE.map(user); - UserDTO deserialized = UserDTO.parseFrom(dto.build().toByteArray()); - User back = UserMapper.INSTANCE.map(deserialized); Assert.assertEquals("",back.getId()); @@ -60,9 +58,7 @@ public void testNulls() throws InvalidProtocolBufferException { user.getPermissions().add(Permission.ADMIN); UserDTO.Builder dto = UserMapper.INSTANCE.map(user); - UserDTO deserialized = UserDTO.parseFrom(dto.build().toByteArray()); - User back = UserMapper.INSTANCE.map(deserialized); Assert.assertEquals("", back.getId()); From 90b38d18833aab123a60385f2032475da6557d3b Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 9 May 2017 08:49:26 +0200 Subject: [PATCH 12/13] formatting --- .../usage/src/test/java/org/mapstruct/example/ProtobufTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java index fa0a0d1..4a6fe44 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java @@ -44,7 +44,7 @@ public void test() throws InvalidProtocolBufferException { UserDTO deserialized = UserDTO.parseFrom(dto.build().toByteArray()); User back = UserMapper.INSTANCE.map(deserialized); - Assert.assertEquals("",back.getId()); + Assert.assertEquals("", back.getId()); Assert.assertEquals("test", back.getEmail()); Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); } From 21f6073e9a596b2414a2eccf7c559444fa1ceb83 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 11 May 2017 08:03:11 +0200 Subject: [PATCH 13/13] get methodname correctly --- .../example/protobuf/ProtobufAccessorNamingStrategy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java index 1765ef5..b2fd240 100644 --- a/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java +++ b/mapstruct-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java @@ -19,7 +19,7 @@ public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrateg @Override public String getElementName(ExecutableElement adderMethod) { - String methodName = getPropertyName(adderMethod); + String methodName = super.getElementName(adderMethod); Element receiver = adderMethod.getEnclosingElement(); if (receiver != null && receiver.getKind() == ElementKind.CLASS) { TypeElement type = (TypeElement) receiver;