From 11b8654e099131b81ef3a4578e4d041407f1f6e2 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 19 Jul 2017 14:11:05 -0400 Subject: [PATCH] AbstractFunctionCompiler cleanup - removed Function/Supplier/ConsumerFactories by modifying SOURCE_CODE_TEMPLATE - removed Example main from src/main/java/org.springframework.cloud.function.compiler --- .../compiler/AbstractFunctionCompiler.java | 9 ++-- .../function/compiler/ConsumerFactory.java | 26 ----------- .../cloud/function/compiler/Example.java | 43 ------------------- .../function/compiler/FunctionFactory.java | 26 ----------- .../function/compiler/SupplierFactory.java | 26 ----------- 5 files changed, 5 insertions(+), 125 deletions(-) delete mode 100644 spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/ConsumerFactory.java delete mode 100644 spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/Example.java delete mode 100644 spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionFactory.java delete mode 100644 spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/SupplierFactory.java 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 e9600d454..f1c8fa4c6 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 @@ -32,6 +32,7 @@ import org.springframework.util.StringUtils; /** * @author Andy Clement * @author Mark Fisher + * @author Oleg Zhurakousky */ public abstract class AbstractFunctionCompiler { @@ -54,12 +55,12 @@ public abstract class AbstractFunctionCompiler { + "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" + + "public class %s implements CompilationResultFactory<%s> {\n" + + " public %s<%s> getResult() {\n" + " %s\n" + " }\n" + "}\n"; -// @formatter:on + // @formatter:on static enum ResultType { Consumer, Function, Supplier @@ -177,7 +178,7 @@ public abstract class AbstractFunctionCompiler { String shortClassName = className.substring(className.lastIndexOf('.') + 1); String s = String.format(SOURCE_CODE_TEMPLATE, shortClassName, resultType, resultType, StringUtils.arrayToCommaDelimitedString(types), methodBody); - System.out.println(s); + logger.info("\n" + s); return s; } } diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/ConsumerFactory.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/ConsumerFactory.java deleted file mode 100644 index babe13f9a..000000000 --- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/ConsumerFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2016 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.cloud.function.compiler; - -import java.util.function.Consumer; - -/** - * @author Mark Fisher - */ -public interface ConsumerFactory extends CompilationResultFactory> { - -} diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/Example.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/Example.java deleted file mode 100644 index f949990af..000000000 --- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/Example.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2016 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.cloud.function.compiler; - -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -import reactor.core.publisher.Flux; - -/** - * @author Mark Fisher - */ -public class Example { - - public static void main(String[] args) { - SupplierCompiler> supplierCompiler = new SupplierCompiler<>(); - CompiledFunctionFactory>> supplierFactory = supplierCompiler.compile("s", "return ()->Flux.just(\"foo\");"); - Flux input = supplierFactory.getResult().get(); - - FunctionCompiler, Flux> functionCompiler = new FunctionCompiler<>(); - CompiledFunctionFactory,Flux>> functionFactory = functionCompiler.compile("f", "f->f.map(s->s.toString().toUpperCase())"); - Flux output = functionFactory.getResult().apply(input); - - ConsumerCompiler consumerCompiler = new ConsumerCompiler<>(); - CompiledFunctionFactory> consumerFactory = consumerCompiler.compile("c", "System.out::println"); - output.subscribe(consumerFactory.getResult()); - } -} diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionFactory.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionFactory.java deleted file mode 100644 index f5f7c864b..000000000 --- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2016 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.cloud.function.compiler; - -import java.util.function.Function; - -/** - * @author Mark Fisher - */ -public interface FunctionFactory extends CompilationResultFactory> { - -} diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/SupplierFactory.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/SupplierFactory.java deleted file mode 100644 index 6cabffb6b..000000000 --- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/SupplierFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2016 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.cloud.function.compiler; - -import java.util.function.Supplier; - -/** - * @author Mark Fisher - */ -public interface SupplierFactory extends CompilationResultFactory> { - -}