Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@
<exclude>**/test/data/**/*.json</exclude>
<exclude>LICENSE</exclude>&gt;
<exclude>**/*.md</exclude>
<exclude>**/src/main/resources/banner.txt</exclude>
<exclude>**/src/main/resources/zipkin.txt</exclude>
<exclude>**/src/main/resources/*.yml</exclude>
<exclude>**/spring.factories</exclude>
<!-- Cassandra integration tests break when license headers are present -->
Expand Down
6 changes: 4 additions & 2 deletions zipkin-server/src/main/java/zipkin/server/ZipkinServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.boot.builder.SpringApplicationBuilder;
import zipkin2.server.internal.EnableZipkinServer;
import zipkin2.server.internal.RegisterZipkinHealthIndicators;
import zipkin2.server.internal.banner.ZipkinBanner;

@SpringBootApplication
@EnableZipkinServer
Expand All @@ -29,7 +30,8 @@ public class ZipkinServer {

public static void main(String[] args) {
new SpringApplicationBuilder(ZipkinServer.class)
.listeners(new RegisterZipkinHealthIndicators())
.properties("spring.config.name=zipkin-server").run(args);
.listeners(new RegisterZipkinHealthIndicators())
.banner(new ZipkinBanner())
.properties("spring.config.name=zipkin-server").run(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2015-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.server.internal.banner;

import org.springframework.boot.ansi.AnsiElement;

/**
* <code>AnsiElement</code> implementation for Ansi256 Color<br>
* TODO: This class should be deleted when this feature is provided by Spring Boot
* @see <a href="https://github.com/spring-projects/spring-boot/pull/18264">https://github.com/spring-projects/spring-boot/pull/18264</a>
*/
public class ZipkinAnsi256Color implements AnsiElement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a TODO to delete on spring boot 2.2 if that's when this is scheduled to be normally possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in edebc31


private final int xtermNumber;

ZipkinAnsi256Color(int xtermNumber) {
if (xtermNumber < 0 || xtermNumber > 255) {
throw new IllegalArgumentException("'xtermNumber' must be 0-255!");
}
this.xtermNumber = xtermNumber;
}

@Override
public String toString() {
return "38;5;" + this.xtermNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2015-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.server.internal.banner;

import org.springframework.boot.ansi.AnsiElement;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.core.env.PropertySource;
import org.springframework.util.StringUtils;

/**
* This class enable to use Ansi256 Color in the banner txt file
* via <code>${ZipkinAnsi256Color.XYZ}</code> format (<code>XYZ</code> must be 0-255.).<br>
* All supported colors can be found <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit">here</a>.<br>
* TODO: This class should be deleted when this feature is provided by Spring Boot
* @see <a href="https://github.com/spring-projects/spring-boot/pull/18264">https://github.com/spring-projects/spring-boot/pull/18264</a>
*/
public class ZipkinAnsi256ColorPropertySource extends PropertySource<AnsiElement> {

private static final String PREFIX = "ZipkinAnsi256Color.";

ZipkinAnsi256ColorPropertySource(String name) {
super(name);
}

@Override
public Object getProperty(String name) {
if (StringUtils.hasLength(name)) {
if (name.startsWith(PREFIX)) {
int xtermNumber = Integer.parseInt(name.substring(PREFIX.length()));
return AnsiOutput.encode(new ZipkinAnsi256Color(xtermNumber));
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2015-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.server.internal.banner;

import org.springframework.boot.ResourceBanner;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertyResolver;
import org.springframework.core.env.PropertySourcesPropertyResolver;
import org.springframework.core.io.ClassPathResource;

import java.util.List;

/**
* <code>Banner</code> implemetation for Ansi256 Color<br>
* TODO: This class should be deleted when this feature is provided by Spring Boot
* @see <a href="https://github.com/spring-projects/spring-boot/pull/18264">https://github.com/spring-projects/spring-boot/pull/18264</a>
*/
public class ZipkinBanner extends ResourceBanner {

public ZipkinBanner() {
super(new ClassPathResource("zipkin.txt"));
}

@Override
protected List<PropertyResolver> getPropertyResolvers(Environment environment, Class<?> sourceClass) {
final List<PropertyResolver> propertyResolvers = super.getPropertyResolvers(environment, sourceClass);
propertyResolvers.add(getZipkinAnsi256Resolver());
return propertyResolvers;
}

private PropertyResolver getZipkinAnsi256Resolver() {
MutablePropertySources sources = new MutablePropertySources();
sources.addFirst(new ZipkinAnsi256ColorPropertySource("zipkinAnsi256"));
return new PropertySourcesPropertyResolver(sources);
}
}
25 changes: 0 additions & 25 deletions zipkin-server/src/main/resources/banner.txt

This file was deleted.

28 changes: 28 additions & 0 deletions zipkin-server/src/main/resources/zipkin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
${ZipkinAnsi256Color.208}
oo
oooo
oooooo
oooooooo
oooooooooo
oooooooooooo
ooooooo ooooooo
oooooo ooooooo
oooooo ooooooo
oooooo o o oooooo
oooooo oo oo oooooo
ooooooo oooo oooo ooooooo
oooooo ooooo ooooo ooooooo
oooooo oooooo oooooo ooooooo
oooooooo oo oo oooooooo
ooooooooooooo oo oo ooooooooooooo
oooooooooooo oooooooooooo
oooooooo oooooooo
oooo oooo
${AnsiStyle.NORMAL}
________ ____ _ _____ _ _
|__ /_ _| _ \| |/ /_ _| \ | |
/ / | || |_) | ' / | || \| |
/ /_ | || __/| . \ | || |\ |
|____|___|_| |_|\_\___|_| \_|

${AnsiColor.GREEN}:: Powered by Spring Boot :: ${AnsiStyle.FAINT}${AnsiColor.BLACK}${spring-boot.formatted-version}${AnsiStyle.NORMAL}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2015-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.server.internal.banner;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.ansi.AnsiOutput;

import static org.assertj.core.api.Assertions.assertThat;

public class ZipkinAnsi256ColorPropertySourceTest {

@Before
public void setUp() throws Exception {
AnsiOutput.setEnabled(AnsiOutput.Enabled.ALWAYS);
}

@After
public void tearDown() throws Exception {
AnsiOutput.setEnabled(AnsiOutput.Enabled.DETECT);
}

@Test
public void getPropertyFoundShouldConvertAnsiColor() {
final ZipkinAnsi256ColorPropertySource propertySource = new ZipkinAnsi256ColorPropertySource("test");
final Object property = propertySource.getProperty("ZipkinAnsi256Color.100");
assertThat(property).isEqualTo("\033[38;5;100m");
}

@Test
public void getPropertyNotFoundShouldReturnNull() {
final ZipkinAnsi256ColorPropertySource propertySource = new ZipkinAnsi256ColorPropertySource("test");
final Object property = propertySource.getProperty("foo");
assertThat(property).isNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2015-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.server.internal.banner;

import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;

public class ZipkinAnsi256ColorTest {

@Test
public void testToString() {
final ZipkinAnsi256Color ansi256Color = new ZipkinAnsi256Color(208);
assertThat(ansi256Color.toString()).isEqualTo("38;5;208");
}

@Test
public void testIllegalXtermNumber() {
try {
new ZipkinAnsi256Color(256);
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException e) {
assertThat(e.getMessage()).isEqualTo("'xtermNumber' must be 0-255!");
}
}
}