mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
feat: log warning in case of finding spring.jpa properties configuration
Related to #6192
This commit is contained in:
@@ -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 @@ import io.quarkus.spring.data.deployment.generate.SpringDataRepositoryCreator;
|
||||
|
||||
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 @@ public class SpringDataJPAProcessor {
|
||||
BuildProducer<GeneratedBeanBuildItem> generatedBeans,
|
||||
BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
|
||||
|
||||
detectAndLogSpecificSpringPropertiesIfExist();
|
||||
|
||||
IndexView indexIndex = index.getIndex();
|
||||
List<ClassInfo> interfacesExtendingCrudRepository = getAllInterfacesExtending(DotNames.SUPPORTED_REPOSITORIES,
|
||||
indexIndex);
|
||||
@@ -66,6 +79,35 @@ public class SpringDataJPAProcessor {
|
||||
interfacesExtendingCrudRepository, indexIndex);
|
||||
}
|
||||
|
||||
private void detectAndLogSpecificSpringPropertiesIfExist() {
|
||||
Config config = ConfigProvider.getConfig();
|
||||
Map<String, String> 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<String> iterablePropertyNames = config.getPropertyNames();
|
||||
List<String> propertyNames = new ArrayList<String>();
|
||||
iterablePropertyNames.forEach(propertyNames::add);
|
||||
Pattern pattern = Pattern.compile("spring\\.jpa\\..*");
|
||||
Matcher matcher = pattern.matcher("");
|
||||
List<String> 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<ClassInfo> interfacesExtendingCrudRepository) {
|
||||
Iterator<ClassInfo> iterator = interfacesExtendingCrudRepository.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
@@ -55,6 +55,12 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>src/it</directory>
|
||||
<filtering>true</filtering>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
@@ -68,6 +74,36 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-invoker-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration-tests</id>
|
||||
<goals>
|
||||
<goal>install</goal>
|
||||
<goal>run</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
|
||||
<cloneClean>true</cloneClean>
|
||||
<postBuildHookScript>verify</postBuildHookScript>
|
||||
<addTestClassPath>true</addTestClassPath>
|
||||
<skipInvocation>${skipTests}</skipInvocation>
|
||||
<streamLogs>true</streamLogs>
|
||||
<invokerPropertiesFile>invoker.properties</invokerPropertiesFile>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
<version>2.5.8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.acme</groupId>
|
||||
<artifactId>spring-configuration</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<surefire-plugin.version>2.22.0</surefire-plugin.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<compiler-plugin.version>3.8.1</compiler-plugin.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-bom</artifactId>
|
||||
<version>@project.version@</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-resteasy</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-spring-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-jdbc-h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-resteasy-jsonb</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>@project.version@</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>build</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>native</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>@project.version@</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>native-image</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<enableHttpUrlHandler>true</enableHttpUrlHandler>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<quarkus.package.type>native</quarkus.package.type>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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.")
|
||||
Reference in New Issue
Block a user