Support for Start-Class as main
This commit is contained in:
@@ -79,8 +79,8 @@ public class ApplicationRunner {
|
|||||||
|
|
||||||
private Map<String, String> defaultProperties(String id) {
|
private Map<String, String> defaultProperties(String id) {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME, "function-invoker-" + id);
|
map.put(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME, "function-deployer-" + id);
|
||||||
map.put("spring.jmx.default-domain", "function-invoker-" + id);
|
map.put("spring.jmx.default-domain", "function-deployer-" + id);
|
||||||
map.put("spring.jmx.enabled", "false");
|
map.put("spring.jmx.enabled", "false");
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class FunctionCreatorConfiguration {
|
|||||||
try {
|
try {
|
||||||
logger.info(
|
logger.info(
|
||||||
"Locating function from " + Arrays.asList(properties.getLocation()));
|
"Locating function from " + Arrays.asList(properties.getLocation()));
|
||||||
this.creator = new BeanCreator(expand(urls));
|
this.creator = new BeanCreator(urls);
|
||||||
this.creator.run(properties.getMain());
|
this.creator.run(properties.getMain());
|
||||||
Arrays.stream(properties.getBean()).map(this.creator::create).sequential()
|
Arrays.stream(properties.getBean()).map(this.creator::create).sequential()
|
||||||
.forEach(this.creator::register);
|
.forEach(this.creator::register);
|
||||||
@@ -125,30 +125,6 @@ class FunctionCreatorConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL[] expand(URL[] urls) {
|
|
||||||
List<URL> result = new ArrayList<>();
|
|
||||||
for (URL url : urls) {
|
|
||||||
result.addAll(expand(url));
|
|
||||||
}
|
|
||||||
return result.toArray(new URL[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<URL> expand(URL url) {
|
|
||||||
if (!"file".equals(url.getProtocol())) {
|
|
||||||
return Collections.singletonList(url);
|
|
||||||
}
|
|
||||||
if (!url.toString().endsWith(".jar")) {
|
|
||||||
return Collections.singletonList(url);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JarFileArchive archive = new JarFileArchive(new File(url.toURI()));
|
|
||||||
return Arrays.asList(new ComputeLauncher(archive).getClassLoaderUrls());
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new IllegalStateException("Cannot create class loader for " + url, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void close() {
|
public void close() {
|
||||||
if (this.creator != null) {
|
if (this.creator != null) {
|
||||||
@@ -188,6 +164,15 @@ class FunctionCreatorConfiguration {
|
|||||||
super(archive);
|
super(archive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMainClass() throws Exception {
|
||||||
|
try {
|
||||||
|
return super.getMainClass();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public URL[] getClassLoaderUrls() throws Exception {
|
public URL[] getClassLoaderUrls() throws Exception {
|
||||||
List<Archive> archives = getClassPathArchives();
|
List<Archive> archives = getClassPathArchives();
|
||||||
if (archives.isEmpty()) {
|
if (archives.isEmpty()) {
|
||||||
@@ -254,12 +239,62 @@ class FunctionCreatorConfiguration {
|
|||||||
|
|
||||||
private ApplicationRunner runner;
|
private ApplicationRunner runner;
|
||||||
|
|
||||||
|
private String defaultMain;
|
||||||
|
|
||||||
public BeanCreator(URL[] urls) {
|
public BeanCreator(URL[] urls) {
|
||||||
functionClassLoader = new BeanCreatorClassLoader(urls,
|
functionClassLoader = new BeanCreatorClassLoader(expand(urls),
|
||||||
getClass().getClassLoader().getParent());
|
getClass().getClassLoader().getParent());
|
||||||
|
this.defaultMain = findMain(urls);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String findMain(URL[] urls) {
|
||||||
|
for (URL url : urls) {
|
||||||
|
try {
|
||||||
|
File file = new File(url.toURI());
|
||||||
|
if (file.exists()) {
|
||||||
|
JarFileArchive archive = new JarFileArchive(file);
|
||||||
|
String main = new ComputeLauncher(archive).getMainClass();
|
||||||
|
if (main !=null) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private URL[] expand(URL[] urls) {
|
||||||
|
List<URL> result = new ArrayList<>();
|
||||||
|
for (URL url : urls) {
|
||||||
|
result.addAll(expand(url));
|
||||||
|
}
|
||||||
|
return result.toArray(new URL[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<URL> expand(URL url) {
|
||||||
|
if (!"file".equals(url.getProtocol())) {
|
||||||
|
return Collections.singletonList(url);
|
||||||
|
}
|
||||||
|
if (!url.toString().endsWith(".jar")) {
|
||||||
|
return Collections.singletonList(url);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JarFileArchive archive = new JarFileArchive(new File(url.toURI()));
|
||||||
|
return Arrays.asList(new ComputeLauncher(archive).getClassLoaderUrls());
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IllegalStateException("Cannot create class loader for " + url,
|
||||||
|
e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(String main) {
|
public void run(String main) {
|
||||||
|
if (main == null) {
|
||||||
|
main = this.defaultMain;
|
||||||
|
}
|
||||||
if (main == null) {
|
if (main == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ public abstract class SpringFunctionAppConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@TestPropertySource(properties = { "function.bean=myEmitter,myCounter",
|
@TestPropertySource(properties = { "function.bean=myEmitter,myCounter" })
|
||||||
"function.main=com.example.functions.FunctionApp" })
|
|
||||||
public static class CompositeTests extends SpringFunctionAppConfigurationTests {
|
public static class CompositeTests extends SpringFunctionAppConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -74,8 +73,7 @@ public abstract class SpringFunctionAppConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@TestPropertySource(properties = { "function.bean=myCounter",
|
@TestPropertySource(properties = { "function.bean=myCounter" })
|
||||||
"function.main=com.example.functions.FunctionApp" })
|
|
||||||
public static class ProcessorTests extends SpringFunctionAppConfigurationTests {
|
public static class ProcessorTests extends SpringFunctionAppConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,8 +86,7 @@ public abstract class SpringFunctionAppConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@TestPropertySource(properties = { "function.bean=myDoubler",
|
@TestPropertySource(properties = { "function.bean=myDoubler" })
|
||||||
"function.main=com.example.functions.FunctionApp" })
|
|
||||||
public static class SinkTests extends SpringFunctionAppConfigurationTests {
|
public static class SinkTests extends SpringFunctionAppConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ boms.spring-cloud-dependencies: org.springframework.cloud:spring-cloud-dependenc
|
|||||||
dependencies.spring-cloud-function-stream: org.springframework.cloud:spring-cloud-function-stream
|
dependencies.spring-cloud-function-stream: org.springframework.cloud:spring-cloud-function-stream
|
||||||
dependencies.spring-cloud-stream-rabbit: org.springframework.cloud:spring-cloud-starter-stream-rabbit
|
dependencies.spring-cloud-stream-rabbit: org.springframework.cloud:spring-cloud-starter-stream-rabbit
|
||||||
exclusions.spring-cloud-function-web: org.springframework.cloud:spring-cloud-starter-function-web
|
exclusions.spring-cloud-function-web: org.springframework.cloud:spring-cloud-starter-function-web
|
||||||
|
exclusions.http-client: com.rabbitmq:http-client
|
||||||
|
|||||||
Reference in New Issue
Block a user