Restructure packages

This commit is contained in:
Phillip Webb
2013-07-06 18:38:30 -07:00
parent 764a0a9af8
commit 2c05e9f150
90 changed files with 205 additions and 196 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.reflect.Method;
import java.util.ArrayList;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.apache.commons.logging.Log;
import org.springframework.core.type.AnnotatedTypeMetadata;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.springframework.context.annotation.Condition;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.util.ArrayList;
import java.util.List;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.util.ArrayList;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.util.ArrayList;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@@ -14,22 +14,28 @@
* limitations under the License.
*/
package org.springframework.zero.properties;
package org.springframework.zero.context.embedded;
import java.io.File;
import java.net.InetAddress;
import javax.validation.constraints.NotNull;
import org.springframework.zero.context.annotation.ConfigurationProperties;
import org.apache.catalina.valves.AccessLogValve;
import org.apache.catalina.valves.RemoteIpValve;
import org.springframework.util.StringUtils;
import org.springframework.zero.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.zero.context.properties.ConfigurationProperties;
/**
* Properties for the web server (e.g. port and path settings).
* {@link ConfigurationProperties properties} for a web server (e.g. port and path
* settings). Will be used to customize an {@link EmbeddedServletContainerFactory} when an
* {@link EmbeddedServletContainerCustomizerBeanPostProcessor} is active.
*
* @author Dave Syer
*/
@ConfigurationProperties(name = "server", ignoreUnknownFields = false)
public class ServerProperties {
public class ServerProperties implements EmbeddedServletContainerCustomizer {
private int port = 8080;
@@ -68,8 +74,14 @@ public class ServerProperties {
this.address = address;
}
public void setLoader(String value) {
// no op
@Override
public void customize(ConfigurableEmbeddedServletContainerFactory factory) {
factory.setPort(getPort());
factory.setAddress(getAddress());
factory.setContextPath(getContextPath());
if (factory instanceof TomcatEmbeddedServletContainerFactory) {
getTomcat().customizeTomcat((TomcatEmbeddedServletContainerFactory) factory);
}
}
public static class Tomcat {
@@ -114,6 +126,30 @@ public class ServerProperties {
this.remoteIpHeader = remoteIpHeader;
}
void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {
if (getBasedir() != null) {
factory.setBaseDirectory(getBasedir());
}
String remoteIpHeader = getRemoteIpHeader();
String protocolHeader = getProtocolHeader();
if (StringUtils.hasText(remoteIpHeader)
|| StringUtils.hasText(protocolHeader)) {
RemoteIpValve valve = new RemoteIpValve();
valve.setRemoteIpHeader(remoteIpHeader);
valve.setProtocolHeader(protocolHeader);
factory.addContextValves(valve);
}
String accessLogPattern = getAccessLogPattern();
if (accessLogPattern != null) {
AccessLogValve valve = new AccessLogValve();
valve.setPattern(accessLogPattern);
valve.setSuffix(".log");
factory.addContextValves(valve);
}
}
}
}

View File

@@ -338,6 +338,8 @@ public class TomcatEmbeddedServletContainerFactory extends
this.contextLifecycleListeners.addAll(Arrays.asList(contextLifecycleListeners));
}
// FIXME JavaDoc
// FIXME Is this still needed?
public TomcatEmbeddedServletContainerFactory getChildContextFactory(final String name) {
final Server server = this.tomcat.getServer();

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.properties;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@@ -26,7 +26,7 @@ import java.lang.annotation.Target;
* Annotation for externalized configuration. Add this to a class definition if you want
* to bind and validate some external Properties (e.g. from a .properties file).
*
* @see PropertySourcesBindingPostProcessor
* @see ConfigurationPropertiesBindingPostProcessor
*
* @author Dave Syer
*/

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -30,6 +30,8 @@ import org.springframework.core.env.PropertySource;
import org.springframework.core.env.PropertySources;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.zero.context.condition.ConditionalOnClass;
import org.springframework.zero.context.condition.ConditionalOnMissingBean;
/**
* Configuration for binding externalized application properties to
@@ -72,7 +74,7 @@ public class ConfigurationPropertiesBindingConfiguration {
* @return a bean post processor to bind application properties
*/
@Bean
public PropertySourcesBindingPostProcessor propertySourcesBinder() {
public ConfigurationPropertiesBindingPostProcessor propertySourcesBinder() {
PropertySources propertySources;
if (this.configurer != null) {
@@ -87,7 +89,7 @@ public class ConfigurationPropertiesBindingConfiguration {
propertySources = new MutablePropertySources();
}
PropertySourcesBindingPostProcessor processor = new PropertySourcesBindingPostProcessor();
ConfigurationPropertiesBindingPostProcessor processor = new ConfigurationPropertiesBindingPostProcessor();
processor.setValidator(this.validator);
processor.setConversionService(this.conversionService);
processor.setPropertySources(propertySources);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
@@ -29,7 +29,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.env.PropertySources;
import org.springframework.validation.Validator;
import org.springframework.zero.bind.PropertiesConfigurationFactory;
import org.springframework.zero.context.annotation.EnableConfigurationPropertiesImportSelector.ConfigurationPropertiesHolder;
import org.springframework.zero.context.properties.EnableConfigurationPropertiesImportSelector.ConfigurationPropertiesHolder;
/**
* {@link BeanPostProcessor} to bind {@link PropertySources} to beans annotated with
@@ -37,7 +37,7 @@ import org.springframework.zero.context.annotation.EnableConfigurationProperties
*
* @author Dave Syer
*/
public class PropertySourcesBindingPostProcessor implements BeanPostProcessor,
public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProcessor,
BeanFactoryAware {
private PropertySources propertySources;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.properties;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.properties;
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +39,7 @@ import org.springframework.util.MultiValueMap;
*
* @author Dave Syer
*/
public class EnableConfigurationPropertiesImportSelector implements ImportSelector {
class EnableConfigurationPropertiesImportSelector implements ImportSelector {
@Override
public String[] selectImports(AnnotationMetadata metadata) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.zero.context.annotation.ConditionalOnMissingBean;
import org.springframework.zero.context.condition.ConditionalOnMissingBean;
/**
* {@link Conditional} that only matches when the specified bean classes and/or names are

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import java.util.List;
@@ -22,7 +22,7 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.zero.context.annotation.OnMissingBeanCondition;
import org.springframework.zero.context.condition.OnMissingBeanCondition;
/**
* {@link Condition} that checks that specific beans are missing.

View File

@@ -14,14 +14,14 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.zero.context.annotation.ConditionalOnNotWebApplication;
import org.springframework.zero.context.annotation.ConditionalOnWebApplication;
import org.springframework.zero.context.condition.ConditionalOnNotWebApplication;
import org.springframework.zero.context.condition.ConditionalOnWebApplication;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.junit.Ignore;
import org.junit.Test;
@@ -23,6 +23,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.zero.context.condition.ConditionalOnBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -93,13 +93,13 @@ public class OnClassConditionTests {
}
@Configuration
@ImportResource("org/springframework/zero/context/annotation/foo.xml")
@ImportResource("org/springframework/zero/context/foo.xml")
protected static class XmlConfiguration {
}
@Configuration
@Import(BasicConfiguration.class)
@ImportResource("org/springframework/zero/context/annotation/foo.xml")
@ImportResource("org/springframework/zero/context/foo.xml")
protected static class CombinedXmlConfiguration {
}
}

View File

@@ -14,13 +14,13 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.zero.context.annotation.ConditionalOnExpression;
import org.springframework.zero.context.condition.ConditionalOnExpression;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

View File

@@ -14,14 +14,14 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.zero.context.annotation.ConditionalOnMissingBean;
import org.springframework.zero.context.annotation.OnMissingBeanCondition;
import org.springframework.zero.context.condition.ConditionalOnMissingBean;
import org.springframework.zero.context.condition.OnMissingBeanCondition;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -49,7 +49,7 @@ public class OnMissingClassConditionTests {
}
@Configuration
@ConditionalOnMissingClass("org.springframework.zero.context.annotation.OnMissingClassConditionTests")
@ConditionalOnMissingClass("org.springframework.zero.context.condition.OnMissingClassConditionTests")
protected static class BasicConfiguration {
@Bean
public String bar() {

View File

@@ -14,13 +14,13 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.zero.context.annotation.ConditionalOnResource;
import org.springframework.zero.context.condition.ConditionalOnResource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

View File

@@ -14,15 +14,15 @@
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.condition;
import org.junit.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.zero.context.annotation.ConditionalOnNotWebApplication;
import org.springframework.zero.context.annotation.ConditionalOnWebApplication;
import org.springframework.zero.context.condition.ConditionalOnNotWebApplication;
import org.springframework.zero.context.condition.ConditionalOnWebApplication;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.zero.properties;
package org.springframework.zero.context.embedded;
import java.net.InetAddress;
import java.util.Collections;
@@ -24,13 +24,12 @@ import java.util.Map;
import org.junit.Test;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.zero.bind.RelaxedDataBinder;
import org.springframework.zero.properties.ServerProperties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* Externalized configuration for server properties
* Tests for {@link ServerProperties}.
*
* @author Dave Syer
*/
@@ -69,4 +68,6 @@ public class ServerPropertiesTests {
.getProtocolHeader());
}
// FIXME test customize
}

View File

@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.zero.context.annotation;
package org.springframework.zero.context.properties;
import java.util.Arrays;
@@ -28,11 +29,15 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Component;
import org.springframework.zero.TestUtils;
import org.springframework.zero.context.condition.AssertMissingBean;
import org.springframework.zero.context.condition.ConditionalOnMissingBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Tests for {@link EnableConfigurationProperties}.
*
* @author Dave Syer
*/
public class EnableConfigurationPropertiesTests {
@@ -168,7 +173,7 @@ public class EnableConfigurationPropertiesTests {
}
@Configuration
@ImportResource("org/springframework/zero/context/annotation/testProperties.xml")
@ImportResource("org/springframework/zero/context/properties/testProperties.xml")
protected static class DefaultXmlConfiguration {
}

View File

@@ -27,8 +27,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.zero.context.annotation.ConfigurationProperties;
import org.springframework.zero.context.annotation.EnableConfigurationProperties;
import org.springframework.zero.context.properties.ConfigurationProperties;
import org.springframework.zero.context.properties.EnableConfigurationProperties;
import static org.junit.Assert.assertEquals;

View File

@@ -4,8 +4,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean
id="org.springframework.zero.context.annotation.EnableConfigurationPropertiesTests$TestProperties"
class="org.springframework.zero.context.annotation.EnableConfigurationPropertiesTests$TestProperties">
id="org.springframework.zero.context.properties.EnableConfigurationPropertiesTests$TestProperties"
class="org.springframework.zero.context.properties.EnableConfigurationPropertiesTests$TestProperties">
<property name="name" value="bar"/>
</bean>