1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.brabenetz.app.springstompserver;
21
22 import org.springframework.boot.Banner;
23 import org.springframework.boot.ansi.AnsiColor;
24 import org.springframework.boot.ansi.AnsiOutput;
25 import org.springframework.boot.ansi.AnsiStyle;
26 import org.springframework.core.env.Environment;
27
28 import java.io.PrintStream;
29 import java.util.Arrays;
30
31
32
33
34 public class SpringStompServerBanner implements Banner {
35
36
37 private static final String[] BANNER = {"",
38
39 " _____ _ _____ ",
40 " / ____| | / ____| ",
41 " | (___ | |_ ___ _ __ ___ _ __ _____| (___ ___ _ ____ _____ _ __ ",
42 " \\___ \\| __/ _ \\| '_ ` _ \\| '_ \\______\\___ \\ / _ \\ '__\\ \\ / / _ \\ '__|",
43 " ____) | || (_) | | | | | | |_) | ____) | __/ | \\ V / __/ | ",
44 " |_____/ \\__\\___/|_| |_| |_| .__/ |_____/ \\___|_| \\_/ \\___|_| ",
45 " _________________________ | | ________________________________________",
46 " ------------------------- |_| ----------------------------------------",
47 };
48
49 private static final String APP_NAME = " :: Stomp-Server ::";
50
51 private static final int STRAP_LINE_SIZE = Arrays.stream(BANNER).map(String::length).max(Integer::compare).orElse(0);
52
53 @Override
54 @SuppressWarnings("PMD.UseStringBufferForStringAppends")
55 public void printBanner(final Environment environment, final Class<?> sourceClass, final PrintStream printStream) {
56 for (String line : BANNER) {
57 printStream.println(line);
58 }
59 String version = SpringStompServerApplication.class.getPackage().getImplementationVersion();
60
61 version = (version != null) ? " v" + version : "";
62 StringBuilder padding = new StringBuilder();
63 while (padding.length() < STRAP_LINE_SIZE - (version.length() + APP_NAME.length())) {
64 padding.append(' ');
65 }
66
67 printStream.println(AnsiOutput.toString(AnsiColor.GREEN, APP_NAME, AnsiColor.DEFAULT, padding.toString(),
68 AnsiStyle.FAINT, version));
69 printStream.println();
70 }
71
72 }