From bf41055dc783f78e6bcd69a523905e3862bdab0d Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 23 Feb 2018 12:12:06 +0000 Subject: [PATCH] Some dependency hygiene and update to Boot 1.5.10 The web module doesn't really need to depend on tomcat and all of the Spring Boot web stack, but users need a way to grab that stuff quickly if they want it (hence the new starter). Also removed all spring-boot-starter dependencies from core and context modules. --- pom.xml | 3 +- spring-cloud-function-context/pom.xml | 4 ++ spring-cloud-function-core/pom.xml | 10 +--- .../function/core/FunctionFactoryUtils.java | 55 +++++++++++-------- spring-cloud-function-dependencies/pom.xml | 9 ++- .../function-sample-aws/pom.xml | 4 +- .../function-sample-azure/pom.xml | 2 +- .../function-sample-compiler/pom.xml | 4 +- .../function-sample-pof/pom.xml | 4 +- .../function-sample-pojo/pom.xml | 4 +- .../function-sample-task/pom.xml | 4 +- .../function-sample/pom.xml | 4 +- spring-cloud-function-web/pom.xml | 31 ++++++----- .../flux/response/FluxReturnValueHandler.java | 2 +- spring-cloud-starter-function-web/pom.xml | 29 ++++++++++ .../main/resources/META-INF/spring.provides | 1 + 16 files changed, 107 insertions(+), 63 deletions(-) create mode 100644 spring-cloud-starter-function-web/pom.xml create mode 100644 spring-cloud-starter-function-web/src/main/resources/META-INF/spring.provides diff --git a/pom.xml b/pom.xml index a63de8dde..cf8d065fd 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-build - 1.3.7.RELEASE + 1.3.8.RELEASE @@ -58,6 +58,7 @@ spring-cloud-function-stream spring-cloud-function-task spring-cloud-function-web + spring-cloud-starter-function-web spring-cloud-function-samples spring-cloud-function-deployer spring-cloud-function-adapters diff --git a/spring-cloud-function-context/pom.xml b/spring-cloud-function-context/pom.xml index f86de9a6d..f111e1a40 100644 --- a/spring-cloud-function-context/pom.xml +++ b/spring-cloud-function-context/pom.xml @@ -15,6 +15,10 @@ + + org.springframework.boot + spring-boot-autoconfigure + org.springframework.cloud spring-cloud-function-core diff --git a/spring-cloud-function-core/pom.xml b/spring-cloud-function-core/pom.xml index 86179f447..21cf54a23 100644 --- a/spring-cloud-function-core/pom.xml +++ b/spring-cloud-function-core/pom.xml @@ -18,17 +18,9 @@ io.projectreactor reactor-core - - org.springframework.boot - spring-boot-starter - org.springframework - spring-context - - - org.springframework.boot - spring-boot-starter-logging + spring-core org.springframework.boot diff --git a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FunctionFactoryUtils.java b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FunctionFactoryUtils.java index 253714c02..ccdd9aea8 100644 --- a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FunctionFactoryUtils.java +++ b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/core/FunctionFactoryUtils.java @@ -29,7 +29,6 @@ import java.util.stream.Stream; import org.reactivestreams.Publisher; -import org.springframework.context.annotation.Bean; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -37,16 +36,15 @@ import reactor.core.publisher.Flux; /** *

- * Miscellaneous utility operations to interrogate functional - * components (beans) configured in BeanFactory. + * Miscellaneous utility operations to interrogate functional components (beans) + * configured in BeanFactory. *

*

- * It is important to understand that it is not a general purpose utility - * to interrogate "any" functional component. Certain operations may/will - * not work as expected due to java type erasure. While BeanFactory is not - * the requirement, this utility is targeting only the components - * defined in such way where they could be configured as - * @{@link Component} or @{@link Bean} within BeanFactory. + * It is important to understand that it is not a general purpose utility to interrogate + * "any" functional component. Certain operations may/will not work as expected due to + * java type erasure. While BeanFactory is not the requirement, this utility is targeting + * only the components defined in such way where they could be configured beans within + * BeanFactory. *

