Skip to content

Commit

Permalink
refactor: integrate code review comments
Browse files Browse the repository at this point in the history
Related to #6192
  • Loading branch information
aureamunoz committed Feb 4, 2020
1 parent 5078d3c commit da3b741
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -83,28 +84,33 @@ 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", "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());
List<String> 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<String> 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<String> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.open-in-view=false
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit da3b741

Please sign in to comment.