Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ming zheng
Spring Cloud Function
Commits
e1bb5259
Commit
e1bb5259
authored
7 years ago
by
Dave Syer
Browse files
Options
Download
Email Patches
Plain Diff
Support for Start-Class as main
parent
e34324b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationRunner.java
+2
-2
...gframework/cloud/function/deployer/ApplicationRunner.java
spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionCreatorConfiguration.java
+61
-26
...cloud/function/deployer/FunctionCreatorConfiguration.java
spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppConfigurationTests.java
+3
-6
...unction/deployer/SpringFunctionAppConfigurationTests.java
spring-cloud-function-samples/function-sample/src/main/resources/META-INF/thin-rabbit.properties
+1
-0
...sample/src/main/resources/META-INF/thin-rabbit.properties
with
67 additions
and
34 deletions
+67
-34
spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationRunner.java
+
2
-
2
View file @
e1bb5259
...
...
@@ -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-
invok
er-"
+
id
);
map
.
put
(
"spring.jmx.default-domain"
,
"function-
invok
er-"
+
id
);
map
.
put
(
LiveBeansView
.
MBEAN_DOMAIN_PROPERTY_NAME
,
"function-
deploy
er-"
+
id
);
map
.
put
(
"spring.jmx.default-domain"
,
"function-
deploy
er-"
+
id
);
map
.
put
(
"spring.jmx.enabled"
,
"false"
);
return
map
;
}
...
...
This diff is collapsed.
Click to expand it.
spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionCreatorConfiguration.java
+
61
-
26
View file @
e1bb5259
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppConfigurationTests.java
+
3
-
6
View file @
e1bb5259
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
spring-cloud-function-samples/function-sample/src/main/resources/META-INF/thin-rabbit.properties
+
1
-
0
View file @
e1bb5259
...
...
@@ -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-stream-rabbit
:
org.springframework.cloud:spring-cloud-starter-stream-rabbit
exclusions.spring-cloud-function-web
:
org.springframework.cloud:spring-cloud-starter-function-web
exclusions.http-client
:
com.rabbitmq:http-client
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment