Skip to content

Commit 187aa14

Browse files
committed
startup banner fix #353
1 parent 4e0d6d0 commit 187aa14

174 files changed

Lines changed: 134166 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

coverage-report/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<source>${project.parent.basedir}/jooby-querydsl/src/main/java</source>
7070
<source>${project.parent.basedir}/jooby-sitemap/src/main/java</source>
7171
<source>${project.parent.basedir}/jooby-rxjava/src/main/java</source>
72+
<source>${project.parent.basedir}/jooby-banner/src/main/java</source>
7273
</sources>
7374
</configuration>
7475
</execution>
@@ -117,6 +118,7 @@
117118
<source>${project.parent.basedir}/jooby-querydsl/src/test/java</source>
118119
<source>${project.parent.basedir}/jooby-sitemap/src/test/java</source>
119120
<source>${project.parent.basedir}/jooby-rxjava/src/test/java</source>
121+
<source>${project.parent.basedir}/jooby-banner/src/test/java</source>
120122
</sources>
121123
</configuration>
122124
</execution>
@@ -470,6 +472,12 @@
470472
</exclusions>
471473
</dependency>
472474

475+
<dependency>
476+
<groupId>org.jooby</groupId>
477+
<artifactId>jooby-banner</artifactId>
478+
<version>${project.version}</version>
479+
</dependency>
480+
473481
<dependency>
474482
<groupId>org.avaje</groupId>
475483
<artifactId>avaje-agentloader</artifactId>

jooby-banner/pom.xml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<parent>
6+
<groupId>org.jooby</groupId>
7+
<artifactId>jooby-project</artifactId>
8+
<version>1.0.0.CR3</version>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<artifactId>jooby-banner</artifactId>
13+
14+
<name>banner module</name>
15+
16+
<build>
17+
<plugins>
18+
<!-- sure-fire -->
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-surefire-plugin</artifactId>
22+
<configuration>
23+
<includes>
24+
<include>**/*Test.java</include>
25+
<include>**/*Feature.java</include>
26+
<include>**/Issue*.java</include>
27+
</includes>
28+
</configuration>
29+
</plugin>
30+
31+
</plugins>
32+
</build>
33+
34+
<dependencies>
35+
<!-- Jooby -->
36+
<dependency>
37+
<groupId>org.jooby</groupId>
38+
<artifactId>jooby</artifactId>
39+
<version>${project.version}</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.github.lalyos</groupId>
44+
<artifactId>jfiglet</artifactId>
45+
</dependency>
46+
47+
<!-- Test dependencies -->
48+
<dependency>
49+
<groupId>org.jooby</groupId>
50+
<artifactId>jooby</artifactId>
51+
<version>${project.version}</version>
52+
<scope>test</scope>
53+
<classifier>tests</classifier>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>junit</groupId>
58+
<artifactId>junit</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.easymock</groupId>
64+
<artifactId>easymock</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
68+
<dependency>
69+
<groupId>org.powermock</groupId>
70+
<artifactId>powermock-api-easymock</artifactId>
71+
<scope>test</scope>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.powermock</groupId>
76+
<artifactId>powermock-module-junit4</artifactId>
77+
<scope>test</scope>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>org.jacoco</groupId>
82+
<artifactId>org.jacoco.agent</artifactId>
83+
<classifier>runtime</classifier>
84+
<scope>test</scope>
85+
</dependency>
86+
87+
</dependencies>
88+
89+
</project>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.jooby.banner;
20+
21+
import static com.github.lalyos.jfiglet.FigletFont.convertOneLine;
22+
import static java.util.Objects.requireNonNull;
23+
24+
import java.util.Optional;
25+
26+
import org.jooby.Env;
27+
import org.jooby.Jooby.Module;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
31+
import com.google.inject.Binder;
32+
import com.typesafe.config.Config;
33+
34+
/**
35+
* <h1>banner</h1>
36+
* <p>
37+
* Prints out an ASCII art banner on startup using
38+
* <a href="https://github.com/lalyos/jfiglet">jfiglet</a>.
39+
* </p>
40+
*
41+
* <h2>usage</h2>
42+
*
43+
* <pre>{@code
44+
* package com.myapp;
45+
*
46+
* {
47+
* use(new Banner());
48+
* }
49+
* }</pre>
50+
*
51+
* <p>
52+
* Prints out the value of <code>application.name</code> which here is <code>myapp</code>. Or you
53+
* can specify the text to prints out:
54+
* </p>
55+
*
56+
* <pre>{@code
57+
* package com.myapp;
58+
*
59+
* {
60+
* use(new Banner("my awesome app"));
61+
* }
62+
* }</pre>
63+
*
64+
* <h2>font</h2>
65+
* <p>
66+
* You can pick and use the font of your choice via {@link #font(String)} option:
67+
* </p>
68+
*
69+
* <pre>{@code
70+
* package com.myapp;
71+
*
72+
* {
73+
* use(new Banner("my awesome app").font("slant"));
74+
* }
75+
* }</pre>
76+
*
77+
* <p>
78+
* Font are distributed within the library inside the <code>/flf</code> classpath folder. A full
79+
* list of fonts is available <a href="http://patorjk.com/software/taag">here</a>.
80+
* </p>
81+
*
82+
* @author edgar
83+
* @since 1.0.0.CR3
84+
*/
85+
public class Banner implements Module {
86+
87+
private static final String FONT = "classpath:/flf/%s.flf";
88+
89+
private String font = "speed";
90+
91+
private final Optional<String> text;
92+
93+
public Banner(final String text) {
94+
this.text = Optional.of(text);
95+
}
96+
97+
public Banner() {
98+
this.text = Optional.empty();
99+
}
100+
101+
@Override
102+
public void configure(final Env env, final Config conf, final Binder binder) {
103+
String name = conf.getString("application.name");
104+
Logger log = LoggerFactory.getLogger(name);
105+
String v = conf.getString("application.version");
106+
String text = this.text.orElse(name);
107+
108+
env.onStart(
109+
() -> log.info("\n{} v{}\n", convertOneLine(String.format(FONT, font), text).trim(), v));
110+
}
111+
112+
public Banner font(final String font) {
113+
this.font = requireNonNull(font, "Font is required.");
114+
return this;
115+
}
116+
117+
}

0 commit comments

Comments
 (0)