result type
* @author Oleg Zhurakousky
+ * @author Chris Bono
* @since 3.2
*/
public class FunctionInvoker {
@@ -120,37 +121,119 @@ else if (function == null && StringUtils.hasText(functionDefinition) && APPLICAT
return function;
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
public O handleRequest(I input, ExecutionContext executionContext) {
String functionDefinition = executionContext.getFunctionName();
FunctionInvocationWrapper function = this.discoverFunction(functionDefinition);
Object enhancedInput = enhanceInputIfNecessary(input, executionContext);
- Object output = function.apply(enhancedInput);
- if (output instanceof Publisher) {
- if (FunctionTypeUtils.isMono(function.getOutputType())) {
- return (O) this.convertOutputIfNecessary(input, Mono.from((Publisher) output).blockOptional().get());
+ Object functionResult = function.apply(enhancedInput);
+
+ if (functionResult instanceof Publisher) {
+ return postProcessReactiveFunctionResult(input, enhancedInput, (Publisher>) functionResult, function, executionContext);
+ }
+ return postProcessImperativeFunctionResult(input, enhancedInput, functionResult, function, executionContext);
+ }
+
+ /**
+ * Post-processes the result from a non-reactive function invocation before returning it to the Azure
+ * runtime. The default behavior is to {@link #convertOutputIfNecessary possibly convert} the result.
+ *
+ * Provides a hook for custom function invokers to extend/modify the function results handling.
+ *
+ * @param rawInputs the inputs passed in from the Azure runtime
+ * @param functionInputs the actual inputs used for the function invocation; may be
+ * {@link #enhanceInputIfNecessary different} from the {@literal rawInputs}
+ * @param functionResult the result from the function invocation
+ * @param function the invoked function
+ * @param executionContext the Azure execution context
+ * @return the possibly modified function results
+ */
+ @SuppressWarnings("unchecked")
+ protected O postProcessImperativeFunctionResult(I rawInputs, Object functionInputs, Object functionResult,
+ FunctionInvocationWrapper function, ExecutionContext executionContext
+ ) {
+ return (O) this.convertOutputIfNecessary(rawInputs, functionResult);
+ }
+
+ /**
+ * Post-processes the result from a reactive function invocation before returning it to the Azure
+ * runtime. The default behavior is to delegate to {@link #postProcessMonoFunctionResult} or
+ * {@link #postProcessFluxFunctionResult} based on the result type.
+ *
+ *
Provides a hook for custom function invokers to extend/modify the function results handling.
+ *
+ * @param rawInputs the inputs passed in from the Azure runtime
+ * @param functionInputs the actual inputs used for the function invocation; may be
+ * {@link #enhanceInputIfNecessary different} from the {@literal rawInputs}
+ * @param functionResult the result from the function invocation
+ * @param function the invoked function
+ * @param executionContext the Azure execution context
+ * @return the possibly modified function results
+ */
+ protected O postProcessReactiveFunctionResult(I rawInputs, Object functionInputs, Publisher> functionResult,
+ FunctionInvocationWrapper function, ExecutionContext executionContext
+ ) {
+ if (FunctionTypeUtils.isMono(function.getOutputType())) {
+ return postProcessMonoFunctionResult(rawInputs, functionInputs, Mono.from(functionResult), function, executionContext);
+ }
+ return postProcessFluxFunctionResult(rawInputs, functionInputs, Flux.from(functionResult), function, executionContext);
+ }
+
+ /**
+ * Post-processes the {@code Mono} result from a reactive function invocation before returning it to the Azure
+ * runtime. The default behavior is to {@link Mono#blockOptional()} and {@link #convertOutputIfNecessary possibly convert} the result.
+ *
+ *
Provides a hook for custom function invokers to extend/modify the function results handling.
+ *
+ * @param rawInputs the inputs passed in from the Azure runtime
+ * @param functionInputs the actual inputs used for the function invocation; may be
+ * {@link #enhanceInputIfNecessary different} from the {@literal rawInputs}
+ * @param functionResult the Mono result from the function invocation
+ * @param function the invoked function
+ * @param executionContext the Azure execution context
+ * @return the possibly modified function results
+ */
+ @SuppressWarnings("unchecked")
+ protected O postProcessMonoFunctionResult(I rawInputs, Object functionInputs, Mono> functionResult,
+ FunctionInvocationWrapper function, ExecutionContext executionContext
+ ) {
+ return (O) this.convertOutputIfNecessary(rawInputs, functionResult.blockOptional().get());
+ }
+
+ /**
+ * Post-processes the {@code Flux} result from a reactive function invocation before returning it to the Azure
+ * runtime. The default behavior is to {@link Flux#toIterable() block} and {@link #convertOutputIfNecessary possibly convert} the results.
+ *
+ *
Provides a hook for custom function invokers to extend/modify the function results handling.
+ *
+ * @param rawInputs the inputs passed in from the Azure runtime
+ * @param functionInputs the actual inputs used for the function invocation; may be
+ * {@link #enhanceInputIfNecessary different} from the {@literal rawInputs}
+ * @param functionResult the Mono result from the function invocation
+ * @param function the invoked function
+ * @param executionContext the Azure execution context
+ * @return the possibly modified function results
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected O postProcessFluxFunctionResult(I rawInputs, Object functionInputs, Flux> functionResult,
+ FunctionInvocationWrapper function, ExecutionContext executionContext
+ ) {
+ List resultList = new ArrayList<>();
+ for (Object resultItem : functionResult.toIterable()) {
+ if (resultItem instanceof Collection) {
+ resultList.addAll((Collection) resultItem);
}
else {
- List resultList = new ArrayList<>();
- for (Object resultItem : Flux.from((Publisher) output).toIterable()) {
- if (resultItem instanceof Collection) {
- resultList.addAll((Collection) resultItem);
- }
- else {
- if (!function.isSupplier() && Collection.class.isAssignableFrom(FunctionTypeUtils.getRawType(function.getInputType()))
- && !Collection.class.isAssignableFrom(FunctionTypeUtils.getRawType(function.getOutputType()))) {
- return (O) this.convertOutputIfNecessary(input, resultItem);
- }
- else {
- resultList.add(resultItem);
- }
- }
+ if (!function.isSupplier() && Collection.class.isAssignableFrom(FunctionTypeUtils.getRawType(function.getInputType()))
+ && !Collection.class.isAssignableFrom(FunctionTypeUtils.getRawType(function.getOutputType()))) {
+ return (O) this.convertOutputIfNecessary(rawInputs, resultItem);
+ }
+ else {
+ resultList.add(resultItem);
}
- return (O) this.convertOutputIfNecessary(input, resultList);
}
}
- return (O) this.convertOutputIfNecessary(input, output);
+ return (O) this.convertOutputIfNecessary(rawInputs, resultList);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/main/resources/META-INF/services/com.microsoft.azure.functions.spi.inject.FunctionInstanceInjector b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/main/resources/META-INF/services/com.microsoft.azure.functions.spi.inject.FunctionInstanceInjector
new file mode 100644
index 000000000..247910e32
--- /dev/null
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/main/resources/META-INF/services/com.microsoft.azure.functions.spi.inject.FunctionInstanceInjector
@@ -0,0 +1 @@
+org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector
\ No newline at end of file
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/test/java/org/springframework/cloud/function/adapter/azure/CustomFunctionInvokerTests.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/test/java/org/springframework/cloud/function/adapter/azure/CustomFunctionInvokerTests.java
new file mode 100644
index 000000000..3d39543ec
--- /dev/null
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/test/java/org/springframework/cloud/function/adapter/azure/CustomFunctionInvokerTests.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2022-2022 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
+ *
+ * https://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.adapter.azure;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import com.microsoft.azure.functions.ExecutionContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.reactivestreams.Publisher;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.messaging.support.GenericMessage;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.util.Lists.list;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+/**
+ * Unit tests for {@link FunctionInvoker} custom result handling.
+ *
+ * @author Chris Bono
+ */
+class CustomFunctionInvokerTests {
+
+ private FunctionInvoker, ?> currentInvoker;
+
+ @AfterEach
+ void closeCurrentInvoker() {
+ if (this.currentInvoker != null) {
+ this.currentInvoker.close();
+ }
+ }
+
+ /**
+ * Verifies custom result handling and proper post-process callback invocation for an imperative function.
+ */
+ @Test
+ void customImperativeResultHandling() {
+ FunctionInvoker invoker = new FunctionInvoker(TestFunctionsConfig.class) {
+ @Override
+ protected String postProcessImperativeFunctionResult(String rawInputs, Object functionInputs,
+ Object functionResult, FunctionInvocationWrapper function, ExecutionContext executionContext
+ ) {
+ return functionResult + "+imperative";
+ }
+ };
+ invoker = spyOnAndCloseAfterTest(invoker);
+ ExecutionContext executionContext = new TestExecutionContext("imperativeUppercase");
+ String result = invoker.handleRequest("foo", executionContext);
+ assertThat(result).isEqualTo("FOO+imperative");
+
+ // Below here verifies that the expected callback(s) were invoked w/ the expected arguments
+
+ // Only imperative post-process callback should be called
+ verify(invoker, never()).postProcessReactiveFunctionResult(anyString(), any(), any(Publisher.class), any(), same(executionContext));
+ verify(invoker, never()).postProcessMonoFunctionResult(anyString(), any(), any(Mono.class), any(), same(executionContext));
+ verify(invoker, never()).postProcessFluxFunctionResult(anyString(), any(), any(Flux.class), any(), same(executionContext));
+
+ // Only sniff-test the payload of the input message (the other fields are problematic to verify and no value doing that here)
+ ArgumentCaptor functionInputsCaptor = ArgumentCaptor.forClass(GenericMessage.class);
+ verify(invoker).postProcessImperativeFunctionResult(eq("foo"), functionInputsCaptor.capture(), eq("FOO"), any(), same(executionContext));
+ assertThat(functionInputsCaptor.getValue()).extracting(GenericMessage::getPayload).isEqualTo("foo");
+ }
+
+ /**
+ * Verifies custom result handling and proper post-process callback invocation for a reactive Mono function.
+ */
+ @Test
+ void customReactiveMonoResultHandling() {
+ FunctionInvoker invoker = new FunctionInvoker(TestFunctionsConfig.class) {
+ @Override
+ protected String postProcessMonoFunctionResult(String rawInputs, Object functionInputs, Mono> functionResult,
+ FunctionInvocationWrapper function, ExecutionContext executionContext
+ ) {
+ return functionResult.block().toString() + "+mono";
+ }
+ };
+ invoker = spyOnAndCloseAfterTest(invoker);
+ ExecutionContext executionContext = new TestExecutionContext("reactiveMonoUppercase");
+ String result = invoker.handleRequest("foo", executionContext);
+ assertThat(result).isEqualTo("FOO+mono");
+
+ // Below here verifies that the expected callback(s) were invoked w/ the expected arguments
+
+ // Only publisher->mono post-process callbacks should be called
+ verify(invoker, never()).postProcessImperativeFunctionResult(anyString(), any(), any(), any(), same(executionContext));
+ verify(invoker, never()).postProcessFluxFunctionResult(anyString(), any(), any(Flux.class), any(), same(executionContext));
+
+ // Only sniff-test the payload of the input message and the mono (the other fields are problematic to verify and no value doing that here)
+ ArgumentCaptor functionInputsCaptor = ArgumentCaptor.forClass(GenericMessage.class);
+ ArgumentCaptor functionResultCaptor = ArgumentCaptor.forClass(Mono.class);
+ verify(invoker).postProcessReactiveFunctionResult(eq("foo"), functionInputsCaptor.capture(), functionResultCaptor.capture(), any(), same(executionContext));
+ verify(invoker).postProcessMonoFunctionResult(eq("foo"), functionInputsCaptor.capture(), functionResultCaptor.capture(), any(), same(executionContext));
+ // NOTE: The captors get called twice as the args are just delegated from publisher->mono callback
+ assertThat(functionInputsCaptor.getAllValues()).extracting(GenericMessage::getPayload).containsExactly("foo", "foo");
+ assertThat(functionResultCaptor.getAllValues()).extracting(Mono::block).containsExactly("FOO", "FOO");
+ }
+
+ /**
+ * Verifies custom result handling and proper post-process callback invocation for a reactive Flux function.
+ */
+ @Test
+ void customReactiveFluxResultHandling() {
+ FunctionInvoker, String> invoker = new FunctionInvoker, String>(TestFunctionsConfig.class) {
+ @Override
+ protected String postProcessFluxFunctionResult(List rawInputs, Object functionInputs,
+ Flux> functionResult, FunctionInvocationWrapper function, ExecutionContext executionContext
+ ) {
+ return functionResult.map(o -> o.toString() + "+flux").collectList().block().stream().collect(Collectors.joining("/"));
+ }
+ };
+ invoker = spyOnAndCloseAfterTest(invoker);
+ ExecutionContext executionContext = new TestExecutionContext("reactiveFluxUppercase");
+ List rawInputs = Arrays.asList("foo", "bar");
+ String result = invoker.handleRequest(rawInputs, executionContext);
+ assertThat(result).isEqualTo("FOO+flux/BAR+flux");
+
+ // Below here verifies that the expected callback(s) were invoked w/ the expected arguments
+
+ // Only publisher->flux post-process callbacks should be called
+ verify(invoker, never()).postProcessImperativeFunctionResult(anyList(), any(), any(), any(), same(executionContext));
+ verify(invoker, never()).postProcessMonoFunctionResult(anyList(), any(), any(Mono.class), any(), same(executionContext));
+
+ // Only sniff-test the payload of the input message and the mono (the other fields are problematic to verify and no value doing that here)
+ ArgumentCaptor> functionInputsCaptor = ArgumentCaptor.forClass(Flux.class);
+ ArgumentCaptor functionResultCaptor = ArgumentCaptor.forClass(Flux.class);
+ verify(invoker).postProcessReactiveFunctionResult(same(rawInputs), functionInputsCaptor.capture(), functionResultCaptor.capture(), any(), same(executionContext));
+ verify(invoker).postProcessFluxFunctionResult(same(rawInputs), functionInputsCaptor.capture(), functionResultCaptor.capture(), any(), same(executionContext));
+
+ // NOTE: The captors get called twice as the args are just delegated from publisher->flux callback
+
+ // The functionInputs for each call is Flux with 2 items - one for 'foo' and one for 'bar'
+ assertThat(functionInputsCaptor.getAllValues())
+ .extracting(Flux::collectList).extracting(Mono::block)
+ .flatExtracting(fluxAsList -> fluxAsList.stream().collect(Collectors.toList()))
+ .extracting(GenericMessage::getPayload).containsExactlyInAnyOrder("foo", "bar", "foo", "bar");
+
+ // The functionResult for each call is a Flux w/ 2 items { "FOO", "BAR" }
+ assertThat(functionResultCaptor.getAllValues())
+ .extracting(Flux::collectList).extracting(Mono::block)
+ .containsExactlyInAnyOrder(list("FOO", "BAR"), list("FOO", "BAR"));
+ }
+
+ private FunctionInvoker spyOnAndCloseAfterTest(FunctionInvoker invoker) {
+ this.currentInvoker = invoker;
+ return spy(invoker);
+ }
+
+ @Configuration
+ @EnableAutoConfiguration
+ static class TestFunctionsConfig {
+
+ @Bean
+ public Function imperativeUppercase() {
+ return (s) -> s.toUpperCase();
+ }
+
+ @Bean
+ public Function, Mono> reactiveMonoUppercase() {
+ return (m) -> m.map(String::toUpperCase);
+ }
+
+ @Bean
+ public Function, Flux> reactiveFluxUppercase() {
+ return (f) -> f.map(String::toUpperCase);
+ }
+
+ }
+}
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-gcp/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-adapter-gcp/pom.xml
index f348aac6a..41df7e6e1 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-gcp/pom.xml
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-gcp/pom.xml
@@ -11,7 +11,7 @@
spring-cloud-function-adapter-parent
org.springframework.cloud
- 3.2.2-SNAPSHOT
+ 3.2.13-SNAPSHOT
@@ -68,6 +68,7 @@
com.github.blindpirate
junit5-capture-system-output-extension
0.1.2
+ test
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/pom.xml
index a7fbb0e60..d3a32847d 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/pom.xml
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/pom.xml
@@ -13,7 +13,7 @@
org.springframework.cloud
spring-cloud-function-adapter-parent
- 3.2.2-SNAPSHOT
+ 3.2.13-SNAPSHOT
diff --git a/spring-cloud-function-adapters/spring-cloud-function-grpc-cloudevent-ext/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-grpc-cloudevent-ext/pom.xml
index 3e38496f9..5735ac26d 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-grpc-cloudevent-ext/pom.xml
+++ b/spring-cloud-function-adapters/spring-cloud-function-grpc-cloudevent-ext/pom.xml
@@ -5,13 +5,13 @@
org.springframework.cloud
spring-cloud-function-adapter-parent
- 3.2.2-SNAPSHOT
+ 3.2.13-SNAPSHOT
spring-cloud-function-grpc-cloudevent-ext
spring-cloud-function-grpc-cloudevent-ext
CloudEvent extension for spring-cloud-function-grpc
- 1.8
+ 1.55.1
@@ -23,7 +23,11 @@
spring-cloud-function-grpc
${project.version}
-
+
+ io.grpc
+ grpc-stub
+ ${grpc.version}
+
org.springframework.boot
spring-boot-starter-test
@@ -41,16 +45,26 @@
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+
+ checkstyle-validation
+ none
+
+
+
+
org.xolstice.maven.plugins
protobuf-maven-plugin
0.6.1
- com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}
+ com.google.protobuf:protoc:3.23.0:exe:${os.detected.classifier}
grpc-java
- io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}
+ io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
@@ -64,41 +78,4 @@
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- false
-
-
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- false
-
-
-
-
diff --git a/spring-cloud-function-adapters/spring-cloud-function-grpc/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-grpc/pom.xml
index 2dbdff528..067b318fc 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-grpc/pom.xml
+++ b/spring-cloud-function-adapters/spring-cloud-function-grpc/pom.xml
@@ -12,34 +12,38 @@
org.springframework.cloud
spring-cloud-function-adapter-parent
- 3.2.2-SNAPSHOT
+ 3.2.13-SNAPSHOT
- 1.16.1
+ 1.55.1
true
-
- io.grpc
- grpc-netty
- ${grpc.version}
+ javax.annotation
+ javax.annotation-api
+ 1.3.2
+
+
+ io.grpc
+ grpc-netty
+ ${grpc.version}
- io.grpc
- grpc-protobuf
- ${grpc.version}
+ io.grpc
+ grpc-protobuf
+ ${grpc.version}
- io.grpc
- grpc-services
- ${grpc.version}
+ io.grpc
+ grpc-services
+ ${grpc.version}
- io.grpc
- grpc-stub
- ${grpc.version}
+ io.grpc
+ grpc-stub
+ ${grpc.version}
org.springframework.cloud
@@ -55,44 +59,47 @@
spring-boot-starter-test
test
+
+ org.awaitility
+ awaitility
+ test
+
-
-
- kr.motd.maven
- os-maven-plugin
- 1.6.1
-
+
+ kr.motd.maven
+ os-maven-plugin
+ 1.6.1
+
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
-
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
- org.xolstice.maven.plugins
- protobuf-maven-plugin
- 0.6.1
-
-
- com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}
+ org.xolstice.maven.plugins
+ protobuf-maven-plugin
+ 0.6.1
+
+
+ com.google.protobuf:protoc:3.23.0:exe:${os.detected.classifier}
- grpc-java
-
- io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}
+ grpc-java
+
+ io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
-
-
-
-
- compile
- compile-custom
-
-
-
-
+
+
+
+
+ compile
+ compile-custom
+
+
+
+
diff --git a/spring-cloud-function-compiler/.jdk8 b/spring-cloud-function-compiler/.jdk8
deleted file mode 100644
index e69de29bb..000000000
diff --git a/spring-cloud-function-compiler/pom.xml b/spring-cloud-function-compiler/pom.xml
index 602f0449d..3c47d5d3f 100644
--- a/spring-cloud-function-compiler/pom.xml
+++ b/spring-cloud-function-compiler/pom.xml
@@ -12,7 +12,7 @@
org.springframework.cloud
spring-cloud-function-parent
- 3.2.2-SNAPSHOT
+ 3.2.13-SNAPSHOT
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
deleted file mode 100644
index e9f1179be..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.List;
-import java.util.regex.Matcher;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.springframework.cloud.function.compiler.java.CompilationFailedException;
-import org.springframework.cloud.function.compiler.java.CompilationMessage;
-import org.springframework.cloud.function.compiler.java.CompilationResult;
-import org.springframework.cloud.function.compiler.java.RuntimeJavaCompiler;
-import org.springframework.util.ObjectUtils;
-import org.springframework.util.StringUtils;
-
-/**
- * @param result type
- * @author Andy Clement
- * @author Mark Fisher
- * @author Oleg Zhurakousky
- */
-public abstract class AbstractFunctionCompiler {
-
- // Newlines in the property are escaped
- private static final String NEWLINE_ESCAPE = Matcher.quoteReplacement("\\n");
-
- // Individual double-quote characters are represented by two double quotes in the DSL
- private static final String DOUBLE_DOUBLE_QUOTE = Matcher.quoteReplacement("\"\"");
-
- private static Logger logger = LoggerFactory
- .getLogger(AbstractFunctionCompiler.class);
-
- /**
- * The user supplied code snippet is inserted into the template and then the result is
- * compiled.
- */
- // @formatter:off
- private static String SOURCE_CODE_TEMPLATE = "package "
- + AbstractFunctionCompiler.class.getPackage().getName() + ";\n"
- + "import java.util.*;\n" // Helpful to include this
- + "import java.time.*;\n" // Helpful to include this
- + "import java.util.function.*;\n"
- + "import reactor.core.publisher.Flux;\n"
- + "public class %s implements CompilationResultFactory<%s> {\n"
- + " public %s<%s> getResult() {\n"
- + " %s\n"
- + " }\n"
- + "}\n";
- // @formatter:on
- private final ResultType resultType;
-
- private final String[] defaultResultTypeParameterizations;
-
- private final RuntimeJavaCompiler compiler = new RuntimeJavaCompiler();
-
- AbstractFunctionCompiler(ResultType type,
- String... defaultResultTypeParameterizations) {
- this.resultType = type;
- this.defaultResultTypeParameterizations = defaultResultTypeParameterizations;
- }
-
- private static String decode(String input) {
- return input.replaceAll(NEWLINE_ESCAPE, "\n").replaceAll(DOUBLE_DOUBLE_QUOTE,
- "\"");
- }
-
- /**
- * 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
- * Returning that instance.
- *
- * @param name - name of the function
- * @param code - code of the function
- * @param resultTypeParameterizations - result types
- * @return a factory instance
- */
- public final 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[] parameterizedTypes = (!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;",
- this.resultType,
- StringUtils.arrayToCommaDelimitedString(parameterizedTypes), 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, this.resultType);
- CompilationResult compilationResult = buildAndCompileSourceCode(className, code,
- parameterizedTypes);
- if (compilationResult.wasSuccessful()) {
- CompiledFunctionFactory factory = new CompiledFunctionFactory<>(className,
- compilationResult);
- return this.postProcessCompiledFunctionFactory(factory);
- }
- List compilationMessages = compilationResult
- .getCompilationMessages();
- throw new CompilationFailedException(compilationMessages);
- }
-
- /**
- * Implementing subclasses may override this, e.g. to set the input and/or output
- * types.
- * @param factory the {@link CompiledFunctionFactory} produced by
- * {@link #compile(String, String, String...)}
- * @return the post-processed {@link CompiledFunctionFactory}
- */
- protected CompiledFunctionFactory postProcessCompiledFunctionFactory(
- CompiledFunctionFactory factory) {
- return factory;
- }
-
- /**
- * 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 parameterizedTypes the array of String representations for the parameterized
- * input and/or output types, e.g.: <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[] parameterizedTypes) {
- String sourceCode = makeSourceClassDefinition(className, methodBody,
- parameterizedTypes);
- return this.compiler.compile(className, sourceCode);
- }
-
- /**
- * 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
- * @param types the parameterized input and/or output types as Strings
- * @return a complete Java Class definition
- */
- private String makeSourceClassDefinition(String className, String methodBody,
- String[] types) {
- String shortClassName = className.substring(className.lastIndexOf('.') + 1);
- String s = String.format(SOURCE_CODE_TEMPLATE, shortClassName, this.resultType,
- this.resultType, StringUtils.arrayToCommaDelimitedString(types),
- methodBody);
- logger.info("\n" + s);
- return s;
- }
-
- enum ResultType {
-
- Consumer, Function, Supplier
-
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/CompilationResultFactory.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/CompilationResultFactory.java
deleted file mode 100644
index 1f643b80b..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/CompilationResultFactory.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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;
-
-/**
- * @param result type
- * @author Mark Fisher
- */
-public interface CompilationResultFactory {
-
- T getResult();
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/CompiledFunctionFactory.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/CompiledFunctionFactory.java
deleted file mode 100644
index 0083b2fdc..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/CompiledFunctionFactory.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.lang.reflect.Method;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.springframework.cloud.function.compiler.java.CompilationResult;
-import org.springframework.util.ReflectionUtils;
-
-/**
- * @param result type
- * @author Mark Fisher
- */
-public class CompiledFunctionFactory implements CompilationResultFactory {
-
- private final T result;
-
- private final byte[] generatedClassBytes;
-
- private String inputType;
-
- private String outputType;
-
- private Method method;
-
- public CompiledFunctionFactory(String className,
- CompilationResult compilationResult) {
- List> clazzes = compilationResult.getCompiledClasses();
- T result = null;
- Method method = null;
- for (Class> clazz : clazzes) {
- if (clazz.getName().equals(className)) {
- try {
- @SuppressWarnings("unchecked")
- CompilationResultFactory factory = (CompilationResultFactory) clazz
- .newInstance();
- result = factory.getResult();
- method = findFactoryMethod(clazz);
- }
- catch (Exception e) {
- throw new IllegalArgumentException(
- "Unexpected problem during retrieval of Function from compiled class",
- e);
- }
- }
- }
- if (result == null) {
- throw new IllegalArgumentException("Failed to extract compilation result.");
- }
- this.result = result;
- this.method = method;
- this.generatedClassBytes = compilationResult.getClassBytes(className);
- }
-
- private Method findFactoryMethod(Class> clazz) {
- AtomicReference method = new AtomicReference<>();
- ReflectionUtils.doWithLocalMethods(clazz, m -> {
- if (m.getName().equals("getResult")
- && m.getReturnType().getName().startsWith("java.util.function")) {
- method.set(m);
- }
- });
- return method.get();
- }
-
- public T getResult() {
- return this.result;
- }
-
- public Method getFactoryMethod() {
- return this.method;
- }
-
- public String getInputType() {
- return this.inputType;
- }
-
- public void setInputType(String inputType) {
- this.inputType = inputType;
- }
-
- public String getOutputType() {
- return this.outputType;
- }
-
- public void setOutputType(String outputType) {
- this.outputType = outputType;
- }
-
- public byte[] getGeneratedClassBytes() {
- return this.generatedClassBytes;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/ConsumerCompiler.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/ConsumerCompiler.java
deleted file mode 100644
index e098f9049..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/ConsumerCompiler.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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;
-
-/**
- * @param result type
- * @author Mark Fisher
- */
-public class ConsumerCompiler extends AbstractFunctionCompiler> {
-
- private final String inputType;
-
- public ConsumerCompiler() {
- this("Flux");
- }
-
- public ConsumerCompiler(String inputType) {
- super(ResultType.Consumer, inputType);
- this.inputType = inputType;
- }
-
- @Override
- protected CompiledFunctionFactory> postProcessCompiledFunctionFactory(
- CompiledFunctionFactory> factory) {
- factory.setInputType(this.inputType);
- return factory;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionCompiler.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionCompiler.java
deleted file mode 100644
index ad3ce77dd..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionCompiler.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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;
-
-/**
- * @param function input type
- * @param function output type
- * @author Mark Fisher
- */
-public class FunctionCompiler extends AbstractFunctionCompiler> {
-
- private final String inputType;
-
- private final String outputType;
-
- public FunctionCompiler() {
- this("Flux");
- }
-
- public FunctionCompiler(String type) {
- this(type, type);
- }
-
- public FunctionCompiler(String inputType, String outputType) {
- super(ResultType.Function, inputType, outputType);
- this.inputType = inputType;
- this.outputType = outputType;
- }
-
- @Override
- protected CompiledFunctionFactory> postProcessCompiledFunctionFactory(
- CompiledFunctionFactory> factory) {
- factory.setInputType(this.inputType);
- factory.setOutputType(this.outputType);
-
- return factory;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/SupplierCompiler.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/SupplierCompiler.java
deleted file mode 100644
index 57ab191bd..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/SupplierCompiler.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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;
-
-/**
- * @param input type
- * @author Mark Fisher
- */
-public class SupplierCompiler extends AbstractFunctionCompiler> {
-
- private final String outputType;
-
- public SupplierCompiler() {
- this("Flux");
- }
-
- public SupplierCompiler(String outputType) {
- super(ResultType.Supplier, outputType);
- this.outputType = outputType;
- }
-
- @Override
- protected CompiledFunctionFactory> postProcessCompiledFunctionFactory(
- CompiledFunctionFactory> factory) {
- factory.setOutputType(this.outputType);
- return factory;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/app/CompiledFunctionRegistry.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/app/CompiledFunctionRegistry.java
deleted file mode 100644
index 3717514d5..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/app/CompiledFunctionRegistry.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.app;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-import reactor.core.publisher.Flux;
-
-import org.springframework.cloud.function.compiler.AbstractFunctionCompiler;
-import org.springframework.cloud.function.compiler.CompiledFunctionFactory;
-import org.springframework.cloud.function.compiler.ConsumerCompiler;
-import org.springframework.cloud.function.compiler.FunctionCompiler;
-import org.springframework.cloud.function.compiler.SupplierCompiler;
-import org.springframework.util.Assert;
-import org.springframework.util.FileCopyUtils;
-
-/**
- * @author Mark Fisher
- * @author Oleg Zhurakousky
- */
-public class CompiledFunctionRegistry {
-
- private static final String SUPPLIER_DIRECTORY = "suppliers";
-
- private static final String FUNCTION_DIRECTORY = "functions";
-
- private static final String CONSUMER_DIRECTORY = "consumers";
-
- private final File supplierDirectory;
-
- private final File functionDirectory;
-
- private final File consumerDirectory;
-
- private final AbstractFunctionCompiler>> supplierCompiler = new SupplierCompiler<>();
-
- private final AbstractFunctionCompiler, Flux>>> functionCompiler = new FunctionCompiler<>();
-
- private final AbstractFunctionCompiler>> consumerCompiler = new ConsumerCompiler<>();
-
- public CompiledFunctionRegistry() {
- this(new File("/tmp/function-registry"));
- }
-
- public CompiledFunctionRegistry(File directory) {
- Assert.notNull(directory, "Directory must not be null");
- if (!directory.exists()) {
- directory.mkdirs();
- }
- else {
- Assert.isTrue(directory.isDirectory(),
- String.format("%s is not a directory.", directory.getAbsolutePath()));
- }
- this.supplierDirectory = new File(directory, SUPPLIER_DIRECTORY);
- this.functionDirectory = new File(directory, FUNCTION_DIRECTORY);
- this.consumerDirectory = new File(directory, CONSUMER_DIRECTORY);
- this.supplierDirectory.mkdir();
- this.functionDirectory.mkdir();
- this.consumerDirectory.mkdir();
- }
-
- public void registerSupplier(String name, String lambda, String type) {
- this.doRegister(this.supplierCompiler, this.supplierDirectory, name, lambda,
- type);
- }
-
- public void registerFunction(String name, String lambda, String... types) {
- this.doRegister(this.functionCompiler, this.functionDirectory, name, lambda,
- types);
- }
-
- public void registerConsumer(String name, String lambda, String type) {
- this.doRegister(this.consumerCompiler, this.consumerDirectory, name, lambda,
- type);
- }
-
- private void doRegister(AbstractFunctionCompiler> compiler, File directory,
- String name, String lambda, String... types) {
- CompiledFunctionFactory> factory = compiler.compile(name, lambda, types);
- File file = new File(directory, fileName(name));
- try {
- FileCopyUtils.copy(factory.getGeneratedClassBytes(), file);
- }
- catch (IOException e) {
- throw new IllegalArgumentException(
- String.format("failed to register '%s'", name), e);
- }
- }
-
- private String fileName(String functionName) {
- return String.format("%s.%s", functionName, "fun");
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/app/CompilerController.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/app/CompilerController.java
deleted file mode 100644
index ca949d66f..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/app/CompilerController.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.app;
-
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * @author Mark Fisher
- */
-@RestController
-public class CompilerController {
-
- private final CompiledFunctionRegistry registry = new CompiledFunctionRegistry();
-
- @PostMapping(path = "/supplier/{name}")
- public void registerSupplier(@PathVariable String name, @RequestBody String lambda,
- @RequestParam(defaultValue = "Flux") String type) {
- this.registry.registerSupplier(name, lambda, type);
- }
-
- @PostMapping(path = "/function/{name}")
- public void registerFunction(@PathVariable String name, @RequestBody String lambda,
- @RequestParam(defaultValue = "Flux") String inputType,
- @RequestParam(defaultValue = "Flux") String outputType) {
- this.registry.registerFunction(name, lambda, inputType, outputType);
- }
-
- @PostMapping(path = "/consumer/{name}")
- public void registerConsumer(@PathVariable String name, @RequestBody String lambda,
- @RequestParam(defaultValue = "Flux") String type) {
- this.registry.registerConsumer(name, lambda, type);
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/config/FunctionProxyApplicationListener.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/config/FunctionProxyApplicationListener.java
deleted file mode 100644
index 1d93c74b0..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/config/FunctionProxyApplicationListener.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.config;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.springframework.beans.MutablePropertyValues;
-import org.springframework.beans.factory.config.ConstructorArgumentValues;
-import org.springframework.beans.factory.support.DefaultListableBeanFactory;
-import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.boot.context.event.ApplicationPreparedEvent;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.bind.Bindable;
-import org.springframework.boot.context.properties.bind.Binder;
-import org.springframework.cloud.function.compiler.ConsumerCompiler;
-import org.springframework.cloud.function.compiler.FunctionCompiler;
-import org.springframework.cloud.function.compiler.SupplierCompiler;
-import org.springframework.cloud.function.compiler.proxy.ByteCodeLoadingConsumer;
-import org.springframework.cloud.function.compiler.proxy.ByteCodeLoadingFunction;
-import org.springframework.cloud.function.compiler.proxy.ByteCodeLoadingSupplier;
-import org.springframework.cloud.function.compiler.proxy.LambdaCompilingConsumer;
-import org.springframework.cloud.function.compiler.proxy.LambdaCompilingFunction;
-import org.springframework.cloud.function.compiler.proxy.LambdaCompilingSupplier;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.core.io.ByteArrayResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.Assert;
-
-/**
- * @author Mark Fisher
- */
-@ConfigurationProperties("spring.cloud.function")
-public class FunctionProxyApplicationListener
- implements ApplicationListener {
-
- private final SupplierCompiler> supplierCompiler = new SupplierCompiler<>();
-
- private final FunctionCompiler, ?> functionCompiler = new FunctionCompiler<>();
-
- private final ConsumerCompiler> consumerCompiler = new ConsumerCompiler<>();
-
- /**
- * Configuration for function bodies, which will be compiled. The key in the map is
- * the function name and the value is a map containing a key "lambda" which is the
- * body to compile, and optionally a "type" (defaults to "function"). Can also contain
- * "inputType" and "outputType" in case it is ambiguous.
- */
- private final Map compile = new HashMap<>();
-
- /**
- * Configuration for a set of files containing function bodies, which will be imported
- * and compiled. The key in the map is the function name and the value is another map,
- * containing a "location" of the file to compile and (optionally) a "type" (defaults
- * to "function").
- */
- private final Map imports = new HashMap<>();
-
- public Map getCompile() {
- return this.compile;
- }
-
- public Map getImports() {
- return this.imports;
- }
-
- @Override
- public void onApplicationEvent(ApplicationPreparedEvent event) {
- ConfigurableApplicationContext context = event.getApplicationContext();
- DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context
- .getBeanFactory();
- bind(context, beanFactory);
- for (Map.Entry entry : this.compile.entrySet()) {
- String name = entry.getKey();
- @SuppressWarnings("unchecked")
- Map properties = (Map) entry.getValue();
- String type = (properties.get("type") != null) ? properties.get("type")
- : "function";
- String lambda = properties.get("lambda");
- Assert.notNull(lambda, () -> String.format(
- "The 'lambda' property is required for compiling Function: %s",
- name));
- String inputType = properties.get("inputType");
- String outputType = properties.get("outputType");
- registerLambdaCompilingProxy(name, type, inputType, outputType, lambda,
- beanFactory);
- }
- for (Map.Entry entry : this.imports.entrySet()) {
- String name = entry.getKey();
- @SuppressWarnings("unchecked")
- Map properties = (Map) entry.getValue();
- String type = (properties.get("type") != null) ? properties.get("type")
- : "function";
- String location = properties.get("location");
- Assert.notNull(location, String.format(
- "The 'location' property is required for importing Function: %s",
- name));
- registerByteCodeLoadingProxy(name, type, context.getResource(location),
- beanFactory);
- }
- }
-
- private void bind(ConfigurableApplicationContext application,
- DefaultListableBeanFactory context) {
- Binder.get(application.getEnvironment()).bind("spring.cloud.function",
- Bindable.ofInstance(this));
- }
-
- private void registerByteCodeLoadingProxy(String name, String type, Resource resource,
- DefaultListableBeanFactory beanFactory) {
- Class> proxyClass = null;
- if ("supplier".equals(type.toLowerCase())) {
- proxyClass = ByteCodeLoadingSupplier.class;
- }
- else if ("consumer".equals(type.toLowerCase())) {
- proxyClass = ByteCodeLoadingConsumer.class;
- }
- else {
- proxyClass = ByteCodeLoadingFunction.class;
- }
- RootBeanDefinition beanDefinition = new RootBeanDefinition(proxyClass);
- ConstructorArgumentValues args = new ConstructorArgumentValues();
- args.addGenericArgumentValue(resource);
- beanDefinition.setConstructorArgumentValues(args);
- beanFactory.registerBeanDefinition(name, beanDefinition);
- }
-
- private void registerLambdaCompilingProxy(String name, String type, String inputType,
- String outputType, String lambda, DefaultListableBeanFactory beanFactory) {
- Resource resource = new ByteArrayResource(lambda.getBytes());
- ConstructorArgumentValues args = new ConstructorArgumentValues();
- MutablePropertyValues props = new MutablePropertyValues();
- args.addGenericArgumentValue(resource);
- Class> proxyClass = null;
- if ("supplier".equals(type.toLowerCase())) {
- proxyClass = LambdaCompilingSupplier.class;
- args.addGenericArgumentValue(this.supplierCompiler);
- if (outputType != null) {
- props.add("typeParameterizations", outputType);
- }
- }
- else if ("consumer".equals(type.toLowerCase())) {
- proxyClass = LambdaCompilingConsumer.class;
- args.addGenericArgumentValue(this.consumerCompiler);
- if (inputType != null) {
- props.add("typeParameterizations", inputType);
- }
- }
- else {
- proxyClass = LambdaCompilingFunction.class;
- args.addGenericArgumentValue(this.functionCompiler);
- if ((inputType == null && outputType != null)
- || (outputType == null && inputType != null)) {
- throw new IllegalArgumentException(
- "if either input or output type is set, the other is also required");
- }
- if (inputType != null) {
- props.add("typeParameterizations",
- new String[] { inputType, outputType });
- }
- }
- RootBeanDefinition beanDefinition = new RootBeanDefinition(proxyClass);
- beanDefinition.setConstructorArgumentValues(args);
- beanDefinition.setPropertyValues(props);
- beanFactory.registerBeanDefinition(name, beanDefinition);
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CloseableFilterableJavaFileObjectIterable.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CloseableFilterableJavaFileObjectIterable.java
deleted file mode 100644
index 80605e030..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CloseableFilterableJavaFileObjectIterable.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-
-import javax.tools.JavaFileObject;
-
-import org.springframework.cloud.function.compiler.java.MemoryBasedJavaFileManager.CompilationInfoCache;
-
-/**
- * Common superclass for iterables that need to handle closing when finished with and that
- * need to handle possible constraints on the values that are iterated over.
- *
- * @author Andy Clement
- */
-public abstract class CloseableFilterableJavaFileObjectIterable
- implements Iterable {
-
- // private final static Logger logger =
- // LoggerFactory.getLogger(CloseableFilterableJavaFileObjectIterable.class);
-
- private final static boolean BOOT_PACKAGING_AWARE = true;
-
- private final static String BOOT_PACKAGING_PREFIX_FOR_CLASSES = "BOOT-INF/classes/";
-
- // If set specifies the package the iterator consumer is interested in. Only
- // return results in this package. Will have a trailing separator to speed
- // matching. '/' on its own represents the default package
- protected String packageNameFilter;
-
- // Indicates whether the consumer of the iterator wants to see classes
- // that are in subpackages of those matching the filter.
- protected boolean includeSubpackages;
-
- protected CompilationInfoCache compilationInfoCache;
-
- public CloseableFilterableJavaFileObjectIterable(
- CompilationInfoCache compilationInfoCache, String packageNameFilter,
- boolean includeSubpackages) {
- if (packageNameFilter != null && packageNameFilter.contains(File.separator)) {
- throw new IllegalArgumentException(
- "Package name filters should use dots to separate components: "
- + packageNameFilter);
- }
- this.compilationInfoCache = compilationInfoCache;
- // Normalize filter to forward slashes
- this.packageNameFilter = packageNameFilter == null ? null
- : packageNameFilter.replace('.', '/') + '/';
- this.includeSubpackages = includeSubpackages;
- }
-
- /**
- * Used by subclasses to check values against any specified constraints.
- * @param name the name to check against the criteria
- * @return true if the name is a valid iterator result based on the specified criteria
- */
- protected boolean accept(String name) {
- // logger.debug("checking {} against constraints packageNameFilter={}
- // includeSubpackages={}",name,packageNameFilter,includeSubpackages);
- if (!name.endsWith(".class")) {
- return false;
- }
- if (this.packageNameFilter == null) {
- return true;
- }
- boolean accept;
- // Normalize to forward slashes (some jars are producing paths with forward
- // slashes, some with backward slashes)
- name = name.replace('\\', '/');
- if (this.packageNameFilter.length() == 1 && this.packageNameFilter.equals("/")) {
- // This is the 'default package' filter representation
- if (name.indexOf('/') == -1) {
- accept = true;
- }
- else if (BOOT_PACKAGING_AWARE) {
- accept = name.startsWith(BOOT_PACKAGING_PREFIX_FOR_CLASSES) && name
- .indexOf('/', BOOT_PACKAGING_PREFIX_FOR_CLASSES.length()) == -1;
- }
- return accept;
- }
- if (this.includeSubpackages) {
- accept = name.startsWith(this.packageNameFilter);
- if (!accept && BOOT_PACKAGING_AWARE) {
- accept = name.startsWith(BOOT_PACKAGING_PREFIX_FOR_CLASSES)
- && name.indexOf(
- this.packageNameFilter) == BOOT_PACKAGING_PREFIX_FOR_CLASSES
- .length();
- }
- }
- else {
- accept = name.startsWith(this.packageNameFilter)
- && name.indexOf("/", this.packageNameFilter.length()) == -1;
- if (!accept && BOOT_PACKAGING_AWARE) {
- accept = name.startsWith(BOOT_PACKAGING_PREFIX_FOR_CLASSES)
- && name.indexOf(
- this.packageNameFilter) == BOOT_PACKAGING_PREFIX_FOR_CLASSES
- .length()
- && name.indexOf("/", BOOT_PACKAGING_PREFIX_FOR_CLASSES.length()
- + this.packageNameFilter.length()) == -1;
- }
- }
- return accept;
- }
-
- abstract void close();
-
- abstract void reset();
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationFailedException.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationFailedException.java
deleted file mode 100644
index 503e7a0c6..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationFailedException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.util.List;
-
-/**
- * @author Mark Fisher
- */
-@SuppressWarnings("serial")
-public class CompilationFailedException extends RuntimeException {
-
- public CompilationFailedException(List messages) {
- super(consolidateMessages(messages));
- }
-
- private static String consolidateMessages(List messages) {
- if (messages == null || messages.isEmpty()) {
- return "";
- }
- StringBuilder sb = new StringBuilder();
- for (CompilationMessage message : messages) {
- sb.append(message.toString());
- }
- return sb.toString();
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationMessage.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationMessage.java
deleted file mode 100644
index bd3bcc933..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationMessage.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-/**
- * Encapsulate information produced during compilation. A message may be an error or
- * something less serious (warning/informational). The toString() method will
- * produce a formatted error include source context indicating the precise location of the
- * problem.
- *
- * @author Andy Clement
- */
-public class CompilationMessage {
-
- private Kind kind;
-
- private String message;
-
- private String sourceCode;
-
- private int startPosition;
-
- private int endPosition;
-
- public CompilationMessage(Kind kind, String message, String sourceCode,
- int startPosition, int endPosition) {
- this.kind = kind;
- this.message = message;
- this.sourceCode = sourceCode;
- this.startPosition = startPosition;
- this.endPosition = endPosition;
- }
-
- /**
- * @return the type of message
- */
- public Kind getKind() {
- return this.kind;
- }
-
- /**
- * @return the message text
- */
- public String getMessage() {
- return this.message;
- }
-
- /**
- * @return the source code for the file associated with the message
- */
- public String getSourceCode() {
- return this.sourceCode;
- }
-
- /**
- * @return offset from start of source file where the error begins
- */
- public int getStartPosition() {
- return this.startPosition;
- }
-
- /**
- * @return offset from start of source file where the error ends
- */
- public int getEndPosition() {
- return this.endPosition;
- }
-
- public String toString() {
- StringBuilder s = new StringBuilder();
- s.append("==========\n");
- if (this.sourceCode != null) { // Cannot include source context if no source
- // available
- int[] lineStartEnd = getLineStartEnd(this.startPosition);
- s.append(this.sourceCode.substring(lineStartEnd[0], lineStartEnd[1]))
- .append("\n");
- int col = lineStartEnd[0];
- // When inserting the whitespace, ensure tabs in the source line are respected
- while ((col) < this.startPosition) {
- s.append(this.sourceCode.charAt(col++) == '\t' ? "\t" : " ");
- }
- // Want at least one ^
- s.append("^");
- col++;
- while ((col++) < this.endPosition) {
- s.append("^");
- }
- s.append("\n");
- }
- s.append(this.kind).append(":").append(this.message).append("\n");
- s.append("==========\n");
- return s.toString();
- }
-
- /**
- * For a given position in the source code this method returns a pair of int that
- * indicate the start and end of the line within the source code that contain the
- * position.
- * @param searchPos the position of interest in the source code
- * @return an int array of length 2 containing the start and end positions of the line
- */
- private int[] getLineStartEnd(int searchPos) {
- int previousPos = -1;
- int pos = 0;
- do {
- pos = this.sourceCode.indexOf('\n', previousPos + 1);
- if (searchPos < pos) {
- return new int[] { previousPos + 1, pos };
- }
- previousPos = pos;
- }
- while (pos != -1);
- return new int[] { previousPos + 1, this.sourceCode.length() };
- }
-
- enum Kind {
-
- ERROR, OTHER
-
- }
- // TODO test coverage for first line/last line situations
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationOutputCollector.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationOutputCollector.java
deleted file mode 100644
index 2dfe424b6..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationOutputCollector.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.tools.FileObject;
-import javax.tools.JavaFileManager.Location;
-import javax.tools.JavaFileObject.Kind;
-
-/**
- * During compilation instances of this class will collect up the output files from the
- * compilation process. Any kind of file is collected upon but access is only currently
- * provided to retrieve classes produced during compilation. Annotation processors that
- * run may create other kinds of artifact.
- *
- * @author Andy Clement
- */
-public class CompilationOutputCollector {
-
- private List outputFiles = new ArrayList<>();
-
- /**
- * Retrieve compiled classes that have been collected since this collector was built.
- * Due to annotation processing it is possible other source files or metadata files
- * may be produced during compilation - those are not included in the returned list.
- * @return list of compiled classes
- */
- public List getCompiledClasses() {
- List compiledClassDefinitions = new ArrayList<>();
- for (InMemoryJavaFileObject outputFile : this.outputFiles) {
- if (outputFile.getKind() == Kind.CLASS) {
- CompiledClassDefinition compiledClassDefinition = new CompiledClassDefinition(
- outputFile.getName(), outputFile.getBytes());
- compiledClassDefinitions.add(compiledClassDefinition);
- }
- }
- return compiledClassDefinitions;
- }
-
- public InMemoryJavaFileObject getJavaFileForOutput(Location location,
- String className, Kind kind, FileObject sibling) {
- InMemoryJavaFileObject jfo = InMemoryJavaFileObject.getJavaFileObject(location,
- className, kind, sibling);
- this.outputFiles.add(jfo);
- return jfo;
- }
-
- public InMemoryJavaFileObject getFileForOutput(Location location, String packageName,
- String relativeName, FileObject sibling) {
- InMemoryJavaFileObject ojfo = InMemoryJavaFileObject.getFileObject(location,
- packageName, relativeName, sibling);
- this.outputFiles.add(ojfo);
- return ojfo;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationResult.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationResult.java
deleted file mode 100644
index 373ecb80c..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompilationResult.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Holder for the results of compilation. If compilation was successful the set of classes
- * that resulted from compilation will be available. If compilation was not successful the
- * error messages should provide information about why. Note that compilation may succeed
- * and yet there will still be informational or warning messages collected.
- *
- * @author Andy Clement
- * @author Mark Fisher
- */
-public class CompilationResult {
-
- List compilationMessages = new ArrayList<>();
-
- List> compiledClasses = new ArrayList<>();
-
- private boolean successfulCompilation;
-
- private Map classBytes = new HashMap<>();
-
- private List resolvedAdditionalDependencies = new ArrayList<>();
-
- public CompilationResult(boolean successfulCompilation) {
- this.successfulCompilation = successfulCompilation;
- }
-
- public void addClassBytes(String name, byte[] bytes) {
- this.classBytes.put(name, bytes);
- }
-
- public List getResolvedAdditionalDependencies() {
- return this.resolvedAdditionalDependencies;
- }
-
- public void setResolvedAdditionalDependencies(
- List resolvedAdditionalDependencies) {
- this.resolvedAdditionalDependencies = resolvedAdditionalDependencies;
- }
-
- public byte[] getClassBytes(String classname) {
- return this.classBytes.get(classname);
- }
-
- public boolean wasSuccessful() {
- return this.successfulCompilation;
- }
-
- public List> getCompiledClasses() {
- return this.compiledClasses;
- }
-
- public void setCompiledClasses(List> compiledClasses) {
- this.compiledClasses = compiledClasses;
- }
-
- public List getCompilationMessages() {
- return Collections.unmodifiableList(this.compilationMessages);
- }
-
- public void recordCompilationMessage(CompilationMessage message) {
- this.compilationMessages.add(message);
- }
-
- public void recordCompilationMessages(List messages) {
- this.compilationMessages.addAll(messages);
- }
-
- public String toString() {
- StringBuilder s = new StringBuilder();
- s.append("Compilation result: #classes=" + this.compiledClasses.size()
- + " #messages=" + this.compilationMessages.size() + "\n");
- s.append("Compiled classes:\n").append(this.compiledClasses).append("\n");
- s.append("Compilation messages:\n").append(this.compilationMessages).append("\n");
- return s.toString();
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompiledClassDefinition.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompiledClassDefinition.java
deleted file mode 100644
index 9502f5ff9..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompiledClassDefinition.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-/**
- * Encapsulates a name with the bytes for its class definition.
- *
- * @author Andy Clement
- */
-public class CompiledClassDefinition {
-
- private byte[] bytes;
-
- private String filename;
-
- private String classname;
-
- public CompiledClassDefinition(String filename, byte[] bytes) {
- this.filename = filename;
- this.bytes = bytes;
- this.classname = filename;
- if (this.classname.startsWith("/")) {
- this.classname = this.classname.substring(1);
- }
- this.classname = this.classname.replace('/', '.').substring(0,
- this.classname.length() - 6); // strip
- // off
- // .class
- }
-
- public String getName() {
- return this.filename;
- }
-
- public byte[] getBytes() {
- return this.bytes;
- }
-
- @Override
- public String toString() {
- return "CompiledClassDefinition(name=" + getName() + ",#bytes="
- + getBytes().length + ")";
- }
-
- public String getClassName() {
- return this.classname;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompositeProxySelector.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompositeProxySelector.java
deleted file mode 100644
index 0e3cc7f4d..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/CompositeProxySelector.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.aether.repository.Proxy;
-import org.eclipse.aether.repository.ProxySelector;
-import org.eclipse.aether.repository.RemoteRepository;
-
-/**
- * Composite {@link ProxySelector}.
- *
- * @author Dave Syer
- */
-public class CompositeProxySelector implements ProxySelector {
-
- private List selectors = new ArrayList();
-
- public CompositeProxySelector(List selectors) {
- this.selectors = selectors;
- }
-
- @Override
- public Proxy getProxy(RemoteRepository repository) {
- for (ProxySelector selector : this.selectors) {
- Proxy proxy = selector.getProxy(repository);
- if (proxy != null) {
- return proxy;
- }
- }
- return null;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DependencyResolver.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DependencyResolver.java
deleted file mode 100644
index a7ee52c50..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DependencyResolver.java
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.inject.Singleton;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import com.google.inject.name.Named;
-import com.google.inject.name.Names;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.repository.MavenArtifactRepository;
-import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.DefaultModelReader;
-import org.apache.maven.model.io.ModelReader;
-import org.apache.maven.model.locator.DefaultModelLocator;
-import org.apache.maven.model.locator.ModelLocator;
-import org.apache.maven.model.validation.DefaultModelValidator;
-import org.apache.maven.model.validation.ModelValidator;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.DependencyResolutionResult;
-import org.apache.maven.project.ProjectBuilder;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.project.ProjectBuildingRequest.RepositoryMerging;
-import org.apache.maven.project.ProjectBuildingResult;
-import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
-import org.apache.maven.repository.internal.DefaultVersionRangeResolver;
-import org.apache.maven.repository.internal.DefaultVersionResolver;
-import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
-import org.apache.maven.repository.internal.SnapshotMetadataGeneratorFactory;
-import org.apache.maven.repository.internal.VersionsMetadataGeneratorFactory;
-import org.apache.maven.settings.Profile;
-import org.apache.maven.settings.Repository;
-import org.codehaus.plexus.ContainerConfiguration;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.MutablePlexusContainer;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.classworlds.ClassWorld;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.RepositorySystem;
-import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
-import org.eclipse.aether.graph.Dependency;
-import org.eclipse.aether.impl.ArtifactDescriptorReader;
-import org.eclipse.aether.impl.MetadataGeneratorFactory;
-import org.eclipse.aether.impl.VersionRangeResolver;
-import org.eclipse.aether.impl.VersionResolver;
-import org.eclipse.aether.impl.guice.AetherModule;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
-import org.eclipse.aether.repository.ProxySelector;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.repository.RepositoryPolicy;
-import org.eclipse.aether.resolution.ArtifactRequest;
-import org.eclipse.aether.resolution.ArtifactResult;
-import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
-import org.eclipse.aether.spi.connector.transport.TransporterFactory;
-import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory;
-import org.eclipse.aether.transport.file.FileTransporterFactory;
-import org.eclipse.aether.transport.http.HttpTransporterFactory;
-import org.eclipse.aether.util.repository.JreProxySelector;
-import org.eclipse.sisu.inject.DefaultBeanLocator;
-import org.eclipse.sisu.plexus.ClassRealmManager;
-
-import org.springframework.core.io.Resource;
-import org.springframework.util.StringUtils;
-
-/**
- * Dependency resolver utility class.
- *
- * @author Andy Clement
- */
-public final class DependencyResolver {
-
- private static DependencyResolver instance = new DependencyResolver();
-
- private static Properties globals;
-
- private final Object lock = new Object();
-
- private LocalRepositoryManagerFactory localRepositoryManagerFactory;
-
- private PlexusContainer container;
-
- private ProjectBuilder projectBuilder;
-
- private RepositorySystem repositorySystem;
-
- private MavenSettings settings;
-
- private DependencyResolver() {
- }
-
- public static DependencyResolver instance() {
- return instance;
- }
-
- public static void close() {
- instance = new DependencyResolver();
- }
-
- static Properties getGlobals() {
- return globals;
- }
-
- private void initialize() {
- if (this.container == null) {
- synchronized (this.lock) {
- if (this.container == null) {
- ClassWorld classWorld = new ClassWorld("plexus.core",
- Thread.currentThread().getContextClassLoader());
- ContainerConfiguration config = new DefaultContainerConfiguration()
- .setClassWorld(classWorld)
- .setRealm(classWorld.getClassRealm("plexus.core"))
- .setClassPathScanning(PlexusConstants.SCANNING_INDEX)
- .setAutoWiring(true).setName("maven");
- PlexusContainer container;
- try {
- container = new DefaultPlexusContainer(config, new AetherModule(),
- new DependencyResolutionModule());
- this.localRepositoryManagerFactory = container
- .lookup(LocalRepositoryManagerFactory.class);
- container.addComponent(
- new ClassRealmManager((MutablePlexusContainer) container,
- new DefaultBeanLocator()),
- ClassRealmManager.class.getName());
- this.projectBuilder = container.lookup(ProjectBuilder.class);
- this.repositorySystem = container.lookup(RepositorySystem.class);
- }
- catch (Exception e) {
- throw new IllegalStateException("Cannot create container", e);
- }
- this.container = container;
- this.settings = new MavenSettingsReader().readSettings();
- }
- }
- }
- }
-
- public List dependencies(Resource resource) {
- return dependencies(resource, new Properties());
- }
-
- public List dependencies(final Resource resource,
- final Properties properties) {
- initialize();
- try {
- ProjectBuildingRequest request = getProjectBuildingRequest(properties);
- request.setResolveDependencies(true);
- synchronized (DependencyResolver.class) {
- ProjectBuildingResult result = this.projectBuilder
- .build(new PropertiesModelSource(properties, resource), request);
- DependencyResolver.globals = null;
- DependencyResolutionResult dependencies = result
- .getDependencyResolutionResult();
- if (!dependencies.getUnresolvedDependencies().isEmpty()) {
- StringBuilder builder = new StringBuilder();
- for (Dependency dependency : dependencies
- .getUnresolvedDependencies()) {
- List errors = dependencies
- .getResolutionErrors(dependency);
- for (Exception exception : errors) {
- if (builder.length() > 0) {
- builder.append("\n");
- }
- builder.append(exception.getMessage());
- }
- }
- throw new RuntimeException(builder.toString());
- }
- return runtime(dependencies.getDependencies());
- }
- }
- catch (ProjectBuildingException | NoLocalRepositoryManagerException e) {
- throw new IllegalStateException("Cannot build model", e);
- }
- }
-
- public File resolve(Dependency dependency) {
- initialize();
- return collectNonTransitive(Arrays.asList(dependency)).iterator().next()
- .getArtifact().getFile();
- }
-
- private List runtime(List dependencies) {
- List list = new ArrayList<>();
- for (Dependency dependency : dependencies) {
- if (!"test".equals(dependency.getScope())
- && !"provided".equals(dependency.getScope())) {
- list.add(dependency);
- }
- }
- return list;
- }
-
- private ProjectBuildingRequest getProjectBuildingRequest(Properties properties)
- throws NoLocalRepositoryManagerException {
- DefaultProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest();
- DefaultRepositorySystemSession session = createSession(properties);
- projectBuildingRequest.setRepositoryMerging(RepositoryMerging.REQUEST_DOMINANT);
- projectBuildingRequest.setRemoteRepositories(mavenRepositories(properties));
- projectBuildingRequest.getRemoteRepositories()
- .addAll(mavenRepositories(this.settings));
- projectBuildingRequest.setRepositorySession(session);
- projectBuildingRequest.setProcessPlugins(false);
- projectBuildingRequest.setBuildStartTime(new Date());
- projectBuildingRequest.setUserProperties(properties);
- projectBuildingRequest.setSystemProperties(System.getProperties());
- return projectBuildingRequest;
- }
-
- private Collection extends ArtifactRepository> mavenRepositories(
- MavenSettings settings) {
- List list = new ArrayList<>();
- for (Profile profile : settings.getActiveProfiles()) {
- for (Repository repository : profile.getRepositories()) {
- addRepositoryIfMissing(list, repository.getId(), repository.getUrl(),
- repository.getReleases() != null
- ? repository.getReleases().isEnabled() : true,
- repository.getSnapshots() != null
- ? repository.getSnapshots().isEnabled() : false);
- }
- }
- return list;
- }
-
- private List mavenRepositories(Properties properties) {
- List list = new ArrayList<>();
- addRepositoryIfMissing(list, "spring-snapshots",
- "https://repo.spring.io/libs-snapshot", true, true);
- addRepositoryIfMissing(list, "central", "https://repo1.maven.org/maven2", true,
- false);
- return list;
- }
-
- private List aetherRepositories(Properties properties) {
- List list = new ArrayList<>();
- for (ArtifactRepository input : mavenRepositories(properties)) {
- list.add(remote(input));
- }
- return list;
- }
-
- private RemoteRepository remote(ArtifactRepository input) {
- return new RemoteRepository.Builder(input.getId(), input.getLayout().getId(),
- input.getUrl()).setSnapshotPolicy(policy(input.getSnapshots()))
- .setReleasePolicy(policy(input.getReleases())).build();
- }
-
- private RepositoryPolicy policy(ArtifactRepositoryPolicy input) {
- RepositoryPolicy policy = new RepositoryPolicy(input.isEnabled(),
- RepositoryPolicy.UPDATE_POLICY_DAILY,
- RepositoryPolicy.CHECKSUM_POLICY_WARN);
- return policy;
- }
-
- private void addRepositoryIfMissing(List list, String id,
- String url, boolean releases, boolean snapshots) {
- for (ArtifactRepository repo : list) {
- if (url.equals(repo.getUrl())) {
- return;
- }
- if (id.equals(repo.getId())) {
- return;
- }
- }
- list.add(repo(id, url, releases, snapshots));
- }
-
- private ArtifactRepository repo(String id, String url, boolean releases,
- boolean snapshots) {
- MavenArtifactRepository repository = new MavenArtifactRepository();
- repository.setLayout(new DefaultRepositoryLayout());
- repository.setId(id);
- repository.setUrl(url);
- ArtifactRepositoryPolicy enabled = new ArtifactRepositoryPolicy();
- enabled.setEnabled(true);
- ArtifactRepositoryPolicy disabled = new ArtifactRepositoryPolicy();
- disabled.setEnabled(false);
- repository.setReleaseUpdatePolicy(releases ? enabled : disabled);
- repository.setSnapshotUpdatePolicy(snapshots ? enabled : disabled);
- return repository;
- }
-
- private DefaultRepositorySystemSession createSession(Properties properties)
- throws NoLocalRepositoryManagerException {
- DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
- LocalRepository repository = localRepository(properties);
- session.setLocalRepositoryManager(
- this.localRepositoryManagerFactory.newInstance(session, repository));
- applySettings(session);
- ProxySelector existing = session.getProxySelector();
- if (existing == null || !(existing instanceof CompositeProxySelector)) {
- JreProxySelector fallback = new JreProxySelector();
- ProxySelector selector = existing == null ? fallback
- : new CompositeProxySelector(Arrays.asList(existing, fallback));
- session.setProxySelector(selector);
- }
- return session;
- }
-
- private void applySettings(DefaultRepositorySystemSession session) {
- MavenSettingsReader.applySettings(this.settings, session);
- }
-
- private LocalRepository localRepository(Properties properties) {
- return new LocalRepository(getM2RepoDirectory());
- }
-
- public Model readModel(Resource resource) {
- return readModel(resource, new Properties());
- }
-
- public Model readModel(final Resource resource, final Properties properties) {
- initialize();
- try {
- ProjectBuildingRequest request = getProjectBuildingRequest(properties);
- request.setResolveDependencies(false);
- ProjectBuildingResult result = this.projectBuilder
- .build(new PropertiesModelSource(properties, resource), request);
- return result.getProject().getModel();
- }
- catch (Exception e) {
- throw new IllegalStateException("Failed to build model from effective pom",
- e);
- }
- }
-
- private File getM2RepoDirectory() {
- return new File(getDefaultM2HomeDirectory(), "repository");
- }
-
- private File getDefaultM2HomeDirectory() {
- String mavenRoot = System.getProperty("maven.home");
- if (StringUtils.hasLength(mavenRoot)) {
- return new File(mavenRoot);
- }
- return new File(System.getProperty("user.home"), ".m2");
- }
-
- private List collectNonTransitive(List dependencies) {
- try {
- List artifactRequests = getArtifactRequests(dependencies);
- List result = this.repositorySystem
- .resolveArtifacts(createSession(new Properties()), artifactRequests);
- return result;
- }
- catch (Exception ex) {
- throw new IllegalStateException(ex);
- }
- }
-
- private List getArtifactRequests(List dependencies) {
- List list = new ArrayList<>();
- for (Dependency dependency : dependencies) {
- ArtifactRequest request = new ArtifactRequest(dependency.getArtifact(), null,
- null);
- request.setRepositories(aetherRepositories(new Properties()));
- list.add(request);
- }
- return list;
- }
-
- @SuppressWarnings("deprecation")
- private static final class PropertiesModelSource
- implements org.apache.maven.model.building.ModelSource {
-
- private final Properties properties;
-
- private final Resource resource;
-
- private PropertiesModelSource(Properties properties, Resource resource) {
- this.properties = properties;
- this.resource = resource;
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- DependencyResolver.globals = this.properties;
- return new BufferedInputStream(this.resource.getInputStream()) {
- @Override
- public void close() throws IOException {
- DependencyResolver.globals = null;
- super.close();
- }
- };
- }
-
- @Override
- public String getLocation() {
- return this.resource.getDescription();
- }
-
- }
-
-}
-
-class DependencyResolutionModule extends AbstractModule {
-
- @Override
- protected void configure() {
- bind(ModelLocator.class).to(DefaultModelLocator.class).in(Singleton.class);
- bind(ModelReader.class).to(DefaultModelReader.class).in(Singleton.class);
- bind(ModelValidator.class).to(DefaultModelValidator.class).in(Singleton.class);
- bind(RepositoryConnectorFactory.class).to(BasicRepositoryConnectorFactory.class)
- .in(Singleton.class);
- bind(ArtifactDescriptorReader.class) //
- .to(DefaultArtifactDescriptorReader.class).in(Singleton.class);
- bind(VersionResolver.class) //
- .to(DefaultVersionResolver.class).in(Singleton.class);
- bind(VersionRangeResolver.class) //
- .to(DefaultVersionRangeResolver.class).in(Singleton.class);
- bind(MetadataGeneratorFactory.class).annotatedWith(Names.named("snapshot")) //
- .to(SnapshotMetadataGeneratorFactory.class).in(Singleton.class);
- bind(MetadataGeneratorFactory.class).annotatedWith(Names.named("versions")) //
- .to(VersionsMetadataGeneratorFactory.class).in(Singleton.class);
- bind(TransporterFactory.class).annotatedWith(Names.named("http"))
- .to(HttpTransporterFactory.class).in(Singleton.class);
- bind(TransporterFactory.class).annotatedWith(Names.named("file"))
- .to(FileTransporterFactory.class).in(Singleton.class);
- }
-
- @Provides
- @Singleton
- Set provideMetadataGeneratorFactories(
- @Named("snapshot") MetadataGeneratorFactory snapshot,
- @Named("versions") MetadataGeneratorFactory versions) {
- Set factories = new HashSet<>();
- factories.add(snapshot);
- factories.add(versions);
- return Collections.unmodifiableSet(factories);
- }
-
- @Provides
- @Singleton
- Set provideRepositoryConnectorFactories(
- RepositoryConnectorFactory factory) {
- return Collections.singleton(factory);
- }
-
- @Provides
- @Singleton
- Set provideTransporterFactories(
- @Named("file") TransporterFactory file,
- @Named("http") TransporterFactory http) {
- // Order is decided elsewhere (by priority)
- Set factories = new HashSet();
- factories.add(file);
- factories.add(http);
- return Collections.unmodifiableSet(factories);
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DirEntryJavaFileObject.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DirEntryJavaFileObject.java
deleted file mode 100644
index c4557ddff..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DirEntryJavaFileObject.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URI;
-
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.NestingKind;
-import javax.tools.JavaFileObject;
-
-/**
- * A JavaFileObject that represents a file in a directory.
- *
- * @author Andy Clement
- */
-public class DirEntryJavaFileObject implements JavaFileObject {
-
- private File file;
-
- private File basedir;
-
- public DirEntryJavaFileObject(File basedir, File file) {
- this.basedir = basedir;
- this.file = file;
- }
-
- @Override
- public URI toUri() {
- return this.file.toURI();
- }
-
- /**
- * @return the path of the file relative to the base directory, for example:
- * a/b/c/D.class
- */
- @Override
- public String getName() {
- String basedirPath = this.basedir.getPath();
- String filePath = this.file.getPath();
- return filePath.substring(basedirPath.length() + 1);
- }
-
- @Override
- public InputStream openInputStream() throws IOException {
- return new FileInputStream(this.file);
- }
-
- @Override
- public OutputStream openOutputStream() throws IOException {
- throw new IllegalStateException("Only expected to be used for input");
- }
-
- @Override
- public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
- // It is bytecode
- throw new UnsupportedOperationException(
- "openReader() not supported on class file: " + getName());
- }
-
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- // It is bytecode
- throw new UnsupportedOperationException(
- "getCharContent() not supported on class file: " + getName());
- }
-
- @Override
- public Writer openWriter() throws IOException {
- throw new IllegalStateException("only expected to be used for input");
- }
-
- @Override
- public long getLastModified() {
- return this.file.lastModified();
- }
-
- @Override
- public boolean delete() {
- return false; // This object is for read only access to a class
- }
-
- @Override
- public Kind getKind() {
- return Kind.CLASS;
- }
-
- @Override
- public boolean isNameCompatible(String simpleName, Kind kind) {
- if (kind != Kind.CLASS) {
- return false;
- }
- String name = getName();
- int lastSlash = name.lastIndexOf('/');
- return name.substring(lastSlash + 1).equals(simpleName + ".class");
- }
-
- @Override
- public NestingKind getNestingKind() {
- return null;
- }
-
- @Override
- public Modifier getAccessLevel() {
- return null;
- }
-
- @Override
- public int hashCode() {
- return this.file.getName().hashCode() * 37 + this.basedir.getName().hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof DirEntryJavaFileObject)) {
- return false;
- }
- DirEntryJavaFileObject that = (DirEntryJavaFileObject) obj;
- return (this.basedir.getName().equals(that.basedir.getName()))
- && (this.file.getName().equals(that.file.getName()));
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DirEnumeration.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DirEnumeration.java
deleted file mode 100644
index 48017ea84..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/DirEnumeration.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * Walks a directory hierarchy from some base directory discovering files.
- *
- * @author Andy Clement
- */
-public class DirEnumeration implements Enumeration {
-
- // The starting point
- private File basedir;
-
- // Candidates collected so far
- private List filesToReturn;
-
- // Places still to explore for candidates
- private List directoriesToExplore;
-
- public DirEnumeration(File basedir) {
- this.basedir = basedir;
- }
-
- private void computeValue() {
- if (this.filesToReturn == null) { // Indicates we haven't started yet
- this.filesToReturn = new ArrayList<>();
- this.directoriesToExplore = new ArrayList<>();
- visitDirectory(this.basedir);
- }
- if (this.filesToReturn.size() == 0) {
- while (this.filesToReturn.size() == 0
- && this.directoriesToExplore.size() != 0) {
- File nextDir = this.directoriesToExplore.get(0);
- this.directoriesToExplore.remove(0);
- visitDirectory(nextDir);
- }
- }
- }
-
- @Override
- public boolean hasMoreElements() {
- computeValue();
- return this.filesToReturn.size() != 0;
- }
-
- @Override
- public File nextElement() {
- computeValue();
- if (this.filesToReturn.size() == 0) {
- throw new NoSuchElementException();
- }
- File toReturn = this.filesToReturn.get(0);
- this.filesToReturn.remove(0);
- return toReturn;
- }
-
- private void visitDirectory(File dir) {
- File[] files = dir.listFiles();
- if (files != null) {
- for (File file : files) {
- if (file.isDirectory()) {
- this.directoriesToExplore.add(file);
- }
- else {
- this.filesToReturn.add(file);
- }
- }
- }
- }
-
- public File getDirectory() {
- return this.basedir;
- }
-
- /**
- * Return the relative path of this file to the base directory that the directory
- * enumeration was started for.
- * @param file a file discovered returned by this enumeration
- * @return the relative path of the file (for example: a/b/c/D.class)
- */
- public String getName(File file) {
- String basedirPath = this.basedir.getPath();
- String filePath = file.getPath();
- if (!filePath.startsWith(basedirPath)) {
- throw new IllegalStateException("The file '" + filePath
- + "' is not nested below the base directory '" + basedirPath + "'");
- }
- return filePath.substring(basedirPath.length() + 1);
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/InMemoryJavaFileObject.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/InMemoryJavaFileObject.java
deleted file mode 100644
index 5203fb374..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/InMemoryJavaFileObject.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.CharArrayWriter;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.Charset;
-
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.NestingKind;
-import javax.tools.FileObject;
-import javax.tools.JavaFileManager.Location;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardLocation;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A JavaFileObject that represents a source artifact created for compilation or an output
- * artifact producing during compilation (a .class file or some other thing if an
- * annotation processor has run). In order to be clear what it is being used for there are
- * static factory methods that ask for specific types of file.
- *
- * @author Andy Clement
- */
-public final class InMemoryJavaFileObject implements JavaFileObject {
-
- private final static Logger logger = LoggerFactory
- .getLogger(InMemoryJavaFileObject.class);
-
- private Location location;
-
- private String packageName;
-
- private String relativeName;
-
- private FileObject sibling;
-
- private String className;
-
- private Kind kind;
-
- private byte[] content = null;
-
- private long lastModifiedTime = 0;
-
- private URI uri = null;
-
- private InMemoryJavaFileObject() {
- }
-
- public static InMemoryJavaFileObject getFileObject(Location location,
- String packageName, String relativeName, FileObject sibling) {
- InMemoryJavaFileObject retval = new InMemoryJavaFileObject();
- retval.kind = Kind.OTHER;
- retval.location = location;
- retval.packageName = packageName;
- retval.relativeName = relativeName;
- retval.sibling = sibling;
- return retval;
- }
-
- public static InMemoryJavaFileObject getJavaFileObject(Location location,
- String className, Kind kind, FileObject sibling) {
- InMemoryJavaFileObject retval = new InMemoryJavaFileObject();
- retval.location = location;
- retval.className = className;
- retval.kind = kind;
- retval.sibling = sibling;
- return retval;
- }
-
- public static InMemoryJavaFileObject getSourceJavaFileObject(String className,
- String content) {
- InMemoryJavaFileObject retval = new InMemoryJavaFileObject();
- retval.location = StandardLocation.SOURCE_PATH;
- retval.className = className;
- retval.kind = Kind.SOURCE;
- retval.content = content.getBytes();
- return retval;
- }
-
- public byte[] getBytes() {
- return this.content;
- }
-
- public String toString() {
- return "OutputJavaFileObject: Location=" + this.location + ",className="
- + this.className + ",kind=" + this.kind + ",relativeName="
- + this.relativeName + ",sibling=" + this.sibling + ",packageName="
- + this.packageName;
- }
-
- @Override
- public URI toUri() {
- // These memory based output files 'pretend' to be relative to the file system
- // root
- if (this.uri == null) {
- String name = null;
- if (this.className != null) {
- name = this.className.replace('.', '/');
- }
- else if (this.packageName != null && this.packageName.length() != 0) {
- name = this.packageName.replace('.', '/') + '/' + this.relativeName;
- }
- else {
- name = this.relativeName;
- }
-
- String uriString = null;
- try {
- uriString = "file:/" + name + this.kind.extension;
- this.uri = new URI(uriString);
- }
- catch (URISyntaxException e) {
- throw new IllegalStateException(
- "Unexpected URISyntaxException for string '" + uriString + "'",
- e);
- }
- }
- return this.uri;
- }
-
- @Override
- public String getName() {
- return toUri().getPath();
- }
-
- @Override
- public InputStream openInputStream() throws IOException {
- if (this.content == null) {
- throw new FileNotFoundException();
- }
- logger.debug("opening input stream for {}", getName());
- return new ByteArrayInputStream(this.content);
- }
-
- @Override
- public OutputStream openOutputStream() throws IOException {
- logger.debug("opening output stream for {}", getName());
- return new ByteArrayOutputStream() {
- @Override
- public void close() throws IOException {
- super.close();
- InMemoryJavaFileObject.this.lastModifiedTime = System.currentTimeMillis();
- InMemoryJavaFileObject.this.content = this.toByteArray();
- }
- };
- }
-
- @Override
- public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
- return new InputStreamReader(openInputStream(), Charset.defaultCharset());
- }
-
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- if (this.kind != Kind.SOURCE) {
- throw new UnsupportedOperationException(
- "getCharContent() not supported on file object: " + getName());
- }
- // Not yet supporting encodings
- return (this.content == null ? null : new String(this.content));
- }
-
- @Override
- public Writer openWriter() throws IOException {
- // Let's not enforce this restriction right now
- // if (kind == Kind.CLASS) {
- // throw new UnsupportedOperationException("openWriter() not supported on file
- // object: " + getName());
- // }
- return new CharArrayWriter() {
- @Override
- public void close() {
- InMemoryJavaFileObject.this.lastModifiedTime = System.currentTimeMillis();
- InMemoryJavaFileObject.this.content = new String(toCharArray())
- .getBytes(); // Ignoring encoding...
- }
- };
- }
-
- @Override
- public long getLastModified() {
- return this.lastModifiedTime;
- }
-
- @Override
- public boolean delete() {
- return false;
- }
-
- @Override
- public Kind getKind() {
- return this.kind;
- }
-
- public boolean isNameCompatible(String simpleName, Kind kind) {
- String baseName = simpleName + kind.extension;
- return kind.equals(getKind()) && (baseName.equals(toUri().getPath())
- || toUri().getPath().endsWith("/" + baseName));
- }
-
- @Override
- public NestingKind getNestingKind() {
- return null;
- }
-
- @Override
- public Modifier getAccessLevel() {
- return null;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/IterableClasspath.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/IterableClasspath.java
deleted file mode 100644
index b10e7e0fa..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/IterableClasspath.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Stack;
-import java.util.StringTokenizer;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipInputStream;
-
-import javax.tools.JavaFileObject;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.springframework.cloud.function.compiler.java.MemoryBasedJavaFileManager.CompilationInfoCache;
-import org.springframework.cloud.function.compiler.java.MemoryBasedJavaFileManager.CompilationInfoCache.ArchiveInfo;
-
-/**
- * Iterable that will produce an iterator that returns classes found on a specified
- * classpath that meet specified criteria. For jars it finds, the iterator will go into
- * nested jars - this handles the situation with a spring boot uberjar.
- *
- * @author Andy Clement
- */
-public class IterableClasspath extends CloseableFilterableJavaFileObjectIterable {
-
- private static Logger logger = LoggerFactory.getLogger(IterableClasspath.class);
-
- private List classpathEntries = new ArrayList<>();
-
- private List openArchives = new ArrayList<>();
-
- /**
- * @param compilationInfoCache cache of info that may help accelerate compilation
- * @param classpath a classpath of jars/directories
- * @param packageNameFilter an optional package name if choosing to filter (e.g.
- * com.example)
- * @param includeSubpackages if true, include results in subpackages of the specified
- * package filter
- */
- IterableClasspath(CompilationInfoCache compilationInfoCache, String classpath,
- String packageNameFilter, boolean includeSubpackages) {
- super(compilationInfoCache, packageNameFilter, includeSubpackages);
- StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
- while (tokenizer.hasMoreElements()) {
- String nextEntry = tokenizer.nextToken();
- File f = new File(nextEntry);
- if (f.exists()) {
- // Skip iterating over archives that cannot possibly match the filter
- if (this.packageNameFilter != null
- && this.packageNameFilter.length() > 0) {
- ArchiveInfo archiveInfo = compilationInfoCache.getArchiveInfoFor(f);
- if (archiveInfo != null
- && !archiveInfo.containsPackage(this.packageNameFilter,
- this.includeSubpackages)) {
- continue;
- }
- }
- this.classpathEntries.add(f);
- }
- else {
- logger.debug("path element does not exist {}", f);
- }
- }
- }
-
- public void close() {
- for (ZipFile openArchive : this.openArchives) {
- try {
- openArchive.close();
- }
- catch (IOException ioe) {
- logger.debug("Unexpected error closing archive {}", openArchive, ioe);
- }
- }
- this.openArchives.clear();
- }
-
- public Iterator iterator() {
- return new ClasspathEntriesIterator();
- }
-
- public void reset() {
- close();
- }
-
- static class ZipEnumerator implements Enumeration {
-
- private ZipInputStream zis;
-
- private ZipEntry nextEntry = null;
-
- ZipEnumerator(ZipInputStream zis) {
- this.zis = zis;
- }
-
- @Override
- public boolean hasMoreElements() {
- try {
- this.nextEntry = this.zis.getNextEntry();
- }
- catch (IOException ioe) {
- this.nextEntry = null;
- }
- return this.nextEntry != null;
- }
-
- @Override
- public ZipEntry nextElement() {
- ZipEntry retval = this.nextEntry;
- this.nextEntry = null;
- return retval;
- }
-
- }
-
- class ClasspathEntriesIterator implements Iterator {
-
- private int currentClasspathEntriesIndex = 0;
-
- // Walking one of three possible things: directory tree, zip, or Java runtime
- // packaged in JDK9+ form
- private File openDirectory = null;
-
- private DirEnumeration openDirectoryEnumeration = null;
-
- private ZipFile openArchive = null;
-
- private File openFile = null;
-
- private ZipEntry nestedZip = null;
-
- private Stack> openArchiveEnumeration = null;
-
- private File openJrt;
-
- private JrtFsEnumeration openJrtEnumeration = null;
-
- private JavaFileObject nextEntry = null;
-
- private void findNext() {
- if (this.nextEntry == null) {
- try {
- while (this.openArchive != null || this.openDirectory != null
- || this.openJrt != null
- || this.currentClasspathEntriesIndex < IterableClasspath.this.classpathEntries
- .size()) {
- if (this.openArchive == null && this.openDirectory == null
- && this.openJrt == null) {
- // Open the next item
- File nextFile = IterableClasspath.this.classpathEntries
- .get(this.currentClasspathEntriesIndex);
- if (nextFile.isDirectory()) {
- this.openDirectory = nextFile;
- this.openDirectoryEnumeration = new DirEnumeration(
- nextFile);
- }
- else if (nextFile.getName().endsWith("jrt-fs.jar")) {
- this.openJrt = nextFile;
- this.openJrtEnumeration = new JrtFsEnumeration(nextFile,
- null);
- }
- else {
- this.openFile = nextFile;
- this.openArchive = new ZipFile(nextFile);
- IterableClasspath.this.openArchives.add(this.openArchive);
- this.openArchiveEnumeration = new Stack>();
- this.openArchiveEnumeration
- .push(this.openArchive.entries());
- }
- this.currentClasspathEntriesIndex++;
- }
- if (this.openArchiveEnumeration != null) {
- while (!this.openArchiveEnumeration.isEmpty()) {
- while (this.openArchiveEnumeration.peek()
- .hasMoreElements()) {
- ZipEntry entry = this.openArchiveEnumeration.peek()
- .nextElement();
- String entryName = entry.getName();
- if (accept(entryName)) {
- if (this.nestedZip != null) {
- this.nextEntry = new NestedZipEntryJavaFileObject(
- this.openFile, this.openArchive,
- this.nestedZip, entry);
- }
- else {
- this.nextEntry = new ZipEntryJavaFileObject(
- this.openFile, this.openArchive,
- entry);
- }
- return;
- }
- else if (this.nestedZip == null
- && entryName.startsWith(
- MemoryBasedJavaFileManager.BOOT_PACKAGING_PREFIX_FOR_LIBRARIES)
- && entryName.endsWith(".jar")) {
- // nested jar in uber jar
- logger.debug("opening nested archive {}",
- entry.getName());
- ZipInputStream zis = new ZipInputStream(
- this.openArchive.getInputStream(entry));
- Enumeration extends ZipEntry> nestedZipEnumerator = new ZipEnumerator(
- zis);
- this.nestedZip = entry;
- this.openArchiveEnumeration
- .push(nestedZipEnumerator);
- }
- }
- this.openArchiveEnumeration.pop();
- if (this.nestedZip == null) {
- this.openArchive = null;
- this.openFile = null;
- }
- else {
- this.nestedZip = null;
- }
- }
- this.openArchiveEnumeration = null;
- this.openArchive = null;
- this.openFile = null;
- }
- else if (this.openDirectoryEnumeration != null) {
- while (this.openDirectoryEnumeration.hasMoreElements()) {
- File entry = this.openDirectoryEnumeration.nextElement();
- String name = this.openDirectoryEnumeration
- .getName(entry);
- if (accept(name)) {
- this.nextEntry = new DirEntryJavaFileObject(
- this.openDirectoryEnumeration.getDirectory(),
- entry);
- return;
- }
- }
- this.openDirectoryEnumeration = null;
- this.openDirectory = null;
- }
- else if (this.openJrtEnumeration != null) {
- while (this.openJrtEnumeration.hasMoreElements()) {
- JrtEntryJavaFileObject jrtEntry = this.openJrtEnumeration
- .nextElement();
- String name = this.openJrtEnumeration.getName(jrtEntry);
- if (accept(name)) {
- this.nextEntry = jrtEntry;
- return;
- }
- }
- this.openJrtEnumeration = null;
- this.openJrt = null;
- }
- }
- }
- catch (IOException ioe) {
- logger.debug("Unexpected error whilst processing classpath entries",
- ioe);
- }
- }
- }
-
- public boolean hasNext() {
- findNext();
- return this.nextEntry != null;
- }
-
- public JavaFileObject next() {
- findNext();
- if (this.nextEntry == null) {
- throw new NoSuchElementException();
- }
- JavaFileObject retval = this.nextEntry;
- this.nextEntry = null;
- return retval;
- }
-
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/IterableJrtModule.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/IterableJrtModule.java
deleted file mode 100644
index 50d5c9266..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/IterableJrtModule.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.nio.file.Path;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-import javax.tools.JavaFileObject;
-
-import org.springframework.cloud.function.compiler.java.MemoryBasedJavaFileManager.CompilationInfoCache;
-
-/**
- * Iterable that will produce an iterator that returns classes found in a specific module
- * tree within the Java runtime image that exists in Java 9 and later.
- *
- * @author Andy Clement
- */
-public class IterableJrtModule extends CloseableFilterableJavaFileObjectIterable {
-
- // private static Logger logger = LoggerFactory.getLogger(IterableJrtModule.class);
-
- Map walkers = new HashMap<>();
-
- private Path moduleRootPath;
-
- /**
- * @param compilationInfoCache cache of info that may help accelerate compilation
- * @param moduleRootPath path to the base of the relevant module within the JRT image
- * @param packageNameFilter an optional package name if choosing to filter (e.g.
- * com.example)
- * @param includeSubpackages if true, include results in subpackages of the specified
- * package filter
- */
- public IterableJrtModule(CompilationInfoCache compilationInfoCache,
- Path moduleRootPath, String packageNameFilter, boolean includeSubpackages) {
- super(compilationInfoCache, packageNameFilter, includeSubpackages);
- this.moduleRootPath = moduleRootPath;
- }
-
- public Iterator iterator() {
- JrtFsEnumeration jrtFsWalker = this.walkers.get(this.moduleRootPath.toString());
- if (jrtFsWalker == null) {
- jrtFsWalker = new JrtFsEnumeration(null, this.moduleRootPath);
- this.walkers.put(this.moduleRootPath.toString(), jrtFsWalker);
- }
- jrtFsWalker.reset();
- return new IteratorOverJrtFsEnumeration(jrtFsWalker);
- }
-
- public void close() {
- }
-
- public void reset() {
- close();
- }
-
- class IteratorOverJrtFsEnumeration implements Iterator {
-
- private JavaFileObject nextEntry = null;
-
- private JrtFsEnumeration jrtEnumeration;
-
- IteratorOverJrtFsEnumeration(JrtFsEnumeration jrtFsWalker) {
- this.jrtEnumeration = jrtFsWalker;
- }
-
- private void findNext() {
- if (this.nextEntry == null) {
- while (this.jrtEnumeration.hasMoreElements()) {
- JrtEntryJavaFileObject jrtEntry = this.jrtEnumeration.nextElement();
- String name = this.jrtEnumeration.getName(jrtEntry);
- if (accept(name)) {
- this.nextEntry = jrtEntry;
- return;
- }
- }
- }
- }
-
- public boolean hasNext() {
- findNext();
- return this.nextEntry != null;
- }
-
- public JavaFileObject next() {
- findNext();
- if (this.nextEntry == null) {
- throw new NoSuchElementException();
- }
- JavaFileObject retval = this.nextEntry;
- this.nextEntry = null;
- return retval;
- }
-
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/JrtEntryJavaFileObject.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/JrtEntryJavaFileObject.java
deleted file mode 100644
index 385d0577d..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/JrtEntryJavaFileObject.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.NestingKind;
-import javax.tools.JavaFileObject;
-
-/**
- * A JavaFileObject that represents a class from the Java runtime as packaged in Java 9
- * and later.
- *
- * @author Andy Clement
- */
-public class JrtEntryJavaFileObject implements JavaFileObject {
-
- private String pathToClassString;
-
- private Path path;
-
- /**
- * @param path entry in the Java runtime filesystem, for example
- * '/modules/java.base/java/lang/Object.class'
- */
- public JrtEntryJavaFileObject(Path path) {
- this.pathToClassString = path.subpath(2, path.getNameCount()).toString(); // e.g.
- // java/lang/Object.class
- this.path = path;
- }
-
- @Override
- public URI toUri() {
- return this.path.toUri();
- }
-
- /**
- * @return the path of the file relative to the base directory, for example:
- * a/b/c/D.class
- */
- @Override
- public String getName() {
- return this.pathToClassString;
- }
-
- @Override
- public InputStream openInputStream() throws IOException {
- byte[] bytes = Files.readAllBytes(this.path);
- return new ByteArrayInputStream(bytes);
- }
-
- @Override
- public OutputStream openOutputStream() throws IOException {
- throw new IllegalStateException("Only expected to be used for input");
- }
-
- @Override
- public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
- // It is bytecode
- throw new UnsupportedOperationException(
- "openReader() not supported on class file: " + getName());
- }
-
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- // It is bytecode
- throw new UnsupportedOperationException(
- "getCharContent() not supported on class file: " + getName());
- }
-
- @Override
- public Writer openWriter() throws IOException {
- throw new IllegalStateException("only expected to be used for input");
- }
-
- @Override
- public long getLastModified() {
- try {
- return Files.getLastModifiedTime(this.path).toMillis();
- }
- catch (IOException ioe) {
- throw new RuntimeException(
- "Unable to determine last modified time of " + this.pathToClassString,
- ioe);
- }
- }
-
- @Override
- public boolean delete() {
- return false; // This object is for read only access to a class
- }
-
- @Override
- public Kind getKind() {
- return Kind.CLASS;
- }
-
- @Override
- public boolean isNameCompatible(String simpleName, Kind kind) {
- if (kind != Kind.CLASS) {
- return false;
- }
- String name = getName();
- int lastSlash = name.lastIndexOf('/');
- return name.substring(lastSlash + 1).equals(simpleName + ".class");
- }
-
- @Override
- public NestingKind getNestingKind() {
- return null;
- }
-
- @Override
- public Modifier getAccessLevel() {
- return null;
- }
-
- @Override
- public int hashCode() {
- return getName().hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof JrtEntryJavaFileObject)) {
- return false;
- }
- JrtEntryJavaFileObject that = (JrtEntryJavaFileObject) obj;
- return (getName().equals(that.getName()));
- }
-
- public String getPathToClassString() {
- return this.pathToClassString;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/JrtFsEnumeration.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/JrtFsEnumeration.java
deleted file mode 100644
index ed9b1eb93..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/JrtFsEnumeration.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * Walks a JrtFS treating it like a directory (to avoid overcomplicating the walking logic
- * in IterableClasspath).
- *
- * @author Andy Clement
- */
-public class JrtFsEnumeration implements Enumeration {
-
- // private final static Logger logger =
- // LoggerFactory.getLogger(JrtFsEnumeration.class);
-
- private static URI JRT_URI = URI.create("jrt:/"); //$NON-NLS-1$
-
- private final static FileSystem fs = FileSystems.getFileSystem(JRT_URI);
-
- private Path pathWithinJrt;
-
- private List jfos = new ArrayList<>();
-
- private Integer counter = 0;
-
- private Boolean initialized = false;
-
- public JrtFsEnumeration(File jrtFsFile, Path pathWithinJrt) {
- this.pathWithinJrt = pathWithinJrt;
- ensureInitialized();
- }
-
- private void ensureInitialized() {
- synchronized (this.initialized) {
- if (this.initialized) {
- return;
- }
- FileCacheBuilderVisitor visitor = new FileCacheBuilderVisitor();
- if (this.pathWithinJrt != null) {
- try {
- Files.walkFileTree(this.pathWithinJrt, visitor);
- // System.out.println("JrtFs enumeration for '"+pathWithinJrt+"' with
- // #"+jfos.size()+" entries");
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- else {
- Iterable roots = fs.getRootDirectories();
- try {
- for (java.nio.file.Path path : roots) {
- Files.walkFileTree(path, visitor);
- }
- // System.out.println("JrtFs enumeration initialized with
- // #"+jfos.size()+" entries");
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- this.initialized = true;
- }
- }
-
- @Override
- public boolean hasMoreElements() {
- return this.counter < this.jfos.size();
- }
-
- @Override
- public JrtEntryJavaFileObject nextElement() {
- if (this.counter >= this.jfos.size()) {
- throw new NoSuchElementException();
- }
- JrtEntryJavaFileObject toReturn = this.jfos.get(this.counter++);
- return toReturn;
- }
-
- /**
- * Return the relative path of this file to the base directory that the directory
- * enumeration was started for.
- * @param file a file discovered returned by this enumeration
- * @return the relative path of the file (for example: a/b/c/D.class)
- */
- public String getName(JrtEntryJavaFileObject file) {
- return file.getPathToClassString();
- }
-
- public void reset() {
- this.counter = 0;
- }
-
- class FileCacheBuilderVisitor extends SimpleFileVisitor {
-
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- throws IOException {
- int fnc = file.getNameCount();
- if (fnc >= 3 && file.toString().endsWith(".class")) { // There is a preceeding
- // module name - e.g.
- // /modules/java.base/java/lang/Object.class
- // file.subpath(2, fnc); // e.g. java/lang/Object.class
- JrtFsEnumeration.this.jfos.add(new JrtEntryJavaFileObject(file));
- }
- return FileVisitResult.CONTINUE;
- }
-
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MavenSettings.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MavenSettings.java
deleted file mode 100644
index da210daf4..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MavenSettings.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.maven.model.ActivationFile;
-import org.apache.maven.model.ActivationOS;
-import org.apache.maven.model.ActivationProperty;
-import org.apache.maven.model.building.ModelProblemCollector;
-import org.apache.maven.model.building.ModelProblemCollectorRequest;
-import org.apache.maven.model.path.DefaultPathTranslator;
-import org.apache.maven.model.profile.DefaultProfileSelector;
-import org.apache.maven.model.profile.ProfileActivationContext;
-import org.apache.maven.model.profile.activation.FileProfileActivator;
-import org.apache.maven.model.profile.activation.JdkVersionProfileActivator;
-import org.apache.maven.model.profile.activation.OperatingSystemProfileActivator;
-import org.apache.maven.model.profile.activation.PropertyProfileActivator;
-import org.apache.maven.settings.Activation;
-import org.apache.maven.settings.Mirror;
-import org.apache.maven.settings.Profile;
-import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Server;
-import org.apache.maven.settings.Settings;
-import org.apache.maven.settings.crypto.SettingsDecryptionResult;
-import org.eclipse.aether.repository.Authentication;
-import org.eclipse.aether.repository.AuthenticationSelector;
-import org.eclipse.aether.repository.MirrorSelector;
-import org.eclipse.aether.repository.ProxySelector;
-import org.eclipse.aether.util.repository.AuthenticationBuilder;
-import org.eclipse.aether.util.repository.ConservativeAuthenticationSelector;
-import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
-import org.eclipse.aether.util.repository.DefaultMirrorSelector;
-import org.eclipse.aether.util.repository.DefaultProxySelector;
-
-/**
- * An encapsulation of settings read from a user's Maven settings.xml.
- *
- * @author Andy Wilkinson
- * @see MavenSettingsReader
- */
-public class MavenSettings {
-
- private final boolean offline;
-
- private final MirrorSelector mirrorSelector;
-
- private final AuthenticationSelector authenticationSelector;
-
- private final ProxySelector proxySelector;
-
- private final String localRepository;
-
- private final List activeProfiles;
-
- /**
- * Create a new {@link MavenSettings} instance.
- * @param settings the source settings
- * @param decryptedSettings the decrypted settings
- */
- public MavenSettings(Settings settings, SettingsDecryptionResult decryptedSettings) {
- this.offline = settings.isOffline();
- this.mirrorSelector = createMirrorSelector(settings);
- this.authenticationSelector = createAuthenticationSelector(decryptedSettings);
- this.proxySelector = createProxySelector(decryptedSettings);
- this.localRepository = settings.getLocalRepository();
- this.activeProfiles = determineActiveProfiles(settings);
- }
-
- private MirrorSelector createMirrorSelector(Settings settings) {
- DefaultMirrorSelector selector = new DefaultMirrorSelector();
- for (Mirror mirror : settings.getMirrors()) {
- selector.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(), false,
- mirror.getMirrorOf(), mirror.getMirrorOfLayouts());
- }
- return selector;
- }
-
- private AuthenticationSelector createAuthenticationSelector(
- SettingsDecryptionResult decryptedSettings) {
- DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector();
- for (Server server : decryptedSettings.getServers()) {
- AuthenticationBuilder auth = new AuthenticationBuilder();
- auth.addUsername(server.getUsername()).addPassword(server.getPassword());
- auth.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
- selector.add(server.getId(), auth.build());
- }
- return new ConservativeAuthenticationSelector(selector);
- }
-
- private ProxySelector createProxySelector(
- SettingsDecryptionResult decryptedSettings) {
- DefaultProxySelector selector = new DefaultProxySelector();
- for (Proxy proxy : decryptedSettings.getProxies()) {
- Authentication authentication = new AuthenticationBuilder()
- .addUsername(proxy.getUsername()).addPassword(proxy.getPassword())
- .build();
- selector.add(
- new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
- proxy.getHost(), proxy.getPort(), authentication),
- proxy.getNonProxyHosts());
- }
- return selector;
- }
-
- private List determineActiveProfiles(Settings settings) {
- SpringBootCliModelProblemCollector problemCollector = new SpringBootCliModelProblemCollector();
- List activeModelProfiles = createProfileSelector()
- .getActiveProfiles(createModelProfiles(settings.getProfiles()),
- new SpringBootCliProfileActivationContext(
- settings.getActiveProfiles()),
- problemCollector);
- if (!problemCollector.getProblems().isEmpty()) {
- throw new IllegalStateException(createFailureMessage(problemCollector));
- }
- List activeProfiles = new ArrayList();
- Map profiles = settings.getProfilesAsMap();
- for (org.apache.maven.model.Profile modelProfile : activeModelProfiles) {
- activeProfiles.add(profiles.get(modelProfile.getId()));
- }
- return activeProfiles;
- }
-
- private String createFailureMessage(
- SpringBootCliModelProblemCollector problemCollector) {
- StringWriter message = new StringWriter();
- PrintWriter printer = new PrintWriter(message);
- printer.println("Failed to determine active profiles:");
- for (ModelProblemCollectorRequest problem : problemCollector.getProblems()) {
- printer.println(" " + problem.getMessage() + (problem.getLocation() != null
- ? " at " + problem.getLocation() : ""));
- if (problem.getException() != null) {
- printer.println(indentStackTrace(problem.getException(), " "));
- }
- }
- return message.toString();
- }
-
- private String indentStackTrace(Exception ex, String indent) {
- return indentLines(printStackTrace(ex), indent);
- }
-
- private String printStackTrace(Exception ex) {
- StringWriter stackTrace = new StringWriter();
- PrintWriter printer = new PrintWriter(stackTrace);
- ex.printStackTrace(printer);
- return stackTrace.toString();
- }
-
- private String indentLines(String input, String indent) {
- StringWriter indented = new StringWriter();
- PrintWriter writer = new PrintWriter(indented);
- String line;
- BufferedReader reader = new BufferedReader(new StringReader(input));
- try {
- while ((line = reader.readLine()) != null) {
- writer.println(indent + line);
- }
- }
- catch (IOException ex) {
- return input;
- }
- return indented.toString();
- }
-
- private DefaultProfileSelector createProfileSelector() {
- DefaultProfileSelector selector = new DefaultProfileSelector();
-
- selector.addProfileActivator(new FileProfileActivator()
- .setPathTranslator(new DefaultPathTranslator()));
- selector.addProfileActivator(new JdkVersionProfileActivator());
- selector.addProfileActivator(new PropertyProfileActivator());
- selector.addProfileActivator(new OperatingSystemProfileActivator());
- return selector;
- }
-
- private List createModelProfiles(
- List profiles) {
- List modelProfiles = new ArrayList();
- for (Profile profile : profiles) {
- org.apache.maven.model.Profile modelProfile = new org.apache.maven.model.Profile();
- modelProfile.setId(profile.getId());
- if (profile.getActivation() != null) {
- modelProfile
- .setActivation(createModelActivation(profile.getActivation()));
- }
- modelProfiles.add(modelProfile);
- }
- return modelProfiles;
- }
-
- private org.apache.maven.model.Activation createModelActivation(
- Activation activation) {
- org.apache.maven.model.Activation modelActivation = new org.apache.maven.model.Activation();
- modelActivation.setActiveByDefault(activation.isActiveByDefault());
- if (activation.getFile() != null) {
- ActivationFile activationFile = new ActivationFile();
- activationFile.setExists(activation.getFile().getExists());
- activationFile.setMissing(activation.getFile().getMissing());
- modelActivation.setFile(activationFile);
- }
- modelActivation.setJdk(activation.getJdk());
- if (activation.getOs() != null) {
- ActivationOS os = new ActivationOS();
- os.setArch(activation.getOs().getArch());
- os.setFamily(activation.getOs().getFamily());
- os.setName(activation.getOs().getName());
- os.setVersion(activation.getOs().getVersion());
- modelActivation.setOs(os);
- }
- if (activation.getProperty() != null) {
- ActivationProperty property = new ActivationProperty();
- property.setName(activation.getProperty().getName());
- property.setValue(activation.getProperty().getValue());
- modelActivation.setProperty(property);
- }
- return modelActivation;
- }
-
- public boolean getOffline() {
- return this.offline;
- }
-
- public MirrorSelector getMirrorSelector() {
- return this.mirrorSelector;
- }
-
- public AuthenticationSelector getAuthenticationSelector() {
- return this.authenticationSelector;
- }
-
- public ProxySelector getProxySelector() {
- return this.proxySelector;
- }
-
- public String getLocalRepository() {
- return this.localRepository;
- }
-
- public List getActiveProfiles() {
- return this.activeProfiles;
- }
-
- private static final class SpringBootCliProfileActivationContext
- implements ProfileActivationContext {
-
- private final List activeProfiles;
-
- SpringBootCliProfileActivationContext(List activeProfiles) {
- this.activeProfiles = activeProfiles;
- }
-
- @Override
- public List getActiveProfileIds() {
- return this.activeProfiles;
- }
-
- @Override
- public List getInactiveProfileIds() {
- return Collections.emptyList();
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override
- public Map getSystemProperties() {
- return (Map) System.getProperties();
- }
-
- @Override
- public Map getUserProperties() {
- return Collections.emptyMap();
- }
-
- @Override
- public File getProjectDirectory() {
- return new File(".");
- }
-
- @Override
- public Map getProjectProperties() {
- return Collections.emptyMap();
- }
-
- }
-
- private static final class SpringBootCliModelProblemCollector
- implements ModelProblemCollector {
-
- private final List problems = new ArrayList();
-
- @Override
- public void add(ModelProblemCollectorRequest req) {
- this.problems.add(req);
- }
-
- List getProblems() {
- return this.problems;
- }
-
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MavenSettingsReader.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MavenSettingsReader.java
deleted file mode 100644
index a2292f982..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MavenSettingsReader.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.lang.reflect.Field;
-
-import org.apache.maven.settings.Settings;
-import org.apache.maven.settings.building.DefaultSettingsBuilderFactory;
-import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
-import org.apache.maven.settings.building.SettingsBuildingException;
-import org.apache.maven.settings.building.SettingsBuildingRequest;
-import org.apache.maven.settings.crypto.DefaultSettingsDecrypter;
-import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
-import org.apache.maven.settings.crypto.SettingsDecrypter;
-import org.apache.maven.settings.crypto.SettingsDecryptionResult;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
-import org.sonatype.plexus.components.cipher.PlexusCipherException;
-import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
-
-/**
- * {@code MavenSettingsReader} reads settings from a user's Maven settings.xml file,
- * decrypting them if necessary using settings-security.xml.
- *
- * @author Andy Wilkinson
- */
-public class MavenSettingsReader {
-
- private static final Logger log = LoggerFactory.getLogger(MavenSettingsReader.class);
-
- private final String homeDir;
-
- public MavenSettingsReader() {
- this(System.getProperty("user.home"));
- }
-
- public MavenSettingsReader(String homeDir) {
- this.homeDir = homeDir;
- }
-
- public static void applySettings(MavenSettings settings,
- DefaultRepositorySystemSession session) {
- if (settings.getLocalRepository() != null) {
- try {
- session.setLocalRepositoryManager(
- new SimpleLocalRepositoryManagerFactory().newInstance(session,
- new LocalRepository(settings.getLocalRepository())));
- }
- catch (NoLocalRepositoryManagerException e) {
- throw new IllegalStateException(
- "Cannot set local repository to " + settings.getLocalRepository(),
- e);
- }
- }
- session.setOffline(settings.getOffline());
- session.setMirrorSelector(settings.getMirrorSelector());
- session.setAuthenticationSelector(settings.getAuthenticationSelector());
- session.setProxySelector(settings.getProxySelector());
- }
-
- public MavenSettings readSettings() {
- Settings settings = loadSettings();
- SettingsDecryptionResult decrypted = decryptSettings(settings);
- if (!decrypted.getProblems().isEmpty()) {
- log.error(
- "Maven settings decryption failed. Some Maven repositories may be inaccessible");
- // Continue - the encrypted credentials may not be used
- }
- return new MavenSettings(settings, decrypted);
- }
-
- private Settings loadSettings() {
- File settingsFile = new File(this.homeDir, ".m2/settings.xml");
- if (settingsFile.exists()) {
- log.info("Reading settings from: " + settingsFile);
- }
- else {
- log.info("No settings found at: " + settingsFile);
- }
- SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
- request.setUserSettingsFile(settingsFile);
- request.setSystemProperties(System.getProperties());
- try {
- return new DefaultSettingsBuilderFactory().newInstance().build(request)
- .getEffectiveSettings();
- }
- catch (SettingsBuildingException ex) {
- throw new IllegalStateException(
- "Failed to build settings from " + settingsFile, ex);
- }
- }
-
- private SettingsDecryptionResult decryptSettings(Settings settings) {
- DefaultSettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(
- settings);
-
- return createSettingsDecrypter().decrypt(request);
- }
-
- private SettingsDecrypter createSettingsDecrypter() {
- SettingsDecrypter settingsDecrypter = new DefaultSettingsDecrypter();
- setField(DefaultSettingsDecrypter.class, "securityDispatcher", settingsDecrypter,
- new SpringBootSecDispatcher());
- return settingsDecrypter;
- }
-
- private void setField(Class> sourceClass, String fieldName, Object target,
- Object value) {
- try {
- Field field = sourceClass.getDeclaredField(fieldName);
- field.setAccessible(true);
- field.set(target, value);
- }
- catch (Exception ex) {
- throw new IllegalStateException(
- "Failed to set field '" + fieldName + "' on '" + target + "'", ex);
- }
- }
-
- private class SpringBootSecDispatcher extends DefaultSecDispatcher {
-
- private static final String SECURITY_XML = ".m2/settings-security.xml";
-
- SpringBootSecDispatcher() {
- File file = new File(MavenSettingsReader.this.homeDir, SECURITY_XML);
- this._configurationFile = file.getAbsolutePath();
- try {
- this._cipher = new DefaultPlexusCipher();
- }
- catch (PlexusCipherException e) {
- throw new IllegalStateException(e);
- }
- }
-
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MemoryBasedJavaFileManager.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MemoryBasedJavaFileManager.java
deleted file mode 100644
index 2b20695cf..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/MemoryBasedJavaFileManager.java
+++ /dev/null
@@ -1,769 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipInputStream;
-
-import javax.tools.FileObject;
-import javax.tools.JavaFileManager;
-import javax.tools.JavaFileObject;
-import javax.tools.JavaFileObject.Kind;
-import javax.tools.StandardLocation;
-
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.graph.Dependency;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.springframework.cloud.function.compiler.java.IterableClasspath.ZipEnumerator;
-
-/**
- * A file manager that serves source code from in memory and ensures output results are
- * kept in memory rather than being flushed out to disk. The JavaFileManager is also used
- * as a lookup mechanism for resolving types.
- *
- * @author Andy Clement
- * @author Oleg Zhurakousky
- */
-public class MemoryBasedJavaFileManager implements JavaFileManager {
-
- final static String BOOT_PACKAGING_PREFIX_FOR_CLASSES = "BOOT-INF/classes/";
-
- final static String BOOT_PACKAGING_PREFIX_FOR_LIBRARIES = "BOOT-INF/lib/";
-
- private static Logger logger = LoggerFactory
- .getLogger(MemoryBasedJavaFileManager.class);
-
- private static URI JRT_URI = URI.create("jrt:/");
-
- private static FileSystem fs;
-
- private CompilationOutputCollector outputCollector;
-
- private Map resolvedAdditionalDependencies = new LinkedHashMap<>();
-
- private String platformClasspath;
-
- private String classpath;
-
- private CompilationInfoCache compilationInfoCache;
-
- private Map iterables = new HashMap<>();
-
- private String jrtFsFilePath = null;
-
- private boolean checkedForJrtFsPath = false;
-
- public MemoryBasedJavaFileManager() {
- this.outputCollector = new CompilationOutputCollector();
- this.compilationInfoCache = new CompilationInfoCache();
- }
-
- private static FileSystem getJrtFs() {
- if (fs == null) {
- fs = FileSystems.getFileSystem(JRT_URI);
- }
- return fs;
- }
-
- @Override
- public int isSupportedOption(String option) {
- logger.debug("isSupportedOption({})", option);
- return -1; // Not yet supporting options
- }
-
- @Override
- public ClassLoader getClassLoader(Location location) {
- // Do not simply return the context classloader as it may get closed and then
- // be unusable for loading any further classes
- logger.debug("getClassLoader({})", location);
- return null; // Do not currently need to load plugins
- }
-
- private String getPlatformClassPath() {
- if (this.platformClasspath == null) {
- this.platformClasspath = System.getProperty("sun.boot.class.path");
- }
- if (this.platformClasspath == null) {
- this.platformClasspath = "";
- }
- return this.platformClasspath;
- }
-
- @Override
- public Iterable list(Location location, String packageName,
- Set kinds, boolean recurse) throws IOException {
- logger.debug("list({},{},{},{})", location, packageName, kinds, recurse);
- String classpath = "";
- Path moduleRootPath = null;
- if (location instanceof JDKModuleLocation
- && (kinds == null || kinds.contains(Kind.CLASS))) {
- // list(org.springframework.cloud.function.compiler.java.MemoryBasedJavaFileManager$JDKModuleLocation@550a1967,
- // java.lang,[SOURCE, CLASS, HTML, OTHER],false)
- moduleRootPath = ((JDKModuleLocation) location).getModuleRootPath();
- logger.debug("For JDKModuleLocation " + location.toString() + " root path is "
- + moduleRootPath);
- }
- else if (location == StandardLocation.PLATFORM_CLASS_PATH
- && (kinds == null || kinds.contains(Kind.CLASS))) {
- classpath = getPlatformClassPath();
- // if (classpath.length() == 0) {
- // if (hasJrtFsPath()) {
- // classpath = getJrtFsPath();
- // }
- // }
- logger.debug("Creating iterable for boot class path: {}", classpath);
- }
- else if (location == StandardLocation.CLASS_PATH
- && (kinds == null || kinds.contains(Kind.CLASS))) {
- String javaClassPath = getClassPath();
- if (!this.resolvedAdditionalDependencies.isEmpty()) {
- for (File resolvedAdditionalDependency : this.resolvedAdditionalDependencies
- .values()) {
- javaClassPath += File.pathSeparatorChar + resolvedAdditionalDependency
- .toURI().toString().substring("file:".length());
- }
- }
- classpath = javaClassPath;
- logger.debug("Creating iterable for class path: {}", classpath);
- }
- Key k = new Key(location, classpath, packageName, kinds, recurse);
- CloseableFilterableJavaFileObjectIterable resultIterable = this.iterables.get(k);
- if (resultIterable == null) {
- if (moduleRootPath != null) {
- resultIterable = new IterableJrtModule(this.compilationInfoCache,
- moduleRootPath, packageName, recurse);
- }
- else {
- resultIterable = new IterableClasspath(this.compilationInfoCache,
- classpath, packageName, recurse);
- }
- this.iterables.put(k, resultIterable);
- }
- resultIterable.reset();
- return resultIterable;
- }
-
- private String getClassPath() {
- if (this.classpath == null) {
- ClassLoader loader = InMemoryJavaFileObject.class.getClassLoader();
- String cp = null;
- if (loader instanceof URLClassLoader) {
- cp = classPath((URLClassLoader) loader, cp);
- }
- if (cp == null) {
- cp = System.getProperty("java.class.path");
- }
- if (hasJrtFsPath()) {
- cp = cp + File.pathSeparator + getJrtFsPath();
- }
- this.classpath = pathWithPlatformClassPathRemoved(cp);
- }
- return this.classpath;
- }
-
- private String classPath(URLClassLoader loader, String cp) {
- URL[] urls = loader.getURLs();
- if (urls.length > 1) { // heuristic that catches Maven surefire tests
- if (!urls[0].toString().startsWith("jar:file:")) { // heuristic for
- // Spring Boot fat
- // jar
- StringBuilder builder = new StringBuilder();
- for (URL url : urls) {
- if (builder.length() > 0) {
- builder.append(File.pathSeparator);
- }
- String path = url.toString();
- if (path.startsWith("file:")) {
- path = path.substring("file:".length());
- }
- builder.append(path);
- }
- cp = builder.toString();
- }
- }
- return cp;
- }
-
- // remove the platform classpath entries, they will be search separately (and earlier)
- private String pathWithPlatformClassPathRemoved(String classpath) {
- Set pcps = toList(getPlatformClassPath());
- Set cps = toList(classpath);
- cps.removeAll(pcps);
- StringBuilder builder = new StringBuilder();
- for (String cpe : cps) {
- if (builder.length() > 0) {
- builder.append(File.pathSeparator);
- }
- builder.append(cpe);
- }
- return builder.toString();
- }
-
- private Set toList(String path) {
- Set result = new LinkedHashSet<>();
- StringTokenizer tokenizer = new StringTokenizer(path, File.pathSeparator);
- while (tokenizer.hasMoreTokens()) {
- result.add(tokenizer.nextToken());
- }
- return result;
- }
-
- @Override
- public boolean hasLocation(Location location) {
- logger.debug("hasLocation({})", location);
- return (location == StandardLocation.SOURCE_PATH
- || location == StandardLocation.CLASS_PATH
- || location == StandardLocation.PLATFORM_CLASS_PATH);
- }
-
- @Override
- public String inferBinaryName(Location location, JavaFileObject file) {
- if (location == StandardLocation.SOURCE_PATH) {
- return null;
- }
- // Kind of ignoring location here... assuming we want basically the FQ type name
- // Example value from getName(): javax/validation/bootstrap/GenericBootstrap.class
- String classname = file.getName().replace('/', '.').replace('\\', '.');
- return classname.substring(0, classname.lastIndexOf(".class"));
- }
-
- @Override
- public boolean isSameFile(FileObject a, FileObject b) {
- logger.debug("isSameFile({},{})", a, b);
- return a.equals(b);
- }
-
- @Override
- public boolean handleOption(String current, Iterator remaining) {
- logger.debug("handleOption({},{})", current, remaining);
- return false; // This file manager does not manage any options
- }
-
- @Override
- public JavaFileObject getJavaFileForInput(Location location, String className,
- Kind kind) throws IOException {
- logger.debug("getJavaFileForInput({},{},{})", location, className, kind);
- // getJavaFileForInput(SOURCE_PATH,module-info,SOURCE)
- if (className.equals("module-info")) {
- return null;
- }
- throw new IllegalStateException("Not expected to be used in this context");
- }
-
- @Override
- public JavaFileObject getJavaFileForOutput(Location location, String className,
- Kind kind, FileObject sibling) throws IOException {
- logger.debug("getJavaFileForOutput({},{},{},{})", location, className, kind,
- sibling);
- // Example parameters: CLASS_OUTPUT, Foo, CLASS,
- // StringBasedJavaSourceFileObject[string:///a/b/c/Foo.java]
- return this.outputCollector.getJavaFileForOutput(location, className, kind,
- sibling);
- }
-
- @Override
- public FileObject getFileForInput(Location location, String packageName,
- String relativeName) throws IOException {
- logger.debug("getFileForInput({},{},{})", location, packageName, relativeName);
- throw new IllegalStateException("Not expected to be used in this context");
- }
-
- @Override
- public FileObject getFileForOutput(Location location, String packageName,
- String relativeName, FileObject sibling) throws IOException {
- logger.debug("getFileForOutput({},{},{},{})", location, packageName, relativeName,
- sibling);
- // This can be called when the annotation config processor runs
- // Example parameters: CLASS_OUTPUT, ,
- // META-INF/spring-configuration-metadata.json, null
- return this.outputCollector.getFileForOutput(location, packageName, relativeName,
- sibling);
- }
-
- @Override
- public void flush() throws IOException {
- }
-
- @Override
- public void close() throws IOException {
- Collection toClose = this.iterables
- .values();
- for (CloseableFilterableJavaFileObjectIterable icp : toClose) {
- icp.close();
- }
- }
-
- public List getCompiledClasses() {
- return this.outputCollector.getCompiledClasses();
- }
-
- public List addAndResolveDependencies(String[] dependencies) {
- List resolutionMessages = new ArrayList<>();
- for (String dependency : dependencies) {
- if (dependency.startsWith("maven:")) {
- // Resolving an explicit external archive
- String coordinates = dependency.replaceFirst("maven:\\/*", "");
- DependencyResolver engine = DependencyResolver.instance();
- try {
- File resolved = engine.resolve(
- new Dependency(new DefaultArtifact(coordinates), "runtime"));
- // Example:
- // dependency =
- // maven://org.springframework:spring-expression:4.3.9.RELEASE
- // resolved.toURI() =
- // file:/Users/aclement/.m2/repository/
- // org/springframework/spring-expression/4.3.9.RELEASE/spring-expression-4.3.9.RELEASE.jar
- this.resolvedAdditionalDependencies.put(dependency, resolved);
- }
- catch (RuntimeException re) {
- CompilationMessage compilationMessage = new CompilationMessage(
- CompilationMessage.Kind.ERROR, re.getMessage(), null, 0, 0);
- resolutionMessages.add(compilationMessage);
- }
- }
- else if (dependency.startsWith("file:")) {
- this.resolvedAdditionalDependencies.put(dependency,
- new File(URI.create(dependency)));
- }
- else {
- resolutionMessages.add(new CompilationMessage(
- CompilationMessage.Kind.ERROR,
- "Unrecognized dependency: " + dependency
- + " (expected something of the form: maven://groupId:artifactId:version)",
- null, 0, 0));
- }
- }
- return resolutionMessages;
- }
-
- public Map getResolvedAdditionalDependencies() {
- return this.resolvedAdditionalDependencies;
- }
-
- public String inferModuleName(Location location) throws IOException {
- if (location instanceof JDKModuleLocation) {
- JDKModuleLocation m = (JDKModuleLocation) location;
- return m.getModuleName();
- }
- throw new IllegalStateException(
- "Asked to inferModuleName from a " + location.getClass().getName());
- }
-
- private boolean hasJrtFsPath() {
- return getJrtFsPath() != null;
- }
-
- private String getJrtFsPath() {
- if (!this.checkedForJrtFsPath) {
- String javaHome = System.getProperty("java.home");
- String jrtFsFilePath = javaHome + File.separator + "lib" + File.separator
- + "jrt-fs.jar";
- File jrtFsFile = new File(jrtFsFilePath);
- if (jrtFsFile.exists()) {
- this.jrtFsFilePath = jrtFsFilePath;
- }
- this.checkedForJrtFsPath = true;
- }
- return this.jrtFsFilePath;
- }
-
- public Iterable> listLocationsForModules(Location location)
- throws IOException {
- if (getJrtFsPath() != null
- && location == StandardLocation.valueOf("SYSTEM_MODULES")) {
- Set> ss = new HashSet<>();
- HashSet moduleLocations = new HashSet<>();
- ModuleIdentifierVisitor visitor = new ModuleIdentifierVisitor();
- Iterable roots = getJrtFs().getRootDirectories();
- try {
- for (Path path : roots) {
- Files.walkFileTree(path, visitor);
- }
- moduleLocations.addAll(visitor.getModuleLocations());
- }
- catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- ss.add(moduleLocations);
- return ss;
- }
- else {
- return Collections.emptySet();
- }
- }
-
- // Holds information that may help speed up compilation
- static class CompilationInfoCache {
-
- private Map archivePackageCache;
-
- private boolean packageCacheInitialized = false;
-
- private Map packageCache = new HashMap();
-
- private ArchiveInfo moduleArchiveInfo;
-
- ArchiveInfo getArchiveInfoFor(File archive) {
- if (!archive.isFile() || !(archive.getName().endsWith(".zip")
- || archive.getName().endsWith(".jar"))) {
- // it is not an archive
- return null;
- }
- if (this.archivePackageCache == null) {
- this.archivePackageCache = new HashMap<>();
- }
- try {
- ArchiveInfo result = this.archivePackageCache.get(archive);
- if (result == null) {
- result = buildArchiveInfo(archive);
- this.archivePackageCache.put(archive, result);
- }
- return result;
- }
- catch (Exception e) {
- throw new IllegalStateException(
- "Unexpected problem caching entries from " + archive.getName(),
- e);
- }
- }
-
- private synchronized ArchiveInfo buildPackageMap() {
- if (!this.packageCacheInitialized) {
- this.packageCacheInitialized = true;
- Iterable roots = getJrtFs().getRootDirectories();
- PackageCacheBuilderVisitor visitor = new PackageCacheBuilderVisitor();
- try {
- for (java.nio.file.Path path : roots) {
- Files.walkFileTree(path, visitor);
- }
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- List ls = new ArrayList<>();
- ls.addAll(this.packageCache.keySet());
- Collections.sort(ls);
- this.moduleArchiveInfo = new ArchiveInfo(ls, false);
- }
- return this.moduleArchiveInfo;
- }
-
- /**
- * Walk the specified archive and collect up the package names of any .class files
- * encountered. If the archive contains nested jars packaged in a BOOT style way
- * (under a BOOT-INF/lib folder) then walk those too and include relevant
- * packages.
- * @param file archive file to discover packages from
- * @return an ArchiveInfo encapsulating package info from the archive
- */
- private ArchiveInfo buildArchiveInfo(File file) {
- if (file.toString().endsWith("jrt-fs.jar")) {
- // Special treatment for >=JDK9 - treat this as intention to use modules
- return buildPackageMap();
- }
- List packageNames = new ArrayList<>();
- boolean isBootJar = false;
- try (ZipFile openArchive = new ZipFile(file)) {
- Enumeration extends ZipEntry> entries = openArchive.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = entries.nextElement();
- String name = entry.getName();
- if (name.endsWith(".class")) {
- if (name.startsWith(BOOT_PACKAGING_PREFIX_FOR_CLASSES)) {
- isBootJar = true;
- int idx = name.lastIndexOf('/') + 1;
- if (idx != 0) {
- if (idx == BOOT_PACKAGING_PREFIX_FOR_CLASSES.length()) {
- // default package
- packageNames.add("/");
- }
- else {
- // Normalize to forward slashes
- name = name.substring(
- BOOT_PACKAGING_PREFIX_FOR_CLASSES.length(),
- idx);
- name = name.replace('\\', '/');
- packageNames.add(name);
- }
- }
- }
- else {
- int idx = name.lastIndexOf('/') + 1;
- if (idx != 0) {
- // Normalize to forward slashes
- name = name.replace('\\', '/');
- name = name.substring(0, idx);
- packageNames.add(name);
- }
- else if (idx == 0) {
- // default package entries in here
- packageNames.add("/");
- }
- }
- }
- else if (name.startsWith(BOOT_PACKAGING_PREFIX_FOR_LIBRARIES)
- && name.endsWith(".jar")) {
- isBootJar = true;
- try (ZipInputStream zis = new ZipInputStream(
- openArchive.getInputStream(entry))) {
- Enumeration extends ZipEntry> nestedZipEnumerator = new ZipEnumerator(
- zis);
- while (nestedZipEnumerator.hasMoreElements()) {
- ZipEntry innerEntry = nestedZipEnumerator.nextElement();
- String innerEntryName = innerEntry.getName();
- if (innerEntryName.endsWith(".class")) {
- int idx = innerEntryName.lastIndexOf('/') + 1;
- if (idx != 0) {
- // Normalize to forward slashes
- innerEntryName = innerEntryName.replace('\\',
- '/');
- innerEntryName = innerEntryName.substring(0, idx);
- packageNames.add(innerEntryName);
- }
- else if (idx == 0) {
- // default package entries in here
- packageNames.add("/");
- }
- }
- }
- }
- }
- }
- }
- catch (IOException ioe) {
- throw new IllegalStateException(
- "Unexpected problem determining packages in " + file, ioe);
- }
- return new ArchiveInfo(packageNames, isBootJar);
- }
-
- static class ArchiveInfo {
-
- // The packages identified in a particular archive
- private List packageNames;
-
- private boolean isBootJar = false;
-
- ArchiveInfo(List packageNames, boolean isBootJar) {
- this.packageNames = packageNames;
- Collections.sort(this.packageNames);
- this.isBootJar = isBootJar;
- }
-
- public List getPackageNames() {
- return this.packageNames;
- }
-
- public boolean isBootJar() {
- return this.isBootJar;
- }
-
- public boolean containsPackage(String packageName,
- boolean subpackageMatchesAllowed) {
- if (subpackageMatchesAllowed) {
- for (String candidatePackageName : this.packageNames) {
- if (candidatePackageName.startsWith(packageName)) {
- return true;
- }
- }
- return false;
- }
- else {
- // Must be an exact match, fast binary search:
- int pos = Collections.binarySearch(this.packageNames, packageName);
- return (pos >= 0);
- }
- }
-
- }
-
- private class PackageCacheBuilderVisitor extends SimpleFileVisitor {
-
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- throws IOException {
- if (file.getNameCount() > 3 && file.toString().endsWith(".class")) {
- int fnc = file.getNameCount();
- if (fnc > 3) { // There is a package name - e.g.
- // /modules/java.base/java/lang/Object.class
- Path packagePath = file.subpath(2, fnc - 1); // e.g. java/lang
- String packagePathString = packagePath.toString() + "/";
- CompilationInfoCache.this.packageCache.put(packagePathString,
- file.subpath(0, fnc - 1)); // java/lang
- // ->
- // /modules/java.base/java/lang
- }
- }
- return FileVisitResult.CONTINUE;
- }
-
- }
-
- }
-
- static class Key {
-
- private Location location;
-
- private String classpath;
-
- private String packageName;
-
- private Set kinds;
-
- private boolean recurse;
-
- Key(Location location, String classpath, String packageName, Set kinds,
- boolean recurse) {
- this.location = location;
- this.classpath = classpath;
- this.packageName = packageName;
- this.kinds = kinds;
- this.recurse = recurse;
- }
-
- @Override
- public int hashCode() {
- return (((this.location.hashCode() * 37) + this.classpath.hashCode() * 37
- + (this.packageName == null ? 0 : this.packageName.hashCode())) * 37
- + this.kinds.hashCode()) * 37 + (this.recurse ? 1 : 0);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Key)) {
- return false;
- }
- Key that = (Key) obj;
- return this.location.equals(that.location)
- && this.classpath.equals(that.classpath)
- && this.kinds.equals(that.kinds) && (this.recurse == that.recurse)
- && (this.packageName == null ? (that.packageName == null)
- : this.packageName.equals(that.packageName));
- }
-
- }
-
- static class JDKModuleLocation implements Location {
-
- private String moduleName;
-
- private Path moduleRootPath;
-
- JDKModuleLocation(String moduleName, Path moduleRootPath) {
- this.moduleName = moduleName;
- this.moduleRootPath = moduleRootPath;
- }
-
- @Override
- public String getName() {
- return "MODULE";
- }
-
- @Override
- public boolean isOutputLocation() {
- return false;
- }
-
- public String getModuleName() {
- return this.moduleName;
- }
-
- public Path getModuleRootPath() {
- return this.moduleRootPath;
- }
-
- public String toString() {
- return "JDKModuleLocation(" + this.moduleName + ")";
- }
-
- public int hashCode() {
- return this.moduleName.hashCode();
- }
-
- public boolean equals(Object other) {
- if (!(other instanceof JDKModuleLocation)) {
- return false;
- }
- return this.hashCode() == ((JDKModuleLocation) other).hashCode();
- }
-
- }
-
- static class ModuleIdentifierVisitor extends SimpleFileVisitor {
-
- private Map modules = new HashMap<>();
-
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- throws IOException {
- if (file.getNameCount() > 2 && file.toString().endsWith(".class")) {
- // /modules/jdk.rmic/sun/tools/tree/CaseStatement.class
- String moduleName = file.getName(1).toString(); // jdk.rmic
- Path moduleRootPath = file.subpath(0, 2); // /modules/jdk.rmic
- if (!this.modules.containsKey(moduleName)) {
- this.modules.put(moduleName, moduleRootPath);
- }
- }
- return FileVisitResult.CONTINUE;
- }
-
- public Set getModuleLocations() {
- if (this.modules.size() == 0) {
- return Collections.emptySet();
- }
- else {
- Set locations = new HashSet<>();
- for (Map.Entry moduleEntry : this.modules.entrySet()) {
- locations.add(new JDKModuleLocation(moduleEntry.getKey(),
- moduleEntry.getValue()));
- }
- return locations;
- }
- }
-
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/NestedZipEntryJavaFileObject.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/NestedZipEntryJavaFileObject.java
deleted file mode 100644
index b78889dec..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/NestedZipEntryJavaFileObject.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipInputStream;
-
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.NestingKind;
-import javax.tools.JavaFileObject;
-
-/**
- * Represents an element inside in zip which is itself inside a zip. These objects are not
- * initially created with the content of the file they represent, only enough information
- * to find that content because many will typically be created but only few will be
- * opened.
- *
- * @author Andy Clement
- */
-public class NestedZipEntryJavaFileObject implements JavaFileObject {
-
- private File outerFile;
-
- private ZipFile outerZipFile;
-
- private ZipEntry innerZipFile;
-
- private ZipEntry innerZipFileEntry;
-
- private URI uri;
-
- public NestedZipEntryJavaFileObject(File outerFile, ZipFile outerZipFile,
- ZipEntry innerZipFile, ZipEntry innerZipFileEntry) {
- this.outerFile = outerFile;
- this.outerZipFile = outerZipFile;
- this.innerZipFile = innerZipFile;
- this.innerZipFileEntry = innerZipFileEntry;
- }
-
- @Override
- public String getName() {
- return this.innerZipFileEntry.getName(); // Example: a/b/C.class
- }
-
- @Override
- public URI toUri() {
- if (this.uri == null) {
- String uriString = null;
- try {
- uriString = "zip:" + this.outerFile.getAbsolutePath() + "!"
- + this.innerZipFile.getName() + "!"
- + this.innerZipFileEntry.getName();
- this.uri = new URI(uriString);
- }
- catch (URISyntaxException e) {
- throw new IllegalStateException(
- "Unexpected URISyntaxException for string '" + uriString + "'",
- e);
- }
- }
- return this.uri;
- }
-
- @Override
- public InputStream openInputStream() throws IOException {
- // Find the inner zip file inside the outer zip file, then
- // find the relevant entry, then return the stream.
- InputStream innerZipFileInputStream = this.outerZipFile
- .getInputStream(this.innerZipFile);
- ZipInputStream innerZipInputStream = new ZipInputStream(innerZipFileInputStream);
- ZipEntry nextEntry = innerZipInputStream.getNextEntry();
- while (nextEntry != null) {
- if (nextEntry.getName().equals(this.innerZipFileEntry.getName())) {
- return innerZipInputStream;
- }
- nextEntry = innerZipInputStream.getNextEntry();
- }
- throw new IllegalStateException(
- "Unable to locate nested zip entry " + this.innerZipFileEntry.getName()
- + " in zip " + this.innerZipFile.getName() + " inside zip "
- + this.outerZipFile.getName());
- }
-
- @Override
- public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
- // It is bytecode
- throw new UnsupportedOperationException(
- "getCharContent() not supported on class file: " + getName());
- }
-
- @Override
- public long getLastModified() {
- return this.innerZipFileEntry.getTime();
- }
-
- @Override
- public Kind getKind() {
- // The filtering before this object was created ensure it is only used for classes
- return Kind.CLASS;
- }
-
- @Override
- public boolean delete() {
- return false; // Cannot delete entries inside nested zips
- }
-
- @Override
- public OutputStream openOutputStream() throws IOException {
- throw new IllegalStateException("cannot write to nested zip entry: " + toUri());
- }
-
- @Override
- public Writer openWriter() throws IOException {
- throw new IllegalStateException("cannot write to nested zip entry: " + toUri());
- }
-
- @Override
- public boolean isNameCompatible(String simpleName, Kind kind) {
- if (kind != Kind.CLASS) {
- return false;
- }
- String name = getName();
- int lastSlash = name.lastIndexOf('/');
- return name.substring(lastSlash + 1).equals(simpleName + ".class");
- }
-
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- // It is bytecode
- throw new UnsupportedOperationException(
- "getCharContent() not supported on class file: " + getName());
- }
-
- @Override
- public NestingKind getNestingKind() {
- return null; // nesting level not known
- }
-
- @Override
- public Modifier getAccessLevel() {
- return null; // access level not known
- }
-
- @Override
- public int hashCode() {
- int hc = this.outerFile.getName().hashCode();
- hc = hc * 37 + this.innerZipFile.getName().hashCode();
- hc = hc * 37 + this.innerZipFileEntry.getName().hashCode();
- return hc;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof NestedZipEntryJavaFileObject)) {
- return false;
- }
- NestedZipEntryJavaFileObject that = (NestedZipEntryJavaFileObject) obj;
- return (this.outerFile.getName().equals(that.outerFile.getName()))
- && (this.innerZipFile.getName().equals(that.innerZipFile.getName()))
- && (this.innerZipFileEntry.getName()
- .equals(that.innerZipFileEntry.getName()));
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/RuntimeJavaCompiler.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/RuntimeJavaCompiler.java
deleted file mode 100644
index 699dda570..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/RuntimeJavaCompiler.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.tools.Diagnostic;
-import javax.tools.Diagnostic.Kind;
-import javax.tools.DiagnosticCollector;
-import javax.tools.JavaCompiler;
-import javax.tools.JavaCompiler.CompilationTask;
-import javax.tools.JavaFileObject;
-import javax.tools.ToolProvider;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Compile Java source at runtime and load it.
- *
- * @author Andy Clement
- */
-public class RuntimeJavaCompiler {
-
- private static Logger logger = LoggerFactory.getLogger(RuntimeJavaCompiler.class);
-
- private JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-
- /**
- * Compile the named class consisting of the supplied source code. If successful load
- * the class and return it. Multiple classes may get loaded if the source code
- * included anonymous/inner/local classes.
- * @param className the name of the class (dotted form, e.g. com.foo.bar.Goo)
- * @param classSourceCode the full source code for the class
- * @param dependencies optional coordinates for dependencies, maven
- * 'maven://groupId:artifactId:version', or 'file:' URIs for local files
- * @return a CompilationResult that encapsulates what happened during compilation
- * (classes/messages produced)
- */
- public CompilationResult compile(String className, String classSourceCode,
- String... dependencies) {
- logger.info("Compiling source for class {} using compiler {}", className,
- this.compiler.getClass().getName());
-
- DiagnosticCollector diagnosticCollector = new DiagnosticCollector();
- MemoryBasedJavaFileManager fileManager = new MemoryBasedJavaFileManager();
- List resolutionMessages = fileManager
- .addAndResolveDependencies(dependencies);
- JavaFileObject sourceFile = InMemoryJavaFileObject
- .getSourceJavaFileObject(className, classSourceCode);
-
- Iterable extends JavaFileObject> compilationUnits = Arrays.asList(sourceFile);
- List options = new ArrayList<>();
- options.add("-source");
- options.add("1.8");
- CompilationTask task = this.compiler.getTask(null, fileManager,
- diagnosticCollector, options, null, compilationUnits);
-
- boolean success = task.call();
- CompilationResult compilationResult = new CompilationResult(success);
- compilationResult.recordCompilationMessages(resolutionMessages);
- compilationResult.setResolvedAdditionalDependencies(new ArrayList<>(
- fileManager.getResolvedAdditionalDependencies().values()));
-
- // If successful there may be no errors but there might be info/warnings
- for (Diagnostic extends JavaFileObject> diagnostic : diagnosticCollector
- .getDiagnostics()) {
- CompilationMessage.Kind kind = (diagnostic.getKind() == Kind.ERROR
- ? CompilationMessage.Kind.ERROR : CompilationMessage.Kind.OTHER);
- // String sourceCode =
- // ((StringBasedJavaSourceFileObject)diagnostic.getSource()).getSourceCode();
- String sourceCode = null;
- try {
- sourceCode = (String) diagnostic.getSource().getCharContent(true);
- }
- catch (IOException ioe) {
- // Unexpected, but leave sourceCode null to indicate it was not
- // retrievable
- }
- catch (NullPointerException npe) {
- // TODO: should we skip warning diagnostics in the loop altogether?
- }
- int startPosition = (int) diagnostic.getPosition();
- if (startPosition == Diagnostic.NOPOS) {
- startPosition = (int) diagnostic.getStartPosition();
- }
- CompilationMessage compilationMessage = new CompilationMessage(kind,
- diagnostic.getMessage(null), sourceCode, startPosition,
- (int) diagnostic.getEndPosition());
- compilationResult.recordCompilationMessage(compilationMessage);
- }
- if (success) {
- List ccds = fileManager.getCompiledClasses();
- List> classes = new ArrayList<>();
- try (SimpleClassLoader ccl = new SimpleClassLoader(
- this.getClass().getClassLoader())) {
- for (CompiledClassDefinition ccd : ccds) {
- Class> clazz = ccl.defineClass(ccd.getClassName(), ccd.getBytes());
- classes.add(clazz);
- compilationResult.addClassBytes(ccd.getClassName(), ccd.getBytes());
- }
- }
- catch (IOException ioe) {
- logger.debug("Unexpected exception defining classes", ioe);
- }
- compilationResult.setCompiledClasses(classes);
- }
- return compilationResult;
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/SimpleClassLoader.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/SimpleClassLoader.java
deleted file mode 100644
index 797e55538..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/SimpleClassLoader.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.List;
-
-/**
- * Very simple classloader that can be used to load the compiled types.
- *
- * @author Andy Clement
- */
-public class SimpleClassLoader extends URLClassLoader {
-
- private static final URL[] NO_URLS = new URL[0];
-
- public SimpleClassLoader(ClassLoader classLoader) {
- super(NO_URLS, classLoader);
- }
-
- public SimpleClassLoader(List resolvedAdditionalDependencies,
- ClassLoader classLoader) {
- super(toUrls(resolvedAdditionalDependencies), classLoader);
- }
-
- private static URL[] toUrls(List resolvedAdditionalDependencies) {
- URL[] urls = new URL[resolvedAdditionalDependencies.size()];
- for (int i = 0, max = resolvedAdditionalDependencies.size(); i < max; i++) {
- try {
- urls[i] = resolvedAdditionalDependencies.get(i).toURI().toURL();
- }
- catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
- return urls;
- }
-
- public Class> defineClass(String name, byte[] bytes) {
- return super.defineClass(name, bytes, 0, bytes.length);
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/ZipEntryJavaFileObject.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/ZipEntryJavaFileObject.java
deleted file mode 100644
index 306300aec..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/java/ZipEntryJavaFileObject.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.java;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.NestingKind;
-import javax.tools.JavaFileObject;
-
-/**
- * A {@link JavaFileObject} that works on a ZIP entry.
- *
- * @author Mark Fisher
- */
-public class ZipEntryJavaFileObject implements JavaFileObject {
-
- private File containingFile;
-
- private ZipFile zf;
-
- private ZipEntry ze;
-
- private URI uri;
-
- public ZipEntryJavaFileObject(File containingFile, ZipFile zipFile, ZipEntry entry) {
- this.containingFile = containingFile;
- this.zf = zipFile;
- this.ze = entry;
- }
-
- @Override
- public URI toUri() {
- if (this.uri == null) {
- String uriString = null;
- try {
- uriString = "zip:" + this.containingFile.getAbsolutePath() + "!"
- + this.ze.getName();
- this.uri = new URI(uriString);
- }
- catch (URISyntaxException e) {
- throw new IllegalStateException(
- "Unexpected URISyntaxException for string '" + uriString + "'",
- e);
- }
- }
- return this.uri;
- }
-
- @Override
- public String getName() {
- return this.ze.getName(); // a/b/C.class
- }
-
- @Override
- public InputStream openInputStream() throws IOException {
- return this.zf.getInputStream(this.ze);
- }
-
- @Override
- public OutputStream openOutputStream() throws IOException {
- throw new IllegalStateException("only expected to be used for input");
- }
-
- @Override
- public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
- // It is bytecode
- throw new UnsupportedOperationException(
- "openReader() not supported on class file: " + getName());
- }
-
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- // It is bytecode
- throw new UnsupportedOperationException(
- "getCharContent() not supported on class file: " + getName());
- }
-
- @Override
- public Writer openWriter() throws IOException {
- throw new IllegalStateException("only expected to be used for input");
- }
-
- @Override
- public long getLastModified() {
- return this.ze.getTime();
- }
-
- @Override
- public boolean delete() {
- return false; // Cannot delete entries inside zips
- }
-
- @Override
- public Kind getKind() {
- return Kind.CLASS;
- }
-
- @Override
- public boolean isNameCompatible(String simpleName, Kind kind) {
- if (kind != Kind.CLASS) {
- return false;
- }
- String name = getName();
- int lastSlash = name.lastIndexOf('/');
- return name.substring(lastSlash + 1).equals(simpleName + ".class");
- }
-
- @Override
- public NestingKind getNestingKind() {
- return null;
- }
-
- @Override
- public Modifier getAccessLevel() {
- return null;
- }
-
- @Override
- public int hashCode() {
- int hc = this.containingFile.getName().hashCode();
- hc = hc * 37 + this.ze.getName().hashCode();
- return hc;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof ZipEntryJavaFileObject)) {
- return false;
- }
- ZipEntryJavaFileObject that = (ZipEntryJavaFileObject) obj;
- return (this.containingFile.getName().equals(that.containingFile.getName()))
- && (this.ze.getName().equals(that.ze.getName()));
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/AbstractByteCodeLoadingProxy.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/AbstractByteCodeLoadingProxy.java
deleted file mode 100644
index 0d1b2f472..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/AbstractByteCodeLoadingProxy.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.proxy;
-
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.springframework.asm.ClassReader;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.cloud.function.compiler.CompilationResultFactory;
-import org.springframework.cloud.function.compiler.java.SimpleClassLoader;
-import org.springframework.cloud.function.core.FunctionFactoryMetadata;
-import org.springframework.core.io.Resource;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.ReflectionUtils;
-
-/**
- * @author Mark Fisher
- * @author Oleg Zhurakousky
- */
-abstract class AbstractByteCodeLoadingProxy
- implements InitializingBean, FunctionFactoryMetadata {
-
- private final Resource resource;
-
- private final SimpleClassLoader classLoader = new SimpleClassLoader(
- AbstractByteCodeLoadingProxy.class.getClassLoader());
-
- private T target;
-
- private Method method;
-
- AbstractByteCodeLoadingProxy(Resource resource) {
- this.resource = resource;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public void afterPropertiesSet() throws Exception {
- byte[] bytes = FileCopyUtils.copyToByteArray(this.resource.getInputStream());
- String className = new ClassReader(bytes).getClassName().replace("/", ".");
- Class> factoryClass = this.classLoader.defineClass(className, bytes);
- try {
- this.target = ((CompilationResultFactory) factoryClass.newInstance())
- .getResult();
- this.method = findFactoryMethod(factoryClass);
- }
- catch (InstantiationException | IllegalAccessException e) {
- throw new IllegalArgumentException("failed to load Function byte code", e);
- }
- }
-
- @Override
- public final T getTarget() {
- return this.target;
- }
-
- @Override
- public Method getFactoryMethod() {
- return this.method;
- }
-
- private Method findFactoryMethod(Class> clazz) {
- AtomicReference method = new AtomicReference<>();
- ReflectionUtils.doWithLocalMethods(clazz, m -> {
- if (m.getName().equals("getResult")
- && m.getReturnType().getName().startsWith("java.util.function")) {
- method.set(m);
- }
- });
- return method.get();
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/AbstractLambdaCompilingProxy.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/AbstractLambdaCompilingProxy.java
deleted file mode 100644
index 235501bc9..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/AbstractLambdaCompilingProxy.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.proxy;
-
-import java.io.InputStreamReader;
-import java.lang.reflect.Method;
-
-import org.springframework.beans.factory.BeanNameAware;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.cloud.function.compiler.AbstractFunctionCompiler;
-import org.springframework.cloud.function.compiler.CompiledFunctionFactory;
-import org.springframework.cloud.function.core.FunctionFactoryMetadata;
-import org.springframework.core.io.Resource;
-import org.springframework.util.Assert;
-import org.springframework.util.FileCopyUtils;
-
-/**
- * @param target type
- * @author Mark Fisher
- */
-public class AbstractLambdaCompilingProxy
- implements InitializingBean, BeanNameAware, FunctionFactoryMetadata {
-
- private final Resource resource;
-
- private final AbstractFunctionCompiler compiler;
-
- private String beanName;
-
- private CompiledFunctionFactory factory;
-
- private String[] typeParameterizations;
-
- public AbstractLambdaCompilingProxy(Resource resource,
- AbstractFunctionCompiler compiler) {
- Assert.notNull(resource, "Resource must not be null");
- Assert.notNull(compiler, "Compiler must not be null");
- this.resource = resource;
- this.compiler = compiler;
- }
-
- @Override
- public void setBeanName(String beanName) {
- this.beanName = beanName;
- }
-
- public void setTypeParameterizations(String... typeParameterizations) {
- this.typeParameterizations = typeParameterizations;
- }
-
- @Override
- public void afterPropertiesSet() throws Exception {
- String lambda = FileCopyUtils
- .copyToString(new InputStreamReader(this.resource.getInputStream()));
- this.factory = this.compiler.compile(this.beanName, lambda,
- this.typeParameterizations);
- }
-
- @Override
- public final T getTarget() {
- return this.factory.getResult();
- }
-
- @Override
- public Method getFactoryMethod() {
- return this.factory.getFactoryMethod();
- }
-
-}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/ByteCodeLoadingConsumer.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/ByteCodeLoadingConsumer.java
deleted file mode 100644
index da45e2e47..000000000
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/proxy/ByteCodeLoadingConsumer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2012-2019 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
- *
- * https://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.proxy;
-
-import java.util.function.Consumer;
-
-import org.springframework.cloud.function.core.FunctionFactoryMetadata;
-import org.springframework.core.io.Resource;
-
-/**
- * @param type
- * @author Mark Fisher
- * @author Oleg Zhurakousky
- */
-public class ByteCodeLoadingConsumer extends AbstractByteCodeLoadingProxy>
- implements FunctionFactoryMetadata>, Consumer