diff --git a/src/main/java/org/springframework/data/projection/ProjectionFactory.java b/src/main/java/org/springframework/data/projection/ProjectionFactory.java index 6e080632e..ecd2e2904 100644 --- a/src/main/java/org/springframework/data/projection/ProjectionFactory.java +++ b/src/main/java/org/springframework/data/projection/ProjectionFactory.java @@ -15,8 +15,6 @@ */ package org.springframework.data.projection; -import java.util.List; - /** * A factory to create projecting instances for other objects usually used to allow easy creation of representation * projections to define which properties of a domain objects shall be exported in which way. @@ -44,16 +42,6 @@ public interface ProjectionFactory { */ T createProjection(Class projectionType); - /** - * Returns the properties that will be consumed by the given projection type. - * - * @param projectionType must not be {@literal null}. - * @return - * @deprecated use {@link #getProjectionInformation(Class)} - */ - @Deprecated - List getInputProperties(Class projectionType); - /** * Returns the {@link ProjectionInformation} for the given projection type. * diff --git a/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java b/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java index ea8ca9a4c..95191927e 100644 --- a/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java +++ b/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java @@ -15,7 +15,6 @@ */ package org.springframework.data.projection; -import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; @@ -27,10 +26,8 @@ import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.context.ResourceLoaderAware; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.DefaultConversionService; -import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -45,10 +42,7 @@ import org.springframework.util.ClassUtils; * @see SpelAwareProxyProjectionFactory * @since 1.10 */ -class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware, BeanClassLoaderAware { - - private static final boolean IS_JAVA_8 = org.springframework.util.ClassUtils.isPresent("java.util.Optional", - ProxyProjectionFactory.class.getClassLoader()); +class ProxyProjectionFactory implements ProjectionFactory, BeanClassLoaderAware { private final List factories; private final ConversionService conversionService; @@ -66,16 +60,6 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware, this.conversionService = new DefaultConversionService(); } - /** - * @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader) - * @deprecated rather set the {@link ClassLoader} directly via {@link #setBeanClassLoader(ClassLoader)}. - */ - @Override - @Deprecated - public void setResourceLoader(ResourceLoader resourceLoader) { - this.classLoader = resourceLoader.getClassLoader(); - } - /* * (non-Javadoc) * @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader) @@ -119,10 +103,7 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware, factory.setOpaque(true); factory.setInterfaces(projectionType, TargetAware.class); - if (IS_JAVA_8) { - factory.addAdvice(new DefaultMethodInvokingMethodInterceptor()); - } - + factory.addAdvice(new DefaultMethodInvokingMethodInterceptor()); factory.addAdvice(new TargetAwareMethodInterceptor(source.getClass())); factory.addAdvice(getMethodInterceptor(source, projectionType)); @@ -141,24 +122,6 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware, return createProjection(projectionType, new HashMap()); } - /* - * (non-Javadoc) - * @see org.springframework.data.projection.ProjectionFactory#getProperties(java.lang.Class) - */ - @Override - public List getInputProperties(Class projectionType) { - - Assert.notNull(projectionType, "Projection type must not be null!"); - - List result = new ArrayList<>(); - - for (PropertyDescriptor descriptor : getProjectionInformation(projectionType).getInputProperties()) { - result.add(descriptor.getName()); - } - - return result; - } - /* * (non-Javadoc) * @see org.springframework.data.projection.ProjectionFactory#getProjectionInformation(java.lang.Class) diff --git a/src/main/java/org/springframework/data/projection/SpelAwareProxyProjectionFactory.java b/src/main/java/org/springframework/data/projection/SpelAwareProxyProjectionFactory.java index 1af229b33..07aa06bab 100644 --- a/src/main/java/org/springframework/data/projection/SpelAwareProxyProjectionFactory.java +++ b/src/main/java/org/springframework/data/projection/SpelAwareProxyProjectionFactory.java @@ -77,7 +77,8 @@ public class SpelAwareProxyProjectionFactory extends ProxyProjectionFactory impl } return typeCache.get(projectionType) - ? new SpelEvaluatingMethodInterceptor(interceptor, source, beanFactory, parser, projectionType) : interceptor; + ? new SpelEvaluatingMethodInterceptor(interceptor, source, beanFactory, parser, projectionType) + : interceptor; } /* diff --git a/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java b/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java index 0ab0c9441..2831b502a 100644 --- a/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java +++ b/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java @@ -23,11 +23,9 @@ import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.context.ResourceLoaderAware; import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.convert.ConversionService; -import org.springframework.core.io.ResourceLoader; import org.springframework.data.projection.SpelAwareProxyProjectionFactory; import org.springframework.util.ClassUtils; import org.springframework.web.bind.WebDataBinder; @@ -43,7 +41,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; * @since 1.10 */ public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodProcessor - implements BeanFactoryAware, ResourceLoaderAware, BeanClassLoaderAware { + implements BeanFactoryAware, BeanClassLoaderAware { private static final List IGNORED_PACKAGES = Arrays.asList("java", "org.springframework"); @@ -72,16 +70,6 @@ public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodP this.proxyFactory.setBeanFactory(beanFactory); } - /** - * @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader) - * @deprecated rather set the {@link ClassLoader} via {@link #setBeanClassLoader(ClassLoader)}. - */ - @Override - @Deprecated - public void setResourceLoader(ResourceLoader resourceLoader) { - this.proxyFactory.setResourceLoader(resourceLoader); - } - /* * (non-Javadoc) * @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader) @@ -115,13 +103,9 @@ public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodP } // Fallback for only user defined interfaces - for (String prefix : IGNORED_PACKAGES) { - if (ClassUtils.getPackageName(type).startsWith(prefix)) { - return false; - } - } + String packageName = ClassUtils.getPackageName(type); - return true; + return !IGNORED_PACKAGES.stream().anyMatch(it -> packageName.startsWith(it)); } /* diff --git a/src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java b/src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java index 7fe0a3dd7..0069be1b8 100755 --- a/src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java +++ b/src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java @@ -49,11 +49,6 @@ public class ProxyProjectionFactoryUnitTests { factory.createProjection(null, new Object()); } - @Test(expected = IllegalArgumentException.class) // DATACMNS-630 - public void rejectsNullProjectionTypeForInputProperties() { - factory.getInputProperties(null); - } - @Test // DATACMNS-630 public void returnsNullForNullSource() { assertThat(factory.createProjection(CustomerExcerpt.class, null)).isNull(); diff --git a/src/test/java/org/springframework/data/projection/SpelAwareProxyProjectionFactoryUnitTests.java b/src/test/java/org/springframework/data/projection/SpelAwareProxyProjectionFactoryUnitTests.java index 4e0551d45..46facf61a 100755 --- a/src/test/java/org/springframework/data/projection/SpelAwareProxyProjectionFactoryUnitTests.java +++ b/src/test/java/org/springframework/data/projection/SpelAwareProxyProjectionFactoryUnitTests.java @@ -17,6 +17,7 @@ package org.springframework.data.projection; import static org.assertj.core.api.Assertions.*; +import java.beans.PropertyDescriptor; import java.util.List; import org.junit.Before; @@ -58,9 +59,13 @@ public class SpelAwareProxyProjectionFactoryUnitTests { @Test // DATACMNS-630 public void excludesAtValueAnnotatedMethodsForInputProperties() { - List properties = factory.getInputProperties(CustomerExcerpt.class); + List properties = factory // + .getProjectionInformation(CustomerExcerpt.class) // + .getInputProperties(); - assertThat(properties).containsExactly("firstname"); + assertThat(properties) // + .extracting(PropertyDescriptor::getName) // + .containsExactly("firstname"); } @Test // DATACMNS-89