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) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME, "function-invoker-" + id);
|
||||
map.put("spring.jmx.default-domain", "function-invoker-" + id);
|
||||
map.put(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME, "function-deployer-" + id);
|
||||
map.put("spring.jmx.default-domain", "function-deployer-" + id);
|
||||
map.put("spring.jmx.enabled", "false");
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class FunctionCreatorConfiguration {
|
||||
try {
|
||||
logger.info(
|
||||
"Locating function from " + Arrays.asList(properties.getLocation()));
|
||||
this.creator = new BeanCreator(expand(urls));
|
||||
this.creator = new BeanCreator(urls);
|
||||
this.creator.run(properties.getMain());
|
||||
Arrays.stream(properties.getBean()).map(this.creator::create).sequential()
|
||||
.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
|
||||
public void close() {
|
||||
if (this.creator != null) {
|
||||
@@ -188,6 +164,15 @@ class FunctionCreatorConfiguration {
|
||||
super(archive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainClass() throws Exception {
|
||||
try {
|
||||
return super.getMainClass();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public URL[] getClassLoaderUrls() throws Exception {
|
||||
List<Archive> archives = getClassPathArchives();
|
||||
if (archives.isEmpty()) {
|
||||
@@ -254,12 +239,62 @@ class FunctionCreatorConfiguration {
|
||||
|
||||
private ApplicationRunner runner;
|
||||
|
||||
private String defaultMain;
|
||||
|
||||
public BeanCreator(URL[] urls) {
|
||||
functionClassLoader = new BeanCreatorClassLoader(urls,
|
||||
functionClassLoader = new BeanCreatorClassLoader(expand(urls),
|
||||
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) {
|
||||
if (main == null) {
|
||||
main = this.defaultMain;
|
||||
}
|
||||
if (main == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,7 @@ public abstract class SpringFunctionAppConfigurationTests {
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@TestPropertySource(properties = { "function.bean=myEmitter,myCounter",
|
||||
"function.main=com.example.functions.FunctionApp" })
|
||||
@TestPropertySource(properties = { "function.bean=myEmitter,myCounter" })
|
||||
public static class CompositeTests extends SpringFunctionAppConfigurationTests {
|
||||
|
||||
@Test
|
||||
@@ -74,8 +73,7 @@ public abstract class SpringFunctionAppConfigurationTests {
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@TestPropertySource(properties = { "function.bean=myCounter",
|
||||
"function.main=com.example.functions.FunctionApp" })
|
||||
@TestPropertySource(properties = { "function.bean=myCounter" })
|
||||
public static class ProcessorTests extends SpringFunctionAppConfigurationTests {
|
||||
|
||||
@Test
|
||||
@@ -88,8 +86,7 @@ public abstract class SpringFunctionAppConfigurationTests {
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@TestPropertySource(properties = { "function.bean=myDoubler",
|
||||
"function.main=com.example.functions.FunctionApp" })
|
||||
@TestPropertySource(properties = { "function.bean=myDoubler" })
|
||||
public static class SinkTests extends SpringFunctionAppConfigurationTests {
|
||||
|
||||
@Rule
|
||||
|
||||
Reference in New Issue
Block a user