Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
79c163c6
Commit
79c163c6
authored
Apr 27, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5453 from cjstehno/master
* pr/5453: Fix remote shell to support custom banners
parents
b5679594
309f8484
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
6 deletions
+77
-6
banner.txt
...-boot-sample-actuator-noweb/src/main/resources/banner.txt
+8
-0
login.groovy
...mote-shell/src/main/resources/commands/crash/login.groovy
+18
-1
SpringApplicationBannerPrinter.java
.../springframework/boot/SpringApplicationBannerPrinter.java
+26
-2
BannerTests.java
...t/src/test/java/org/springframework/boot/BannerTests.java
+25
-3
No files found.
spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/banner.txt
0 → 100644
View file @
79c163c6
,--. ,--.
\ /-~-\ /
)' a a `(
( ,---. )
`(_o_o_)'
)`-'(
Spring Boot${spring-boot.formatted-version}
spring-boot-starters/spring-boot-starter-remote-shell/src/main/resources/commands/crash/login.groovy
View file @
79c163c6
welcome
=
{
->
welcome
=
{
->
if
(!
crash
.
context
.
attributes
[
'spring.environment'
].
getProperty
(
"spring.main.show_banner"
,
Boolean
.
class
,
Boolean
.
TRUE
))
{
def
environment
=
crash
.
context
.
attributes
[
'spring.environment'
]
def
propertyResolver
=
new
org
.
springframework
.
boot
.
bind
.
RelaxedPropertyResolver
(
environment
,
"spring.main."
);
def
beanFactory
=
crash
.
context
.
attributes
[
'spring.beanfactory'
]
if
(!
propertyResolver
.
getProperty
(
"show-banner"
,
Boolean
.
class
,
Boolean
.
TRUE
))
{
return
""
return
""
}
}
// Try to print using the banner interface
if
(
beanFactory
!=
null
)
{
try
{
def
banner
=
beanFactory
.
getBean
(
"springBootBanner"
)
def
out
=
new
java
.
io
.
ByteArrayOutputStream
()
banner
.
printBanner
(
environment
,
null
,
new
java
.
io
.
PrintStream
(
out
))
return
out
.
toString
()
}
catch
(
Exception
ex
)
{
// Ignore
}
}
// Resolve hostname
// Resolve hostname
def
hostName
;
def
hostName
;
try
{
try
{
...
...
spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java
View file @
79c163c6
...
@@ -63,13 +63,13 @@ class SpringApplicationBannerPrinter {
...
@@ -63,13 +63,13 @@ class SpringApplicationBannerPrinter {
catch
(
UnsupportedEncodingException
ex
)
{
catch
(
UnsupportedEncodingException
ex
)
{
logger
.
warn
(
"Failed to create String for banner"
,
ex
);
logger
.
warn
(
"Failed to create String for banner"
,
ex
);
}
}
return
banner
;
return
new
PrintedBanner
(
banner
,
sourceClass
)
;
}
}
public
Banner
print
(
Environment
environment
,
Class
<?>
sourceClass
,
PrintStream
out
)
{
public
Banner
print
(
Environment
environment
,
Class
<?>
sourceClass
,
PrintStream
out
)
{
Banner
banner
=
getBanner
(
environment
,
this
.
fallbackBanner
);
Banner
banner
=
getBanner
(
environment
,
this
.
fallbackBanner
);
banner
.
printBanner
(
environment
,
sourceClass
,
out
);
banner
.
printBanner
(
environment
,
sourceClass
,
out
);
return
banner
;
return
new
PrintedBanner
(
banner
,
sourceClass
)
;
}
}
private
Banner
getBanner
(
Environment
environment
,
Banner
definedBanner
)
{
private
Banner
getBanner
(
Environment
environment
,
Banner
definedBanner
)
{
...
@@ -145,4 +145,28 @@ class SpringApplicationBannerPrinter {
...
@@ -145,4 +145,28 @@ class SpringApplicationBannerPrinter {
}
}
/**
* Decorator that allows a {@link Banner} to be printed again without needing to
* specify the source class.
*/
private
static
class
PrintedBanner
implements
Banner
{
private
final
Banner
banner
;
private
final
Class
<?>
sourceClass
;
PrintedBanner
(
Banner
banner
,
Class
<?>
sourceClass
)
{
this
.
banner
=
banner
;
this
.
sourceClass
=
sourceClass
;
}
@Override
public
void
printBanner
(
Environment
environment
,
Class
<?>
sourceClass
,
PrintStream
out
)
{
sourceClass
=
(
sourceClass
==
null
?
this
.
sourceClass
:
sourceClass
);
this
.
banner
.
printBanner
(
environment
,
sourceClass
,
out
);
}
}
}
}
spring-boot/src/test/java/org/springframework/boot/BannerTests.java
View file @
79c163c6
...
@@ -21,14 +21,24 @@ import java.io.PrintStream;
...
@@ -21,14 +21,24 @@ import java.io.PrintStream;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.boot.Banner.Mode
;
import
org.springframework.boot.Banner.Mode
;
import
org.springframework.boot.testutil.InternalOutputCapture
;
import
org.springframework.boot.testutil.InternalOutputCapture
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
reset
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
/**
* Tests for {@link Banner} and its usage by {@link SpringApplication}.
* Tests for {@link Banner} and its usage by {@link SpringApplication}.
...
@@ -37,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -37,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Michael Stummvoll
* @author Michael Stummvoll
* @author Michael Simons
* @author Michael Simons
*/
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
BannerTests
{
public
class
BannerTests
{
private
ConfigurableApplicationContext
context
;
private
ConfigurableApplicationContext
context
;
...
@@ -51,6 +62,9 @@ public class BannerTests {
...
@@ -51,6 +62,9 @@ public class BannerTests {
@Rule
@Rule
public
InternalOutputCapture
out
=
new
InternalOutputCapture
();
public
InternalOutputCapture
out
=
new
InternalOutputCapture
();
@Captor
private
ArgumentCaptor
<
Class
<?>>
sourceClassCaptor
;
@Test
@Test
public
void
testDefaultBanner
()
throws
Exception
{
public
void
testDefaultBanner
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
...
@@ -88,10 +102,18 @@ public class BannerTests {
...
@@ -88,10 +102,18 @@ public class BannerTests {
public
void
testCustomBannerInContext
()
throws
Exception
{
public
void
testCustomBannerInContext
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebEnvironment
(
false
);
application
.
setWebEnvironment
(
false
);
final
DummyBanner
dummyBanner
=
new
DummyBanner
(
);
Banner
banner
=
mock
(
Banner
.
class
);
application
.
setBanner
(
dummyB
anner
);
application
.
setBanner
(
b
anner
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
getBean
(
"springBootBanner"
)).
isEqualTo
(
dummyBanner
);
Banner
printedBanner
=
(
Banner
)
this
.
context
.
getBean
(
"springBootBanner"
);
assertThat
(
ReflectionTestUtils
.
getField
(
printedBanner
,
"banner"
))
.
isEqualTo
(
banner
);
verify
(
banner
).
printBanner
(
any
(
Environment
.
class
),
this
.
sourceClassCaptor
.
capture
(),
any
(
PrintStream
.
class
));
reset
(
banner
);
printedBanner
.
printBanner
(
this
.
context
.
getEnvironment
(),
null
,
System
.
out
);
verify
(
banner
).
printBanner
(
any
(
Environment
.
class
),
eq
(
this
.
sourceClassCaptor
.
getValue
()),
any
(
PrintStream
.
class
));
}
}
@Test
@Test
...
...
Write
Preview
Markdown
is supported
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