From c27bfc0de3253f4922015aa353070020c261229c Mon Sep 17 00:00:00 2001 From: aurea munoz Date: Tue, 11 Feb 2020 22:42:24 +0100 Subject: [PATCH] refactor: rewrite without lambdas Related to #6192 --- .../deployment/SpringDataJPAProcessor.java | 57 +++++++++++-------- .../src/it/spring-configuration/verify.groovy | 2 +- 2 files changed, 35 insertions(+), 24 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 1f4461ee02dbe..5efd48caedc9e 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 @@ -5,14 +5,11 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; @@ -49,6 +46,14 @@ public class SpringDataJPAProcessor { private static final Logger LOGGER = Logger.getLogger(SpringDataJPAProcessor.class.getName()); private static final Pattern pattern = Pattern.compile("spring\\.jpa\\..*"); + public static final String SPRING_JPA_SHOW_SQL = "spring.jpa.show-sql"; + public static final String SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT = "spring.jpa.properties.hibernate.dialect"; + public static final String SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT_STORAGE_ENGINE = "spring.jpa.properties.hibernate.dialect.storage_engine"; + public static final String SPRING_JPA_GENERATE_DDL = "spring.jpa.generate-ddl"; + public static final String QUARKUS_HIBERNATE_ORM_DIALECT = "quarkus.hibernate-orm.dialect"; + public static final String QUARKUS_HIBERNATE_ORM_LOG_SQL = "quarkus.hibernate-orm.log.sql"; + public static final String QUARKUS_HIBERNATE_ORM_DIALECT_STORAGE_ENGINE = "quarkus.hibernate-orm.dialect.storage-engine"; + public static final String QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION = "quarkus.hibernate-orm.database.generation"; @BuildStep FeatureBuildItem registerFeature() { @@ -82,34 +87,40 @@ void build(CombinedIndexBuildItem index, 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.storage_engine", - "quarkus.hibernate-orm.dialect.storage-engine"); - springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.generate-ddl", "quarkus.hibernate-orm.database.generation"); Iterable iterablePropertyNames = config.getPropertyNames(); List propertyNames = new ArrayList(); iterablePropertyNames.forEach(propertyNames::add); List springProperties = propertyNames.stream().filter(s -> pattern.matcher(s).matches()).collect(toList()); + String notSupportedProperties = ""; if (!springProperties.isEmpty()) { - 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")); - + for (String sp : springProperties) { + switch (sp) { + case SPRING_JPA_SHOW_SQL: + notSupportedProperties = notSupportedProperties + "\t- " + SPRING_JPA_SHOW_SQL + + " should be replaced by " + QUARKUS_HIBERNATE_ORM_LOG_SQL + "\n"; + break; + case SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT: + notSupportedProperties = notSupportedProperties + "\t- " + SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT + + " should be replaced by " + QUARKUS_HIBERNATE_ORM_DIALECT + "\n"; + break; + case SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT_STORAGE_ENGINE: + notSupportedProperties = notSupportedProperties + "\t- " + + SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT_STORAGE_ENGINE + " should be replaced by " + + QUARKUS_HIBERNATE_ORM_DIALECT_STORAGE_ENGINE + "\n"; + break; + case SPRING_JPA_GENERATE_DDL: + notSupportedProperties = notSupportedProperties + "\t- " + SPRING_JPA_GENERATE_DDL + + " should be replaced by " + QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION + "\n"; + break; + default: + notSupportedProperties = notSupportedProperties + "\t- " + sp + "\n"; + break; + } + } LOGGER.warnf( - "Quarkus does not support the following Spring Boot configuration properties :%n%s", + "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/verify.groovy b/integration-tests/spring-data-jpa/src/it/spring-configuration/verify.groovy index 1b8f8694dfb91..7acac7094d9ff 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,7 +4,7 @@ File mvnInvokerLog = new File(base, "build.log") assert mvnInvokerLog.exists() def contentFile = mvnInvokerLog.text -assert contentFile.contains("Quarkus does not support the following Spring Boot configuration properties :") +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")