From a7417ab267c7cd1494f978027d9666411772c335 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 13 Aug 2018 08:19:22 +0100 Subject: [PATCH] Update petclinic and remove unused bean info --- .../com/example/PetclinicLatestBenchmark.java | 2 +- petclinic-latest/pom.xml | 1 + .../boot/beans/SpringBeanInfoFactory.java | 75 ---------- .../boot/beans/SpringBootBeanInfo.java | 133 ------------------ .../boot/beans/package-info.java | 20 --- .../main/resources/META-INF/spring.factories | 4 - 6 files changed, 2 insertions(+), 233 deletions(-) delete mode 100644 static/src/main/java/org/springframework/boot/beans/SpringBeanInfoFactory.java delete mode 100644 static/src/main/java/org/springframework/boot/beans/SpringBootBeanInfo.java delete mode 100644 static/src/main/java/org/springframework/boot/beans/package-info.java diff --git a/benchmarks/src/main/java/com/example/PetclinicLatestBenchmark.java b/benchmarks/src/main/java/com/example/PetclinicLatestBenchmark.java index 01de59a..cda6ee6 100644 --- a/benchmarks/src/main/java/com/example/PetclinicLatestBenchmark.java +++ b/benchmarks/src/main/java/com/example/PetclinicLatestBenchmark.java @@ -61,7 +61,7 @@ public void explodedJarFlags(FlagsState state) throws Exception { state.run(); } - @Benchmark + // @Benchmark public void devtoolsRestart(ExplodedDevtoolsState state) throws Exception { state.run(); } diff --git a/petclinic-latest/pom.xml b/petclinic-latest/pom.xml index 13cd71f..3224dc8 100644 --- a/petclinic-latest/pom.xml +++ b/petclinic-latest/pom.xml @@ -34,6 +34,7 @@ 1.0.12.RELEASE 5.1.0.BUILD-SNAPSHOT + Lovelace-BUILD-SNAPSHOT diff --git a/static/src/main/java/org/springframework/boot/beans/SpringBeanInfoFactory.java b/static/src/main/java/org/springframework/boot/beans/SpringBeanInfoFactory.java deleted file mode 100644 index 984d28b..0000000 --- a/static/src/main/java/org/springframework/boot/beans/SpringBeanInfoFactory.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.beans; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; - -import org.springframework.beans.BeanInfoFactory; -import org.springframework.core.annotation.Order; - -/** - * {@link BeanInfoFactory} that uses a simpler algorithm than {@link Introspector} since - * we know that our beans don't implement any of the more exotic specifications and Spring - * only really needs {@link PropertyDescriptor PropertyDescriptors}. - * - * @author Phillip Webb - * @since 2.0.0 - */ -@Order -public class SpringBeanInfoFactory implements BeanInfoFactory { - - private static String SPRING_PACKAGE = "org.springframework"; - - private static Set SUPPORTED_PACKAGES; - - static { - Set supportedPackages = new LinkedHashSet<>(); - supportedPackages.add("org.springframework.boot."); - supportedPackages.add("org.springframework.context."); - supportedPackages.add("org.springframework.http."); - supportedPackages.add("org.springframework.jmx."); - supportedPackages.add("org.springframework.web."); - SUPPORTED_PACKAGES = Collections.unmodifiableSet(supportedPackages); - } - - @Override - public BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException { - String name = beanClass.getName(); - if (name.startsWith(SPRING_PACKAGE) && isSupportedSpringPackage(name)) { - if (beanClass.getName().startsWith("org.springframework.boot")) { - return new SpringBootBeanInfo(beanClass); - } - } - return null; - } - - private boolean isSupportedSpringPackage(String name) { - for (String candidate : SUPPORTED_PACKAGES) { - if (name.startsWith(candidate)) { - return true; - } - } - return false; - } - -} diff --git a/static/src/main/java/org/springframework/boot/beans/SpringBootBeanInfo.java b/static/src/main/java/org/springframework/boot/beans/SpringBootBeanInfo.java deleted file mode 100644 index 999a348..0000000 --- a/static/src/main/java/org/springframework/boot/beans/SpringBootBeanInfo.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.beans; - -import java.awt.Image; -import java.beans.BeanDescriptor; -import java.beans.BeanInfo; -import java.beans.EventSetDescriptor; -import java.beans.IntrospectionException; -import java.beans.MethodDescriptor; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.springframework.util.ReflectionUtils; - -/** - * {@link BeanInfo} implementation returned form {@link SpringBeanInfoFactory}. - * - * @author Phillip Webb - */ -class SpringBootBeanInfo implements BeanInfo { - - private final PropertyDescriptor[] propertyDescriptors; - - public SpringBootBeanInfo(Class beanClass) throws IntrospectionException { - this.propertyDescriptors = extractPropertyDescriptors(beanClass); - } - - private PropertyDescriptor[] extractPropertyDescriptors(Class beanClass) - throws IntrospectionException { - Map getters = new LinkedHashMap<>(); - Map setters = new LinkedHashMap<>(); - Method[] methods = ReflectionUtils.getAllDeclaredMethods(beanClass); - for (Method method : methods) { - collectGetterSetterMethod(method, getters, setters); - } - List descriptors = new ArrayList<>(methods.length); - for (Map.Entry entry : getters.entrySet()) { - String name = entry.getKey(); - Method getter = entry.getValue(); - Method setter = setters.remove(name); - if (setter != null && !getter.getReturnType() - .isAssignableFrom(setter.getParameterTypes()[0])) { - setter = null; - } - descriptors.add(new PropertyDescriptor(name, getter, setter)); - } - for (Map.Entry entry : setters.entrySet()) { - Method setter = entry.getValue(); - String name = entry.getKey(); - descriptors.add(new PropertyDescriptor(name, null, setter)); - } - return descriptors.toArray(new PropertyDescriptor[descriptors.size()]); - } - - private void collectGetterSetterMethod(Method method, Map getters, - Map setters) { - int argSize = method.getParameterTypes().length; - if (!Modifier.isStatic(method.getModifiers()) && argSize <= 1) { - String name = method.getName(); - if (argSize == 0 && name.length() > 3 && name.startsWith("get")) { - getters.putIfAbsent(name.substring(3), method); - } - else if (argSize == 0 && name.length() > 2 && name.startsWith("is") - && method.getReturnType() == boolean.class) { - getters.putIfAbsent(name.substring(2), method); - } - else if (argSize == 1 && name.length() > 3 && name.startsWith("set")) { - setters.putIfAbsent(name.substring(3), method); - } - } - } - - @Override - public BeanDescriptor getBeanDescriptor() { - throw new UnsupportedOperationException(); - } - - @Override - public EventSetDescriptor[] getEventSetDescriptors() { - throw new UnsupportedOperationException(); - } - - @Override - public int getDefaultEventIndex() { - throw new UnsupportedOperationException(); - } - - @Override - public int getDefaultPropertyIndex() { - throw new UnsupportedOperationException(); - } - - @Override - public MethodDescriptor[] getMethodDescriptors() { - throw new UnsupportedOperationException(); - } - - @Override - public BeanInfo[] getAdditionalBeanInfo() { - throw new UnsupportedOperationException(); - } - - @Override - public Image getIcon(int iconKind) { - throw new UnsupportedOperationException(); - } - - @Override - public PropertyDescriptor[] getPropertyDescriptors() { - return this.propertyDescriptors; - } - -} diff --git a/static/src/main/java/org/springframework/boot/beans/package-info.java b/static/src/main/java/org/springframework/boot/beans/package-info.java deleted file mode 100644 index 718d61b..0000000 --- a/static/src/main/java/org/springframework/boot/beans/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Bean related utilities and classes. - */ -package org.springframework.boot.beans; diff --git a/static/src/main/resources/META-INF/spring.factories b/static/src/main/resources/META-INF/spring.factories index a75de8d..1f6defb 100644 --- a/static/src/main/resources/META-INF/spring.factories +++ b/static/src/main/resources/META-INF/spring.factories @@ -5,7 +5,3 @@ com.example.config.ShutdownApplicationListener org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.example.config.CustomConfiguration - -# BeanInfo Factory (doesn't have much of an impact) -#org.springframework.beans.BeanInfoFactory=\ -#org.springframework.boot.beans.SpringBeanInfoFactory