Add springcli.properties for version labels

[Fixes #53030591] [bs-191] Use filtering in maven build
This commit is contained in:
Dave Syer
2013-07-18 16:27:59 +01:00
parent c055cf063d
commit fff2a804bc
15 changed files with 156 additions and 46 deletions

View File

@@ -25,6 +25,7 @@ import java.security.ProtectionDomain;
import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -47,11 +48,17 @@ class StartupInfoLogger {
StringBuilder message = new StringBuilder();
message.append("Starting ");
message.append(getApplicationName());
message.append(getVersion());
message.append(getVersion(this.sourceClass));
message.append(getOn());
message.append(getPid());
message.append(getContext());
log.info(message);
message.setLength(0);
message.append("Running with Spring Bootstrap");
message.append(getVersion(SpringApplication.class));
message.append(", Spring");
message.append(getVersion(ApplicationContext.class));
log.info(message);
}
private String getApplicationName() {
@@ -59,14 +66,13 @@ class StartupInfoLogger {
: "application");
}
private String getVersion() {
private String getVersion(final Class<?> source) {
return getValue(" v", new Callable<Object>() {
@Override
public Object call() throws Exception {
return StartupInfoLogger.this.sourceClass.getPackage()
.getImplementationVersion();
return source.getPackage().getImplementationVersion();
}
});
}, " v[N/A]");
}
private String getOn() {
@@ -129,6 +135,10 @@ class StartupInfoLogger {
}
private String getValue(String prefix, Callable<Object> call) {
return getValue(prefix, call, "");
}
private String getValue(String prefix, Callable<Object> call, String defaultValue) {
try {
Object value = call.call();
if (value != null && StringUtils.hasLength(value.toString())) {
@@ -138,6 +148,6 @@ class StartupInfoLogger {
catch (Exception ex) {
// Swallow and continue
}
return "";
return defaultValue;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2012-2013 the original author or 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 org.springframework.bootstrap;
import org.apache.commons.logging.impl.SimpleLog;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
* @author Dave Syer
*/
public class StartUpLoggerInfoTests {
private StringBuffer output = new StringBuffer();
private SimpleLog log = new SimpleLog("test") {
@Override
protected void write(StringBuffer buffer) {
StartUpLoggerInfoTests.this.output.append(buffer).append("\n");
};
};
@Test
public void sourceClassIncluded() {
new StartupInfoLogger(getClass()).log(this.log);
assertTrue("Wrong output: " + this.output,
this.output.toString().contains("Starting " + getClass().getSimpleName()));
// System.err.println(this.output);
}
@Test
public void bootstrapVersionIncluded() {
new StartupInfoLogger(getClass()).log(this.log);
assertTrue("Wrong output: " + this.output,
this.output.toString().contains("Spring Bootstrap v"));
}
}