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 31845826229c13..6504695371ed71 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 @@ -1,18 +1,27 @@ package io.quarkus.spring.data.deployment; +import static java.util.stream.Collectors.toList; + 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.Matcher; +import java.util.regex.Pattern; +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.CompositeIndex; import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; +import org.jboss.logging.Logger; import org.springframework.data.domain.Auditable; import org.springframework.data.domain.Persistable; import org.springframework.data.jpa.repository.JpaRepository; @@ -38,6 +47,8 @@ public class SpringDataJPAProcessor { + private static final Logger LOGGER = Logger.getLogger(SpringDataJPAProcessor.class.getName()); + @BuildStep FeatureBuildItem registerFeature() { return new FeatureBuildItem(FeatureBuildItem.SPRING_DATA_JPA); @@ -57,6 +68,8 @@ void build(CombinedIndexBuildItem index, BuildProducer generatedBeans, BuildProducer additionalBeans, BuildProducer reflectiveClasses) { + detectAndLogSpecificSpringPropertiesIfExist(); + IndexView indexIndex = index.getIndex(); List interfacesExtendingCrudRepository = getAllInterfacesExtending(DotNames.SUPPORTED_REPOSITORIES, indexIndex); @@ -66,6 +79,35 @@ void build(CombinedIndexBuildItem index, interfacesExtendingCrudRepository, indexIndex); } + 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); + Pattern pattern = Pattern.compile("spring\\.jpa\\..*"); + Matcher matcher = pattern.matcher(""); + List springProperties = propertyNames.stream().filter(s -> matcher.reset(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. "); + } + + } + } + private void removeNoRepositoryBeanClasses(List interfacesExtendingCrudRepository) { Iterator iterator = interfacesExtendingCrudRepository.iterator(); while (iterator.hasNext()) { diff --git a/integration-tests/spring-data-jpa/pom.xml b/integration-tests/spring-data-jpa/pom.xml index 09f0cce83de0c7..9eb64920a2f222 100644 --- a/integration-tests/spring-data-jpa/pom.xml +++ b/integration-tests/spring-data-jpa/pom.xml @@ -55,6 +55,12 @@ + + + src/it + true + + io.quarkus @@ -68,6 +74,36 @@ + + maven-invoker-plugin + 3.1.0 + + + integration-tests + + install + run + verify + + + + + ${project.build.directory}/it + true + verify + true + ${skipTests} + true + invoker.properties + + + + org.codehaus.groovy + groovy + 2.5.8 + + + diff --git a/integration-tests/spring-data-jpa/src/it/spring-configuration/pom.xml b/integration-tests/spring-data-jpa/src/it/spring-configuration/pom.xml new file mode 100644 index 00000000000000..669b9c68f8ad88 --- /dev/null +++ b/integration-tests/spring-data-jpa/src/it/spring-configuration/pom.xml @@ -0,0 +1,133 @@ + + + 4.0.0 + org.acme + spring-configuration + 1.0-SNAPSHOT + + UTF-8 + 2.22.0 + 1.8 + UTF-8 + 1.8 + 3.8.1 + + + + + io.quarkus + quarkus-bom + @project.version@ + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + io.quarkus + quarkus-spring-data-jpa + + + io.quarkus + quarkus-jdbc-h2 + + + io.quarkus + quarkus-resteasy-jsonb + + + + + + io.quarkus + quarkus-maven-plugin + @project.version@ + + + + build + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + + + + + + + + native + + + native + + + + + + io.quarkus + quarkus-maven-plugin + @project.version@ + + + + native-image + + + true + + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + + + + + + native + + + + diff --git a/integration-tests/spring-data-jpa/src/it/spring-configuration/src/main/java/org/acme/spring/data/jpa/FruitResource.java b/integration-tests/spring-data-jpa/src/it/spring-configuration/src/main/java/org/acme/spring/data/jpa/FruitResource.java new file mode 100644 index 00000000000000..50a087579b57a8 --- /dev/null +++ b/integration-tests/spring-data-jpa/src/it/spring-configuration/src/main/java/org/acme/spring/data/jpa/FruitResource.java @@ -0,0 +1,16 @@ +package org.acme.spring.data.jpa; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/greeting") +public class FruitResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } +} \ No newline at end of file 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 new file mode 100644 index 00000000000000..05736228b51ff9 --- /dev/null +++ b/integration-tests/spring-data-jpa/src/it/spring-configuration/src/main/resources/application.properties @@ -0,0 +1,16 @@ +# Configuration file +# key = value +quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:default +quarkus.datasource.driver=org.h2.Driver +quarkus.datasource.username=username-default +quarkus.datasource.min-size=3 +quarkus.datasource.max-size=13 + + +quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect +quarkus.hibernate-orm.database.generation=drop-and-create +#quarkus.hibernate-orm.log.sql=true + +%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 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 new file mode 100644 index 00000000000000..9cd64b37b30207 --- /dev/null +++ b/integration-tests/spring-data-jpa/src/it/spring-configuration/verify.groovy @@ -0,0 +1,8 @@ +//Check that file exits +String base = basedir +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.")