View Javadoc
1   /*-
2    * #%L
3    * Spring Stomp Server
4    * ===============================================================
5    * Copyright (C) 2020 Brabenetz Harald, Austria
6    * ===============================================================
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
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   * Ascii-Art Banner implementation for Spring-Stomp-Server.
33   */
34  public class SpringStompServerBanner implements Banner {
35  
36      // example from http://patorjk.com/software/taag/#p=display&f=Big&t=Stomp-Server
37      private static final String[] BANNER = {"",
38              // Big Variant
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  //        String version = "1.0-SNAPSHOT-2019-09-20T20:00:02Z"; // for manual testing
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  }