More tests for auto detect of start class

This commit is contained in:
Dave Syer
2018-05-18 12:48:36 +01:00
parent e1bb5259a9
commit a64579dbdb
3 changed files with 44 additions and 6 deletions

View File

@@ -47,6 +47,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.loader.JarLauncher;
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.support.DelegatingResourceLoader;
import org.springframework.cloud.function.context.FunctionRegistration;
@@ -160,7 +161,7 @@ class FunctionCreatorConfiguration {
private class ComputeLauncher extends JarLauncher {
public ComputeLauncher(JarFileArchive archive) {
public ComputeLauncher(Archive archive) {
super(archive);
}
@@ -168,7 +169,8 @@ class FunctionCreatorConfiguration {
public String getMainClass() throws Exception {
try {
return super.getMainClass();
} catch (Exception e) {
}
catch (Exception e) {
return null;
}
}
@@ -252,9 +254,11 @@ class FunctionCreatorConfiguration {
try {
File file = new File(url.toURI());
if (file.exists()) {
JarFileArchive archive = new JarFileArchive(file);
Archive archive = file.getName().endsWith(".jar")
? new JarFileArchive(file)
: new ExplodedArchive(file);
String main = new ComputeLauncher(archive).getMainClass();
if (main !=null) {
if (main != null) {
return main;
}
}
@@ -282,8 +286,13 @@ class FunctionCreatorConfiguration {
return Collections.singletonList(url);
}
try {
JarFileArchive archive = new JarFileArchive(new File(url.toURI()));
return Arrays.asList(new ComputeLauncher(archive).getClassLoaderUrls());
File file = new File(url.toURI());
if (file.exists()) {
JarFileArchive archive = new JarFileArchive(file);
return Arrays
.asList(new ComputeLauncher(archive).getClassLoaderUrls());
}
return Collections.singletonList(url);
}
catch (Exception e) {
throw new IllegalStateException("Cannot create class loader for " + url,

View File

@@ -59,6 +59,21 @@ public abstract class FunctionCreatorConfigurationTests {
}
}
@EnableAutoConfiguration
@TestPropertySource(properties = {
"function.location=app:classpath,file:target/test-classes,file:target/test-classes/app",
"function.bean=myDoubler" })
public static class SingleFunctionWithAutoMainTests
extends FunctionCreatorConfigurationTests {
@Test
public void testDouble() {
Function<Flux<Integer>, Flux<Integer>> function = catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo(4);
}
}
@EnableAutoConfiguration
@TestPropertySource(properties = { "function.location=app:classpath",
"function.bean=org.springframework.cloud.function.test.SpringDoubler" })

View File

@@ -0,0 +1,14 @@
Manifest-Version: 1.0
Implementation-Title: function-file-sample
Implementation-Version: 1.0.0.M1
Archiver-Version: Plexus Archiver
Built-By: dsyer
Implementation-Vendor-Id: com.example
Spring-Boot-Version: 1.5.12.RELEASE
Implementation-Vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: org.springframework.cloud.function.test.FunctionApp
Created-By: Apache Maven 3.5.0
Build-Jdk: 1.8.0_131
Implementation-URL: http://projects.spring.io/spring-boot/function-sam
ple/