GH-555 Add missing maven resource support to function deployer
Resolves #555
This commit is contained in:
@@ -33,6 +33,8 @@ import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.boot.loader.archive.Archive;
|
||||
import org.springframework.boot.loader.archive.ExplodedArchive;
|
||||
import org.springframework.boot.loader.archive.JarFileArchive;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenProperties;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenResourceLoader;
|
||||
import org.springframework.cloud.function.context.FunctionProperties;
|
||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
@@ -42,6 +44,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -64,13 +68,23 @@ public class FunctionDeployerConfiguration {
|
||||
|
||||
@Bean
|
||||
SmartLifecycle functionArchiveDeployer(FunctionDeployerProperties functionProperties,
|
||||
FunctionRegistry functionRegistry, ApplicationArguments arguments) {
|
||||
FunctionRegistry functionRegistry, ApplicationArguments arguments, @Nullable MavenProperties mavenProperties) {
|
||||
|
||||
ApplicationArguments updatedArguments = this.updateArguments(arguments);
|
||||
|
||||
Archive archive = null;
|
||||
try {
|
||||
File file = new File(functionProperties.getLocation());
|
||||
File file;
|
||||
String location = functionProperties.getLocation();
|
||||
Assert.hasText(location, "`spring.cloud.function.location` property must be defined.");
|
||||
if (location.startsWith("maven://")) {
|
||||
MavenResourceLoader resourceLoader = new MavenResourceLoader(mavenProperties);
|
||||
file = resourceLoader.getResource(location).getFile();
|
||||
}
|
||||
else {
|
||||
file = new File(location);
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
throw new IllegalStateException("Failed to create archive: " + functionProperties.getLocation() + " does not exist");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.function.deployer;
|
||||
|
||||
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -29,11 +31,14 @@ import reactor.util.function.Tuples;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenProperties;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -48,6 +53,19 @@ public class FunctionDeployerTests {
|
||||
System.clearProperty("spring.cloud.function.definition");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMavenConfiguration() throws Exception {
|
||||
String[] args = new String[] {
|
||||
"--spring.cloud.function.location=maven://oz.demo:demo-stream:0.0.1-SNAPSHOT",
|
||||
"--spring.cloud.function.function-class=oz.demo.demostream.MyFunction" };
|
||||
|
||||
ApplicationContext context = SpringApplication.run(DeployerApplication.class, args);
|
||||
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
|
||||
Function<String, String> function = catalog.lookup("myFunction");
|
||||
|
||||
assertThat(function.apply("bob")).isEqualTo("BOB");
|
||||
}
|
||||
|
||||
/*
|
||||
* Target function `class UpperCaseFunction implements Function<String, String>`
|
||||
* Main/Start class present, no Spring configuration
|
||||
@@ -376,5 +394,11 @@ public class FunctionDeployerTests {
|
||||
|
||||
@SpringBootApplication(proxyBeanMethods = false)
|
||||
private static class DeployerApplication {
|
||||
@Bean
|
||||
public MavenProperties mavenProperties() {
|
||||
MavenProperties properties = new MavenProperties();
|
||||
properties.setLocalRepository("mavenrepo/");
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user