├── .coveralls.yml ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── checkstyle.xml ├── settings.gradle ├── src ├── main │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ └── java │ │ └── com │ │ └── github │ │ └── rozidan │ │ └── springboot │ │ └── modelmapper │ │ ├── ConfigurationConfigurer.java │ │ ├── ConverterConfigurer.java │ │ ├── ModelMapperAutoConfiguration.java │ │ ├── TypeMapConfigurer.java │ │ ├── WithModelMapper.java │ │ └── ModelMapperFactoryBean.java └── test │ └── java │ └── com │ └── github │ └── rozidan │ └── springboot │ └── modelmapper │ ├── entities │ ├── ProdType.java │ ├── User.java │ └── Product.java │ ├── dtos │ ├── ProdTypeDto.java │ ├── ProductDto.java │ └── UserDto.java │ ├── mapping │ ├── GlobalConfiguration.java │ └── UserDtoMapping.java │ ├── ModelMapperFactoryBeanTest.java │ ├── NoConfigurerModelMapperAutoConfigurationTest.java │ ├── WithModelMapperAnnotationTest.java │ ├── ModelMapperAutoConfigurationTest.java │ ├── TypeMapConfigurerTest.java │ ├── TypeMapNameTest.java │ ├── TypeMapConfigurationTest.java │ ├── ConfigurationConfigurerTest.java │ ├── ConverterConfigurerTest.java │ └── TypeMapConfigurationAndNameTest.java ├── .travis.yml ├── .gitignore ├── gradle.properties ├── codequality └── HEADER ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /.coveralls.yml: -------------------------------------------------------------------------------- 1 | repo_token: bAxyAtKfEKmTfzfbJ98dlBYwfes6zwdr0vVRv -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rozidan/modelmapper-spring-boot-starter/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | } 5 | } 6 | 7 | rootProject.name = 'modelmapper-spring-boot-starter' 8 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.github.rozidan.springboot.modelmapper.ModelMapperAutoConfiguration -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | dist: "trusty" 4 | 5 | jdk: 6 | - oraclejdk8 7 | 8 | before_install: 9 | - chmod +x gradlew 10 | 11 | after_success: 12 | - ./gradlew jacocoTestReport coveralls -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | /build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | 15 | ### IntelliJ IDEA ### 16 | .idea 17 | *.iws 18 | *.iml 19 | *.ipr 20 | /out/ 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | 29 | ### VS Code ### 30 | .vscode/ 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=2.3.2-SNAPSHOT 2 | group=com.github.rozidan 3 | sourceCompatibility=1.8 4 | description='A Springboot starter for modelmapper' 5 | 6 | org.gradle.jvmargs=-Xmx2g -XX:MaxPermSize=256m 7 | org.gradle.logging.level=info 8 | 9 | mavenUsername= 10 | mavenPassword= 11 | mavenSnapshotsUrl=https://oss.sonatype.org/content/repositories/snapshots/ 12 | mavenReleasesUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ 13 | 14 | signing.keyId= 15 | signing.password= 16 | signing.secretKeyRingFile= 17 | 18 | -------------------------------------------------------------------------------- /codequality/HEADER: -------------------------------------------------------------------------------- 1 | Copyright (C) ${year} ${name} the original author or authors 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/entities/ProdType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper.entities; 17 | 18 | public enum ProdType { 19 | T1, T2 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/dtos/ProdTypeDto.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper.dtos; 17 | 18 | public enum ProdTypeDto { 19 | TYPE1, TYPE2 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/entities/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper.entities; 17 | 18 | import lombok.AllArgsConstructor; 19 | import lombok.Data; 20 | import lombok.NoArgsConstructor; 21 | 22 | /** 23 | * User domain object. 24 | * 25 | * @author Idan Rozenfeld 26 | */ 27 | @Data 28 | @NoArgsConstructor 29 | @AllArgsConstructor 30 | public class User { 31 | 32 | private String name; 33 | private Integer age; 34 | } -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/dtos/ProductDto.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper.dtos; 17 | 18 | import lombok.AllArgsConstructor; 19 | import lombok.Data; 20 | import lombok.NoArgsConstructor; 21 | 22 | /** 23 | * Product DTO. 24 | * 25 | * @author Idan Rozenfeld 26 | */ 27 | @Data 28 | @AllArgsConstructor 29 | @NoArgsConstructor 30 | public class ProductDto { 31 | private String name; 32 | private ProdTypeDto type; 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/entities/Product.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper.entities; 17 | 18 | import lombok.AllArgsConstructor; 19 | import lombok.Data; 20 | import lombok.NoArgsConstructor; 21 | 22 | /** 23 | * Product domain object. 24 | * 25 | * @author Idan Rozenfeld 26 | */ 27 | @Data 28 | @NoArgsConstructor 29 | @AllArgsConstructor 30 | public class Product { 31 | private String name; 32 | private ProdType type; 33 | } -------------------------------------------------------------------------------- /src/main/java/com/github/rozidan/springboot/modelmapper/ConfigurationConfigurer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import org.modelmapper.ModelMapper; 19 | import org.modelmapper.config.Configuration; 20 | 21 | 22 | public abstract class ConfigurationConfigurer { 23 | 24 | void configureImpl(ModelMapper mapper) { 25 | configure(mapper.getConfiguration()); 26 | } 27 | 28 | public abstract void configure(Configuration configuration); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/github/rozidan/springboot/modelmapper/ConverterConfigurer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import org.modelmapper.Converter; 19 | import org.modelmapper.ModelMapper; 20 | 21 | public abstract class ConverterConfigurer { 22 | 23 | public abstract Converter converter(); 24 | 25 | @SuppressWarnings("unchecked") 26 | void configureImpl(ModelMapper mapper) { 27 | mapper.addConverter(converter()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/dtos/UserDto.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper.dtos; 17 | 18 | import lombok.AllArgsConstructor; 19 | import lombok.Data; 20 | import lombok.NoArgsConstructor; 21 | 22 | /** 23 | * User DTO. 24 | * 25 | * @author Idan Rozenfeld 26 | */ 27 | @Data 28 | @AllArgsConstructor 29 | @NoArgsConstructor 30 | public class UserDto { 31 | 32 | private String firstName; 33 | 34 | private String lastName; 35 | 36 | private int age; 37 | 38 | private String middleName; 39 | 40 | } -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/mapping/GlobalConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper.mapping; 17 | 18 | import com.github.rozidan.springboot.modelmapper.ConfigurationConfigurer; 19 | import org.modelmapper.config.Configuration; 20 | import org.springframework.boot.test.context.TestComponent; 21 | 22 | @TestComponent 23 | public class GlobalConfiguration extends ConfigurationConfigurer { 24 | @Override 25 | public void configure(Configuration configuration) { 26 | configuration.setSkipNullEnabled(true); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/com/github/rozidan/springboot/modelmapper/ModelMapperAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import org.modelmapper.ModelMapper; 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 21 | import org.springframework.context.annotation.Bean; 22 | import org.springframework.context.annotation.Configuration; 23 | 24 | @Configuration 25 | @ConditionalOnClass(ModelMapper.class) 26 | public class ModelMapperAutoConfiguration { 27 | 28 | @Bean 29 | @ConditionalOnMissingBean(ModelMapperFactoryBean.class) 30 | public ModelMapperFactoryBean modelMapperFactoryBean() { 31 | return new ModelMapperFactoryBean(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/ModelMapperFactoryBeanTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import org.junit.Test; 19 | import org.modelmapper.ModelMapper; 20 | 21 | import static org.hamcrest.CoreMatchers.is; 22 | import static org.hamcrest.CoreMatchers.notNullValue; 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | 25 | /** 26 | * Tests the registration of {@link org.modelmapper.ModelMapper}. 27 | * 28 | * @author Idan Rozenfeld 29 | */ 30 | public class ModelMapperFactoryBeanTest { 31 | 32 | @Test 33 | public void shouldInstantiateModelMapper() throws Exception { 34 | final ModelMapperFactoryBean factoryBean = new ModelMapperFactoryBean(); 35 | final ModelMapper modelMapper = factoryBean.getObject(); 36 | assertThat(modelMapper, is(notNullValue())); 37 | } 38 | } -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/mapping/UserDtoMapping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper.mapping; 17 | 18 | import com.github.rozidan.springboot.modelmapper.TypeMapConfigurer; 19 | import com.github.rozidan.springboot.modelmapper.dtos.UserDto; 20 | import com.github.rozidan.springboot.modelmapper.entities.User; 21 | import org.modelmapper.TypeMap; 22 | import org.springframework.boot.test.context.TestComponent; 23 | 24 | @TestComponent 25 | public class UserDtoMapping extends TypeMapConfigurer { 26 | @Override 27 | public void configure(TypeMap typeMap) { 28 | typeMap.addMapping(User::getAge, UserDto::setAge); 29 | typeMap.addMapping(User::getName, UserDto::setFirstName); 30 | typeMap.addMapping(User::getName, UserDto::setLastName); 31 | typeMap.addMapping(User::getName, UserDto::setMiddleName); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/NoConfigurerModelMapperAutoConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.modelmapper.ModelMapper; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 24 | import org.springframework.context.annotation.Configuration; 25 | import org.springframework.test.context.junit4.SpringRunner; 26 | 27 | import static org.hamcrest.CoreMatchers.is; 28 | import static org.hamcrest.CoreMatchers.notNullValue; 29 | import static org.hamcrest.MatcherAssert.assertThat; 30 | 31 | /** 32 | * Tests the registration of {@link org.modelmapper.ModelMapper}. 33 | * 34 | * @author Idan Rozenfeld 35 | */ 36 | @RunWith(SpringRunner.class) 37 | public class NoConfigurerModelMapperAutoConfigurationTest { 38 | 39 | @Autowired 40 | private ModelMapper modelMapper; 41 | 42 | @Test 43 | public void shouldInstantiateMapperWithoutAnyConfigurer() { 44 | assertThat(modelMapper, is(notNullValue())); 45 | } 46 | 47 | @Configuration 48 | @EnableAutoConfiguration 49 | public static class Application { 50 | } 51 | } -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/WithModelMapperAnnotationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import com.github.rozidan.springboot.modelmapper.dtos.UserDto; 19 | import com.github.rozidan.springboot.modelmapper.entities.User; 20 | import com.github.rozidan.springboot.modelmapper.mapping.UserDtoMapping; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.modelmapper.ModelMapper; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | import org.springframework.context.annotation.Configuration; 26 | import org.springframework.test.context.junit4.SpringRunner; 27 | 28 | import static org.hamcrest.CoreMatchers.equalTo; 29 | import static org.hamcrest.MatcherAssert.assertThat; 30 | 31 | @RunWith(SpringRunner.class) 32 | public class WithModelMapperAnnotationTest { 33 | 34 | @Autowired 35 | private ModelMapper mapper; 36 | 37 | @Test 38 | public void annotationTest() { 39 | UserDto dto = new UserDto(); 40 | dto.setAge(20); 41 | dto.setFirstName("aa"); 42 | dto.setLastName("bb"); 43 | dto.setMiddleName("cc"); 44 | 45 | User user = new User(); 46 | user.setAge(null); 47 | user.setName(null); 48 | 49 | mapper.map(user, dto); 50 | 51 | assertThat(dto.getFirstName(), equalTo("aa")); 52 | assertThat(dto.getLastName(), equalTo("bb")); 53 | assertThat(dto.getMiddleName(), equalTo("cc")); 54 | assertThat(dto.getAge(), equalTo(20)); 55 | } 56 | 57 | @Configuration 58 | @WithModelMapper(basePackageClasses = UserDtoMapping.class) 59 | public static class Application { 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/github/rozidan/springboot/modelmapper/TypeMapConfigurer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import org.modelmapper.ModelMapper; 19 | import org.modelmapper.TypeMap; 20 | import org.modelmapper.config.Configuration; 21 | import org.modelmapper.internal.typetools.TypeResolver; 22 | 23 | public abstract class TypeMapConfigurer { 24 | 25 | public String getTypeMapName() { 26 | return null; 27 | } 28 | 29 | /** 30 | * Configuration to apply to TypeMap, leave it unimplemented to use the default. 31 | * 32 | * @return 33 | */ 34 | public Configuration getConfiguration() { 35 | return null; 36 | } 37 | 38 | public abstract void configure(TypeMap typeMap); 39 | 40 | @SuppressWarnings("unchecked") 41 | void configureImpl(ModelMapper mapper) { 42 | Class[] typeArguments = TypeResolver.resolveRawArguments(TypeMapConfigurer.class, getClass()); 43 | String typeMapName = getTypeMapName(); 44 | Configuration configuration = getConfiguration(); 45 | 46 | if (typeMapName == null && configuration == null) { 47 | configure(mapper.createTypeMap((Class) typeArguments[0], (Class) typeArguments[1])); 48 | } else if (typeMapName == null) { 49 | configure(mapper.createTypeMap((Class) typeArguments[0], (Class) typeArguments[1], configuration)); 50 | } else if (configuration == null) { 51 | configure(mapper.createTypeMap((Class) typeArguments[0], (Class) typeArguments[1], typeMapName)); 52 | } else { 53 | configure(mapper.createTypeMap((Class) typeArguments[0], (Class) typeArguments[1], typeMapName, configuration)); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/ModelMapperAutoConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import java.util.List; 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.modelmapper.ModelMapper; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.context.annotation.Configuration; 26 | import org.springframework.test.context.junit4.SpringRunner; 27 | 28 | import static org.hamcrest.CoreMatchers.is; 29 | import static org.hamcrest.CoreMatchers.notNullValue; 30 | import static org.hamcrest.MatcherAssert.assertThat; 31 | import static org.mockito.ArgumentMatchers.any; 32 | import static org.mockito.Mockito.mock; 33 | import static org.mockito.Mockito.verify; 34 | 35 | /** 36 | * Tests the registration of {@link ModelMapper}. 37 | * 38 | * @author Idan Rozenfeld 39 | */ 40 | @RunWith(SpringRunner.class) 41 | public class ModelMapperAutoConfigurationTest { 42 | 43 | @Autowired 44 | private ModelMapper modelMapper; 45 | 46 | @Autowired 47 | private List configurers; 48 | 49 | @Test 50 | public void shouldInstantiateMapper() { 51 | assertThat(modelMapper, is(notNullValue())); 52 | } 53 | 54 | @Test 55 | public void shouldInvokeConfigurer() { 56 | for (TypeMapConfigurer configurer : configurers) { 57 | verify(configurer).configureImpl(any(ModelMapper.class)); 58 | } 59 | } 60 | 61 | @Configuration 62 | @EnableAutoConfiguration 63 | public static class Application { 64 | @Bean 65 | public TypeMapConfigurer typeMapConfigurer() { 66 | return mock(TypeMapConfigurer.class); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/main/java/com/github/rozidan/springboot/modelmapper/WithModelMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 24 | import org.springframework.context.annotation.ComponentScan; 25 | import org.springframework.context.annotation.ComponentScan.Filter; 26 | import org.springframework.context.annotation.FilterType; 27 | import org.springframework.core.annotation.AliasFor; 28 | 29 | /** 30 | *

