Skip to content

Commit

Permalink
feat: log warning in case of finding spring.jpa properties configuration
Browse files Browse the repository at this point in the history
Related to quarkusio#6192
  • Loading branch information
aureamunoz committed Feb 7, 2020
1 parent a2541c7 commit 467f96e
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -57,6 +68,8 @@ void build(CombinedIndexBuildItem index,
BuildProducer<GeneratedBeanBuildItem> generatedBeans,
BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {

detectAndLogSpecificSpringPropertiesIfExist();

IndexView indexIndex = index.getIndex();
List<ClassInfo> interfacesExtendingCrudRepository = getAllInterfacesExtending(DotNames.SUPPORTED_REPOSITORIES,
indexIndex);
Expand All @@ -66,6 +79,35 @@ void build(CombinedIndexBuildItem index,
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()) {
Expand Down
36 changes: 36 additions & 0 deletions integration-tests/spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/it</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
Expand All @@ -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>

Expand Down
133 changes: 133 additions & 0 deletions integration-tests/spring-data-jpa/src/it/spring-configuration/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.")

0 comments on commit 467f96e

Please sign in to comment.