Add springcli.properties for version labels

[Fixes #53030591] [bs-191] Use filtering in maven build
pull/9/head
Dave Syer 11 years ago
parent c055cf063d
commit fff2a804bc

@ -18,6 +18,7 @@
<spring.security.version>3.2.0.M2</spring.security.version>
<spring.integration.version>2.2.4.RELEASE</spring.integration.version>
<spring.batch.version>2.2.0.RELEASE</spring.batch.version>
<groovy.version>2.1.6</groovy.version>
<tomcat.version>7.0.42</tomcat.version>
<jetty.version>8.1.9.v20130131</jetty.version>
<aspectj.version>1.7.3</aspectj.version>
@ -352,12 +353,12 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.1.6</version>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-templates</artifactId>
<version>2.1.6</version>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>

@ -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;
}
}

@ -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"));
}
}

@ -35,6 +35,12 @@
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>

@ -20,11 +20,14 @@ import groovy.grape.Grape;
import groovy.lang.Grapes;
import groovy.lang.GroovyClassLoader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* Customizer that allows dependencies to be added during compilation. Delegates to Groovy
@ -40,6 +43,8 @@ public class DependencyCustomizer {
private final List<Map<String, Object>> dependencies;
private Properties properties;
/**
* Create a new {@link DependencyCustomizer} instance. The {@link #call()} method must
* be used to actually resolve dependencies.
@ -59,6 +64,26 @@ public class DependencyCustomizer {
this.dependencies = parent.dependencies;
}
public String getProperty(String key) {
return getProperty(key, "");
}
public String getProperty(String key, String defaultValue) {
if (this.properties == null) {
this.properties = new Properties();
try {
for (URL url : Collections.list(this.loader
.getResources("META-INF/springcli.properties"))) {
this.properties.load(url.openStream());
}
}
catch (Exception e) {
// swallow and continue
}
}
return this.properties.getProperty(key, defaultValue);
}
/**
* Create a nested {@link DependencyCustomizer} that only applies if any of the
* specified class names are not on the class path.

@ -38,9 +38,11 @@ public class SpringBatchCompilerAutoConfiguration extends CompilerAutoConfigurat
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies.ifAnyMissingClasses("org.springframework.batch.core.Job").add(
"org.springframework.batch", "spring-batch-core", "2.2.0.RC2");
"org.springframework.batch", "spring-batch-core",
dependencies.getProperty("spring.batch.version", "2.2.0.RELEASE"));
dependencies.ifAnyMissingClasses("org.springframework.jdbc.core.JdbcTemplate")
.add("org.springframework", "spring-jdbc", "4.0.0.BUILD-SNAPSHOT");
.add("org.springframework", "spring-jdbc",
dependencies.getProperty("spring.version"));
}
@Override

@ -40,8 +40,8 @@ public class SpringCompilerAutoConfiguration extends CompilerAutoConfiguration {
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies.ifAnyMissingClasses(
"org.springframework.bootstrap.SpringApplication").add(
"org.springframework.zero", "spring-starter", "0.5.0.BUILD-SNAPSHOT");
// FIXME get the version
"org.springframework.zero", "spring-starter",
dependencies.getProperty("spring.zero.version"));
}
@Override
@ -73,7 +73,7 @@ public class SpringCompilerAutoConfiguration extends CompilerAutoConfiguration {
public void applyToMainClass(GroovyClassLoader loader,
GroovyCompilerConfiguration configuration, GeneratorContext generatorContext,
SourceUnit source, ClassNode classNode) throws CompilationFailedException {
// FIXME: add switch for auto config
// Could add switch for auto config, but it seems like it wouldn't get used much
addEnableAutoConfigurationAnnotation(source, classNode);
}

@ -48,11 +48,14 @@ public class SpringIntegrationCompilerAutoConfiguration extends CompilerAutoConf
dependencies
.ifAnyMissingClasses("org.springframework.integration.Message")
.add("org.springframework.integration", "spring-integration-core",
"2.2.3.RELEASE")
dependencies.getProperty("spring.integration.version"))
.add("org.springframework.integration",
"spring-integration-dsl-groovy-core", "1.0.0.M1");
"spring-integration-dsl-groovy-core",
dependencies.getProperty("spring.integration.dsl.version",
"1.0.0.M1"));
dependencies.ifAnyMissingClasses("groovy.util.XmlParser").add(
"org.codehaus.groovy", "groovy-xml", "2.1.6");
"org.codehaus.groovy", "groovy-xml",
dependencies.getProperty("groovy.version"));
}
@Override

@ -34,18 +34,21 @@ public class SpringMvcCompilerAutoConfiguration extends CompilerAutoConfiguratio
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies
.ifAnyMissingClasses("org.springframework.web.servlet.mvc.Controller")
.add("org.springframework", "spring-webmvc", "4.0.0.BUILD-SNAPSHOT");
.add("org.springframework", "spring-webmvc",
dependencies.getProperty("spring.version"));
dependencies.ifAnyMissingClasses("org.apache.catalina.startup.Tomcat",
"org.eclipse.jetty.server.Server").add("org.eclipse.jetty",
"jetty-webapp", "8.1.10.v20130312");
dependencies.ifAnyMissingClasses("org.eclipse.jetty.server.Server").add(
"org.eclipse.jetty", "jetty-webapp",
dependencies.getProperty("jetty.version"));
dependencies.add("org.codehaus.groovy", "groovy-templates", "2.1.6");
dependencies.add("org.codehaus.groovy", "groovy-templates",
dependencies.getProperty("groovy.version"));
// FIXME restore Tomcat when we can get reload to work
// dependencies.ifMissingClasses("org.apache.catalina.startup.Tomcat",
// "org.eclipse.jetty.server.Server")
// .add("org.apache.tomcat.embed", "tomcat-embed-core", "7.0.39")
// .add("org.apache.tomcat.embed", "tomcat-embed-logging-juli", "7.0.39");
// dependencies.ifMissingClasses("org.apache.catalina.startup.Tomcat")
// .add("org.apache.tomcat.embed", "tomcat-embed-core",
// dependencies.getProperty("tomcat.version"))
// .add("org.apache.tomcat.embed", "tomcat-embed-logging-juli",
// dependencies.getProperty("tomcat.version"));
}
@Override

@ -0,0 +1,7 @@
spring.zero.version: ${project.version}
spring.version: ${spring.version}
spring.batch.version: ${spring.batch.version}
spring.integration.version: ${spring.integration.version}
groovy.version: ${groovy.version}
jetty.version: ${jetty.version}
tomcat.version: ${tomcat.version}

@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- NOTE: Intentionally does not inherit from root parent. Autogenerated,
from ../src/main/parent do not edit. -->
do not edit. -->
<groupId>org.springframework.zero</groupId>
<artifactId>spring-starter-parent</artifactId>
<version>0.5.0.BUILD-SNAPSHOT</version>

@ -1,7 +0,0 @@
handlers = java.util.logging.ConsoleHandler
.level = INFO
java.util.logging.ConsoleHandler.level = FINE
sun.net.www.protocol.http.HttpURLConnection.level = ALL
org.springframework.zero.context.annotation.level = ALL
org.springframework.zero.actuate.autoconfigure.level = ALL

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } [%t] --- %-40.40logger{39} : %m%n%wex"/>
<conversionRule conversionWord="wex" converterClass="org.springframework.bootstrap.logging.logback.WhitespaceThrowableProxyConverter" />
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<!--logger name="org.springframework.zero" level="DEBUG"/>
<logger name="org.springframework.security" level="DEBUG"/-->
</configuration>

@ -1,7 +0,0 @@
handlers = java.util.logging.ConsoleHandler
.level = INFO
#java.util.logging.ConsoleHandler.level = FINE
#sun.net.www.protocol.http.HttpURLConnection.level = ALL
#org.springframework.zero.level = ALL
#org.springframework.security.level = ALL

@ -1,6 +0,0 @@
handlers = java.util.logging.ConsoleHandler
.level = INFO
java.util.logging.ConsoleHandler.level = FINE
sun.net.www.protocol.http.HttpURLConnection.level = ALL
org.springframework.zero.context.annotation.level = ALL
Loading…
Cancel
Save