Skip to content

Commit 06b2d5b

Browse files
committed
fix(grailsconsole): bind system out and err stream
1 parent 47eb332 commit 06b2d5b

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

grails-bootstrap/src/main/groovy/grails/build/logging/GrailsConsole.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ protected void initialize(InputStream systemIn, PrintStream systemOut, PrintStre
198198

199199
protected void bindSystemOutAndErr(PrintStream systemOut, PrintStream systemErr) {
200200
originalSystemOut = unwrapPrintStream(systemOut);
201+
out = originalSystemOut;
201202
originalSystemErr = unwrapPrintStream(systemErr);
203+
err = originalSystemErr;
202204
}
203205

204206
private PrintStream unwrapPrintStream(PrintStream printStream) {
@@ -327,7 +329,6 @@ public static synchronized void removeInstance() {
327329
}
328330

329331
public void beforeShutdown() {
330-
AnsiConsole.systemUninstall();
331332
persistHistory();
332333
restoreTerminal();
333334
}

grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/reporting/AnsiConsoleUrlMappingsRendererSpec.groovy

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ import spock.lang.Specification
1313
/**
1414
* @author Graeme Rocher
1515
*/
16-
class AnsiConsoleUrlMappingsRendererSpec extends Specification{
16+
class AnsiConsoleUrlMappingsRendererSpec extends Specification {
1717

1818
void "Test render URL mappings for 3 level resource"() {
19-
given:"A URL mappings renderer"
20-
def sw = new ByteArrayOutputStream()
21-
def ps = new PrintStream(sw)
22-
def renderer = new AnsiConsoleUrlMappingsRenderer(ps)
23-
renderer.isAnsiEnabled = false
24-
def urlMappingsHolder = getUrlMappingsHolder {
25-
"/books"(resources:'book') {
26-
'/authors'(resources:'author') {
27-
'/publisher'(resource:'publisher')
28-
}
19+
given: "A URL mappings renderer"
20+
def sw = new ByteArrayOutputStream()
21+
def ps = new PrintStream(sw)
22+
def renderer = new AnsiConsoleUrlMappingsRenderer(ps)
23+
renderer.isAnsiEnabled = false
24+
def urlMappingsHolder = getUrlMappingsHolder {
25+
"/books"(resources: 'book') {
26+
'/authors'(resources: 'author') {
27+
'/publisher'(resource: 'publisher')
2928
}
3029
}
31-
when:"The URL mappings are rendered"
32-
renderer.render(urlMappingsHolder.urlMappings.toList())
33-
println sw.toString()
34-
then:"The output is correct"
35-
sw.toString() == '''Controller: author
30+
}
31+
when: "The URL mappings are rendered"
32+
renderer.render(urlMappingsHolder.urlMappings.toList())
33+
println sw.toString()
34+
then: "The output is correct"
35+
sw.toString() == '''Controller: author
3636
| GET | /books/${bookId}/authors/create | Action: create |
3737
| GET | /books/${bookId}/authors/${id}/edit | Action: edit |
3838
| POST | /books/${bookId}/authors | Action: save |
@@ -65,25 +65,25 @@ Controller: publisher
6565
}
6666

6767
void "Test render URL mappings to target stream"() {
68-
given:"A URL mappings renderer"
69-
def sw = new ByteArrayOutputStream()
70-
def ps = new PrintStream(sw)
71-
def renderer = new AnsiConsoleUrlMappingsRenderer(ps)
72-
renderer.isAnsiEnabled = false
73-
def urlMappingsHolder = getUrlMappingsHolder {
74-
"/$controller/$action?/$id?(.$format)?"()
75-
"/images/$name**.jpg"(controller:"image")
76-
"/foo"(resources:"foo")
77-
"500"(controller:"errors")
78-
"/"(view:"/index")
68+
given: "A URL mappings renderer"
69+
def sw = new ByteArrayOutputStream()
70+
def ps = new PrintStream(sw)
71+
def renderer = new AnsiConsoleUrlMappingsRenderer(ps)
72+
renderer.isAnsiEnabled = false
73+
def urlMappingsHolder = getUrlMappingsHolder {
74+
"/$controller/$action?/$id?(.$format)?"()
75+
"/images/$name**.jpg"(controller: "image")
76+
"/foo"(resources: "foo")
77+
"500"(controller: "errors")
78+
"/"(view: "/index")
7979

80-
}
80+
}
8181

82-
when:"The URL mappings are rendered"
83-
renderer.render(urlMappingsHolder.urlMappings.toList())
84-
println sw.toString()
85-
then:"The output is correct"
86-
sw.toString() == '''Dynamic Mappings
82+
when: "The URL mappings are rendered"
83+
renderer.render(urlMappingsHolder.urlMappings.toList())
84+
println sw.toString()
85+
then: "The output is correct"
86+
sw.toString() == '''Dynamic Mappings
8787
| * | / | View: /index |
8888
| * | /${controller}/${action}?/${id}?(.${format)? | Action: (default action) |
8989
@@ -105,6 +105,7 @@ Controller: image
105105
106106
'''.denormalize()
107107
}
108+
108109
UrlMappingsHolder getUrlMappingsHolder(Closure mappings) {
109110
def ctx = new MockApplicationContext()
110111
ctx.registerMockBean(GrailsApplication.APPLICATION_ID, new DefaultGrailsApplication())

0 commit comments

Comments
 (0)