31 | * Annotation that can be used in combination with @RunWith(SpringRunner.class) in case model mapper 32 | * component are needed for testing. 33 | *

34 | * 35 | * @author Idan Rozenfeld 36 | */ 37 | @Target(ElementType.TYPE) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Documented 40 | @ImportAutoConfiguration(ModelMapperAutoConfiguration.class) 41 | @ComponentScan(useDefaultFilters = false, 42 | includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, 43 | classes = {TypeMapConfigurer.class, ConverterConfigurer.class, ConfigurationConfigurer.class})) 44 | public @interface WithModelMapper { 45 | 46 | /** 47 | * Base packages to scan for mapper's components. 48 | *

49 | * Use {@link #basePackageClasses} for a type-safe alternative to 50 | * String-based package names. 51 | */ 52 | @AliasFor(annotation = ComponentScan.class) 53 | String[] basePackages() default {}; 54 | 55 | /** 56 | * Type-safe alternative to {@link #basePackages} for specifying the packages 57 | * to scan for annotated components. The package of each class specified will be scanned. 58 | *

59 | * Consider creating a special no-op marker class or interface in each package 60 | * that serves no purpose other than being referenced by this attribute. 61 | */ 62 | @AliasFor(annotation = ComponentScan.class) 63 | Class[] basePackageClasses() default {}; 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/github/rozidan/springboot/modelmapper/ModelMapperFactoryBean.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import java.util.List; 19 | import org.modelmapper.ModelMapper; 20 | import org.springframework.beans.factory.FactoryBean; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | 23 | /** 24 | * A factory bean that instantiates the {@link ModelMapper} and configures it by delegating to registered 25 | * {@link TypeMapConfigurer} instances. 26 | * 27 | * @author Idan Rozenfeld 28 | */ 29 | public class ModelMapperFactoryBean implements FactoryBean { 30 | 31 | /** 32 | * The global configuration used for customizing the behaviour of the model mapper. 33 | */ 34 | @Autowired(required = false) 35 | private ConfigurationConfigurer mapperConfigurer; 36 | 37 | /** 38 | * The list of configurers used for customizing the behaviour of the model mapper. 39 | */ 40 | @Autowired(required = false) 41 | private List configurers; 42 | 43 | /** 44 | * The list of converters used for customizing the behaviour of the model mapper. 45 | */ 46 | @Autowired(required = false) 47 | private List converters; 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public ModelMapper getObject() { 54 | final ModelMapper modelMapper = new ModelMapper(); 55 | configure(modelMapper); 56 | return modelMapper; 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public Class getObjectType() { 64 | return ModelMapper.class; 65 | } 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @Override 71 | public boolean isSingleton() { 72 | return true; 73 | } 74 | 75 | /** 76 | * Configures the model mapper instance be delegating toward registered {@link TypeMapConfigurer} instances. 77 | * 78 | * @param modelMapper the model mapper 79 | */ 80 | private void configure(ModelMapper modelMapper) { 81 | if (mapperConfigurer != null) { 82 | mapperConfigurer.configureImpl(modelMapper); 83 | } 84 | 85 | if (converters != null) { 86 | converters.forEach(typeMapConfigurer -> typeMapConfigurer.configureImpl(modelMapper)); 87 | } 88 | 89 | if (configurers != null) { 90 | configurers.forEach(typeMapConfigurer -> typeMapConfigurer.configureImpl(modelMapper)); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/TypeMapConfigurerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | 19 | import com.github.rozidan.springboot.modelmapper.dtos.UserDto; 20 | import com.github.rozidan.springboot.modelmapper.entities.User; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.modelmapper.ModelMapper; 24 | import org.modelmapper.TypeMap; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 27 | import org.springframework.context.annotation.Bean; 28 | import org.springframework.context.annotation.Configuration; 29 | import org.springframework.test.context.junit4.SpringRunner; 30 | 31 | import static org.hamcrest.CoreMatchers.equalTo; 32 | import static org.hamcrest.CoreMatchers.is; 33 | import static org.hamcrest.CoreMatchers.notNullValue; 34 | import static org.hamcrest.MatcherAssert.assertThat; 35 | 36 | /** 37 | * Tests the {@link TypeMapConfigurer} class. 38 | * 39 | * @author Idan Rozenfeld 40 | */ 41 | @RunWith(SpringRunner.class) 42 | public class TypeMapConfigurerTest { 43 | 44 | @Autowired 45 | private ModelMapper modelMapper; 46 | 47 | @Test 48 | public void shouldInstantiateMapper() { 49 | assertThat(modelMapper, is(notNullValue())); 50 | } 51 | 52 | @Test 53 | public void shouldMapUserEntity() { 54 | final User user = new User("John Doe", 23); 55 | final UserDto userDto = modelMapper.map(user, UserDto.class); 56 | assertThat(userDto.getFirstName(), equalTo("John")); 57 | assertThat(userDto.getLastName(), equalTo("Doe")); 58 | assertThat(userDto.getAge(), equalTo(user.getAge())); 59 | } 60 | 61 | @Configuration 62 | @EnableAutoConfiguration 63 | public static class Application { 64 | 65 | @Bean 66 | public TypeMapConfigurer userMapping() { 67 | return new TypeMapConfigurer() { 68 | 69 | @Override 70 | public void configure(TypeMap typeMap) { 71 | typeMap.addMapping(User::getAge, UserDto::setAge); 72 | typeMap.setPreConverter(context -> { 73 | String[] name = context.getSource().getName().split(" "); 74 | context.getDestination().setFirstName(name[0]); 75 | context.getDestination().setLastName(name[1]); 76 | return context.getDestination(); 77 | }); 78 | } 79 | }; 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/TypeMapNameTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | 19 | import com.github.rozidan.springboot.modelmapper.dtos.UserDto; 20 | import com.github.rozidan.springboot.modelmapper.entities.User; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.modelmapper.ModelMapper; 24 | import org.modelmapper.TypeMap; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 27 | import org.springframework.context.annotation.Bean; 28 | import org.springframework.context.annotation.Configuration; 29 | import org.springframework.test.context.junit4.SpringRunner; 30 | 31 | import static org.hamcrest.CoreMatchers.equalTo; 32 | import static org.hamcrest.CoreMatchers.is; 33 | import static org.hamcrest.CoreMatchers.notNullValue; 34 | import static org.hamcrest.CoreMatchers.nullValue; 35 | import static org.hamcrest.MatcherAssert.assertThat; 36 | 37 | /** 38 | * Tests the {@link TypeMapConfigurer} class. 39 | * 40 | * @author Idan Rozenfeld 41 | */ 42 | @RunWith(SpringRunner.class) 43 | public class TypeMapNameTest { 44 | 45 | @Autowired 46 | private ModelMapper modelMapper; 47 | 48 | @Test 49 | public void shouldInstantiateMapper() { 50 | assertThat(modelMapper, is(notNullValue())); 51 | } 52 | 53 | @Test 54 | public void shouldMapUserEntity() { 55 | final User user = new User("John Doe", 23); 56 | 57 | final UserDto userDto1 = modelMapper.map(user, UserDto.class); 58 | assertThat(userDto1.getFirstName(), is(nullValue())); 59 | 60 | final UserDto userDto2 = modelMapper.map(user, UserDto.class, "userMappingV1"); 61 | assertThat(userDto2.getFirstName(), equalTo("John Doe")); 62 | assertThat(userDto2.getAge(), equalTo(user.getAge())); 63 | } 64 | 65 | @Configuration 66 | @EnableAutoConfiguration 67 | public static class Application { 68 | 69 | @Bean 70 | public TypeMapConfigurer userMapping() { 71 | return new TypeMapConfigurer() { 72 | 73 | @Override 74 | public String getTypeMapName() { 75 | return "userMappingV1"; 76 | } 77 | 78 | @Override 79 | public void configure(TypeMap typeMap) { 80 | typeMap.addMapping(User::getAge, UserDto::setAge); 81 | typeMap.addMapping(User::getName, UserDto::setFirstName); 82 | } 83 | }; 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/TypeMapConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import com.github.rozidan.springboot.modelmapper.dtos.UserDto; 19 | import com.github.rozidan.springboot.modelmapper.entities.User; 20 | import org.junit.Ignore; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.modelmapper.ModelMapper; 24 | import org.modelmapper.TypeMap; 25 | import org.modelmapper.internal.InheritingConfiguration; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.context.annotation.Configuration; 30 | import org.springframework.test.context.junit4.SpringRunner; 31 | 32 | import static org.hamcrest.CoreMatchers.equalTo; 33 | import static org.hamcrest.CoreMatchers.is; 34 | import static org.hamcrest.CoreMatchers.notNullValue; 35 | import static org.hamcrest.MatcherAssert.assertThat; 36 | 37 | /** 38 | * @author Idan Rozenfeld 39 | */ 40 | @RunWith(SpringRunner.class) 41 | public class TypeMapConfigurationTest { 42 | 43 | @Autowired 44 | private ModelMapper modelMapper; 45 | 46 | @Test 47 | public void shouldInstantiateMapper() { 48 | assertThat(modelMapper, is(notNullValue())); 49 | } 50 | 51 | @Test 52 | @Ignore("Applying configuration to specific type map is not working") 53 | public void shouldMapUserEntityWithoutNulls() { 54 | final User user = new User(null, 23); 55 | final UserDto userDto = new UserDto("John", "Doe", 22, "??"); 56 | modelMapper.map(user, userDto); 57 | assertThat(userDto.getFirstName(), equalTo("John")); 58 | assertThat(userDto.getLastName(), equalTo("Doe")); 59 | assertThat(userDto.getAge(), equalTo(user.getAge())); 60 | } 61 | 62 | @Configuration 63 | @EnableAutoConfiguration 64 | public static class Application { 65 | 66 | @Bean 67 | public TypeMapConfigurer userMapping() { 68 | return new TypeMapConfigurer() { 69 | 70 | @Override 71 | public org.modelmapper.config.Configuration getConfiguration() { 72 | return new InheritingConfiguration().setSkipNullEnabled(true); 73 | } 74 | 75 | @Override 76 | public void configure(TypeMap typeMap) { 77 | typeMap.addMapping(User::getAge, UserDto::setAge); 78 | typeMap.addMapping(User::getName, UserDto::setFirstName); 79 | typeMap.addMapping(User::getName, UserDto::setLastName); 80 | } 81 | }; 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/ConfigurationConfigurerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import com.github.rozidan.springboot.modelmapper.dtos.UserDto; 19 | import com.github.rozidan.springboot.modelmapper.entities.User; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.modelmapper.ModelMapper; 23 | import org.modelmapper.TypeMap; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 26 | import org.springframework.context.annotation.Bean; 27 | import org.springframework.context.annotation.Configuration; 28 | import org.springframework.test.context.junit4.SpringRunner; 29 | 30 | import static org.hamcrest.CoreMatchers.equalTo; 31 | import static org.hamcrest.CoreMatchers.is; 32 | import static org.hamcrest.CoreMatchers.notNullValue; 33 | import static org.hamcrest.MatcherAssert.assertThat; 34 | 35 | /** 36 | * @author Idan Rozenfeld 37 | */ 38 | @RunWith(SpringRunner.class) 39 | public class ConfigurationConfigurerTest { 40 | 41 | @Autowired 42 | private ModelMapper modelMapper; 43 | 44 | @Test 45 | public void shouldInstantiateMapper() { 46 | assertThat(modelMapper, is(notNullValue())); 47 | } 48 | 49 | @Test 50 | public void shouldMapUserEntityWithoutNulls() { 51 | final User user = new User(null, 23); 52 | final UserDto userDto = new UserDto("John", "Doe", 24, "??"); 53 | modelMapper.map(user, userDto); 54 | assertThat(userDto.getFirstName(), equalTo("John")); 55 | assertThat(userDto.getLastName(), equalTo("Doe")); 56 | assertThat(userDto.getAge(), equalTo(user.getAge())); 57 | } 58 | 59 | @Configuration 60 | @EnableAutoConfiguration 61 | public static class Application { 62 | 63 | @Bean 64 | public TypeMapConfigurer userMapping() { 65 | return new TypeMapConfigurer() { 66 | 67 | @Override 68 | public void configure(TypeMap typeMap) { 69 | typeMap.addMapping(User::getAge, UserDto::setAge); 70 | typeMap.addMapping(User::getName, UserDto::setFirstName); 71 | typeMap.addMapping(User::getName, UserDto::setLastName); 72 | } 73 | }; 74 | } 75 | 76 | @Bean 77 | public ConfigurationConfigurer mapperConfiguration() { 78 | return new ConfigurationConfigurer() { 79 | @Override 80 | public void configure(org.modelmapper.config.Configuration configuration) { 81 | configuration.setSkipNullEnabled(true); 82 | } 83 | }; 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/ConverterConfigurerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import com.github.rozidan.springboot.modelmapper.dtos.ProdTypeDto; 19 | import com.github.rozidan.springboot.modelmapper.dtos.ProductDto; 20 | import com.github.rozidan.springboot.modelmapper.entities.ProdType; 21 | import com.github.rozidan.springboot.modelmapper.entities.Product; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.modelmapper.AbstractConverter; 25 | import org.modelmapper.Converter; 26 | import org.modelmapper.ModelMapper; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 29 | import org.springframework.context.annotation.Bean; 30 | import org.springframework.context.annotation.Configuration; 31 | import org.springframework.test.context.junit4.SpringRunner; 32 | 33 | import static org.hamcrest.CoreMatchers.equalTo; 34 | import static org.hamcrest.CoreMatchers.is; 35 | import static org.hamcrest.CoreMatchers.notNullValue; 36 | import static org.hamcrest.MatcherAssert.assertThat; 37 | 38 | /** 39 | * Tests the {@link ConverterConfigurer} class. 40 | * 41 | * @author Idan Rozenfeld 42 | */ 43 | @RunWith(SpringRunner.class) 44 | public class ConverterConfigurerTest { 45 | 46 | @Autowired 47 | private ModelMapper modelMapper; 48 | 49 | @Test 50 | public void shouldInstantiateMapper() { 51 | assertThat(modelMapper, is(notNullValue())); 52 | } 53 | 54 | @Test 55 | public void shouldMapProductEntity() { 56 | final Product product = new Product("Banana", ProdType.T1); 57 | final ProductDto productDto = modelMapper.map(product, ProductDto.class); 58 | assertThat(productDto.getName(), equalTo("Banana")); 59 | assertThat(productDto.getType(), equalTo(ProdTypeDto.TYPE1)); 60 | } 61 | 62 | @Configuration 63 | @EnableAutoConfiguration 64 | public static class Application { 65 | 66 | @Bean 67 | public ConverterConfigurer userMapping() { 68 | return new ConverterConfigurer() { 69 | @Override 70 | public Converter converter() { 71 | return new AbstractConverter() { 72 | @Override 73 | protected ProdTypeDto convert(ProdType source) { 74 | switch (source) { 75 | case T1: 76 | return ProdTypeDto.TYPE1; 77 | case T2: 78 | return ProdTypeDto.TYPE2; 79 | } 80 | return null; 81 | } 82 | }; 83 | } 84 | }; 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /src/test/java/com/github/rozidan/springboot/modelmapper/TypeMapConfigurationAndNameTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Idan Roz the original author or authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.rozidan.springboot.modelmapper; 17 | 18 | import com.github.rozidan.springboot.modelmapper.dtos.UserDto; 19 | import com.github.rozidan.springboot.modelmapper.entities.User; 20 | import org.junit.Ignore; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.modelmapper.ModelMapper; 24 | import org.modelmapper.TypeMap; 25 | import org.modelmapper.internal.InheritingConfiguration; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.context.annotation.Configuration; 30 | import org.springframework.test.context.junit4.SpringRunner; 31 | 32 | import static org.hamcrest.CoreMatchers.equalTo; 33 | import static org.hamcrest.CoreMatchers.is; 34 | import static org.hamcrest.CoreMatchers.notNullValue; 35 | import static org.hamcrest.MatcherAssert.assertThat; 36 | 37 | /** 38 | * @author Idan Rozenfeld 39 | */ 40 | @RunWith(SpringRunner.class) 41 | public class TypeMapConfigurationAndNameTest { 42 | 43 | @Autowired 44 | private ModelMapper modelMapper; 45 | 46 | @Test 47 | public void shouldInstantiateMapper() { 48 | assertThat(modelMapper, is(notNullValue())); 49 | } 50 | 51 | @Test 52 | @Ignore("Applying configuration to specific type map is not working") 53 | public void shouldMapUserEntityWithoutNulls() { 54 | final User user = new User(null, 23); 55 | final UserDto userDto = new UserDto("John", "Doe", 22, "??"); 56 | modelMapper.map(user, userDto, "testName"); 57 | assertThat(userDto.getFirstName(), equalTo("John")); 58 | assertThat(userDto.getLastName(), equalTo("Doe")); 59 | assertThat(userDto.getAge(), equalTo(user.getAge())); 60 | } 61 | 62 | @Configuration 63 | @EnableAutoConfiguration 64 | public static class Application { 65 | 66 | @Bean 67 | public TypeMapConfigurer userMapping() { 68 | return new TypeMapConfigurer() { 69 | 70 | @Override 71 | public org.modelmapper.config.Configuration getConfiguration() { 72 | return new InheritingConfiguration().setSkipNullEnabled(true); 73 | } 74 | 75 | @Override 76 | public String getTypeMapName() { 77 | return "testName"; 78 | } 79 | 80 | @Override 81 | public void configure(TypeMap typeMap) { 82 | typeMap.addMapping(User::getAge, UserDto::setAge); 83 | typeMap.addMapping(User::getName, UserDto::setFirstName); 84 | typeMap.addMapping(User::getName, UserDto::setLastName); 85 | } 86 | }; 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot ModelMapper Starter 2 | > A Spring Boot starter that let you use [ModelMapper](http://modelmapper.org) within your Spring Boot application. 3 | 4 | > Base on [jmnarloch modelmapper project](https://github.com/jmnarloch/modelmapper-spring-boot-starter) with Modelmapper newest version adjustments. 5 | 6 | [![Build Status](https://travis-ci.org/rozidan/modelmapper-spring-boot-starter.svg?branch=master)](https://travis-ci.org/rozidan/modelmapper-spring-boot-starter) 7 | [![Coverage Status](https://coveralls.io/repos/github/rozidan/modelmapper-spring-boot-starter/badge.svg?branch=master)](https://coveralls.io/github/rozidan/modelmapper-spring-boot-starter?branch=master) 8 | 9 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.rozidan/modelmapper-spring-boot-starter/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.rozidan/modelmapper-spring-boot-starter/) 10 | [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/com.github.rozidan/modelmapper-spring-boot-starter.svg)](https://oss.sonatype.org/content/repositories/snapshots/com/github/rozidan/modelmapper-spring-boot-starter/) 11 | 12 | [![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) 13 | 14 | ## Features 15 | Register the ModelMapper to your Spring Boot application and allows to configure it and register object mappings. 16 | 17 | ## Setup 18 | In order to add ModelMapper to your project simply add this dependency to your classpath: 19 | ```xml 20 | 21 | com.github.rozidan 22 | modelmapper-spring-boot-starter 23 | 2.3.1 24 | 25 | ``` 26 | 27 | ```groovy 28 | compile 'com.github.rozidan:modelmapper-spring-boot-starter:2.3.1' 29 | ``` 30 | For snapshots versions add the sonatype public repository: 31 | ```groovy 32 | repositories { 33 | mavenCentral() 34 | maven { url "https://oss.sonatype.org/content/groups/public" } 35 | ... 36 | } 37 | ``` 38 | 39 | ### Change ModelMapper global configuration 40 | In order to set change ModelMapper global configuration, simply register within Spring application context instance of `MapperConfigurer`: 41 | ```java 42 | @Component 43 | public class GlobalConfiguration extends MapperConfigurer { 44 | @Override 45 | public void configure(Configuration configuration) { 46 | configuration.setSkipNullEnabled(true); 47 | configuration.setMatchingStrategy(MatchingStrategies.STRICT); 48 | } 49 | } 50 | ``` 51 | 52 | ### Overriding the default mapping 53 | In order to override the default mapping of some object types, lets say User -> UserDto, simply register within Spring application context instance of `TypeMapConfigurer`: 54 | ```java 55 | @Component 56 | public class MapperConfigurer extends TypeMapConfigurer { 57 | @Override 58 | public void configure(TypeMap typeMap) { 59 | typeMap.addMapping(User::getAge, UserDto::setAge); 60 | typeMap.addMappings(mapping -> mapping.skip(UserDto::setMiddleName)); 61 | typeMap.setPreConverter(context -> { 62 | String[] name = context.getSource().getName().split(" "); 63 | context.getDestination().setFirstName(name[0]); 64 | context.getDestination().setLastName(name[1]); 65 | return context.getDestination(); 66 | }); 67 | 68 | } 69 | } 70 | ``` 71 | 72 | ### Custom converter 73 | In order to register ModelMapper Converter, simply register within Spring application context instance of `ConverterConfigurer`: 74 | ```java 75 | @Component 76 | public class SomeEnumTypeConverter extends ConverterConfigurer { 77 | @Override 78 | public Converter converter() { 79 | return new AbstractConverter() { 80 | @Override 81 | protected ProductCategoryDto convert(ProductCategory source) { 82 | ... 83 | } 84 | }; 85 | } 86 | } 87 | ``` 88 | 89 | ### Testing 90 | Scan for mapping components with the `WithModelMapper` annotation 91 | ```java 92 | @RunWith(SpringRunner.class) 93 | public class MapperTest { 94 | 95 | @Test 96 | public void someTest() { 97 | 98 | } 99 | 100 | @Configuration 101 | @WithModelMapper(basePackage = "com.company.program.mapping") 102 | public static class Application { 103 | } 104 | } 105 | ``` 106 | 107 | ## License 108 | [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0) 109 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /gradle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 58 | 59 | 60 | 61 | 62 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 72 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 116 | 117 | 118 | 120 | 121 | 122 | 123 | 125 | 126 | 127 | 128 | 130 | 131 | 132 | 133 | 135 | 136 | 137 | 138 | 139 | 141 | 142 | 143 | 144 | 146 | 147 | 148 | 149 | 151 | 152 | 153 | 154 | 156 | 157 | 158 | 159 | 161 | 163 | 165 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | --------------------------------------------------------------------------------