mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish and fix sonar warnings
This commit is contained in:
parent
346a0bace7
commit
9fde0a3715
@ -67,6 +67,13 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>spring-zero-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.tomcat.embed</groupId>
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
<artifactId>tomcat-embed-logging-juli</artifactId>
|
<artifactId>tomcat-embed-logging-juli</artifactId>
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.autoconfigure;
|
package org.springframework.zero.actuate.autoconfigure;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -67,9 +67,6 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
|||||||
|
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private ServerProperties serverProperties = new ServerProperties();
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private ManagementServerProperties managementServerProperties = new ManagementServerProperties();
|
private ManagementServerProperties managementServerProperties = new ManagementServerProperties();
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.autoconfigure;
|
package org.springframework.zero.actuate.autoconfigure;
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.autoconfigure;
|
package org.springframework.zero.actuate.autoconfigure;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -112,7 +112,7 @@ public class MetricFilterAutoConfiguration {
|
|||||||
try {
|
try {
|
||||||
return response.getStatus();
|
return response.getStatus();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
return UNDEFINED_HTTP_STATUS;
|
return UNDEFINED_HTTP_STATUS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.autoconfigure;
|
package org.springframework.zero.actuate.autoconfigure;
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
import javax.servlet.Servlet;
|
||||||
|
@ -62,7 +62,8 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> impl
|
|||||||
try {
|
try {
|
||||||
Thread.sleep(500L);
|
Thread.sleep(500L);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException ex) {
|
||||||
|
// Swallow exception and continue
|
||||||
}
|
}
|
||||||
ShutdownEndpoint.this.context.close();
|
ShutdownEndpoint.this.context.close();
|
||||||
}
|
}
|
||||||
|
@ -50,9 +50,9 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
|||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @see EndpointHandlerMapping
|
* @see EndpointHandlerMapping
|
||||||
*/
|
*/
|
||||||
public class EndpointHandlerAdapter implements HandlerAdapter {
|
public final class EndpointHandlerAdapter implements HandlerAdapter {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(EndpointHandlerAdapter.class);
|
private final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private static final MediaType MEDIA_TYPE_APPLICATION = new MediaType("application");
|
private static final MediaType MEDIA_TYPE_APPLICATION = new MediaType("application");
|
||||||
|
|
||||||
@ -102,8 +102,8 @@ public class EndpointHandlerAdapter implements HandlerAdapter {
|
|||||||
if (messageConverter.canWrite(resultClass, selectedMediaType)) {
|
if (messageConverter.canWrite(resultClass, selectedMediaType)) {
|
||||||
((HttpMessageConverter<Object>) messageConverter).write(result,
|
((HttpMessageConverter<Object>) messageConverter).write(result,
|
||||||
selectedMediaType, outputMessage);
|
selectedMediaType, outputMessage);
|
||||||
if (logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
logger.debug("Written [" + result + "] as \""
|
this.logger.debug("Written [" + result + "] as \""
|
||||||
+ selectedMediaType + "\" using [" + messageConverter
|
+ selectedMediaType + "\" using [" + messageConverter
|
||||||
+ "]");
|
+ "]");
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.endpoint.mvc;
|
package org.springframework.zero.actuate.endpoint.mvc;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -46,7 +46,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
*/
|
*/
|
||||||
public class WebRequestTraceFilter implements Filter, Ordered {
|
public class WebRequestTraceFilter implements Filter, Ordered {
|
||||||
|
|
||||||
final Log logger = LogFactory.getLog(WebRequestTraceFilter.class);
|
private final Log logger = LogFactory.getLog(WebRequestTraceFilter.class);
|
||||||
|
|
||||||
private boolean dumpRequests = false;
|
private boolean dumpRequests = false;
|
||||||
|
|
||||||
@ -102,8 +102,8 @@ public class WebRequestTraceFilter implements Filter, Ordered {
|
|||||||
this.logger.trace("Headers: "
|
this.logger.trace("Headers: "
|
||||||
+ this.objectMapper.writeValueAsString(headers));
|
+ this.objectMapper.writeValueAsString(headers));
|
||||||
}
|
}
|
||||||
catch (JsonProcessingException e) {
|
catch (JsonProcessingException ex) {
|
||||||
throw new IllegalStateException("Cannot create JSON", e);
|
throw new IllegalStateException("Cannot create JSON", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@ import org.springframework.zero.context.embedded.AbstractEmbeddedServletContaine
|
|||||||
@Controller
|
@Controller
|
||||||
public class BasicErrorController implements ErrorController {
|
public class BasicErrorController implements ErrorController {
|
||||||
|
|
||||||
|
private static final String ERROR_KEY = "error";
|
||||||
|
|
||||||
private Log logger = LogFactory.getLog(BasicErrorController.class);
|
private Log logger = LogFactory.getLog(BasicErrorController.class);
|
||||||
|
|
||||||
@Value("${error.path:/error}")
|
@Value("${error.path:/error}")
|
||||||
@ -60,7 +62,7 @@ public class BasicErrorController implements ErrorController {
|
|||||||
@RequestMapping(value = "${error.path:/error}", produces = "text/html")
|
@RequestMapping(value = "${error.path:/error}", produces = "text/html")
|
||||||
public ModelAndView errorHtml(HttpServletRequest request) {
|
public ModelAndView errorHtml(HttpServletRequest request) {
|
||||||
Map<String, Object> map = error(request);
|
Map<String, Object> map = error(request);
|
||||||
return new ModelAndView("error", map);
|
return new ModelAndView(ERROR_KEY, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "${error.path:/error}")
|
@RequestMapping(value = "${error.path:/error}")
|
||||||
@ -75,10 +77,10 @@ public class BasicErrorController implements ErrorController {
|
|||||||
int status = 999;
|
int status = 999;
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
status = (Integer) obj;
|
status = (Integer) obj;
|
||||||
map.put("error", HttpStatus.valueOf(status).getReasonPhrase());
|
map.put(ERROR_KEY, HttpStatus.valueOf(status).getReasonPhrase());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
map.put("error", "None");
|
map.put(ERROR_KEY, "None");
|
||||||
}
|
}
|
||||||
map.put("status", status);
|
map.put("status", status);
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
@ -102,10 +104,10 @@ public class BasicErrorController implements ErrorController {
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
map.put("error", e.getClass().getName());
|
map.put(ERROR_KEY, ex.getClass().getName());
|
||||||
map.put("message", e.getMessage());
|
map.put("message", ex.getMessage());
|
||||||
this.logger.error(e);
|
this.logger.error(ex);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.zero.actuate;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.core.env.MapPropertySource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class TestUtils {
|
|
||||||
|
|
||||||
public static void addEnviroment(ConfigurableApplicationContext context,
|
|
||||||
String... pairs) {
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
|
||||||
for (String pair : pairs) {
|
|
||||||
int index = pair.indexOf(":");
|
|
||||||
String key = pair.substring(0, index > 0 ? index : pair.length());
|
|
||||||
String value = index > 0 ? pair.substring(index + 1) : "";
|
|
||||||
map.put(key, value);
|
|
||||||
}
|
|
||||||
context.getEnvironment().getPropertySources()
|
|
||||||
.addFirst(new MapPropertySource("test", map));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.audit.listener;
|
package org.springframework.zero.actuate.audit.listener;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -20,8 +21,6 @@ import java.util.Collections;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.zero.actuate.audit.AuditEvent;
|
import org.springframework.zero.actuate.audit.AuditEvent;
|
||||||
import org.springframework.zero.actuate.audit.AuditEventRepository;
|
import org.springframework.zero.actuate.audit.AuditEventRepository;
|
||||||
import org.springframework.zero.actuate.audit.listener.AuditApplicationEvent;
|
|
||||||
import org.springframework.zero.actuate.audit.listener.AuditListener;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.autoconfigure;
|
package org.springframework.zero.actuate.autoconfigure;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.zero.actuate.TestUtils;
|
import org.springframework.zero.TestUtils;
|
||||||
import org.springframework.zero.actuate.autoconfigure.EndpointAutoConfiguration;
|
|
||||||
import org.springframework.zero.actuate.endpoint.BeansEndpoint;
|
import org.springframework.zero.actuate.endpoint.BeansEndpoint;
|
||||||
import org.springframework.zero.actuate.endpoint.DumpEndpoint;
|
import org.springframework.zero.actuate.endpoint.DumpEndpoint;
|
||||||
import org.springframework.zero.actuate.endpoint.EnvironmentEndpoint;
|
import org.springframework.zero.actuate.endpoint.EnvironmentEndpoint;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.autoconfigure;
|
package org.springframework.zero.actuate.autoconfigure;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -32,9 +33,7 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.util.StreamUtils;
|
import org.springframework.util.StreamUtils;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.zero.actuate.TestUtils;
|
import org.springframework.zero.TestUtils;
|
||||||
import org.springframework.zero.actuate.autoconfigure.EndpointWebMvcAutoConfiguration;
|
|
||||||
import org.springframework.zero.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration;
|
|
||||||
import org.springframework.zero.actuate.endpoint.AbstractEndpoint;
|
import org.springframework.zero.actuate.endpoint.AbstractEndpoint;
|
||||||
import org.springframework.zero.actuate.endpoint.Endpoint;
|
import org.springframework.zero.actuate.endpoint.Endpoint;
|
||||||
import org.springframework.zero.actuate.properties.ManagementServerProperties;
|
import org.springframework.zero.actuate.properties.ManagementServerProperties;
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.autoconfigure;
|
package org.springframework.zero.actuate.autoconfigure;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.zero.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration;
|
|
||||||
import org.springframework.zero.actuate.properties.ManagementServerProperties;
|
import org.springframework.zero.actuate.properties.ManagementServerProperties;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
@ -24,8 +24,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
|||||||
import org.springframework.core.env.MapPropertySource;
|
import org.springframework.core.env.MapPropertySource;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.zero.actuate.TestUtils;
|
import org.springframework.zero.TestUtils;
|
||||||
import org.springframework.zero.actuate.endpoint.Endpoint;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.actuate.metrics;
|
package org.springframework.zero.actuate.metrics;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.zero.actuate.metrics.InMemoryMetricRepository;
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.autoconfigure;
|
package org.springframework.zero.autoconfigure;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -28,20 +28,20 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|||||||
* Convenience class for storing base packages during component scan, for reference later
|
* Convenience class for storing base packages during component scan, for reference later
|
||||||
* (e.g. by JPA entity scanner).
|
* (e.g. by JPA entity scanner).
|
||||||
*
|
*
|
||||||
* @author Phil Webb
|
* @author Phillip Webb
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public abstract class AutoConfigurationUtils {
|
public abstract class AutoConfigurationUtils {
|
||||||
|
|
||||||
private static String BASE_PACKAGES_BEAN = AutoConfigurationUtils.class.getName()
|
private static final String BASE_PACKAGES_BEAN = AutoConfigurationUtils.class
|
||||||
+ ".basePackages";
|
.getName() + ".basePackages";
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<String> getBasePackages(BeanFactory beanFactory) {
|
public static List<String> getBasePackages(BeanFactory beanFactory) {
|
||||||
try {
|
try {
|
||||||
return beanFactory.getBean(BASE_PACKAGES_BEAN, List.class);
|
return beanFactory.getBean(BASE_PACKAGES_BEAN, List.class);
|
||||||
}
|
}
|
||||||
catch (NoSuchBeanDefinitionException e) {
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.autoconfigure;
|
package org.springframework.zero.autoconfigure;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
@ -59,9 +59,9 @@ public class BasicDataSourceConfiguration extends AbstractDataSourceConfiguratio
|
|||||||
try {
|
try {
|
||||||
this.pool.close();
|
this.pool.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
catch (SQLException ex) {
|
||||||
throw new DataAccessResourceFailureException(
|
throw new DataAccessResourceFailureException(
|
||||||
"Could not close data source", e);
|
"Could not close data source", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class DataSourceAutoConfiguration {
|
|||||||
|
|
||||||
static class SomeDatabaseCondition implements Condition {
|
static class SomeDatabaseCondition implements Condition {
|
||||||
|
|
||||||
protected Log logger = LogFactory.getLog(getClass());
|
private Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private Condition tomcatCondition = new TomcatDatabaseCondition();
|
private Condition tomcatCondition = new TomcatDatabaseCondition();
|
||||||
|
|
||||||
@ -157,24 +157,22 @@ public class DataSourceAutoConfiguration {
|
|||||||
|| this.dbcpCondition.matches(context, metadata)
|
|| this.dbcpCondition.matches(context, metadata)
|
||||||
|| this.embeddedCondition.matches(context, metadata)) {
|
|| this.embeddedCondition.matches(context, metadata)) {
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
this.logger.debug(checking
|
this.logger.debug(checking + "Existing auto database "
|
||||||
+ "Existing auto database detected: match result true");
|
+ "detected: match result true");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
|
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
|
||||||
context.getBeanFactory(), DataSource.class, true, false).length > 0) {
|
context.getBeanFactory(), DataSource.class, true, false).length > 0) {
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
this.logger
|
this.logger.debug(checking + "Existing bean configured database "
|
||||||
.debug(checking
|
+ "detected: match result true");
|
||||||
+ "Existing bean configured database detected: match result true");
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
this.logger
|
this.logger.debug(checking + "Existing bean configured database not "
|
||||||
.debug(checking
|
+ "detected: match result false");
|
||||||
+ "Existing bean configured database not detected: match result false");
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -210,7 +208,7 @@ public class DataSourceAutoConfiguration {
|
|||||||
|
|
||||||
static abstract class NonEmbeddedDatabaseCondition implements Condition {
|
static abstract class NonEmbeddedDatabaseCondition implements Condition {
|
||||||
|
|
||||||
protected Log logger = LogFactory.getLog(getClass());
|
private Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
protected abstract String getDataSourecClassName();
|
protected abstract String getDataSourecClassName();
|
||||||
|
|
||||||
@ -225,9 +223,29 @@ public class DataSourceAutoConfiguration {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String driverClassName = getDriverClassName(context, checking);
|
||||||
|
String url = getUrl(context);
|
||||||
|
|
||||||
|
if (driverClassName != null && url != null
|
||||||
|
&& ClassUtils.isPresent(driverClassName, null)) {
|
||||||
|
if (this.logger.isDebugEnabled()) {
|
||||||
|
this.logger.debug(checking + "Driver class " + driverClassName
|
||||||
|
+ " found");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.logger.isDebugEnabled()) {
|
||||||
|
this.logger.debug(checking + "Driver class " + driverClassName
|
||||||
|
+ " not found");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDriverClassName(ConditionContext context, String checking) {
|
||||||
String driverClassName = context.getEnvironment().getProperty(
|
String driverClassName = context.getEnvironment().getProperty(
|
||||||
"spring.database.driverClassName");
|
"spring.database.driverClassName");
|
||||||
String url = context.getEnvironment().getProperty("spring.database.url");
|
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
this.logger.debug(checking
|
this.logger.debug(checking
|
||||||
+ "Spring JDBC detected (embedded database type is "
|
+ "Spring JDBC detected (embedded database type is "
|
||||||
@ -238,31 +256,23 @@ public class DataSourceAutoConfiguration {
|
|||||||
.getEmbeddedDatabaseDriverClass(EmbeddedDatabaseConfiguration
|
.getEmbeddedDatabaseDriverClass(EmbeddedDatabaseConfiguration
|
||||||
.getEmbeddedDatabaseType());
|
.getEmbeddedDatabaseType());
|
||||||
}
|
}
|
||||||
|
return driverClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getUrl(ConditionContext context) {
|
||||||
|
String url = context.getEnvironment().getProperty("spring.database.url");
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
url = EmbeddedDatabaseConfiguration
|
url = EmbeddedDatabaseConfiguration
|
||||||
.getEmbeddedDatabaseUrl(EmbeddedDatabaseConfiguration
|
.getEmbeddedDatabaseUrl(EmbeddedDatabaseConfiguration
|
||||||
.getEmbeddedDatabaseType());
|
.getEmbeddedDatabaseType());
|
||||||
}
|
}
|
||||||
if (driverClassName != null && url != null
|
return url;
|
||||||
&& ClassUtils.isPresent(driverClassName, null)) {
|
|
||||||
if (this.logger.isDebugEnabled()) {
|
|
||||||
this.logger.debug(checking + "Driver class " + driverClassName
|
|
||||||
+ " found");
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (this.logger.isDebugEnabled()) {
|
|
||||||
this.logger.debug(checking + "Driver class " + driverClassName
|
|
||||||
+ " not found");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class EmbeddedDatabaseCondition implements Condition {
|
static class EmbeddedDatabaseCondition implements Condition {
|
||||||
|
|
||||||
protected Log logger = LogFactory.getLog(getClass());
|
private Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private Condition tomcatCondition = new TomcatDatabaseCondition();
|
private Condition tomcatCondition = new TomcatDatabaseCondition();
|
||||||
|
|
||||||
@ -276,9 +286,8 @@ public class DataSourceAutoConfiguration {
|
|||||||
if (this.tomcatCondition.matches(context, metadata)
|
if (this.tomcatCondition.matches(context, metadata)
|
||||||
|| this.dbcpCondition.matches(context, metadata)) {
|
|| this.dbcpCondition.matches(context, metadata)) {
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
this.logger
|
this.logger.debug(checking + "Existing non-embedded "
|
||||||
.debug(checking
|
+ "database detected: match result false");
|
||||||
+ "Existing non-embedded database detected: match result false");
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -43,14 +43,6 @@ import org.springframework.zero.context.condition.ConditionalOnClass;
|
|||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration {
|
public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration {
|
||||||
|
|
||||||
public static enum DDLAUTO {
|
|
||||||
none, validate, update, create, create_drop;
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return this.name().toLowerCase().replace("_", "-");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Map<EmbeddedDatabaseType, String> EMBEDDED_DATABASE_DIALECTS;
|
private static final Map<EmbeddedDatabaseType, String> EMBEDDED_DATABASE_DIALECTS;
|
||||||
static {
|
static {
|
||||||
EMBEDDED_DATABASE_DIALECTS = new LinkedHashMap<EmbeddedDatabaseType, String>();
|
EMBEDDED_DATABASE_DIALECTS = new LinkedHashMap<EmbeddedDatabaseType, String>();
|
||||||
@ -68,7 +60,7 @@ public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration {
|
|||||||
private boolean showSql;
|
private boolean showSql;
|
||||||
|
|
||||||
@Value("${spring.jpa.ddlAuto:${spring.jpa.ddl_auto:none}}")
|
@Value("${spring.jpa.ddlAuto:${spring.jpa.ddl_auto:none}}")
|
||||||
private DDLAUTO ddlAuto;
|
private String ddlAuto; // e.g. none, validate, update, create, create-drop
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Override
|
@Override
|
||||||
@ -89,10 +81,9 @@ public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration {
|
|||||||
// FIXME: detect EhCache
|
// FIXME: detect EhCache
|
||||||
properties.put("hibernate.cache.provider_class",
|
properties.put("hibernate.cache.provider_class",
|
||||||
"org.hibernate.cache.HashtableCacheProvider");
|
"org.hibernate.cache.HashtableCacheProvider");
|
||||||
if (this.ddlAuto != DDLAUTO.none) {
|
if (StringUtils.hasLength(this.ddlAuto) && !"none".equals(this.ddlAuto)) {
|
||||||
properties.put("hibernate.hbm2ddl.auto", this.ddlAuto.toString());
|
properties.put("hibernate.hbm2ddl.auto", this.ddlAuto);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public abstract class JpaAutoConfiguration implements BeanFactoryAware {
|
|||||||
return EmbeddedDatabaseConfiguration.class.getName().equals(
|
return EmbeddedDatabaseConfiguration.class.getName().equals(
|
||||||
beanDefinition.getFactoryBeanName());
|
beanDefinition.getFactoryBeanName());
|
||||||
}
|
}
|
||||||
catch (NoSuchBeanDefinitionException e) {
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ public abstract class JpaAutoConfiguration implements BeanFactoryAware {
|
|||||||
try {
|
try {
|
||||||
return this.beanFactory.getBean("dataSource", DataSource.class);
|
return this.beanFactory.getBean("dataSource", DataSource.class);
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException ex) {
|
||||||
return this.beanFactory.getBean(DataSource.class);
|
return this.beanFactory.getBean(DataSource.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public class ThymeleafAutoConfiguration {
|
|||||||
return DefaultTemplateResolverConfiguration.this.resourceLoader
|
return DefaultTemplateResolverConfiguration.this.resourceLoader
|
||||||
.getResource(resourceName).getInputStream();
|
.getResource(resourceName).getInputStream();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ import org.springframework.zero.autoconfigure.EnableAutoConfiguration;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
public class Spring {
|
public abstract class Spring {
|
||||||
|
|
||||||
// FIXME can we delete this? is it used? does it belong here
|
// FIXME can we delete this? is it used? does it belong here
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.autoconfigure;
|
package org.springframework.zero.autoconfigure;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -25,8 +26,6 @@ import org.junit.rules.ExpectedException;
|
|||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
import org.springframework.core.io.DefaultResourceLoader;
|
||||||
import org.springframework.zero.autoconfigure.AutoConfigurationSorter;
|
|
||||||
import org.springframework.zero.autoconfigure.AutoConfigureAfter;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
@ -23,12 +23,12 @@ import java.util.Map;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.core.env.MapPropertySource;
|
import org.springframework.core.env.MapPropertySource;
|
||||||
import org.springframework.zero.autoconfigure.MessageSourceAutoConfiguration;
|
|
||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link MessageSourceAutoConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class MessageSourceAutoConfigurationTests {
|
public class MessageSourceAutoConfigurationTests {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.autoconfigure;
|
package org.springframework.zero.autoconfigure;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -24,7 +25,6 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
||||||
import org.springframework.zero.autoconfigure.SpringJUnitTests.TestConfiguration;
|
import org.springframework.zero.autoconfigure.SpringJUnitTests.TestConfiguration;
|
||||||
import org.springframework.zero.context.initializer.ConfigFileApplicationContextInitializer;
|
import org.springframework.zero.context.initializer.ConfigFileApplicationContextInitializer;
|
||||||
|
|
||||||
@ -33,7 +33,6 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = TestConfiguration.class, initializers = ConfigFileApplicationContextInitializer.class)
|
@ContextConfiguration(classes = TestConfiguration.class, initializers = ConfigFileApplicationContextInitializer.class)
|
||||||
|
@ -34,13 +34,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.batch.BatchAutoConfiguration;
|
|
||||||
import org.springframework.zero.autoconfigure.batch.JobLauncherCommandLineRunner;
|
|
||||||
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link BatchAutoConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class BatchAutoConfigurationTests {
|
public class BatchAutoConfigurationTests {
|
||||||
|
@ -19,12 +19,12 @@ package org.springframework.zero.autoconfigure.batch;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.batch.core.BatchStatus;
|
import org.springframework.batch.core.BatchStatus;
|
||||||
import org.springframework.batch.core.JobExecution;
|
import org.springframework.batch.core.JobExecution;
|
||||||
import org.springframework.zero.autoconfigure.batch.JobExecutionEvent;
|
|
||||||
import org.springframework.zero.autoconfigure.batch.JobExecutionExitCodeGenerator;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link JobExecutionExitCodeGenerator}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class JobExecutionExitCodeGeneratorTests {
|
public class JobExecutionExitCodeGeneratorTests {
|
||||||
|
@ -25,7 +25,6 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.zero.autoconfigure.ComponentScanDetectorConfiguration;
|
import org.springframework.zero.autoconfigure.ComponentScanDetectorConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.data.JpaRepositoriesAutoConfiguration;
|
|
||||||
import org.springframework.zero.autoconfigure.data.test.City;
|
import org.springframework.zero.autoconfigure.data.test.City;
|
||||||
import org.springframework.zero.autoconfigure.data.test.CityRepository;
|
import org.springframework.zero.autoconfigure.data.test.CityRepository;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
||||||
@ -34,6 +33,8 @@ import org.springframework.zero.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link JpaRepositoriesAutoConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class JpaRepositoriesAutoConfigurationTests {
|
public class JpaRepositoriesAutoConfigurationTests {
|
||||||
|
@ -24,7 +24,6 @@ import org.springframework.data.repository.support.DomainClassConverter;
|
|||||||
import org.springframework.mock.web.MockServletContext;
|
import org.springframework.mock.web.MockServletContext;
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.data.JpaRepositoriesAutoConfiguration;
|
|
||||||
import org.springframework.zero.autoconfigure.data.test.City;
|
import org.springframework.zero.autoconfigure.data.test.City;
|
||||||
import org.springframework.zero.autoconfigure.data.test.CityRepository;
|
import org.springframework.zero.autoconfigure.data.test.CityRepository;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
||||||
@ -36,7 +35,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
@Ignore
|
@Ignore
|
||||||
// until spring data commons 1.6.0, jpa 1.5.0 available
|
// FIXME until spring data commons 1.6.0, jpa 1.5.0 available
|
||||||
public class JpaWebAutoConfigurationTests {
|
public class JpaWebAutoConfigurationTests {
|
||||||
|
|
||||||
private AnnotationConfigWebApplicationContext context;
|
private AnnotationConfigWebApplicationContext context;
|
||||||
|
@ -20,11 +20,12 @@ import javax.sql.DataSource;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.BasicDataSourceConfiguration;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link BasicDataSourceConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class BasicDataSourceConfigurationTests {
|
public class BasicDataSourceConfigurationTests {
|
||||||
|
@ -32,13 +32,14 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link DataSourceAutoConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class DataSourceAutoConfigurationTests {
|
public class DataSourceAutoConfigurationTests {
|
||||||
|
@ -21,13 +21,13 @@ import javax.sql.DataSource;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
|
||||||
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link DataSourceTransactionManagerAutoConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class DataSourceTransactionManagerAutoConfigurationTests {
|
public class DataSourceTransactionManagerAutoConfigurationTests {
|
||||||
|
@ -20,11 +20,12 @@ import javax.sql.DataSource;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link EmbeddedDatabaseConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class EmbeddedDatabaseConfigurationTests {
|
public class EmbeddedDatabaseConfigurationTests {
|
||||||
|
@ -28,12 +28,12 @@ import org.springframework.beans.factory.BeanCreationException;
|
|||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
|
||||||
import org.springframework.zero.autoconfigure.jdbc.TomcatDataSourceConfiguration;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link TomcatDataSourceConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class TomcatDataSourceConfigurationTests {
|
public class TomcatDataSourceConfigurationTests {
|
||||||
|
@ -26,13 +26,14 @@ import org.springframework.zero.autoconfigure.ComponentScanDetectorConfiguration
|
|||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
import org.springframework.zero.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
import org.springframework.zero.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
|
||||||
import org.springframework.zero.autoconfigure.orm.jpa.test.City;
|
import org.springframework.zero.autoconfigure.orm.jpa.test.City;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link HibernateJpaAutoConfiguration}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class HibernateJpaAutoConfigurationTests {
|
public class HibernateJpaAutoConfigurationTests {
|
||||||
|
@ -30,7 +30,6 @@ import org.springframework.mock.web.MockServletContext;
|
|||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
import org.springframework.web.servlet.support.RequestContext;
|
import org.springframework.web.servlet.support.RequestContext;
|
||||||
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.zero.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
|
|
||||||
import org.thymeleaf.TemplateEngine;
|
import org.thymeleaf.TemplateEngine;
|
||||||
import org.thymeleaf.context.Context;
|
import org.thymeleaf.context.Context;
|
||||||
import org.thymeleaf.spring3.view.ThymeleafView;
|
import org.thymeleaf.spring3.view.ThymeleafView;
|
||||||
@ -40,6 +39,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link ThymeleafAutoConfiguration}
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class ThymeleafAutoConfigurationTests {
|
public class ThymeleafAutoConfigurationTests {
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.autoconfigure.web;
|
package org.springframework.zero.autoconfigure.web;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.springframework.zero.autoconfigure.web.WebMvcAutoConfiguration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link WebMvcAutoConfiguration}.
|
* Tests for {@link WebMvcAutoConfiguration}.
|
||||||
@ -25,6 +25,7 @@ import org.springframework.zero.autoconfigure.web.WebMvcAutoConfiguration;
|
|||||||
*/
|
*/
|
||||||
@Ignore
|
@Ignore
|
||||||
public class WebMvcAutoConfigurationTests {
|
public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,12 @@ import org.junit.Test;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.zero.main.Spring;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link Spring}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class SimpleMainTests {
|
public class SimpleMainTests {
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.zero.cli;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple logger used by the CLI.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public abstract class Log {
|
||||||
|
|
||||||
|
public static void info(String message) {
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String message) {
|
||||||
|
System.err.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(Exception ex) {
|
||||||
|
ex.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -92,6 +92,11 @@ public class SpringZeroCli {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
return handleError(debug, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int handleError(boolean debug, Exception ex) {
|
||||||
Set<SpringZeroCliException.Option> options = NO_EXCEPTION_OPTIONS;
|
Set<SpringZeroCliException.Option> options = NO_EXCEPTION_OPTIONS;
|
||||||
if (ex instanceof SpringZeroCliException) {
|
if (ex instanceof SpringZeroCliException) {
|
||||||
options = ((SpringZeroCliException) ex).getOptions();
|
options = ((SpringZeroCliException) ex).getOptions();
|
||||||
@ -107,7 +112,6 @@ public class SpringZeroCli {
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the arguments and run a suitable command.
|
* Parse the arguments and run a suitable command.
|
||||||
@ -133,28 +137,28 @@ public class SpringZeroCli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void showUsage() {
|
protected void showUsage() {
|
||||||
System.out.print("usage: " + CLI_APP + " ");
|
Log.info("usage: " + CLI_APP + " ");
|
||||||
System.out.println("");
|
Log.info("");
|
||||||
System.out.println(" <command> [<args>]");
|
Log.info(" <command> [<args>]");
|
||||||
System.out.println("");
|
Log.info("");
|
||||||
System.out.println("Available commands are:");
|
Log.info("Available commands are:");
|
||||||
for (Command command : this.commands) {
|
for (Command command : this.commands) {
|
||||||
System.out.println(String.format("\n %1$s %2$-15s\n %3$s",
|
Log.info(String.format("\n %1$s %2$-15s\n %3$s", command.getName(),
|
||||||
command.getName(), command.getUsageHelp(), command.getDescription()));
|
command.getUsageHelp(), command.getDescription()));
|
||||||
}
|
}
|
||||||
System.out.println("");
|
Log.info("");
|
||||||
System.out.println("See '" + CLI_APP
|
Log.info("See '" + CLI_APP
|
||||||
+ " help <command>' for more information on a specific command.");
|
+ " help <command>' for more information on a specific command.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void errorMessage(String message) {
|
protected void errorMessage(String message) {
|
||||||
System.err.println(message == null ? "Unexpected error" : message);
|
Log.error(message == null ? "Unexpected error" : message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void printStackTrace(Exception ex) {
|
protected void printStackTrace(Exception ex) {
|
||||||
System.err.println("");
|
Log.error("");
|
||||||
ex.printStackTrace(System.err);
|
Log.error(ex);
|
||||||
System.err.println("");
|
Log.error("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] removeDebugFlags(String[] args) {
|
private String[] removeDebugFlags(String[] args) {
|
||||||
@ -187,16 +191,16 @@ public class SpringZeroCli {
|
|||||||
String commandName = args[0];
|
String commandName = args[0];
|
||||||
for (Command command : SpringZeroCli.this.commands) {
|
for (Command command : SpringZeroCli.this.commands) {
|
||||||
if (command.getName().equals(commandName)) {
|
if (command.getName().equals(commandName)) {
|
||||||
System.out.println(CLI_APP + " " + command.getName() + " - "
|
Log.info(CLI_APP + " " + command.getName() + " - "
|
||||||
+ command.getDescription());
|
+ command.getDescription());
|
||||||
System.out.println();
|
Log.info("");
|
||||||
if (command.getUsageHelp() != null) {
|
if (command.getUsageHelp() != null) {
|
||||||
System.out.println("usage: " + CLI_APP + " " + command.getName()
|
Log.info("usage: " + CLI_APP + " " + command.getName() + " "
|
||||||
+ " " + command.getUsageHelp());
|
+ command.getUsageHelp());
|
||||||
System.out.println();
|
Log.info("");
|
||||||
}
|
}
|
||||||
if (command.getHelp() != null) {
|
if (command.getHelp() != null) {
|
||||||
System.out.println(command.getHelp());
|
Log.info(command.getHelp());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import joptsimple.OptionSpec;
|
|||||||
|
|
||||||
import org.apache.ivy.util.FileUtil;
|
import org.apache.ivy.util.FileUtil;
|
||||||
import org.springframework.zero.cli.Command;
|
import org.springframework.zero.cli.Command;
|
||||||
|
import org.springframework.zero.cli.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Command} to 'clean' up grapes, removing cached dependencies and forcing a
|
* {@link Command} to 'clean' up grapes, removing cached dependencies and forcing a
|
||||||
@ -35,9 +36,8 @@ import org.springframework.zero.cli.Command;
|
|||||||
public class CleanCommand extends OptionParsingCommand {
|
public class CleanCommand extends OptionParsingCommand {
|
||||||
|
|
||||||
public CleanCommand() {
|
public CleanCommand() {
|
||||||
super(
|
super("clean", "Clean up groovy grapes "
|
||||||
"clean",
|
+ "(useful if snapshots are needed and you need an update)",
|
||||||
"Clean up groovy grapes (useful if snapshots are needed and you need an update)",
|
|
||||||
new CleanOptionHandler());
|
new CleanOptionHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,10 +48,6 @@ public class CleanCommand extends OptionParsingCommand {
|
|||||||
|
|
||||||
private static class CleanOptionHandler extends OptionHandler {
|
private static class CleanOptionHandler extends OptionHandler {
|
||||||
|
|
||||||
private static enum Layout {
|
|
||||||
IVY, MAVEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
private OptionSpec<Void> allOption;
|
private OptionSpec<Void> allOption;
|
||||||
|
|
||||||
private OptionSpec<Void> ivyOption;
|
private OptionSpec<Void> ivyOption;
|
||||||
@ -61,59 +57,66 @@ public class CleanCommand extends OptionParsingCommand {
|
|||||||
@Override
|
@Override
|
||||||
protected void options() {
|
protected void options() {
|
||||||
this.allOption = option("all", "Clean all files (not just snapshots)");
|
this.allOption = option("all", "Clean all files (not just snapshots)");
|
||||||
this.ivyOption = option("ivy",
|
this.ivyOption = option("ivy", "Clean just ivy (grapes) cache. "
|
||||||
"Clean just ivy (grapes) cache. Default is on unless --maven is used.");
|
+ "Default is on unless --maven is used.");
|
||||||
this.mvnOption = option("maven", "Clean just maven cache. Default is off.");
|
this.mvnOption = option("maven", "Clean just maven cache. Default is off.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(OptionSet options) throws Exception {
|
protected void run(OptionSet options) throws Exception {
|
||||||
if (!options.has(this.ivyOption)) {
|
if (!options.has(this.ivyOption)) {
|
||||||
clean(options, getGrapesHome(options), Layout.IVY);
|
clean(options, getGrapesHome(), Layout.IVY);
|
||||||
}
|
}
|
||||||
if (options.has(this.mvnOption)) {
|
if (options.has(this.mvnOption)) {
|
||||||
if (options.has(this.ivyOption)) {
|
if (options.has(this.ivyOption)) {
|
||||||
clean(options, getGrapesHome(options), Layout.IVY);
|
clean(options, getGrapesHome(), Layout.IVY);
|
||||||
}
|
}
|
||||||
clean(options, getMavenHome(options), Layout.MAVEN);
|
clean(options, getMavenHome(), Layout.MAVEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clean(OptionSet options, File root, Layout layout) {
|
private void clean(OptionSet options, File root, Layout layout) {
|
||||||
|
|
||||||
if (root == null || !root.exists()) {
|
if (root == null || !root.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> specs = new ArrayList<String>(options.nonOptionArguments());
|
ArrayList<String> specs = new ArrayList<String>(options.nonOptionArguments());
|
||||||
if (!specs.contains("org.springframework.zero") && layout == Layout.IVY) {
|
if (!specs.contains("org.springframework.zero") && layout == Layout.IVY) {
|
||||||
specs.add(0, "org.springframework.zero");
|
specs.add(0, "org.springframework.zero");
|
||||||
}
|
}
|
||||||
for (String spec : specs) {
|
for (String spec : specs) {
|
||||||
|
clean(options, root, layout, spec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clean(OptionSet options, File root, Layout layout, String spec) {
|
||||||
String group = spec;
|
String group = spec;
|
||||||
String module = null;
|
String module = null;
|
||||||
if (spec.contains(":")) {
|
if (spec.contains(":")) {
|
||||||
group = spec.substring(0, spec.indexOf(":"));
|
group = spec.substring(0, spec.indexOf(':'));
|
||||||
module = spec.substring(spec.indexOf(":") + 1);
|
module = spec.substring(spec.indexOf(':') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = getModulePath(root, group, module, layout);
|
File file = getModulePath(root, group, module, layout);
|
||||||
if (file.exists()) {
|
if (!file.exists()) {
|
||||||
if (options.has(this.allOption)
|
return;
|
||||||
|| group.equals("org.springframework.zero")) {
|
|
||||||
System.out.println("Deleting: " + file);
|
|
||||||
FileUtil.forceDelete(file);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
if (options.has(this.allOption) || group.equals("org.springframework.zero")) {
|
||||||
|
delete(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (Object obj : FileUtil.listAll(file, Collections.emptyList())) {
|
for (Object obj : FileUtil.listAll(file, Collections.emptyList())) {
|
||||||
File candidate = (File) obj;
|
File candidate = (File) obj;
|
||||||
if (candidate.getName().contains("SNAPSHOT")) {
|
if (candidate.getName().contains("SNAPSHOT")) {
|
||||||
System.out.println("Deleting: " + candidate);
|
delete(candidate);
|
||||||
FileUtil.forceDelete(candidate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void delete(File file) {
|
||||||
|
Log.info("Deleting: " + file);
|
||||||
|
FileUtil.forceDelete(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getModulePath(File root, String group, String module, Layout layout) {
|
private File getModulePath(File root, String group, String module, Layout layout) {
|
||||||
@ -133,11 +136,9 @@ public class CleanCommand extends OptionParsingCommand {
|
|||||||
return new File(parent, module);
|
return new File(parent, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getGrapesHome(OptionSet options) {
|
private File getGrapesHome() {
|
||||||
|
|
||||||
String dir = System.getenv("GROOVY_HOME");
|
String dir = System.getenv("GROOVY_HOME");
|
||||||
String userdir = System.getProperty("user.home");
|
String userdir = System.getProperty("user.home");
|
||||||
|
|
||||||
File home;
|
File home;
|
||||||
if (dir == null || !new File(dir).exists()) {
|
if (dir == null || !new File(dir).exists()) {
|
||||||
dir = userdir;
|
dir = userdir;
|
||||||
@ -149,20 +150,20 @@ public class CleanCommand extends OptionParsingCommand {
|
|||||||
if (dir == null || !new File(dir).exists()) {
|
if (dir == null || !new File(dir).exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return new File(home, "grapes");
|
||||||
File grapes = new File(home, "grapes");
|
|
||||||
return grapes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getMavenHome(OptionSet options) {
|
private File getMavenHome() {
|
||||||
String dir = System.getProperty("user.home");
|
String dir = System.getProperty("user.home");
|
||||||
|
|
||||||
if (dir == null || !new File(dir).exists()) {
|
if (dir == null || !new File(dir).exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
File home = new File(dir);
|
File home = new File(dir);
|
||||||
File grapes = new File(new File(home, ".m2"), "repository");
|
return new File(new File(home, ".m2"), "repository");
|
||||||
return grapes;
|
}
|
||||||
|
|
||||||
|
private static enum Layout {
|
||||||
|
IVY, MAVEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public class OptionHandler {
|
|||||||
try {
|
try {
|
||||||
getParser().printHelpOn(out);
|
getParser().printHelpOn(out);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
return "Help not available";
|
return "Help not available";
|
||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
|
@ -41,7 +41,7 @@ import org.springframework.zero.cli.compiler.GroovyCompilerConfiguration;
|
|||||||
*/
|
*/
|
||||||
public class ScriptCommand implements Command {
|
public class ScriptCommand implements Command {
|
||||||
|
|
||||||
private static String[] DEFAULT_PATHS = new String[] { "${SPRING_HOME}/ext",
|
private static final String[] DEFAULT_PATHS = new String[] { "${SPRING_HOME}/ext",
|
||||||
"${SPRING_HOME}/bin" };
|
"${SPRING_HOME}/bin" };
|
||||||
|
|
||||||
private String[] paths = DEFAULT_PATHS;
|
private String[] paths = DEFAULT_PATHS;
|
||||||
@ -124,7 +124,7 @@ public class ScriptCommand implements Command {
|
|||||||
* @param paths the paths to set
|
* @param paths the paths to set
|
||||||
*/
|
*/
|
||||||
public void setPaths(String[] paths) {
|
public void setPaths(String[] paths) {
|
||||||
this.paths = paths;
|
this.paths = (paths == null ? null : paths.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -140,9 +140,9 @@ public class ScriptCommand implements Command {
|
|||||||
try {
|
try {
|
||||||
this.main = getMainClass().newInstance();
|
this.main = getMainClass().newInstance();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException("Cannot create main class: " + this.name,
|
throw new IllegalStateException("Cannot create main class: " + this.name,
|
||||||
e);
|
ex);
|
||||||
}
|
}
|
||||||
if (this.main instanceof OptionHandler) {
|
if (this.main instanceof OptionHandler) {
|
||||||
((OptionHandler) this.main).options();
|
((OptionHandler) this.main).options();
|
||||||
@ -167,11 +167,11 @@ public class ScriptCommand implements Command {
|
|||||||
try {
|
try {
|
||||||
classes = compiler.compile(source);
|
classes = compiler.compile(source);
|
||||||
}
|
}
|
||||||
catch (CompilationFailedException e) {
|
catch (CompilationFailedException ex) {
|
||||||
throw new IllegalStateException("Could not compile script", e);
|
throw new IllegalStateException("Could not compile script", ex);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
throw new IllegalStateException("Could not compile script", e);
|
throw new IllegalStateException("Could not compile script", ex);
|
||||||
}
|
}
|
||||||
this.mainClass = classes[0];
|
this.mainClass = classes[0];
|
||||||
}
|
}
|
||||||
@ -188,44 +188,45 @@ public class ScriptCommand implements Command {
|
|||||||
if (!name.endsWith(".groovy")) {
|
if (!name.endsWith(".groovy")) {
|
||||||
resource = "commands/" + name + ".groovy";
|
resource = "commands/" + name + ".groovy";
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = getClass().getClassLoader().getResource(resource);
|
URL url = getClass().getClassLoader().getResource(resource);
|
||||||
File file = null;
|
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
if (url.toString().startsWith("file:")) {
|
return locateSourceFromUrl(name, url);
|
||||||
file = new File(url.toString().substring("file:".length()));
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// probably in JAR file
|
|
||||||
try {
|
|
||||||
file = File.createTempFile(name, ".groovy");
|
|
||||||
file.deleteOnExit();
|
|
||||||
FileUtil.copy(url, file, null);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Could not create temp file for source: " + name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
String home = System.getProperty("SPRING_HOME", System.getenv("SPRING_HOME"));
|
String home = System.getProperty("SPRING_HOME", System.getenv("SPRING_HOME"));
|
||||||
if (home == null) {
|
if (home == null) {
|
||||||
home = ".";
|
home = ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String path : this.paths) {
|
for (String path : this.paths) {
|
||||||
String subbed = path.replace("${SPRING_HOME}", home);
|
String subbed = path.replace("${SPRING_HOME}", home);
|
||||||
File test = new File(subbed, resource);
|
File file = new File(subbed, resource);
|
||||||
if (test.exists()) {
|
if (file.exists()) {
|
||||||
file = test;
|
return file;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (file == null) {
|
|
||||||
throw new IllegalStateException("No script found for : " + name);
|
throw new IllegalStateException("No script found for : " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File locateSourceFromUrl(String name, URL url) {
|
||||||
|
if (url.toString().startsWith("file:")) {
|
||||||
|
return new File(url.toString().substring("file:".length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// probably in JAR file
|
||||||
|
try {
|
||||||
|
File file = File.createTempFile(name, ".groovy");
|
||||||
|
file.deleteOnExit();
|
||||||
|
FileUtil.copy(url, file, null);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
throw new IllegalStateException("Could not create temp file for source: "
|
||||||
|
+ name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class ScriptConfiguration implements GroovyCompilerConfiguration {
|
private static class ScriptConfiguration implements GroovyCompilerConfiguration {
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ public class DependencyCustomizer {
|
|||||||
try {
|
try {
|
||||||
DependencyCustomizer.this.loader.loadClass(classname);
|
DependencyCustomizer.this.loader.loadClass(classname);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +97,8 @@ public class DependencyCustomizer {
|
|||||||
DependencyCustomizer.this.loader.loadClass(classname);
|
DependencyCustomizer.this.loader.loadClass(classname);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
|
// swallow exception and continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DependencyCustomizer.this.canAdd();
|
return DependencyCustomizer.this.canAdd();
|
||||||
@ -122,7 +123,8 @@ public class DependencyCustomizer {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
|
// swallow exception and continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DependencyCustomizer.this.canAdd();
|
return DependencyCustomizer.this.canAdd();
|
||||||
@ -147,7 +149,8 @@ public class DependencyCustomizer {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
|
// swallow exception and continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DependencyCustomizer.this.canAdd();
|
return DependencyCustomizer.this.canAdd();
|
||||||
|
@ -84,10 +84,9 @@ public class SpringZeroCompilerAutoConfiguration extends CompilerAutoConfigurati
|
|||||||
public void applyToMainClass(GroovyClassLoader loader,
|
public void applyToMainClass(GroovyClassLoader loader,
|
||||||
GroovyCompilerConfiguration configuration, GeneratorContext generatorContext,
|
GroovyCompilerConfiguration configuration, GeneratorContext generatorContext,
|
||||||
SourceUnit source, ClassNode classNode) throws CompilationFailedException {
|
SourceUnit source, ClassNode classNode) throws CompilationFailedException {
|
||||||
if (true) { // FIXME: add switch for auto config
|
// FIXME: add switch for auto config
|
||||||
addEnableAutoConfigurationAnnotation(source, classNode);
|
addEnableAutoConfigurationAnnotation(source, classNode);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void addEnableAutoConfigurationAnnotation(SourceUnit source,
|
private void addEnableAutoConfigurationAnnotation(SourceUnit source,
|
||||||
ClassNode classNode) {
|
ClassNode classNode) {
|
||||||
@ -101,8 +100,8 @@ public class SpringZeroCompilerAutoConfiguration extends CompilerAutoConfigurati
|
|||||||
annotationClass));
|
annotationClass));
|
||||||
classNode.addAnnotation(annotationNode);
|
classNode.addAnnotation(annotationNode);
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e) {
|
catch (ClassNotFoundException ex) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,8 @@ public class SpringZeroRunner {
|
|||||||
public SpringZeroRunner(final SpringZeroRunnerConfiguration configuration,
|
public SpringZeroRunner(final SpringZeroRunnerConfiguration configuration,
|
||||||
File[] files, String... args) {
|
File[] files, String... args) {
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.files = files;
|
this.files = files.clone();
|
||||||
this.args = args;
|
this.args = args.clone();
|
||||||
this.compiler = new GroovyCompiler(configuration);
|
this.compiler = new GroovyCompiler(configuration);
|
||||||
if (configuration.getLogLevel().intValue() <= Level.FINE.intValue()) {
|
if (configuration.getLogLevel().intValue() <= Level.FINE.intValue()) {
|
||||||
System.setProperty("groovy.grape.report.downloads", "true");
|
System.setProperty("groovy.grape.report.downloads", "true");
|
||||||
|
@ -30,7 +30,7 @@ import org.codehaus.groovy.control.CompilationFailedException;
|
|||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class GroovyTemplate {
|
public abstract class GroovyTemplate {
|
||||||
|
|
||||||
// FIXME is this used?
|
// FIXME is this used?
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Integration tests to exercise the samples.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class SampleIntegrationTests {
|
public class SampleIntegrationTests {
|
||||||
|
@ -13,22 +13,22 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.cli.command;
|
package org.springframework.zero.cli.command;
|
||||||
|
|
||||||
import groovy.lang.GroovyObjectSupport;
|
import groovy.lang.GroovyObjectSupport;
|
||||||
import groovy.lang.Script;
|
import groovy.lang.Script;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.zero.cli.command.OptionHandler;
|
|
||||||
import org.springframework.zero.cli.command.ScriptCommand;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* Tests for {@link ScriptCommand}.
|
||||||
*
|
*
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class ScriptCommandTests {
|
public class ScriptCommandTests {
|
||||||
|
|
||||||
|
@ -118,28 +118,43 @@ class BeanDefinitionLoader {
|
|||||||
private int load(Object source) {
|
private int load(Object source) {
|
||||||
Assert.notNull(source, "Source must not be null");
|
Assert.notNull(source, "Source must not be null");
|
||||||
if (source instanceof Class<?>) {
|
if (source instanceof Class<?>) {
|
||||||
Class<?> type = (Class<?>) source;
|
return load((Class<?>) source);
|
||||||
if (isComponent(type)) {
|
}
|
||||||
this.annotatedReader.register(type);
|
if (source instanceof Resource) {
|
||||||
|
return load((Resource) source);
|
||||||
|
}
|
||||||
|
if (source instanceof Package) {
|
||||||
|
return load((Package) source);
|
||||||
|
}
|
||||||
|
if (source instanceof CharSequence) {
|
||||||
|
return load((CharSequence) source);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Invalid source type " + source.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int load(Class<?> source) {
|
||||||
|
if (isComponent(source)) {
|
||||||
|
this.annotatedReader.register(source);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source instanceof Resource) {
|
private int load(Resource source) {
|
||||||
return this.xmlReader.loadBeanDefinitions((Resource) source);
|
return this.xmlReader.loadBeanDefinitions(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source instanceof Package) {
|
private int load(Package source) {
|
||||||
// FIXME register the scanned package for data to pick up
|
// FIXME register the scanned package for data to pick up
|
||||||
return this.scanner.scan(((Package) source).getName());
|
return this.scanner.scan(source.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source instanceof CharSequence) {
|
private int load(CharSequence source) {
|
||||||
try {
|
try {
|
||||||
return load(Class.forName(source.toString()));
|
return load(Class.forName(source.toString()));
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e) {
|
catch (ClassNotFoundException ex) {
|
||||||
|
// swallow exception and continue
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource loadedResource = (this.resourceLoader != null ? this.resourceLoader
|
Resource loadedResource = (this.resourceLoader != null ? this.resourceLoader
|
||||||
@ -151,8 +166,6 @@ class BeanDefinitionLoader {
|
|||||||
if (packageResource != null) {
|
if (packageResource != null) {
|
||||||
return load(packageResource);
|
return load(packageResource);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("Invalid source '" + source + "'");
|
throw new IllegalArgumentException("Invalid source '" + source + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ public class SpringApplication {
|
|||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initialize() {
|
private void initialize() {
|
||||||
this.webEnvironment = deduceWebEnvironment();
|
this.webEnvironment = deduceWebEnvironment();
|
||||||
this.initializers = new ArrayList<ApplicationContextInitializer<?>>();
|
this.initializers = new ArrayList<ApplicationContextInitializer<?>>();
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@ -376,8 +376,8 @@ public class SpringApplication {
|
|||||||
String optionName;
|
String optionName;
|
||||||
String optionValue = "";
|
String optionValue = "";
|
||||||
if (optionText.contains("=")) {
|
if (optionText.contains("=")) {
|
||||||
optionName = optionText.substring(0, optionText.indexOf("="));
|
optionName = optionText.substring(0, optionText.indexOf('='));
|
||||||
optionValue = optionText.substring(optionText.indexOf("=") + 1,
|
optionValue = optionText.substring(optionText.indexOf('=') + 1,
|
||||||
optionText.length());
|
optionText.length());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -439,8 +439,8 @@ public class SpringApplication {
|
|||||||
try {
|
try {
|
||||||
runner.run(args);
|
runner.run(args);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException("Failed to execute CommandLineRunner", e);
|
throw new IllegalStateException("Failed to execute CommandLineRunner", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -617,8 +617,8 @@ public class SpringApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
e.printStackTrace();
|
ex.printStackTrace();
|
||||||
exitCode = (exitCode == 0 ? 1 : exitCode);
|
exitCode = (exitCode == 0 ? 1 : exitCode);
|
||||||
}
|
}
|
||||||
return exitCode;
|
return exitCode;
|
||||||
@ -633,9 +633,9 @@ public class SpringApplication {
|
|||||||
exitCode = value;
|
exitCode = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
exitCode = (exitCode == 0 ? 1 : exitCode);
|
exitCode = (exitCode == 0 ? 1 : exitCode);
|
||||||
e.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
@ -75,8 +75,8 @@ public class CustomPropertyConstructor extends Constructor {
|
|||||||
try {
|
try {
|
||||||
typeMap.put(alias, this.propertyUtils.getProperty(type, name));
|
typeMap.put(alias, this.propertyUtils.getProperty(type, name));
|
||||||
}
|
}
|
||||||
catch (IntrospectionException e) {
|
catch (IntrospectionException ex) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ public class InetAddressEditor extends PropertyEditorSupport implements Property
|
|||||||
try {
|
try {
|
||||||
setValue(InetAddress.getByName(text));
|
setValue(InetAddress.getByName(text));
|
||||||
}
|
}
|
||||||
catch (UnknownHostException e) {
|
catch (UnknownHostException ex) {
|
||||||
throw new IllegalArgumentException("Cannot locate host", e);
|
throw new IllegalArgumentException("Cannot locate host", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,7 @@ import org.springframework.validation.Validator;
|
|||||||
public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
||||||
MessageSourceAware, InitializingBean {
|
MessageSourceAware, InitializingBean {
|
||||||
|
|
||||||
private static final Log logger = LogFactory
|
private final Log logger = LogFactory.getLog(getClass());
|
||||||
.getLog(PropertiesConfigurationFactory.class);
|
|
||||||
|
|
||||||
private boolean ignoreUnknownFields = true;
|
private boolean ignoreUnknownFields = true;
|
||||||
|
|
||||||
@ -193,23 +192,23 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
|||||||
Assert.state(this.properties != null || this.propertySources != null,
|
Assert.state(this.properties != null || this.propertySources != null,
|
||||||
"Properties or propertySources should not be null");
|
"Properties or propertySources should not be null");
|
||||||
try {
|
try {
|
||||||
if (logger.isTraceEnabled()) {
|
if (this.logger.isTraceEnabled()) {
|
||||||
if (this.properties != null) {
|
if (this.properties != null) {
|
||||||
logger.trace("Properties:\n" + this.properties);
|
this.logger.trace("Properties:\n" + this.properties);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.trace("Property Sources: " + this.propertySources);
|
this.logger.trace("Property Sources: " + this.propertySources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.hasBeenBound = true;
|
this.hasBeenBound = true;
|
||||||
doBindPropertiesToTarget();
|
doBindPropertiesToTarget();
|
||||||
}
|
}
|
||||||
catch (BindException e) {
|
catch (BindException ex) {
|
||||||
if (this.exceptionIfInvalid) {
|
if (this.exceptionIfInvalid) {
|
||||||
throw e;
|
throw ex;
|
||||||
}
|
}
|
||||||
logger.error("Failed to load Properties validation bean. "
|
this.logger.error("Failed to load Properties validation bean. "
|
||||||
+ "Your Properties may be invalid.", e);
|
+ "Your Properties may be invalid.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,10 +240,11 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
|||||||
dataBinder.validate();
|
dataBinder.validate();
|
||||||
BindingResult errors = dataBinder.getBindingResult();
|
BindingResult errors = dataBinder.getBindingResult();
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
logger.error("Properties configuration failed validation");
|
this.logger.error("Properties configuration failed validation");
|
||||||
for (ObjectError error : errors.getAllErrors()) {
|
for (ObjectError error : errors.getAllErrors()) {
|
||||||
logger.error(this.messageSource != null ? this.messageSource.getMessage(
|
this.logger.error(this.messageSource != null ? this.messageSource
|
||||||
error, Locale.getDefault()) + " (" + error + ")" : error);
|
.getMessage(error, Locale.getDefault()) + " (" + error + ")"
|
||||||
|
: error);
|
||||||
}
|
}
|
||||||
if (this.exceptionIfInvalid) {
|
if (this.exceptionIfInvalid) {
|
||||||
BindException summary = new BindException(errors);
|
BindException summary = new BindException(errors);
|
||||||
|
@ -199,6 +199,7 @@ public class RelaxedDataBinder extends DataBinder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InvalidPropertyException ex) {
|
catch (InvalidPropertyException ex) {
|
||||||
|
// swallow and contrinue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ import org.yaml.snakeyaml.error.YAMLException;
|
|||||||
public class YamlConfigurationFactory<T> implements FactoryBean<T>, MessageSourceAware,
|
public class YamlConfigurationFactory<T> implements FactoryBean<T>, MessageSourceAware,
|
||||||
InitializingBean {
|
InitializingBean {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(YamlConfigurationFactory.class);
|
private final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private Class<?> type;
|
private Class<?> type;
|
||||||
|
|
||||||
@ -128,29 +128,40 @@ public class YamlConfigurationFactory<T> implements FactoryBean<T>, MessageSourc
|
|||||||
Charset.defaultCharset());
|
Charset.defaultCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.state(
|
Assert.state(this.yaml != null, "Yaml document should not be null: "
|
||||||
this.yaml != null,
|
+ "either set it directly or set the resource to load it from");
|
||||||
"Yaml document should not be null: either set it directly or set the resource to load it from");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.trace("Yaml document is\n" + this.yaml);
|
if (this.logger.isTraceEnabled()) {
|
||||||
|
this.logger.trace("Yaml document is\n" + this.yaml);
|
||||||
|
}
|
||||||
Constructor constructor = new CustomPropertyConstructor(this.type,
|
Constructor constructor = new CustomPropertyConstructor(this.type,
|
||||||
this.propertyAliases);
|
this.propertyAliases);
|
||||||
this.configuration = (T) (new Yaml(constructor)).load(this.yaml);
|
this.configuration = (T) (new Yaml(constructor)).load(this.yaml);
|
||||||
|
|
||||||
if (this.validator != null) {
|
if (this.validator != null) {
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (YAMLException ex) {
|
||||||
|
if (this.exceptionIfInvalid) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
this.logger.error("Failed to load YAML validation bean. "
|
||||||
|
+ "Your YAML file may be invalid.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate() throws BindException {
|
||||||
BindingResult errors = new BeanPropertyBindingResult(this.configuration,
|
BindingResult errors = new BeanPropertyBindingResult(this.configuration,
|
||||||
"configuration");
|
"configuration");
|
||||||
this.validator.validate(this.configuration, errors);
|
this.validator.validate(this.configuration, errors);
|
||||||
|
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
logger.error("YAML configuration failed validation");
|
this.logger.error("YAML configuration failed validation");
|
||||||
for (ObjectError error : errors.getAllErrors()) {
|
for (ObjectError error : errors.getAllErrors()) {
|
||||||
logger.error(this.messageSource != null ? this.messageSource
|
this.logger.error(this.messageSource != null ? this.messageSource
|
||||||
.getMessage(error, Locale.getDefault())
|
.getMessage(error, Locale.getDefault()) + " (" + error + ")"
|
||||||
+ " ("
|
: error);
|
||||||
+ error
|
|
||||||
+ ")" : error);
|
|
||||||
}
|
}
|
||||||
if (this.exceptionIfInvalid) {
|
if (this.exceptionIfInvalid) {
|
||||||
BindException summary = new BindException(errors);
|
BindException summary = new BindException(errors);
|
||||||
@ -158,16 +169,6 @@ public class YamlConfigurationFactory<T> implements FactoryBean<T>, MessageSourc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (YAMLException e) {
|
|
||||||
if (this.exceptionIfInvalid) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
logger.error(
|
|
||||||
"Failed to load YAML validation bean. Your YAML file may be invalid.",
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.config;
|
package org.springframework.zero.config;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -29,26 +30,24 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
public class JacksonJsonParser implements JsonParser {
|
public class JacksonJsonParser implements JsonParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Map<String, Object> parseMap(String json) {
|
public Map<String, Object> parseMap(String json) {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
return new ObjectMapper().readValue(json, Map.class);
|
||||||
Map<String, Object> map = new ObjectMapper().readValue(json, Map.class);
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new IllegalArgumentException("Cannot parse JSON", e);
|
throw new IllegalArgumentException("Cannot parse JSON", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public List<Object> parseList(String json) {
|
public List<Object> parseList(String json) {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
return new ObjectMapper().readValue(json, List.class);
|
||||||
List<Object> list = new ObjectMapper().readValue(json, List.class);
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new IllegalArgumentException("Cannot parse JSON", e);
|
throw new IllegalArgumentException("Cannot parse JSON", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.config;
|
package org.springframework.zero.config;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -26,7 +26,7 @@ import org.springframework.util.ClassUtils;
|
|||||||
* @see YamlJsonParser
|
* @see YamlJsonParser
|
||||||
* @see SimpleJsonParser
|
* @see SimpleJsonParser
|
||||||
*/
|
*/
|
||||||
public class JsonParserFactory {
|
public abstract class JsonParserFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static factory for the "best" JSON parser available on the classpath. Tries Jackson
|
* Static factory for the "best" JSON parser available on the classpath. Tries Jackson
|
||||||
|
@ -30,17 +30,15 @@ import org.yaml.snakeyaml.Yaml;
|
|||||||
public class YamlJsonParser implements JsonParser {
|
public class YamlJsonParser implements JsonParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> parseMap(String json) {
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> map = new Yaml().loadAs(json, Map.class);
|
public Map<String, Object> parseMap(String json) {
|
||||||
return map;
|
return new Yaml().loadAs(json, Map.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Object> parseList(String json) {
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Object> list = new Yaml().loadAs(json, List.class);
|
public List<Object> parseList(String json) {
|
||||||
return list;
|
return new Yaml().loadAs(json, List.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,35 +38,7 @@ import org.yaml.snakeyaml.Yaml;
|
|||||||
*/
|
*/
|
||||||
public class YamlProcessor {
|
public class YamlProcessor {
|
||||||
|
|
||||||
public interface MatchCallback {
|
private final Log logger = LogFactory.getLog(getClass());
|
||||||
void process(Properties properties, Map<String, Object> map);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface DocumentMatcher {
|
|
||||||
MatchStatus matches(Properties properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(YamlProcessor.class);
|
|
||||||
|
|
||||||
public static enum ResolutionMethod {
|
|
||||||
OVERRIDE, OVERRIDE_AND_IGNORE, FIRST_FOUND
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum MatchStatus {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A match was found.
|
|
||||||
*/
|
|
||||||
FOUND,
|
|
||||||
/**
|
|
||||||
* A match was not found.
|
|
||||||
*/
|
|
||||||
NOT_FOUND,
|
|
||||||
/**
|
|
||||||
* Not enough information to decide.
|
|
||||||
*/
|
|
||||||
ABSTAIN
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResolutionMethod resolutionMethod = ResolutionMethod.OVERRIDE;
|
private ResolutionMethod resolutionMethod = ResolutionMethod.OVERRIDE;
|
||||||
|
|
||||||
@ -139,7 +111,7 @@ public class YamlProcessor {
|
|||||||
* @param resources the resources to set
|
* @param resources the resources to set
|
||||||
*/
|
*/
|
||||||
public void setResources(Resource[] resources) {
|
public void setResources(Resource[] resources) {
|
||||||
this.resources = resources;
|
this.resources = (resources == null ? null : resources.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,52 +126,56 @@ public class YamlProcessor {
|
|||||||
*/
|
*/
|
||||||
protected void process(MatchCallback callback) {
|
protected void process(MatchCallback callback) {
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
boolean found = false;
|
|
||||||
for (Resource resource : this.resources) {
|
for (Resource resource : this.resources) {
|
||||||
try {
|
boolean found = process(callback, yaml, resource);
|
||||||
logger.info("Loading from YAML: " + resource);
|
|
||||||
int count = 0;
|
|
||||||
for (Object object : yaml.loadAll(resource.getInputStream())) {
|
|
||||||
if (this.resolutionMethod != ResolutionMethod.FIRST_FOUND || !found) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> map = (Map<String, Object>) object;
|
|
||||||
if (map != null) {
|
|
||||||
found = process(map, callback);
|
|
||||||
if (found) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Loaded " + count + " document" + (count > 1 ? "s" : "")
|
|
||||||
+ " from YAML resource: " + resource);
|
|
||||||
|
|
||||||
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
|
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
|
||||||
// No need to load any more resources
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
|
||||||
|
int count = 0;
|
||||||
|
try {
|
||||||
|
this.logger.info("Loading from YAML: " + resource);
|
||||||
|
for (Object object : yaml.loadAll(resource.getInputStream())) {
|
||||||
|
if (object != null && process(asMap(object), callback)) {
|
||||||
|
count++;
|
||||||
|
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
}
|
||||||
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND
|
this.logger.info("Loaded " + count + " document" + (count > 1 ? "s" : "")
|
||||||
|| this.resolutionMethod == ResolutionMethod.OVERRIDE_AND_IGNORE) {
|
+ " from YAML resource: " + resource);
|
||||||
if (logger.isWarnEnabled()) {
|
}
|
||||||
logger.warn("Could not load map from " + resource + ": "
|
catch (IOException ex) {
|
||||||
+ e.getMessage());
|
handleProcessError(resource, ex);
|
||||||
}
|
}
|
||||||
}
|
return count > 0;
|
||||||
else {
|
}
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
private void handleProcessError(Resource resource, IOException ex) {
|
||||||
|
if (this.resolutionMethod != ResolutionMethod.FIRST_FOUND
|
||||||
|
&& this.resolutionMethod != ResolutionMethod.OVERRIDE_AND_IGNORE) {
|
||||||
|
throw new IllegalStateException(ex);
|
||||||
|
}
|
||||||
|
if (this.logger.isWarnEnabled()) {
|
||||||
|
this.logger.warn("Could not load map from " + resource + ": "
|
||||||
|
+ ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Map<String, Object> asMap(Object object) {
|
||||||
|
return (Map<String, Object>) object;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean process(Map<String, Object> map, MatchCallback callback) {
|
private boolean process(Map<String, Object> map, MatchCallback callback) {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
assignProperties(properties, map, null);
|
assignProperties(properties, map, null);
|
||||||
if (this.documentMatchers.isEmpty()) {
|
if (this.documentMatchers.isEmpty()) {
|
||||||
logger.debug("Merging document (no matchers set)" + map);
|
this.logger.debug("Merging document (no matchers set)" + map);
|
||||||
callback.process(properties, map);
|
callback.process(properties, map);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -209,7 +185,8 @@ public class YamlProcessor {
|
|||||||
MatchStatus match = matcher.matches(properties);
|
MatchStatus match = matcher.matches(properties);
|
||||||
result = match.ordinal() < result.ordinal() ? match : result;
|
result = match.ordinal() < result.ordinal() ? match : result;
|
||||||
if (match == MatchStatus.FOUND) {
|
if (match == MatchStatus.FOUND) {
|
||||||
logger.debug("Matched document with document matcher: " + properties);
|
this.logger.debug("Matched document with document matcher: "
|
||||||
|
+ properties);
|
||||||
callback.process(properties, map);
|
callback.process(properties, map);
|
||||||
valueFound = true;
|
valueFound = true;
|
||||||
// No need to check for more matches
|
// No need to check for more matches
|
||||||
@ -217,11 +194,11 @@ public class YamlProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == MatchStatus.ABSTAIN && this.matchDefault) {
|
if (result == MatchStatus.ABSTAIN && this.matchDefault) {
|
||||||
logger.debug("Matched document with default matcher: " + map);
|
this.logger.debug("Matched document with default matcher: " + map);
|
||||||
callback.process(properties, map);
|
callback.process(properties, map);
|
||||||
}
|
}
|
||||||
else if (!valueFound) {
|
else if (!valueFound) {
|
||||||
logger.debug("Unmatched document");
|
this.logger.debug("Unmatched document");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,13 +245,26 @@ public class YamlProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface MatchCallback {
|
||||||
|
void process(Properties properties, Map<String, Object> map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface DocumentMatcher {
|
||||||
|
MatchStatus matches(Properties properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum ResolutionMethod {
|
||||||
|
OVERRIDE, OVERRIDE_AND_IGNORE, FIRST_FOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum MatchStatus {
|
||||||
|
FOUND, NOT_FOUND, ABSTAIN
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches a document containing a given key and where the value of that key is an
|
* Matches a document containing a given key and where the value of that key is an
|
||||||
* array containing one of the given values, or where one of the values matches one of
|
* array containing one of the given values, or where one of the values matches one of
|
||||||
* the given values (interpreted as regexes).
|
* the given values (interpreted as regexes).
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static class ArrayDocumentMatcher implements DocumentMatcher {
|
public static class ArrayDocumentMatcher implements DocumentMatcher {
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ import org.springframework.util.ReflectionUtils.MethodCallback;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractOnBeanCondition implements ConfigurationCondition {
|
abstract class AbstractOnBeanCondition implements ConfigurationCondition {
|
||||||
|
|
||||||
protected Log logger = LogFactory.getLog(getClass());
|
private final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
protected abstract Class<?> annotationClass();
|
protected abstract Class<?> annotationClass();
|
||||||
|
|
||||||
@ -79,7 +79,8 @@ abstract class AbstractOnBeanCondition implements ConfigurationCondition {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
|
// swallow exception and continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,6 +120,7 @@ abstract class AbstractOnBeanCondition implements ConfigurationCondition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
|
// swallow exception and continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String beanName : beanNames) {
|
for (String beanName : beanNames) {
|
||||||
|
@ -26,7 +26,7 @@ import org.springframework.core.type.MethodMetadata;
|
|||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class ConditionLogUtils {
|
public abstract class ConditionLogUtils {
|
||||||
|
|
||||||
public static String getPrefix(Log logger, AnnotatedTypeMetadata metadata) {
|
public static String getPrefix(Log logger, AnnotatedTypeMetadata metadata) {
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.context.condition;
|
package org.springframework.zero.context.condition;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -77,7 +77,8 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
* @param port the port number for the embedded servlet container
|
* @param port the port number for the embedded servlet container
|
||||||
*/
|
*/
|
||||||
public AbstractEmbeddedServletContainerFactory(int port) {
|
public AbstractEmbeddedServletContainerFactory(int port) {
|
||||||
setPort(port);
|
checkPort(port);
|
||||||
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,8 +88,10 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
* @param port the port number for the embedded servlet container
|
* @param port the port number for the embedded servlet container
|
||||||
*/
|
*/
|
||||||
public AbstractEmbeddedServletContainerFactory(String contextPath, int port) {
|
public AbstractEmbeddedServletContainerFactory(String contextPath, int port) {
|
||||||
setContextPath(contextPath);
|
checkContextPath(contextPath);
|
||||||
setPort(port);
|
checkPort(port);
|
||||||
|
this.contextPath = contextPath;
|
||||||
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,6 +103,11 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setContextPath(String contextPath) {
|
public void setContextPath(String contextPath) {
|
||||||
|
checkContextPath(contextPath);
|
||||||
|
this.contextPath = contextPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkContextPath(String contextPath) {
|
||||||
Assert.notNull(contextPath, "ContextPath must not be null");
|
Assert.notNull(contextPath, "ContextPath must not be null");
|
||||||
if (contextPath.length() > 0) {
|
if (contextPath.length() > 0) {
|
||||||
if ("/".equals(contextPath)) {
|
if ("/".equals(contextPath)) {
|
||||||
@ -111,7 +119,6 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
"ContextPath must start with '/ and not end with '/'");
|
"ContextPath must start with '/ and not end with '/'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.contextPath = contextPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,10 +138,14 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setPort(int port) {
|
public void setPort(int port) {
|
||||||
|
checkPort(port);
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPort(int port) {
|
||||||
if (port < 0 || port > 65535) {
|
if (port < 0 || port > 65535) {
|
||||||
throw new IllegalArgumentException("Port must be between 1 and 65535");
|
throw new IllegalArgumentException("Port must be between 1 and 65535");
|
||||||
}
|
}
|
||||||
this.port = port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -333,32 +344,33 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
* warning and returning {@code null} otherwise.
|
* warning and returning {@code null} otherwise.
|
||||||
*/
|
*/
|
||||||
protected final File getValidDocumentRoot() {
|
protected final File getValidDocumentRoot() {
|
||||||
|
File file = getDocumentRoot();
|
||||||
// User specified
|
file = file != null ? file : getWarFileDocumentRoot();
|
||||||
if (getDocumentRoot() != null) {
|
file = file != null ? file : getCommonDocumentRoot();
|
||||||
return getDocumentRoot();
|
if (file == null && this.logger.isWarnEnabled()) {
|
||||||
|
this.logger.warn("None of the document roots "
|
||||||
|
+ Arrays.asList(COMMON_DOC_ROOTS)
|
||||||
|
+ " point to a directory and will be ignored.");
|
||||||
|
}
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Packaged as a WAR file
|
private File getWarFileDocumentRoot() {
|
||||||
File warFile = getCodeSourceArchive();
|
File warFile = getCodeSourceArchive();
|
||||||
if (warFile.exists() && !warFile.isDirectory()
|
if (warFile.exists() && !warFile.isDirectory()
|
||||||
&& warFile.getName().toLowerCase().endsWith(".war")) {
|
&& warFile.getName().toLowerCase().endsWith(".war")) {
|
||||||
return warFile.getAbsoluteFile();
|
return warFile.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Common DocRoots
|
private File getCommonDocumentRoot() {
|
||||||
for (String commonDocRoot : COMMON_DOC_ROOTS) {
|
for (String commonDocRoot : COMMON_DOC_ROOTS) {
|
||||||
File root = new File(commonDocRoot);
|
File root = new File(commonDocRoot);
|
||||||
if (root != null && root.exists() && root.isDirectory()) {
|
if (root != null && root.exists() && root.isDirectory()) {
|
||||||
return root.getAbsoluteFile();
|
return root.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.logger.isWarnEnabled()) {
|
|
||||||
this.logger.warn("None of the document roots "
|
|
||||||
+ Arrays.asList(COMMON_DOC_ROOTS)
|
|
||||||
+ " point to a directory and will be ignored.");
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +391,7 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
}
|
}
|
||||||
return new File(path);
|
return new File(path);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.zero.context.embedded;
|
package org.springframework.zero.context.embedded;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||||
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
||||||
@ -152,7 +153,7 @@ public class AnnotationConfigEmbeddedWebApplicationContext extends
|
|||||||
* @see #scan(String...)
|
* @see #scan(String...)
|
||||||
* @see #refresh()
|
* @see #refresh()
|
||||||
*/
|
*/
|
||||||
public void register(Class<?>... annotatedClasses) {
|
public final void register(Class<?>... annotatedClasses) {
|
||||||
this.annotatedClasses = annotatedClasses;
|
this.annotatedClasses = annotatedClasses;
|
||||||
Assert.notEmpty(annotatedClasses,
|
Assert.notEmpty(annotatedClasses,
|
||||||
"At least one annotated class must be specified");
|
"At least one annotated class must be specified");
|
||||||
@ -165,7 +166,7 @@ public class AnnotationConfigEmbeddedWebApplicationContext extends
|
|||||||
* @see #register(Class...)
|
* @see #register(Class...)
|
||||||
* @see #refresh()
|
* @see #refresh()
|
||||||
*/
|
*/
|
||||||
public void scan(String... basePackages) {
|
public final void scan(String... basePackages) {
|
||||||
this.basePackages = basePackages;
|
this.basePackages = basePackages;
|
||||||
Assert.notEmpty(basePackages, "At least one base package must be specified");
|
Assert.notEmpty(basePackages, "At least one base package must be specified");
|
||||||
}
|
}
|
||||||
@ -187,4 +188,9 @@ public class AnnotationConfigEmbeddedWebApplicationContext extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void refresh() throws BeansException, IllegalStateException {
|
||||||
|
super.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.context.embedded;
|
package org.springframework.zero.context.embedded;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -136,9 +136,9 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
|
|||||||
try {
|
try {
|
||||||
getSelfInitializer().onStartup(getServletContext());
|
getSelfInitializer().onStartup(getServletContext());
|
||||||
}
|
}
|
||||||
catch (ServletException e) {
|
catch (ServletException ex) {
|
||||||
throw new ApplicationContextException(
|
throw new ApplicationContextException(
|
||||||
"Cannot initialize servlet context", e);
|
"Cannot initialize servlet context", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory(),
|
WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory(),
|
||||||
|
@ -84,8 +84,13 @@ public class FilterRegistrationBean extends RegistrationBean {
|
|||||||
*/
|
*/
|
||||||
public FilterRegistrationBean(Filter filter,
|
public FilterRegistrationBean(Filter filter,
|
||||||
ServletRegistrationBean... servletRegistrationBeans) {
|
ServletRegistrationBean... servletRegistrationBeans) {
|
||||||
setFilter(filter);
|
Assert.notNull(filter, "Filter must not be null");
|
||||||
addServletRegistrationBeans(servletRegistrationBeans);
|
Assert.notNull(servletRegistrationBeans,
|
||||||
|
"ServletRegistrationBeans must not be null");
|
||||||
|
this.filter = filter;
|
||||||
|
for (ServletRegistrationBean servletRegistrationBean : servletRegistrationBeans) {
|
||||||
|
this.servletRegistrationBeans.add(servletRegistrationBean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,8 +69,10 @@ public class ServletRegistrationBean extends RegistrationBean {
|
|||||||
* @param urlMappings the URLs being mapped
|
* @param urlMappings the URLs being mapped
|
||||||
*/
|
*/
|
||||||
public ServletRegistrationBean(Servlet servlet, String... urlMappings) {
|
public ServletRegistrationBean(Servlet servlet, String... urlMappings) {
|
||||||
setServlet(servlet);
|
Assert.notNull(servlet, "Servlet must not be null");
|
||||||
addUrlMappings(urlMappings);
|
Assert.notNull(urlMappings, "UrlMappings must not be null");
|
||||||
|
this.servlet = servlet;
|
||||||
|
this.urlMappings.addAll(Arrays.asList(urlMappings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.zero.context.embedded;
|
package org.springframework.zero.context.embedded;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
@ -46,7 +47,7 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
|
|||||||
* {@linkplain #load loaded} and then manually {@link #refresh refreshed}.
|
* {@linkplain #load loaded} and then manually {@link #refresh refreshed}.
|
||||||
*/
|
*/
|
||||||
public XmlEmbeddedWebApplicationContext() {
|
public XmlEmbeddedWebApplicationContext() {
|
||||||
reader.setEnvironment(this.getEnvironment());
|
this.reader.setEnvironment(this.getEnvironment());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,7 +106,7 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
|
|||||||
* Load bean definitions from the given XML resources.
|
* Load bean definitions from the given XML resources.
|
||||||
* @param resources one or more resources to load from
|
* @param resources one or more resources to load from
|
||||||
*/
|
*/
|
||||||
public void load(Resource... resources) {
|
public final void load(Resource... resources) {
|
||||||
this.reader.loadBeanDefinitions(resources);
|
this.reader.loadBeanDefinitions(resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
|
|||||||
* Load bean definitions from the given XML resources.
|
* Load bean definitions from the given XML resources.
|
||||||
* @param resourceLocations one or more resource locations to load from
|
* @param resourceLocations one or more resource locations to load from
|
||||||
*/
|
*/
|
||||||
public void load(String... resourceLocations) {
|
public final void load(String... resourceLocations) {
|
||||||
this.reader.loadBeanDefinitions(resourceLocations);
|
this.reader.loadBeanDefinitions(resourceLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,11 +124,16 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
|
|||||||
* specified resource name
|
* specified resource name
|
||||||
* @param resourceNames relatively-qualified names of resources to load
|
* @param resourceNames relatively-qualified names of resources to load
|
||||||
*/
|
*/
|
||||||
public void load(Class<?> relativeClass, String... resourceNames) {
|
public final void load(Class<?> relativeClass, String... resourceNames) {
|
||||||
Resource[] resources = new Resource[resourceNames.length];
|
Resource[] resources = new Resource[resourceNames.length];
|
||||||
for (int i = 0; i < resourceNames.length; i++) {
|
for (int i = 0; i < resourceNames.length; i++) {
|
||||||
resources[i] = new ClassPathResource(resourceNames[i], relativeClass);
|
resources[i] = new ClassPathResource(resourceNames[i], relativeClass);
|
||||||
}
|
}
|
||||||
this.load(resources);
|
this.reader.loadBeanDefinitions(resources);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void refresh() throws BeansException, IllegalStateException {
|
||||||
|
super.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,8 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|||||||
try {
|
try {
|
||||||
this.tomcat.stop();
|
this.tomcat.stop();
|
||||||
}
|
}
|
||||||
catch (LifecycleException e) {
|
catch (LifecycleException ex) {
|
||||||
|
// swallow and continue
|
||||||
}
|
}
|
||||||
this.tomcat.destroy();
|
this.tomcat.destroy();
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,10 @@ import org.springframework.core.env.PropertiesPropertySource;
|
|||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.zero.config.YamlPropertiesFactoryBean;
|
|
||||||
import org.springframework.zero.config.YamlProcessor.ArrayDocumentMatcher;
|
import org.springframework.zero.config.YamlProcessor.ArrayDocumentMatcher;
|
||||||
import org.springframework.zero.config.YamlProcessor.DocumentMatcher;
|
import org.springframework.zero.config.YamlProcessor.DocumentMatcher;
|
||||||
import org.springframework.zero.config.YamlProcessor.MatchStatus;
|
import org.springframework.zero.config.YamlProcessor.MatchStatus;
|
||||||
|
import org.springframework.zero.config.YamlPropertiesFactoryBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ApplicationContextInitializer} that configures the context environment by
|
* {@link ApplicationContextInitializer} that configures the context environment by
|
||||||
@ -82,7 +82,7 @@ public class ConfigFileApplicationContextInitializer implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||||
List<String> candidates = getCandidateLocations(applicationContext);
|
List<String> candidates = getCandidateLocations();
|
||||||
|
|
||||||
// Initial load allows profiles to be activated
|
// Initial load allows profiles to be activated
|
||||||
for (String candidate : candidates) {
|
for (String candidate : candidates) {
|
||||||
@ -97,8 +97,7 @@ public class ConfigFileApplicationContextInitializer implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getCandidateLocations(
|
private List<String> getCandidateLocations() {
|
||||||
ConfigurableApplicationContext applicationContext) {
|
|
||||||
List<String> candidates = new ArrayList<String>();
|
List<String> candidates = new ArrayList<String>();
|
||||||
for (String searchLocation : this.searchLocations) {
|
for (String searchLocation : this.searchLocations) {
|
||||||
for (Loader loader : LOADERS) {
|
for (Loader loader : LOADERS) {
|
||||||
@ -150,7 +149,7 @@ public class ConfigFileApplicationContextInitializer implements
|
|||||||
* Set the search locations that will be considered.
|
* Set the search locations that will be considered.
|
||||||
*/
|
*/
|
||||||
public void setSearchLocations(String[] searchLocations) {
|
public void setSearchLocations(String[] searchLocations) {
|
||||||
this.searchLocations = searchLocations;
|
this.searchLocations = (searchLocations == null ? null : searchLocations.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -200,9 +199,9 @@ public class ConfigFileApplicationContextInitializer implements
|
|||||||
.getDescription(), properties));
|
.getDescription(), properties));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
throw new IllegalStateException("Could not load properties file from "
|
throw new IllegalStateException("Could not load properties file from "
|
||||||
+ resource, e);
|
+ resource, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,14 +171,10 @@ public class LoggingApplicationContextInitializer implements
|
|||||||
try {
|
try {
|
||||||
doInit(applicationContext, configLocation);
|
doInit(applicationContext, configLocation);
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException("Cannot initialize logging from "
|
throw new IllegalStateException("Cannot initialize logging from "
|
||||||
+ configLocation, ex);
|
+ configLocation, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void doInit(ApplicationContext applicationContext,
|
protected abstract void doInit(ApplicationContext applicationContext,
|
||||||
|
@ -41,15 +41,12 @@ public abstract class JavaLoggerConfigurer {
|
|||||||
LogManager.getLogManager().readConfiguration(
|
LogManager.getLogManager().readConfiguration(
|
||||||
ResourceUtils.getURL(resolvedLocation).openStream());
|
ResourceUtils.getURL(resolvedLocation).openStream());
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e) {
|
catch (Exception ex) {
|
||||||
throw e;
|
if (ex instanceof FileNotFoundException) {
|
||||||
|
throw (FileNotFoundException) ex;
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("Could not initialize logging from "
|
throw new IllegalArgumentException("Could not initialize logging from "
|
||||||
+ location, e);
|
+ location, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,9 +48,9 @@ public abstract class LogbackConfigurer {
|
|||||||
try {
|
try {
|
||||||
new ContextInitializer(context).configureByResource(url);
|
new ContextInitializer(context).configureByResource(url);
|
||||||
}
|
}
|
||||||
catch (JoranException e) {
|
catch (JoranException ex) {
|
||||||
throw new IllegalArgumentException("Could not initialize logging from "
|
throw new IllegalArgumentException("Could not initialize logging from "
|
||||||
+ location, e);
|
+ location, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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.zero.web;
|
package org.springframework.zero.web;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
@ -28,8 +44,7 @@ import org.springframework.zero.context.embedded.AnnotationConfigEmbeddedWebAppl
|
|||||||
*/
|
*/
|
||||||
public abstract class SpringServletInitializer implements WebApplicationInitializer {
|
public abstract class SpringServletInitializer implements WebApplicationInitializer {
|
||||||
|
|
||||||
/** Logger available to subclasses. */
|
private final Log logger = LogFactory.getLog(getClass());
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartup(ServletContext servletContext) throws ServletException {
|
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||||
@ -44,9 +59,9 @@ public abstract class SpringServletInitializer implements WebApplicationInitiali
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger
|
this.logger.debug("No ContextLoaderListener registered, as "
|
||||||
.debug("No ContextLoaderListener registered, as "
|
+ "createRootApplicationContext() did not "
|
||||||
+ "createRootApplicationContext() did not return an application context");
|
+ "return an application context");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +70,7 @@ public abstract class SpringServletInitializer implements WebApplicationInitiali
|
|||||||
ApplicationContext parent = null;
|
ApplicationContext parent = null;
|
||||||
Object object = servletContext
|
Object object = servletContext
|
||||||
.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
||||||
if (object != null && object instanceof ApplicationContext) {
|
if (object instanceof ApplicationContext) {
|
||||||
this.logger.info("Root context already created (using as parent).");
|
this.logger.info("Root context already created (using as parent).");
|
||||||
parent = (ApplicationContext) object;
|
parent = (ApplicationContext) object;
|
||||||
servletContext.setAttribute(
|
servletContext.setAttribute(
|
||||||
|
@ -23,9 +23,11 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||||||
import org.springframework.core.env.MapPropertySource;
|
import org.springframework.core.env.MapPropertySource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* General test utilities.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class TestUtils {
|
public abstract class TestUtils {
|
||||||
|
|
||||||
public static void addEnviroment(ConfigurableApplicationContext context,
|
public static void addEnviroment(ConfigurableApplicationContext context,
|
||||||
String... pairs) {
|
String... pairs) {
|
||||||
|
@ -24,11 +24,11 @@ import org.springframework.core.env.MapPropertySource;
|
|||||||
import org.springframework.core.env.MutablePropertySources;
|
import org.springframework.core.env.MutablePropertySources;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
import org.springframework.validation.DataBinder;
|
import org.springframework.validation.DataBinder;
|
||||||
import org.springframework.zero.bind.PropertySourcesPropertyValues;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link PropertySourcesPropertyValues}.
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class PropertySourcesPropertyValuesTests {
|
public class PropertySourcesPropertyValuesTests {
|
||||||
|
@ -28,12 +28,13 @@ import org.springframework.context.support.StaticMessageSource;
|
|||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
import org.springframework.validation.Validator;
|
import org.springframework.validation.Validator;
|
||||||
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;
|
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;
|
||||||
import org.springframework.zero.bind.YamlConfigurationFactory;
|
|
||||||
import org.yaml.snakeyaml.error.YAMLException;
|
import org.yaml.snakeyaml.error.YAMLException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link YamlConfigurationFactory}
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class YamlConfigurationFactoryTests {
|
public class YamlConfigurationFactoryTests {
|
||||||
|
@ -13,14 +13,14 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.config;
|
package org.springframework.zero.config;
|
||||||
|
|
||||||
import org.springframework.zero.config.JacksonJsonParser;
|
|
||||||
import org.springframework.zero.config.JsonParser;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* Tests for {@link JsonParser}.
|
||||||
*
|
*
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class JacksonParserTests extends SimpleJsonParserTests {
|
public class JacksonParserTests extends SimpleJsonParserTests {
|
||||||
|
|
||||||
|
@ -13,20 +13,20 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.config;
|
package org.springframework.zero.config;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.zero.config.JsonParser;
|
|
||||||
import org.springframework.zero.config.SimpleJsonParser;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* Tests for {@link SimpleJsonParser}.
|
||||||
*
|
*
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class SimpleJsonParserTests {
|
public class SimpleJsonParserTests {
|
||||||
|
|
||||||
|
@ -13,16 +13,16 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.config;
|
package org.springframework.zero.config;
|
||||||
|
|
||||||
import org.springframework.zero.config.JsonParser;
|
|
||||||
import org.springframework.zero.config.YamlJsonParser;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* Tests for {@link YamlJsonParser}.
|
||||||
*
|
*
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class YamlParserTests extends SimpleJsonParserTests {
|
public class YamlJsonParserTests extends SimpleJsonParserTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JsonParser getParser() {
|
protected JsonParser getParser() {
|
@ -25,12 +25,13 @@ import org.springframework.core.io.AbstractResource;
|
|||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.zero.config.YamlMapFactoryBean;
|
|
||||||
import org.springframework.zero.config.YamlProcessor.ResolutionMethod;
|
import org.springframework.zero.config.YamlProcessor.ResolutionMethod;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link YamlMapFactoryBean}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class YamlMapFactoryBeanTests {
|
public class YamlMapFactoryBeanTests {
|
||||||
|
@ -25,7 +25,6 @@ import org.junit.Test;
|
|||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.zero.config.YamlPropertiesFactoryBean;
|
|
||||||
import org.springframework.zero.config.YamlProcessor.DocumentMatcher;
|
import org.springframework.zero.config.YamlProcessor.DocumentMatcher;
|
||||||
import org.springframework.zero.config.YamlProcessor.MatchStatus;
|
import org.springframework.zero.config.YamlProcessor.MatchStatus;
|
||||||
import org.springframework.zero.config.YamlProcessor.ResolutionMethod;
|
import org.springframework.zero.config.YamlProcessor.ResolutionMethod;
|
||||||
@ -34,6 +33,8 @@ import org.yaml.snakeyaml.Yaml;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link YamlPropertiesFactoryBean}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class YamlPropertiesFactoryBeanTests {
|
public class YamlPropertiesFactoryBeanTests {
|
||||||
|
@ -28,6 +28,8 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link OnClassCondition}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class OnClassConditionTests {
|
public class OnClassConditionTests {
|
||||||
|
@ -20,13 +20,14 @@ import org.junit.Test;
|
|||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.zero.context.condition.ConditionalOnExpression;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link OnExpressionCondition}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class OnExpressionConditionTests {
|
public class OnExpressionConditionTests {
|
||||||
|
@ -26,6 +26,8 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link OnMissingClassCondition}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class OnMissingClassConditionTests {
|
public class OnMissingClassConditionTests {
|
||||||
|
@ -28,9 +28,11 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link OnNotWebApplicationCondition}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class NotWebApplicationConditionTests {
|
public class OnNotWebApplicationConditionTests {
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
|
@ -20,13 +20,14 @@ import org.junit.Test;
|
|||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.zero.context.condition.ConditionalOnResource;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link OnResourceCondition}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class OnResourceConditionTests {
|
public class OnResourceConditionTests {
|
||||||
|
@ -29,9 +29,11 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link OnWebApplicationCondition}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class WebApplicationConditionTests {
|
public class OnWebApplicationConditionTests {
|
||||||
|
|
||||||
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||||
|
|
@ -80,7 +80,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|||||||
try {
|
try {
|
||||||
this.container.stop();
|
this.container.stop();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,20 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.context.initializer;
|
package org.springframework.zero.context.initializer;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.zero.TestUtils;
|
import org.springframework.zero.TestUtils;
|
||||||
import org.springframework.zero.context.initializer.ContextIdApplicationContextInitializer;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* Tests for {@link ContextIdApplicationContextInitializer}.
|
||||||
*
|
*
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class ContextIdApplicationContextInitializerTests {
|
public class ContextIdApplicationContextInitializerTests {
|
||||||
|
|
||||||
|
@ -13,19 +13,20 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.zero.context.initializer;
|
package org.springframework.zero.context.initializer;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.zero.TestUtils;
|
import org.springframework.zero.TestUtils;
|
||||||
import org.springframework.zero.context.initializer.VcapApplicationContextInitializer;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* Tests for {@link VcapApplicationContextInitializer}.
|
||||||
*
|
*
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class VcapApplicationContextInitializerTests {
|
public class VcapApplicationContextInitializerTests {
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user