* It is primarily used internally by the framework. * @@ -63,7 +61,8 @@ public abstract class FunctionFactoryUtils { public static boolean isFluxConsumer(Consumer consumer) { return consumer instanceof FunctionFactoryMetadata - ? isFluxConsumer(((FunctionFactoryMetadata) consumer).getFactoryMethod()) + ? isFluxConsumer( + ((FunctionFactoryMetadata) consumer).getFactoryMethod()) : isFlux(1, getParameterizedTypeNames(consumer, Consumer.class)); } @@ -73,7 +72,8 @@ public abstract class FunctionFactoryUtils { public static boolean isFluxSupplier(Supplier supplier) { return supplier instanceof FunctionFactoryMetadata - ? isFluxSupplier(((FunctionFactoryMetadata) supplier).getFactoryMethod()) + ? isFluxSupplier( + ((FunctionFactoryMetadata) supplier).getFactoryMethod()) : isFlux(1, getParameterizedTypeNames(supplier, Supplier.class)); } @@ -83,7 +83,8 @@ public abstract class FunctionFactoryUtils { public static boolean isFluxFunction(Function function) { return function instanceof FunctionFactoryMetadata - ? isFluxFunction(((FunctionFactoryMetadata) function).getFactoryMethod()) + ? isFluxFunction( + ((FunctionFactoryMetadata) function).getFactoryMethod()) : isFlux(1, getParameterizedTypeNames(function, Function.class)); } @@ -91,26 +92,29 @@ public abstract class FunctionFactoryUtils { return isFlux(2, getParameterizedTypeNamesForMethod(method, Function.class)); } - private static String[] getParameterizedTypeNamesForMethod(Method method, Class interfaceClass) { + private static String[] getParameterizedTypeNamesForMethod(Method method, + Class interfaceClass) { String[] types = retrieveTypes(method.getGenericReturnType(), interfaceClass); return types == null ? new String[0] : types; } - private static String[] getParameterizedTypeNames(Object source, Class interfaceClass) { + private static String[] getParameterizedTypeNames(Object source, + Class interfaceClass) { return Stream.of(source.getClass().getGenericInterfaces()) - .map(gi -> retrieveTypes(gi, interfaceClass)) - .filter(s -> s != null) - .findFirst() - .orElse(getSerializedLambdaParameterizedTypeNames(source)); + .map(gi -> retrieveTypes(gi, interfaceClass)).filter(s -> s != null) + .findFirst().orElse(getSerializedLambdaParameterizedTypeNames(source)); } - private static String[] retrieveTypes(Type genericInterface, Class interfaceClass){ + private static String[] retrieveTypes(Type genericInterface, + Class interfaceClass) { if ((genericInterface instanceof ParameterizedType) && interfaceClass - .getTypeName().equals(((ParameterizedType) genericInterface).getRawType().getTypeName())) { + .getTypeName().equals(((ParameterizedType) genericInterface).getRawType() + .getTypeName())) { ParameterizedType type = (ParameterizedType) genericInterface; Type[] args = type.getActualTypeArguments(); if (args != null) { - return Stream.of(args).map(arg -> arg.getTypeName()).toArray(String[]::new); + return Stream.of(args).map(arg -> arg.getTypeName()) + .toArray(String[]::new); } } return null; @@ -124,7 +128,8 @@ public abstract class FunctionFactoryUtils { ReflectionUtils.makeAccessible(method); SerializedLambda serializedLambda = (SerializedLambda) ReflectionUtils .invokeMethod(method, source); - String signature = serializedLambda.getImplMethodSignature().replaceAll("[()]",""); + String signature = serializedLambda.getImplMethodSignature().replaceAll("[()]", + ""); List typeNames = Stream.of(signature.split(";")) .map(t -> t.substring(1).replace('/', '.')).collect(Collectors.toList()); @@ -132,7 +137,9 @@ public abstract class FunctionFactoryUtils { return typeNames.toArray(new String[typeNames.size()]); } - private static boolean isFlux(int length, String... types){ - return !ObjectUtils.isEmpty(types) && types.length == length && Stream.of(types).allMatch(type -> type.startsWith(FLUX_CLASS_NAME) || type.startsWith(PUBLISHER_CLASS_NAME)); + private static boolean isFlux(int length, String... types) { + return !ObjectUtils.isEmpty(types) && types.length == length + && Stream.of(types).allMatch(type -> type.startsWith(FLUX_CLASS_NAME) + || type.startsWith(PUBLISHER_CLASS_NAME)); } } diff --git a/spring-cloud-function-dependencies/pom.xml b/spring-cloud-function-dependencies/pom.xml index 18cbf17ae..f9741bcac 100644 --- a/spring-cloud-function-dependencies/pom.xml +++ b/spring-cloud-function-dependencies/pom.xml @@ -5,7 +5,7 @@ spring-cloud-dependencies-parent org.springframework.cloud - 1.3.5.RELEASE + 1.3.8.RELEASE spring-cloud-function-dependencies @@ -14,7 +14,7 @@ Spring Cloud Function Dependencies Spring Cloud Function Dependencies - Bismuth-SR4 + Bismuth-SR6 @@ -55,6 +55,11 @@ spring-cloud-function-web ${project.version}
+ + org.springframework.cloud + spring-cloud-starter-function-web + ${project.version} + org.springframework.cloud spring-cloud-function-deployer diff --git a/spring-cloud-function-samples/function-sample-aws/pom.xml b/spring-cloud-function-samples/function-sample-aws/pom.xml index 66ebd9b17..cd2e56a1c 100644 --- a/spring-cloud-function-samples/function-sample-aws/pom.xml +++ b/spring-cloud-function-samples/function-sample-aws/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.9.RELEASE + 1.5.10.RELEASE @@ -37,7 +37,7 @@ org.springframework.cloud - spring-cloud-function-web + spring-cloud-starter-function-web provided diff --git a/spring-cloud-function-samples/function-sample-azure/pom.xml b/spring-cloud-function-samples/function-sample-azure/pom.xml index 714b5d177..96471d776 100644 --- a/spring-cloud-function-samples/function-sample-azure/pom.xml +++ b/spring-cloud-function-samples/function-sample-azure/pom.xml @@ -34,7 +34,7 @@ org.springframework.cloud - spring-cloud-function-web + spring-cloud-starter-function-web provided diff --git a/spring-cloud-function-samples/function-sample-compiler/pom.xml b/spring-cloud-function-samples/function-sample-compiler/pom.xml index 4daf6aeb7..512556da4 100644 --- a/spring-cloud-function-samples/function-sample-compiler/pom.xml +++ b/spring-cloud-function-samples/function-sample-compiler/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.9.RELEASE + 1.5.10.RELEASE @@ -28,7 +28,7 @@ org.springframework.cloud - spring-cloud-function-web + spring-cloud-starter-function-web org.springframework.cloud diff --git a/spring-cloud-function-samples/function-sample-pof/pom.xml b/spring-cloud-function-samples/function-sample-pof/pom.xml index 29c06b583..94be47a75 100644 --- a/spring-cloud-function-samples/function-sample-pof/pom.xml +++ b/spring-cloud-function-samples/function-sample-pof/pom.xml @@ -12,7 +12,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.9.RELEASE + 1.5.10.RELEASE @@ -28,7 +28,7 @@ org.springframework.cloud - spring-cloud-function-web + spring-cloud-starter-function-web diff --git a/spring-cloud-function-samples/function-sample-pojo/pom.xml b/spring-cloud-function-samples/function-sample-pojo/pom.xml index b347a8dba..5479dcb5b 100644 --- a/spring-cloud-function-samples/function-sample-pojo/pom.xml +++ b/spring-cloud-function-samples/function-sample-pojo/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.9.RELEASE + 1.5.10.RELEASE @@ -27,7 +27,7 @@ org.springframework.cloud - spring-cloud-function-web + spring-cloud-starter-function-web org.springframework.boot diff --git a/spring-cloud-function-samples/function-sample-task/pom.xml b/spring-cloud-function-samples/function-sample-task/pom.xml index 4bf0811f8..8acf64900 100644 --- a/spring-cloud-function-samples/function-sample-task/pom.xml +++ b/spring-cloud-function-samples/function-sample-task/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.9.RELEASE + 1.5.10.RELEASE @@ -31,7 +31,7 @@ org.springframework.cloud - spring-cloud-function-web + spring-cloud-starter-function-web org.springframework.cloud diff --git a/spring-cloud-function-samples/function-sample/pom.xml b/spring-cloud-function-samples/function-sample/pom.xml index 782f4e19a..0a89fb1cb 100644 --- a/spring-cloud-function-samples/function-sample/pom.xml +++ b/spring-cloud-function-samples/function-sample/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.9.RELEASE + 1.5.10.RELEASE @@ -27,7 +27,7 @@ org.springframework.cloud - spring-cloud-function-web + spring-cloud-starter-function-web org.springframework.cloud diff --git a/spring-cloud-function-web/pom.xml b/spring-cloud-function-web/pom.xml index 09ff77d71..0c078cfb4 100644 --- a/spring-cloud-function-web/pom.xml +++ b/spring-cloud-function-web/pom.xml @@ -16,18 +16,8 @@ - org.springframework.boot - spring-boot-starter-web - - - com.fasterxml.jackson.core - jackson-databind - - - org.hibernate - hibernate-validator - - + org.springframework + spring-webmvc com.google.code.gson @@ -36,13 +26,28 @@ org.springframework.cloud spring-cloud-function-context - ${project.version} + + + javax.servlet + javax.servlet-api + provided + + + commons-logging + commons-logging + 1.2 + provided org.springframework.boot spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-web + test + diff --git a/spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/flux/response/FluxReturnValueHandler.java b/spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/flux/response/FluxReturnValueHandler.java index a54793a52..93a27b7e8 100644 --- a/spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/flux/response/FluxReturnValueHandler.java +++ b/spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/flux/response/FluxReturnValueHandler.java @@ -20,6 +20,7 @@ import java.lang.reflect.Method; import java.time.Duration; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Stream; @@ -28,7 +29,6 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.el.stream.Optional; import org.reactivestreams.Publisher; import org.springframework.cloud.function.context.catalog.FunctionInspector; diff --git a/spring-cloud-starter-function-web/pom.xml b/spring-cloud-starter-function-web/pom.xml new file mode 100644 index 000000000..102dc99d7 --- /dev/null +++ b/spring-cloud-starter-function-web/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + org.springframework.cloud + spring-cloud-function-parent + 1.0.0.BUILD-SNAPSHOT + .. + + spring-cloud-starter-function-web + spring-cloud-starter-starter-function-web + Spring Cloud Starter + https://projects.spring.io/spring-cloud + + Pivotal Software, Inc. + https://www.spring.io + + + + org.springframework.cloud + spring-cloud-function-web + + + org.springframework.boot + spring-boot-starter-web + + + diff --git a/spring-cloud-starter-function-web/src/main/resources/META-INF/spring.provides b/spring-cloud-starter-function-web/src/main/resources/META-INF/spring.provides new file mode 100644 index 000000000..15c50227c --- /dev/null +++ b/spring-cloud-starter-function-web/src/main/resources/META-INF/spring.provides @@ -0,0 +1 @@ +provides: spring-cloud-security \ No newline at end of file