From 7ee3656188b5f4636e669cc1dbac4cc935af7c2b Mon Sep 17 00:00:00 2001 From: Kant Date: Mon, 26 Aug 2019 20:32:28 +0800 Subject: [PATCH 1/2] Polish See gh-17962 --- .../boot/autoconfigure/AutoConfigurationSorter.java | 4 ++-- .../ImportAutoConfigurationImportSelector.java | 4 ++-- .../boot/autoconfigure/condition/OnBeanCondition.java | 8 ++------ .../groovy/template/GroovyTemplateAutoConfiguration.java | 5 +---- .../boot/autoconfigure/jmx/ParentAwareNamingStrategy.java | 5 +++-- .../orm/jpa/DataSourceInitializedPublisher.java | 5 +---- .../boot/autoconfigure/AutoConfigurationSorterTests.java | 5 ++--- 7 files changed, 13 insertions(+), 23 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index f8bebeea45..2c1af6d5f7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -136,8 +136,8 @@ class AutoConfigurationSorter { } Set getClassesRequestedAfter(String className) { - Set classesRequestedAfter = new LinkedHashSet<>(); - classesRequestedAfter.addAll(get(className).getAfter()); + Set setOfClassesRequestedAfter = get(className).getAfter(); + Set classesRequestedAfter = new LinkedHashSet<>(setOfClassesRequestedAfter); this.classes.forEach((name, autoConfigurationClass) -> { if (autoConfigurationClass.getBefore().contains(className)) { classesRequestedAfter.add(name); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java index 6b5f546d93..ec52a64a8a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java @@ -58,8 +58,8 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec @Override public Set determineImports(AnnotationMetadata metadata) { - Set result = new LinkedHashSet<>(); - result.addAll(getCandidateConfigurations(metadata, null)); + List candidateConfigurations = getCandidateConfigurations(metadata, null); + Set result = new LinkedHashSet<>(candidateConfigurations); result.removeAll(getExclusions(metadata, null)); return Collections.unmodifiableSet(result); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java index ab70a9a9b5..665a6776f4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java @@ -376,9 +376,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat return result; } result = (result != null) ? result : new LinkedHashSet<>(); - for (String addition : additional) { - result.add(addition); - } + Collections.addAll(result, additional); return result; } @@ -454,9 +452,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat } private void merge(Set result, String... additional) { - for (String addition : additional) { - result.add(addition); - } + Collections.addAll(result, additional); } private Set> resolveWhenPossible(Set classNames) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java index a4e6c7098e..0bad6a8276 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java @@ -102,10 +102,7 @@ public class GroovyTemplateAutoConfiguration { try { ProtectionDomain domain = MarkupTemplateEngine.class.getProtectionDomain(); CodeSource codeSource = domain.getCodeSource(); - if (codeSource != null && codeSource.getLocation().toString().contains("-all")) { - return true; - } - return false; + return codeSource != null && codeSource.getLocation().toString().contains("-all"); } catch (Exception ex) { return false; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategy.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategy.java index 1b5115debb..71b7e31f68 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategy.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategy.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.jmx; import java.util.Hashtable; +import java.util.Map; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -57,8 +58,8 @@ public class ParentAwareNamingStrategy extends MetadataNamingStrategy implements @Override public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException { ObjectName name = super.getObjectName(managedBean, beanKey); - Hashtable properties = new Hashtable<>(); - properties.putAll(name.getKeyPropertyList()); + Map keyPropertyList = name.getKeyPropertyList(); + Hashtable properties = new Hashtable<>(keyPropertyList); if (this.ensureUniqueRuntimeObjectNames) { properties.put("identity", ObjectUtils.getIdentityHexString(managedBean)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java index 8d9e2f7358..29556fc9c6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java @@ -112,10 +112,7 @@ class DataSourceInitializedPublisher implements BeanPostProcessor { : "none"); Map hibernate = this.hibernateProperties.determineHibernateProperties( this.jpaProperties.getProperties(), new HibernateSettings().ddlAuto(defaultDdlAuto)); - if (hibernate.containsKey("hibernate.hbm2ddl.auto")) { - return true; - } - return false; + return hibernate.containsKey("hibernate.hbm2ddl.auto"); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java index 1ddbcca63d..6d25109e97 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java @@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure; import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Properties; @@ -192,9 +193,7 @@ class AutoConfigurationSorterTests { for (Class type : value) { items.add(type.getName()); } - for (String type : name) { - items.add(type); - } + Collections.addAll(items, name); return StringUtils.collectionToCommaDelimitedString(items); } From 96596f8eccebd08e845e534c91eeabfebf9b23b9 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 28 Aug 2019 10:55:32 +0200 Subject: [PATCH 2/2] Polish contribution See gh-17962 --- .../boot/autoconfigure/AutoConfigurationSorter.java | 3 +-- .../boot/autoconfigure/jmx/ParentAwareNamingStrategy.java | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index 2c1af6d5f7..0aea6a04cb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -136,8 +136,7 @@ class AutoConfigurationSorter { } Set getClassesRequestedAfter(String className) { - Set setOfClassesRequestedAfter = get(className).getAfter(); - Set classesRequestedAfter = new LinkedHashSet<>(setOfClassesRequestedAfter); + Set classesRequestedAfter = new LinkedHashSet<>(get(className).getAfter()); this.classes.forEach((name, autoConfigurationClass) -> { if (autoConfigurationClass.getBefore().contains(className)) { classesRequestedAfter.add(name); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategy.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategy.java index 71b7e31f68..492ca6e119 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategy.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategy.java @@ -17,7 +17,6 @@ package org.springframework.boot.autoconfigure.jmx; import java.util.Hashtable; -import java.util.Map; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -58,8 +57,7 @@ public class ParentAwareNamingStrategy extends MetadataNamingStrategy implements @Override public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException { ObjectName name = super.getObjectName(managedBean, beanKey); - Map keyPropertyList = name.getKeyPropertyList(); - Hashtable properties = new Hashtable<>(keyPropertyList); + Hashtable properties = new Hashtable<>(name.getKeyPropertyList()); if (this.ensureUniqueRuntimeObjectNames) { properties.put("identity", ObjectUtils.getIdentityHexString(managedBean)); }