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