From da013c10159ed78d4b2d6b0ea2d77c58f2809698 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 14 Mar 2017 16:51:23 +0000 Subject: [PATCH] Purge warnings in IDE --- .../compiler/AbstractFunctionCompiler.java | 110 +++++++++++------- .../gateway/LocalFunctionGateway.java | 16 ++- spring-cloud-function-deployer/pom.xml | 10 +- .../function/stream/StreamConfiguration.java | 25 ++-- .../StreamListeningFunctionInvoker.java | 4 +- .../SupplierInvokingMessageProducer.java | 7 +- spring-cloud-function-task/pom.xml | 5 + .../function/task/TaskConfiguration.java | 1 - 8 files changed, 109 insertions(+), 69 deletions(-) diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java index 5044b5341..a8c54f279 100644 --- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java +++ b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java @@ -35,7 +35,8 @@ import org.springframework.util.StringUtils; */ public abstract class AbstractFunctionCompiler { - private static Logger logger = LoggerFactory.getLogger(AbstractFunctionCompiler.class); + private static Logger logger = LoggerFactory + .getLogger(AbstractFunctionCompiler.class); // Newlines in the property are escaped private static final String NEWLINE_ESCAPE = Matcher.quoteReplacement("\\n"); @@ -44,20 +45,25 @@ public abstract class AbstractFunctionCompiler { private static final String DOUBLE_DOUBLE_QUOTE = Matcher.quoteReplacement("\"\""); /** - * The user supplied code snippet is inserted into the template and then the result is compiled + * The user supplied code snippet is inserted into the template and then the result is + * compiled */ - private static String SOURCE_CODE_TEMPLATE = - "package " + AbstractFunctionCompiler.class.getPackage().getName() + ";\n" + - "import java.util.*;\n" + // Helpful to include this - "import java.util.function.*;\n" + - "import reactor.core.publisher.Flux;\n" + - "public class %s implements %sFactory {\n" + - " public %s<%s> getResult() {\n" + - " %s\n" + - " }\n" + - "}\n"; + // @formatter:off + private static String SOURCE_CODE_TEMPLATE = "package " + + AbstractFunctionCompiler.class.getPackage().getName() + ";\n" + + "import java.util.*;\n" // Helpful to include this + + "import java.util.function.*;\n" + + "import reactor.core.publisher.Flux;\n" + + "public class %s implements %sFactory {\n" + + " public %s<%s> getResult() {\n" + + " %s\n" + + " }\n" + + "}\n"; +// @formatter:on - static enum ResultType { Consumer, Function, Supplier } + static enum ResultType { + Consumer, Function, Supplier + } private final ResultType resultType; @@ -65,82 +71,98 @@ public abstract class AbstractFunctionCompiler { private final RuntimeJavaCompiler compiler = new RuntimeJavaCompiler(); - AbstractFunctionCompiler(ResultType type, String... defaultResultTypeParameterizations) { + AbstractFunctionCompiler(ResultType type, + String... defaultResultTypeParameterizations) { this.resultType = type; this.defaultResultTypeParameterizations = defaultResultTypeParameterizations; } /** - * Produce a factory instance by:
    + * Produce a factory instance by: + *
      *
    • Decoding the code String to process any newlines/double-double-quotes *
    • Insert the code into the source code template for a class *
    • Compiling the class using the JDK provided Java Compiler *
    • Loading the compiled class - *
    • Invoking a well known method on the factory class to produce a Consumer, Function, or Supplier instance + *
    • Invoking a well known method on the factory class to produce a Consumer, + * Function, or Supplier instance *
    • Returning that instance. *
    * * @return a factory instance */ - public CompiledFunctionFactory compile(String name, String code, String... resultTypeParameterizations) { + public CompiledFunctionFactory compile(String name, String code, + String... resultTypeParameterizations) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("name must not be empty"); } logger.info("Initial code property value :'{}'", code); - String parameterizations = StringUtils.arrayToCommaDelimitedString( - (!ObjectUtils.isEmpty(resultTypeParameterizations)) ? resultTypeParameterizations : this.defaultResultTypeParameterizations); - code = decode(code); - if (code.startsWith("\"") && code.endsWith("\"")) { - code = code.substring(1,code.length()-1); - } - if (!code.startsWith("return ") && !code.endsWith(";")) { - code = String.format("return (%s<%s> & java.io.Serializable) %s;", resultType, parameterizations, code); + String parameterizations = StringUtils.arrayToCommaDelimitedString( + (!ObjectUtils.isEmpty(resultTypeParameterizations)) + ? resultTypeParameterizations + : this.defaultResultTypeParameterizations); + code = decode(code); + if (code.startsWith("\"") && code.endsWith("\"")) { + code = code.substring(1, code.length() - 1); + } + if (!code.startsWith("return ") && !code.endsWith(";")) { + code = String.format("return (%s<%s> & java.io.Serializable) %s;", resultType, + parameterizations, code); } logger.info("Processed code property value :\n{}\n", code); String firstLetter = name.substring(0, 1).toUpperCase(); name = (name.length() > 1) ? firstLetter + name.substring(1) : firstLetter; - String className = String.format("%s.%s%sFactory", this.getClass().getPackage().getName(), name, resultType); - CompilationResult compilationResult = buildAndCompileSourceCode(className, code, parameterizations); + String className = String.format("%s.%s%sFactory", + this.getClass().getPackage().getName(), name, resultType); + CompilationResult compilationResult = buildAndCompileSourceCode(className, code, + parameterizations); if (compilationResult.wasSuccessful()) { - return new CompiledFunctionFactory(className, compilationResult); + return new CompiledFunctionFactory(className, compilationResult); } - List compilationMessages = compilationResult.getCompilationMessages(); + List compilationMessages = compilationResult + .getCompilationMessages(); throw new CompilationFailedException(compilationMessages); } /** - * Create the source for and then compile and load a class that embodies - * the supplied methodBody. The methodBody is inserted into a class template that - * returns the specified parameterized type. - * This method can return more than one class if the method body includes local class - * declarations. An example methodBody would be return input -> input.buffer(5).map(list->list.get(0));. + * Create the source for and then compile and load a class that embodies the supplied + * methodBody. The methodBody is inserted into a class template that returns the + * specified parameterized type. This method can return more than one class if the + * method body includes local class declarations. An example methodBody would be + * return input -> input.buffer(5).map(list->list.get(0));. * * @param className the name of the class * @param methodBody the source code for a method - * @param parameterTypeString the String representation for the parameterized return type, e.g.: - * <Flux<Object>,Flux<Object> - * @return the list of Classes produced by compiling and then loading the snippet of code + * @param parameterTypeString the String representation for the parameterized return + * type, e.g.: <Flux<Object>,Flux<Object> + * @return the list of Classes produced by compiling and then loading the snippet of + * code */ - private CompilationResult buildAndCompileSourceCode(String className, String methodBody, String parameterTypeString) { - String sourceCode = makeSourceClassDefinition(className, methodBody, parameterTypeString); + private CompilationResult buildAndCompileSourceCode(String className, + String methodBody, String parameterTypeString) { + String sourceCode = makeSourceClassDefinition(className, methodBody, + parameterTypeString); return compiler.compile(className, sourceCode); } private static String decode(String input) { - return input.replaceAll(NEWLINE_ESCAPE, "\n").replaceAll(DOUBLE_DOUBLE_QUOTE, "\""); + return input.replaceAll(NEWLINE_ESCAPE, "\n").replaceAll(DOUBLE_DOUBLE_QUOTE, + "\""); } /** - * Make a full source code definition for a class by applying the specified method body - * to the Reactive template. + * Make a full source code definition for a class by applying the specified method + * body to the Reactive template. * * @param className the name of the class * @param methodBody the code to insert into the Reactive source class template * @return a complete Java Class definition */ - private String makeSourceClassDefinition(String className, String methodBody, String types) { + private String makeSourceClassDefinition(String className, String methodBody, + String types) { String shortClassName = className.substring(className.lastIndexOf('.') + 1); - String s = String.format(SOURCE_CODE_TEMPLATE, shortClassName, resultType, resultType, types, methodBody); + String s = String.format(SOURCE_CODE_TEMPLATE, shortClassName, resultType, + resultType, types, methodBody); System.out.println(s); return s; } diff --git a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/gateway/LocalFunctionGateway.java b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/gateway/LocalFunctionGateway.java index ed8e9e7e5..9398debe8 100644 --- a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/gateway/LocalFunctionGateway.java +++ b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/gateway/LocalFunctionGateway.java @@ -53,21 +53,27 @@ public class LocalFunctionGateway implements FunctionGateway { } @Override - public void schedule(String functionName, Trigger trigger, Supplier supplier, Consumer consumer) { + public void schedule(String functionName, Trigger trigger, + Supplier supplier, Consumer consumer) { Function function = this.catalog.lookupFunction(functionName); - this.scheduler.schedule(new FunctionInvokingRunnable(supplier, function, consumer), trigger); + this.scheduler.schedule( + new FunctionInvokingRunnable(supplier, function, consumer), + trigger); } @Override - public void subscribe(Publisher publisher, String functionName, final Consumer consumer) { + public void subscribe(Publisher publisher, String functionName, + final Consumer consumer) { final Function function = this.catalog.lookupFunction(functionName); publisher.subscribe(new Subscriber() { @Override - public void onComplete() {} + public void onComplete() { + } @Override - public void onError(Throwable error) {} + public void onError(Throwable error) { + } @Override public void onNext(T next) { diff --git a/spring-cloud-function-deployer/pom.xml b/spring-cloud-function-deployer/pom.xml index abcc256fb..d4096c716 100644 --- a/spring-cloud-function-deployer/pom.xml +++ b/spring-cloud-function-deployer/pom.xml @@ -19,11 +19,6 @@ - - org.apache.maven - maven-aether-provider - 3.3.9 - org.springframework.cloud spring-cloud-function-core @@ -58,6 +53,11 @@ + + org.apache.maven + maven-aether-provider + 3.3.9 + org.springframework.cloud spring-cloud-function-parent diff --git a/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/StreamConfiguration.java b/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/StreamConfiguration.java index 2b2c8b629..4cc0881c8 100644 --- a/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/StreamConfiguration.java +++ b/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/StreamConfiguration.java @@ -33,8 +33,6 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.function.invoker.AbstractFunctionInvoker; import org.springframework.cloud.function.registry.FunctionCatalog; -import org.springframework.cloud.function.support.FluxFunction; -import org.springframework.cloud.function.support.FunctionUtils; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.binder.Binder; import org.springframework.cloud.stream.messaging.Processor; @@ -72,7 +70,7 @@ public class StreamConfiguration { long interval = properties.getInterval(); Supplier> supplier = registry.lookupSupplier(name); return new SupplierInvokingMessageProducer(supplier, interval); - } + } } @ConditionalOnFunction @@ -89,7 +87,7 @@ public class StreamConfiguration { Function function = registry.lookupFunction(name); Assert.notNull(function, "no such function: " + name); return new StreamListeningFunctionInvoker(function); - } + } } @ConditionalOnConsumer @@ -105,7 +103,7 @@ public class StreamConfiguration { String name = properties.getEndpoint(); Consumer consumer = registry.lookupConsumer(name); return new StreamListeningConsumerInvoker(consumer); - } + } } @Conditional(SupplierCondition.class) @@ -129,7 +127,8 @@ public class StreamConfiguration { private @interface ConditionalOnConsumer { } - private static abstract class AbstractFunctionCondition extends SpringBootCondition implements ConfigurationCondition { + private static abstract class AbstractFunctionCondition extends SpringBootCondition + implements ConfigurationCondition { private final Class type; @@ -138,8 +137,10 @@ public class StreamConfiguration { } @Override - public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - String functionName = context.getEnvironment().getProperty("spring.cloud.function.stream.endpoint"); + public ConditionOutcome getMatchOutcome(ConditionContext context, + AnnotatedTypeMetadata metadata) { + String functionName = context.getEnvironment() + .getProperty("spring.cloud.function.stream.endpoint"); if (!StringUtils.hasText(functionName)) { return ConditionOutcome.noMatch("no endpoint function name available"); } @@ -150,15 +151,17 @@ public class StreamConfiguration { } Class beanType = context.getBeanFactory().getType(functionName); if (type.isAssignableFrom(beanType)) { - return ConditionOutcome.match(String.format("bean '%s' is a %s", functionName, type)); + return ConditionOutcome + .match(String.format("bean '%s' is a %s", functionName, type)); } - return ConditionOutcome.noMatch(String.format("bean '%s' is not a %s", functionName, type)); + return ConditionOutcome + .noMatch(String.format("bean '%s' is not a %s", functionName, type)); } @Override public ConfigurationPhase getConfigurationPhase() { return ConfigurationPhase.REGISTER_BEAN; - } + } } private static class SupplierCondition extends AbstractFunctionCondition { diff --git a/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/StreamListeningFunctionInvoker.java b/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/StreamListeningFunctionInvoker.java index 2fa0e57b6..acfbaf118 100644 --- a/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/StreamListeningFunctionInvoker.java +++ b/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/StreamListeningFunctionInvoker.java @@ -32,7 +32,8 @@ import reactor.core.publisher.Flux; /** * @author Mark Fisher */ -public class StreamListeningFunctionInvoker extends AbstractFunctionInvoker, Flux> { +public class StreamListeningFunctionInvoker + extends AbstractFunctionInvoker, Flux> { public StreamListeningFunctionInvoker(Function function) { super(wrapIfNecessary(function)); @@ -44,6 +45,7 @@ public class StreamListeningFunctionInvoker extends AbstractFunctionInvoker, Flux> wrapIfNecessary(Function function) { Assert.notNull(function, "Function must not be null"); if (!FunctionUtils.isFluxFunction(function)) { diff --git a/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/SupplierInvokingMessageProducer.java b/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/SupplierInvokingMessageProducer.java index ef3c41409..7a6329143 100644 --- a/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/SupplierInvokingMessageProducer.java +++ b/spring-cloud-function-stream/src/main/java/org/springframework/cloud/function/stream/SupplierInvokingMessageProducer.java @@ -42,12 +42,15 @@ public class SupplierInvokingMessageProducer extends MessageProducerSupport { ? new FluxSupplier<>(supplier, Duration.ofMillis(interval)) : new FluxSupplier<>(supplier); } - this.supplier = (Supplier>) supplier; + @SuppressWarnings("unchecked") + Supplier> unchecked = (Supplier>) supplier; + this.supplier = unchecked; this.setOutputChannelName(Source.OUTPUT); } @Override protected void doStart() { - this.supplier.get().subscribe(m -> this.sendMessage(MessageBuilder.withPayload(m).build())); + this.supplier.get() + .subscribe(m -> this.sendMessage(MessageBuilder.withPayload(m).build())); } } diff --git a/spring-cloud-function-task/pom.xml b/spring-cloud-function-task/pom.xml index ff845d225..f1811b39e 100644 --- a/spring-cloud-function-task/pom.xml +++ b/spring-cloud-function-task/pom.xml @@ -32,6 +32,11 @@ org.springframework.boot spring-boot-starter-logging + + org.springframework.boot + spring-boot-configuration-processor + true + diff --git a/spring-cloud-function-task/src/main/java/org/springframework/cloud/function/task/TaskConfiguration.java b/spring-cloud-function-task/src/main/java/org/springframework/cloud/function/task/TaskConfiguration.java index b6b8b14f0..3acea987a 100644 --- a/spring-cloud-function-task/src/main/java/org/springframework/cloud/function/task/TaskConfiguration.java +++ b/spring-cloud-function-task/src/main/java/org/springframework/cloud/function/task/TaskConfiguration.java @@ -30,7 +30,6 @@ import org.springframework.cloud.function.registry.FunctionCatalog; import org.springframework.cloud.task.configuration.EnableTask; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; import reactor.core.publisher.Flux;