From da3b741173d35e9309291d6df2c16fcf23b76081 Mon Sep 17 00:00:00 2001 From: aurea munoz Date: Tue, 4 Feb 2020 14:54:00 +0100 Subject: [PATCH] refactor: integrate code review comments Related to #6192 --- .../deployment/SpringDataJPAProcessor.java | 34 +++++++++++-------- .../src/main/resources/application.properties | 3 +- .../src/it/spring-configuration/verify.groovy | 6 ++-- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/SpringDataJPAProcessor.java b/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/SpringDataJPAProcessor.java index 6504695371ed71..1f4461ee02dbed 100644 --- a/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/SpringDataJPAProcessor.java +++ b/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/SpringDataJPAProcessor.java @@ -11,8 +11,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; @@ -48,6 +48,7 @@ public class SpringDataJPAProcessor { private static final Logger LOGGER = Logger.getLogger(SpringDataJPAProcessor.class.getName()); + private static final Pattern pattern = Pattern.compile("spring\\.jpa\\..*"); @BuildStep FeatureBuildItem registerFeature() { @@ -83,7 +84,7 @@ private void detectAndLogSpecificSpringPropertiesIfExist() { Config config = ConfigProvider.getConfig(); Map springJpaToQuarkusOrmPropertiesMap = new HashMap<>(); springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.show-sql", "quarkus.hibernate-orm.log.sql"); - springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.properties.hibernate.dialect ", "quarkus.hibernate-orm.dialect"); + springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.properties.hibernate.dialect", "quarkus.hibernate-orm.dialect"); springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.properties.hibernate.dialect.storage_engine", "quarkus.hibernate-orm.dialect.storage-engine"); springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.generate-ddl", "quarkus.hibernate-orm.database.generation"); @@ -91,20 +92,25 @@ private void detectAndLogSpecificSpringPropertiesIfExist() { Iterable iterablePropertyNames = config.getPropertyNames(); List propertyNames = new ArrayList(); iterablePropertyNames.forEach(propertyNames::add); - Pattern pattern = Pattern.compile("spring\\.jpa\\..*"); - Matcher matcher = pattern.matcher(""); - List springProperties = propertyNames.stream().filter(s -> matcher.reset(s).matches()).collect(toList()); + List springProperties = propertyNames.stream().filter(s -> pattern.matcher(s).matches()).collect(toList()); + if (!springProperties.isEmpty()) { - String warningLog = "Quarkus does not support the "; - for (String springProperty : springProperties) { - String quarkusProperty = springJpaToQuarkusOrmPropertiesMap.get(springProperty); - if (quarkusProperty != null) { - warningLog = warningLog + springProperty + " property " + "you may try to use the Quarkus equivalent one : " - + quarkusProperty + "."; - } - LOGGER.warn(warningLog + springProperty + " property. "); - } + List springWithQuarkusEquivalences = springProperties.stream() + .filter(s -> springJpaToQuarkusOrmPropertiesMap.containsKey(s)).collect(Collectors.toList()); + + String notSupportedProperties = springWithQuarkusEquivalences.stream() + .map(d -> "\t- " + d + " should be replaced by " + springJpaToQuarkusOrmPropertiesMap.get(d)) + .collect(Collectors.joining("\n")); + + List others = springProperties.stream().filter(s -> !springJpaToQuarkusOrmPropertiesMap.containsKey(s)) + .collect(Collectors.toList()); + + notSupportedProperties = notSupportedProperties + "\n" + + others.stream().map(d -> "\t- " + d).collect(Collectors.joining("\n")); + LOGGER.warnf( + "Quarkus does not support the following Spring Boot configuration properties :%n%s", + notSupportedProperties); } } diff --git a/integration-tests/spring-data-jpa/src/it/spring-configuration/src/main/resources/application.properties b/integration-tests/spring-data-jpa/src/it/spring-configuration/src/main/resources/application.properties index 05736228b51ff9..fe873ee114f641 100644 --- a/integration-tests/spring-data-jpa/src/it/spring-configuration/src/main/resources/application.properties +++ b/integration-tests/spring-data-jpa/src/it/spring-configuration/src/main/resources/application.properties @@ -13,4 +13,5 @@ quarkus.hibernate-orm.database.generation=drop-and-create %prod.quarkus.hibernate-orm.sql-load-script=import.sql spring.jpa.show-sql=true -spring.jpa.data.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect \ No newline at end of file +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +spring.jpa.open-in-view=false \ No newline at end of file diff --git a/integration-tests/spring-data-jpa/src/it/spring-configuration/verify.groovy b/integration-tests/spring-data-jpa/src/it/spring-configuration/verify.groovy index 9cd64b37b30207..1b8f8694dfb91c 100644 --- a/integration-tests/spring-data-jpa/src/it/spring-configuration/verify.groovy +++ b/integration-tests/spring-data-jpa/src/it/spring-configuration/verify.groovy @@ -4,5 +4,7 @@ File mvnInvokerLog = new File(base, "build.log") assert mvnInvokerLog.exists() def contentFile = mvnInvokerLog.text -assert contentFile.contains("Quarkus does not support the spring.jpa.show-sql property you may try to use the Quarkus equivalent one : quarkus.hibernate-orm.log.sql.spring.jpa.show-sql property.") -assert contentFile.contains("Quarkus does not support the spring.jpa.data.hibernate.dialect property.") +assert contentFile.contains("Quarkus does not support the following Spring Boot configuration properties :") +assert contentFile.contains("- spring.jpa.show-sql should be replaced by quarkus.hibernate-orm.log.sql") +assert contentFile.contains("- spring.jpa.properties.hibernate.dialect should be replaced by quarkus.hibernate-orm.dialect") +assert contentFile.contains("- spring.jpa.open-in-view")