-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#11758] Separate banner into module
- Loading branch information
Showing
19 changed files
with
276 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
...s/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/banner/PinpointBannerImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# pinpoint-banner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.navercorp.pinpoint</groupId> | ||
<artifactId>pinpoint</artifactId> | ||
<version>3.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pinpoint-banner</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
|
||
<!-- Logging dependencies --> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>templating-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
5 changes: 5 additions & 0 deletions
5
banner/src/main/java-templates/com/navercorp/pinpoint/banner/BannerVersionTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.navercorp.pinpoint.banner; | ||
|
||
class BannerVersionTemplate { | ||
Check warning on line 3 in banner/src/main/java-templates/com/navercorp/pinpoint/banner/BannerVersionTemplate.java Codecov / codecov/patchbanner/src/main/java-templates/com/navercorp/pinpoint/banner/BannerVersionTemplate.java#L3
|
||
static final String VERSION = "${project.version}"; | ||
} |
5 changes: 5 additions & 0 deletions
5
banner/src/main/java/com/navercorp/pinpoint/banner/Banner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.navercorp.pinpoint.banner; | ||
|
||
public interface Banner { | ||
void printBanner(); | ||
} |
37 changes: 37 additions & 0 deletions
37
banner/src/main/java/com/navercorp/pinpoint/banner/BannerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.navercorp.pinpoint.banner; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
class BannerUtils { | ||
|
||
static String readAllString(InputStream inputStream, Charset charset) throws IOException { | ||
try (Reader inputStreamReader = new InputStreamReader(inputStream, charset); | ||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { | ||
StringBuilder buffer = new StringBuilder(64); | ||
String line; | ||
while ((line = bufferedReader.readLine()) != null) { | ||
buffer.append(line); | ||
buffer.append(System.lineSeparator()); | ||
} | ||
return buffer.toString(); | ||
} | ||
} | ||
|
||
static String banner() { | ||
return banner("/pinpoint-banner/banner.txt"); | ||
} | ||
|
||
private static String banner(String bannerFile) { | ||
try (InputStream inputStream = BannerUtils.class.getResourceAsStream(bannerFile)) { | ||
return BannerUtils.readAllString(inputStream, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new RuntimeException("banner IO failed", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.navercorp.pinpoint.banner; | ||
|
||
public enum Mode { | ||
OFF, | ||
CONSOLE, | ||
LOG; | ||
} |
59 changes: 59 additions & 0 deletions
59
banner/src/main/java/com/navercorp/pinpoint/banner/PinpointBanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.navercorp.pinpoint.banner; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
public class PinpointBanner implements Banner { | ||
private final Mode bannerMode; | ||
private final Collection<String> dumpKeys; | ||
private final Function<String, String> properties; | ||
private final Consumer<String> consoleWriter = System.out::println; | ||
private final Consumer<String> loggerWriter; | ||
|
||
public PinpointBanner(Mode bannerMode, | ||
Collection<String> dumpKeys, | ||
Function<String, String> properties, | ||
Consumer<String> loggerWriter) { | ||
this.bannerMode = Objects.requireNonNull(bannerMode, "bannerMode"); | ||
this.dumpKeys = Objects.requireNonNull(dumpKeys, "dumpKeys"); | ||
this.properties = Objects.requireNonNull(properties, "properties"); | ||
this.loggerWriter = Objects.requireNonNull(loggerWriter, "loggerWriter"); | ||
} | ||
|
||
|
||
@Override | ||
public void printBanner() { | ||
switch (bannerMode) { | ||
case OFF: | ||
return; | ||
case LOG: | ||
loggerWriter.accept(buildBannerString()); | ||
return; | ||
default: | ||
consoleWriter.accept(buildBannerString()); | ||
} | ||
} | ||
|
||
private String buildBannerString() { | ||
StringBuilder banner = new StringBuilder(128); | ||
banner.append(BannerUtils.banner()); | ||
banner.append(format("Pinpoint Version", BannerVersionTemplate.VERSION)); | ||
banner.append(System.lineSeparator()); | ||
|
||
for (String key : dumpKeys) { | ||
String value = properties.apply(key); | ||
if (value != null) { | ||
banner.append(format(key, value)); | ||
banner.append(System.lineSeparator()); | ||
} | ||
} | ||
return banner.toString(); | ||
} | ||
|
||
protected String format(String key, String value) { | ||
return String.format(" :: %55s :: %35s", key, value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
88888888ba 88 888b 88 88888888ba ,ad8888ba, 88 888b 88 888888888888 | ||
88 ,8P 88 88 `8b 88 88 ,8P d8' `8b 88 88 `8b 88 88 | ||
88aaaaaa8P' 88 88 `8b 88 88aaaaaa8P' 88 da 88 88 88 `8b 88 88 | ||
88 88 88 `8b 88 88 Y8, ,8P 88 88 `8b 88 88 | ||
88 88 88 `888 88 `"Y8888Y"' 88 88 `888 88 | ||
|
||
https://github.com/pinpoint-apm/pinpoint | ||
|
19 changes: 19 additions & 0 deletions
19
banner/src/test/java/com/navercorp/pinpoint/banner/BannerUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.navercorp.pinpoint.banner; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
class BannerUtilsTest { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
@Test | ||
void banner() { | ||
String banner = BannerUtils.banner(); | ||
logger.debug("--------"); | ||
logger.debug(banner); | ||
logger.debug("--------"); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
banner/src/test/java/com/navercorp/pinpoint/banner/PinpointBannerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.navercorp.pinpoint.banner; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
class PinpointBannerTest { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
@Test | ||
void printBanner() { | ||
Properties properties = new Properties(); | ||
properties.put("aaa", "111"); | ||
properties.put("bbb", "222"); | ||
List<String> dumpKeys = keyList(properties); | ||
|
||
Banner banner = new PinpointBanner(Mode.LOG, dumpKeys, | ||
properties::getProperty, logger::info); | ||
banner.printBanner(); | ||
} | ||
|
||
private List<String> keyList(Properties properties) { | ||
@SuppressWarnings("unchecked") | ||
Enumeration<String> enumeration = (Enumeration<String>) properties.propertyNames(); | ||
return Collections.list(enumeration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Configuration status="INFO"> | ||
<Properties> | ||
<Property name="console_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %clr{%-5level} %clr{%-40.40logger{1.}}{cyan}:%3L -- %msg{nolookups}%n</Property> | ||
<Property name="file_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %-5level %-40.40logger{1.}:%3L -- %msg{nolookups}%n</Property> | ||
</Properties> | ||
|
||
<Appenders> | ||
<Console name="console" target="system_out"> | ||
<PatternLayout pattern="${file_message_pattern}"/> | ||
</Console> | ||
</Appenders> | ||
|
||
<Loggers> | ||
<Logger name="com.navercorp.pinpoint" level="DEBUG" additivity="false"> | ||
<AppenderRef ref="console"/> | ||
</Logger> | ||
|
||
<Root level="DEBUG"> | ||
<AppenderRef ref="console"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
Oops, something went wrong.