diff --git a/spring-zero-actuator/pom.xml b/spring-zero-actuator/pom.xml index 528da315bda..a0e2d92625c 100644 --- a/spring-zero-actuator/pom.xml +++ b/spring-zero-actuator/pom.xml @@ -67,6 +67,13 @@ true + + ${project.groupId} + spring-zero-core + ${project.version} + tests + test + org.apache.tomcat.embed tomcat-embed-logging-juli diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointAutoConfiguration.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointAutoConfiguration.java index f6562cb879d..daed4987a74 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointAutoConfiguration.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointAutoConfiguration.java @@ -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; diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java index 44a61686f0b..7064f240c2c 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java @@ -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(); diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java index 067f94c6b27..e5b4e23a7b0 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java @@ -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; diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/ManagementServerPropertiesAutoConfiguration.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/ManagementServerPropertiesAutoConfiguration.java index cfed5aa9c92..a91a51e057e 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/ManagementServerPropertiesAutoConfiguration.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/ManagementServerPropertiesAutoConfiguration.java @@ -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; diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/MetricFilterAutoConfiguration.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/MetricFilterAutoConfiguration.java index 91c73d9dca6..5c883c2ff80 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/MetricFilterAutoConfiguration.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/MetricFilterAutoConfiguration.java @@ -112,7 +112,7 @@ public class MetricFilterAutoConfiguration { try { return response.getStatus(); } - catch (Exception e) { + catch (Exception ex) { return UNDEFINED_HTTP_STATUS; } } diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java index b4f81657830..79a25fd5fc6 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java @@ -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; diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/ShutdownEndpoint.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/ShutdownEndpoint.java index b7816fac960..ec9e8092bb8 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/ShutdownEndpoint.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/ShutdownEndpoint.java @@ -62,7 +62,8 @@ public class ShutdownEndpoint extends AbstractEndpoint> impl try { Thread.sleep(500L); } - catch (InterruptedException e) { + catch (InterruptedException ex) { + // Swallow exception and continue } ShutdownEndpoint.this.context.close(); } diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/mvc/EndpointHandlerAdapter.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/mvc/EndpointHandlerAdapter.java index 3c36e5d2ee2..1691cf06864 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/mvc/EndpointHandlerAdapter.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/mvc/EndpointHandlerAdapter.java @@ -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) 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 + "]"); } diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/mvc/EndpointHandlerMapping.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/mvc/EndpointHandlerMapping.java index 14a680b9266..ea2f38a1ad5 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/mvc/EndpointHandlerMapping.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/endpoint/mvc/EndpointHandlerMapping.java @@ -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; diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/trace/WebRequestTraceFilter.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/trace/WebRequestTraceFilter.java index fd87256609f..19e87b8e6d8 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/trace/WebRequestTraceFilter.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/trace/WebRequestTraceFilter.java @@ -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); } } } diff --git a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/web/BasicErrorController.java b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/web/BasicErrorController.java index ec1d61cd270..a88d145daa7 100644 --- a/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/web/BasicErrorController.java +++ b/spring-zero-actuator/src/main/java/org/springframework/zero/actuate/web/BasicErrorController.java @@ -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 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; } } diff --git a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/TestUtils.java b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/TestUtils.java deleted file mode 100644 index e0e4ea2fec3..00000000000 --- a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/TestUtils.java +++ /dev/null @@ -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 map = new HashMap(); - 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)); - } - -} diff --git a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/audit/listener/AuditListenerTests.java b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/audit/listener/AuditListenerTests.java index 9031611cb81..8ea87c33370 100644 --- a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/audit/listener/AuditListenerTests.java +++ b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/audit/listener/AuditListenerTests.java @@ -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; diff --git a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/EndpointAutoConfigurationTests.java b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/EndpointAutoConfigurationTests.java index 7955089ff55..b78a7b97813 100644 --- a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/EndpointAutoConfigurationTests.java +++ b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/EndpointAutoConfigurationTests.java @@ -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; diff --git a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index 6724007ec6c..4085fe94793 100644 --- a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -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; diff --git a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java index e3ab86f5ebc..ab5e6bb75da 100644 --- a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java +++ b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java @@ -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; diff --git a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/endpoint/AbstractEndpointTests.java b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/endpoint/AbstractEndpointTests.java index 8b3e957e105..9c17c70e3e2 100644 --- a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/endpoint/AbstractEndpointTests.java +++ b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/endpoint/AbstractEndpointTests.java @@ -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; diff --git a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/metrics/InMemoryMetricRepositoryTests.java b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/metrics/InMemoryMetricRepositoryTests.java index d19aca734d2..89cd71d3446 100644 --- a/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/metrics/InMemoryMetricRepositoryTests.java +++ b/spring-zero-actuator/src/test/java/org/springframework/zero/actuate/metrics/InMemoryMetricRepositoryTests.java @@ -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; diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigurationSorter.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigurationSorter.java index 78c328b7606..6655d71525c 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigurationSorter.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigurationSorter.java @@ -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; diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigurationUtils.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigurationUtils.java index a82fd13e7b5..d3cc9d24643 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigurationUtils.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigurationUtils.java @@ -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 getBasePackages(BeanFactory beanFactory) { try { return beanFactory.getBean(BASE_PACKAGES_BEAN, List.class); } - catch (NoSuchBeanDefinitionException e) { + catch (NoSuchBeanDefinitionException ex) { return Collections.emptyList(); } } diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigureAfter.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigureAfter.java index ba145a7f39c..bbb37370024 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigureAfter.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/AutoConfigureAfter.java @@ -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; diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/jdbc/BasicDataSourceConfiguration.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/jdbc/BasicDataSourceConfiguration.java index e72c92d1058..f43b25fbc99 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/jdbc/BasicDataSourceConfiguration.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/jdbc/BasicDataSourceConfiguration.java @@ -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); } } } diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/jdbc/DataSourceAutoConfiguration.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/jdbc/DataSourceAutoConfiguration.java index 11688f071ba..bfb97f2ac5e 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/jdbc/DataSourceAutoConfiguration.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/jdbc/DataSourceAutoConfiguration.java @@ -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; } diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java index 57a5476a57a..6bbce4d8773 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java @@ -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 EMBEDDED_DATABASE_DIALECTS; static { EMBEDDED_DATABASE_DIALECTS = new LinkedHashMap(); @@ -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); } - } } diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/orm/jpa/JpaAutoConfiguration.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/orm/jpa/JpaAutoConfiguration.java index 1f04e3936ad..e52feac6b94 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/orm/jpa/JpaAutoConfiguration.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/orm/jpa/JpaAutoConfiguration.java @@ -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); } } diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index ff4b7a46c55..f5d3c71b70b 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -85,7 +85,7 @@ public class ThymeleafAutoConfiguration { return DefaultTemplateResolverConfiguration.this.resourceLoader .getResource(resourceName).getInputStream(); } - catch (IOException e) { + catch (IOException ex) { return null; } } diff --git a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/main/Spring.java b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/main/Spring.java index ab6776e6167..c43563b7965 100644 --- a/spring-zero-autoconfigure/src/main/java/org/springframework/zero/main/Spring.java +++ b/spring-zero-autoconfigure/src/main/java/org/springframework/zero/main/Spring.java @@ -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 diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/AutoConfigurationSorterTest.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/AutoConfigurationSorterTest.java index b606b3d4034..2af5c7e8843 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/AutoConfigurationSorterTest.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/AutoConfigurationSorterTest.java @@ -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; diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/MessageSourceAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/MessageSourceAutoConfigurationTests.java index 504421bfa64..a3518be1cd5 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/MessageSourceAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/MessageSourceAutoConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/SpringJUnitTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/SpringJUnitTests.java index 585ea7791f3..dc99ba8a6c7 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/SpringJUnitTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/SpringJUnitTests.java @@ -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) diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/batch/BatchAutoConfigurationTests.java index efc393b29b9..e1e2d2e9e02 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/batch/JobExecutionExitCodeGeneratorTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/batch/JobExecutionExitCodeGeneratorTests.java index 4f582039e27..c30dea10259 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/batch/JobExecutionExitCodeGeneratorTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/batch/JobExecutionExitCodeGeneratorTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java index d4cdb555f7d..6b8a9962592 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/data/JpaWebAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/data/JpaWebAutoConfigurationTests.java index 35c3084e2ca..5678f3d1dd3 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/data/JpaWebAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/data/JpaWebAutoConfigurationTests.java @@ -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; diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/BasicDataSourceConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/BasicDataSourceConfigurationTests.java index 6eb40b37593..77fe2c1af29 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/BasicDataSourceConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/BasicDataSourceConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index 8bfa4203e98..95fedfcec43 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationTests.java index 5920d0e11da..7565bbc2a11 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/EmbeddedDatabaseConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/EmbeddedDatabaseConfigurationTests.java index 3df8fa63f2b..b64dd093b8d 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/EmbeddedDatabaseConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/EmbeddedDatabaseConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java index 49a10d279f1..95a3863fa92 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java index fd7100294e0..a27213ff480 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java index 3e205f1d506..a5f9d355bd9 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java @@ -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 { diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/web/WebMvcAutoConfigurationTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/web/WebMvcAutoConfigurationTests.java index 84813d0ba00..6031ab0d180 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/web/WebMvcAutoConfigurationTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/autoconfigure/web/WebMvcAutoConfigurationTests.java @@ -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 } diff --git a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/main/SimpleMainTests.java b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/main/SimpleMainTests.java index 7bdd74f4c0c..3f6e03ed5e8 100644 --- a/spring-zero-autoconfigure/src/test/java/org/springframework/zero/main/SimpleMainTests.java +++ b/spring-zero-autoconfigure/src/test/java/org/springframework/zero/main/SimpleMainTests.java @@ -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 { diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/Log.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/Log.java new file mode 100644 index 00000000000..b13e0428a0b --- /dev/null +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/Log.java @@ -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); + } + +} diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/SpringZeroCli.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/SpringZeroCli.java index ec73d328fbc..2cc2161275a 100644 --- a/spring-zero-cli/src/main/java/org/springframework/zero/cli/SpringZeroCli.java +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/SpringZeroCli.java @@ -92,23 +92,27 @@ public class SpringZeroCli { return 1; } catch (Exception ex) { - Set 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 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(" []"); - System.out.println(""); - System.out.println("Available commands are:"); + Log.info("usage: " + CLI_APP + " "); + Log.info(""); + Log.info(" []"); + 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 ' 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; } diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/CleanCommand.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/CleanCommand.java index a664bc67df6..8c5da886d3b 100644 --- a/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/CleanCommand.java +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/CleanCommand.java @@ -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 allOption; private OptionSpec 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 specs = new ArrayList(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; } } diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/OptionHandler.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/OptionHandler.java index 8b21e932eed..e56b1c43280 100644 --- a/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/OptionHandler.java +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/OptionHandler.java @@ -78,7 +78,7 @@ public class OptionHandler { try { getParser().printHelpOn(out); } - catch (IOException e) { + catch (IOException ex) { return "Help not available"; } return out.toString(); diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/ScriptCommand.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/ScriptCommand.java index c1c47c85fc8..5446518cc17 100644 --- a/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/ScriptCommand.java +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/command/ScriptCommand.java @@ -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 { diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/compiler/DependencyCustomizer.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/compiler/DependencyCustomizer.java index 613c0581191..0a06559376d 100644 --- a/spring-zero-cli/src/main/java/org/springframework/zero/cli/compiler/DependencyCustomizer.java +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/compiler/DependencyCustomizer.java @@ -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(); diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/compiler/autoconfigure/SpringZeroCompilerAutoConfiguration.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/compiler/autoconfigure/SpringZeroCompilerAutoConfiguration.java index 35d70203121..31864a9ef2b 100644 --- a/spring-zero-cli/src/main/java/org/springframework/zero/cli/compiler/autoconfigure/SpringZeroCompilerAutoConfiguration.java +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/compiler/autoconfigure/SpringZeroCompilerAutoConfiguration.java @@ -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); } } } diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/runner/SpringZeroRunner.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/runner/SpringZeroRunner.java index 584fd1a2427..1330089e053 100644 --- a/spring-zero-cli/src/main/java/org/springframework/zero/cli/runner/SpringZeroRunner.java +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/runner/SpringZeroRunner.java @@ -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"); diff --git a/spring-zero-cli/src/main/java/org/springframework/zero/cli/template/GroovyTemplate.java b/spring-zero-cli/src/main/java/org/springframework/zero/cli/template/GroovyTemplate.java index 0494b36ce5e..610a5e867b8 100644 --- a/spring-zero-cli/src/main/java/org/springframework/zero/cli/template/GroovyTemplate.java +++ b/spring-zero-cli/src/main/java/org/springframework/zero/cli/template/GroovyTemplate.java @@ -30,7 +30,7 @@ import org.codehaus.groovy.control.CompilationFailedException; /** * @author Dave Syer */ -public class GroovyTemplate { +public abstract class GroovyTemplate { // FIXME is this used? diff --git a/spring-zero-cli/src/test/java/org/springframework/zero/cli/SampleIntegrationTests.java b/spring-zero-cli/src/test/java/org/springframework/zero/cli/SampleIntegrationTests.java index 5a9dd95b585..4460ac75b7a 100644 --- a/spring-zero-cli/src/test/java/org/springframework/zero/cli/SampleIntegrationTests.java +++ b/spring-zero-cli/src/test/java/org/springframework/zero/cli/SampleIntegrationTests.java @@ -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 { diff --git a/spring-zero-cli/src/test/java/org/springframework/zero/cli/command/ScriptCommandTests.java b/spring-zero-cli/src/test/java/org/springframework/zero/cli/command/ScriptCommandTests.java index ae60d8df673..743bebf5405 100644 --- a/spring-zero-cli/src/test/java/org/springframework/zero/cli/command/ScriptCommandTests.java +++ b/spring-zero-cli/src/test/java/org/springframework/zero/cli/command/ScriptCommandTests.java @@ -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 { diff --git a/spring-zero-core/src/main/java/org/springframework/zero/BeanDefinitionLoader.java b/spring-zero-core/src/main/java/org/springframework/zero/BeanDefinitionLoader.java index c4b02b652fb..50ad915775e 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/BeanDefinitionLoader.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/BeanDefinitionLoader.java @@ -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 + "'"); } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/SpringApplication.java b/spring-zero-core/src/main/java/org/springframework/zero/SpringApplication.java index e5114a2ff3b..da07a747a7e 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/SpringApplication.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/SpringApplication.java @@ -183,7 +183,7 @@ public class SpringApplication { initialize(); } - protected void initialize() { + private void initialize() { this.webEnvironment = deduceWebEnvironment(); this.initializers = new ArrayList>(); @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; diff --git a/spring-zero-core/src/main/java/org/springframework/zero/bind/CustomPropertyConstructor.java b/spring-zero-core/src/main/java/org/springframework/zero/bind/CustomPropertyConstructor.java index a0f2d05f193..d2d54280876 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/bind/CustomPropertyConstructor.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/bind/CustomPropertyConstructor.java @@ -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); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/bind/InetAddressEditor.java b/spring-zero-core/src/main/java/org/springframework/zero/bind/InetAddressEditor.java index f294c128446..7866ffe471e 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/bind/InetAddressEditor.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/bind/InetAddressEditor.java @@ -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); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/bind/PropertiesConfigurationFactory.java b/spring-zero-core/src/main/java/org/springframework/zero/bind/PropertiesConfigurationFactory.java index d22a8d8c48a..cd9806d12e9 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/bind/PropertiesConfigurationFactory.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/bind/PropertiesConfigurationFactory.java @@ -46,8 +46,7 @@ import org.springframework.validation.Validator; public class PropertiesConfigurationFactory implements FactoryBean, 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 implements FactoryBean, 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 implements FactoryBean, 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); diff --git a/spring-zero-core/src/main/java/org/springframework/zero/bind/RelaxedDataBinder.java b/spring-zero-core/src/main/java/org/springframework/zero/bind/RelaxedDataBinder.java index 430fbfd4bc7..8d7ca09621d 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/bind/RelaxedDataBinder.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/bind/RelaxedDataBinder.java @@ -199,6 +199,7 @@ public class RelaxedDataBinder extends DataBinder { } } catch (InvalidPropertyException ex) { + // swallow and contrinue } } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/bind/YamlConfigurationFactory.java b/spring-zero-core/src/main/java/org/springframework/zero/bind/YamlConfigurationFactory.java index 4e86bebf6b4..4bb49bfec47 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/bind/YamlConfigurationFactory.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/bind/YamlConfigurationFactory.java @@ -50,7 +50,7 @@ import org.yaml.snakeyaml.error.YAMLException; public class YamlConfigurationFactory implements FactoryBean, 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 implements FactoryBean, 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); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/config/JacksonJsonParser.java b/spring-zero-core/src/main/java/org/springframework/zero/config/JacksonJsonParser.java index be4780c83cd..df64c81d49c 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/config/JacksonJsonParser.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/config/JacksonJsonParser.java @@ -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 parseMap(String json) { try { - @SuppressWarnings("unchecked") - Map 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 parseList(String json) { try { - @SuppressWarnings("unchecked") - List 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); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/config/JsonParser.java b/spring-zero-core/src/main/java/org/springframework/zero/config/JsonParser.java index a2f0fb119a1..84332763907 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/config/JsonParser.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/config/JsonParser.java @@ -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; diff --git a/spring-zero-core/src/main/java/org/springframework/zero/config/JsonParserFactory.java b/spring-zero-core/src/main/java/org/springframework/zero/config/JsonParserFactory.java index 006ee4352d9..cf92a8aec22 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/config/JsonParserFactory.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/config/JsonParserFactory.java @@ -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 diff --git a/spring-zero-core/src/main/java/org/springframework/zero/config/YamlJsonParser.java b/spring-zero-core/src/main/java/org/springframework/zero/config/YamlJsonParser.java index 0a46f379831..6eb723d4d70 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/config/YamlJsonParser.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/config/YamlJsonParser.java @@ -30,17 +30,15 @@ import org.yaml.snakeyaml.Yaml; public class YamlJsonParser implements JsonParser { @Override + @SuppressWarnings("unchecked") public Map parseMap(String json) { - @SuppressWarnings("unchecked") - Map map = new Yaml().loadAs(json, Map.class); - return map; + return new Yaml().loadAs(json, Map.class); } @Override + @SuppressWarnings("unchecked") public List parseList(String json) { - @SuppressWarnings("unchecked") - List list = new Yaml().loadAs(json, List.class); - return list; + return new Yaml().loadAs(json, List.class); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/config/YamlProcessor.java b/spring-zero-core/src/main/java/org/springframework/zero/config/YamlProcessor.java index 14764108b5c..de1fc092b11 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/config/YamlProcessor.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/config/YamlProcessor.java @@ -38,35 +38,7 @@ import org.yaml.snakeyaml.Yaml; */ public class YamlProcessor { - public interface MatchCallback { - void process(Properties properties, Map 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 map = (Map) 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 asMap(Object object) { + return (Map) object; + } + private boolean process(Map 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 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 { diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/condition/AbstractOnBeanCondition.java b/spring-zero-core/src/main/java/org/springframework/zero/context/condition/AbstractOnBeanCondition.java index 0698a9772b7..cb16ac442bc 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/condition/AbstractOnBeanCondition.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/condition/AbstractOnBeanCondition.java @@ -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) { diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/condition/ConditionLogUtils.java b/spring-zero-core/src/main/java/org/springframework/zero/context/condition/ConditionLogUtils.java index 9fda8cf1062..d896c24631f 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/condition/ConditionLogUtils.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/condition/ConditionLogUtils.java @@ -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 = ""; diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/condition/OnExpressionCondition.java b/spring-zero-core/src/main/java/org/springframework/zero/context/condition/OnExpressionCondition.java index 90d81e7753c..03f1f28886f 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/condition/OnExpressionCondition.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/condition/OnExpressionCondition.java @@ -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; diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/AbstractEmbeddedServletContainerFactory.java b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/AbstractEmbeddedServletContainerFactory.java index 663e6f0214b..5a068f4ac5c 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/AbstractEmbeddedServletContainerFactory.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/AbstractEmbeddedServletContainerFactory.java @@ -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; } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/AnnotationConfigEmbeddedWebApplicationContext.java b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/AnnotationConfigEmbeddedWebApplicationContext.java index 60477fd6137..81bb275455c 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/AnnotationConfigEmbeddedWebApplicationContext.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/AnnotationConfigEmbeddedWebApplicationContext.java @@ -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(); + } + } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/EmbeddedServletContainerCustomizerBeanPostProcessor.java b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/EmbeddedServletContainerCustomizerBeanPostProcessor.java index cf0ecee2062..dfaa91df2e2 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/EmbeddedServletContainerCustomizerBeanPostProcessor.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/EmbeddedServletContainerCustomizerBeanPostProcessor.java @@ -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; diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/EmbeddedWebApplicationContext.java b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/EmbeddedWebApplicationContext.java index b319ab9691d..7267d37ce5f 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/EmbeddedWebApplicationContext.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/EmbeddedWebApplicationContext.java @@ -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(), diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/FilterRegistrationBean.java b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/FilterRegistrationBean.java index e2699dd2820..bbe3af8745f 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/FilterRegistrationBean.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/FilterRegistrationBean.java @@ -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); + } } /** diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/ServletRegistrationBean.java b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/ServletRegistrationBean.java index 0756ba01852..312dcf45b80 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/ServletRegistrationBean.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/ServletRegistrationBean.java @@ -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)); } /** diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/XmlEmbeddedWebApplicationContext.java b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/XmlEmbeddedWebApplicationContext.java index 895222ec447..60a3b0c0c93 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/XmlEmbeddedWebApplicationContext.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/XmlEmbeddedWebApplicationContext.java @@ -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(); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/tomcat/TomcatEmbeddedServletContainer.java b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/tomcat/TomcatEmbeddedServletContainer.java index 9caf560d926..f9a45d08936 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/tomcat/TomcatEmbeddedServletContainer.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/embedded/tomcat/TomcatEmbeddedServletContainer.java @@ -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(); } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/initializer/ConfigFileApplicationContextInitializer.java b/spring-zero-core/src/main/java/org/springframework/zero/context/initializer/ConfigFileApplicationContextInitializer.java index 1c4c4eef338..8db25ecb8d1 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/initializer/ConfigFileApplicationContextInitializer.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/initializer/ConfigFileApplicationContextInitializer.java @@ -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 candidates = getCandidateLocations(applicationContext); + List candidates = getCandidateLocations(); // Initial load allows profiles to be activated for (String candidate : candidates) { @@ -97,8 +97,7 @@ public class ConfigFileApplicationContextInitializer implements } } - private List getCandidateLocations( - ConfigurableApplicationContext applicationContext) { + private List getCandidateLocations() { List candidates = new ArrayList(); 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); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/context/initializer/LoggingApplicationContextInitializer.java b/spring-zero-core/src/main/java/org/springframework/zero/context/initializer/LoggingApplicationContextInitializer.java index 0809d0475b5..868d92644e6 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/context/initializer/LoggingApplicationContextInitializer.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/context/initializer/LoggingApplicationContextInitializer.java @@ -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, diff --git a/spring-zero-core/src/main/java/org/springframework/zero/logging/JavaLoggerConfigurer.java b/spring-zero-core/src/main/java/org/springframework/zero/logging/JavaLoggerConfigurer.java index 4213bf56368..f4ae67c05f7 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/logging/JavaLoggerConfigurer.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/logging/JavaLoggerConfigurer.java @@ -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); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/logging/LogbackConfigurer.java b/spring-zero-core/src/main/java/org/springframework/zero/logging/LogbackConfigurer.java index 63da7cf340f..f5ae1b5ce10 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/logging/LogbackConfigurer.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/logging/LogbackConfigurer.java @@ -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); } } diff --git a/spring-zero-core/src/main/java/org/springframework/zero/web/SpringServletInitializer.java b/spring-zero-core/src/main/java/org/springframework/zero/web/SpringServletInitializer.java index 2b2d22297e7..5bafb1216f6 100644 --- a/spring-zero-core/src/main/java/org/springframework/zero/web/SpringServletInitializer.java +++ b/spring-zero-core/src/main/java/org/springframework/zero/web/SpringServletInitializer.java @@ -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( diff --git a/spring-zero-core/src/test/java/org/springframework/zero/TestUtils.java b/spring-zero-core/src/test/java/org/springframework/zero/TestUtils.java index 1bfb39243f8..f9f35eaedeb 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/TestUtils.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/TestUtils.java @@ -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) { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/bind/PropertySourcesPropertyValuesTests.java b/spring-zero-core/src/test/java/org/springframework/zero/bind/PropertySourcesPropertyValuesTests.java index d3a29c8fbc1..9ad499fd806 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/bind/PropertySourcesPropertyValuesTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/bind/PropertySourcesPropertyValuesTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/bind/YamlConfigurationFactoryTests.java b/spring-zero-core/src/test/java/org/springframework/zero/bind/YamlConfigurationFactoryTests.java index 1fcab855034..20e5a9aea82 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/bind/YamlConfigurationFactoryTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/bind/YamlConfigurationFactoryTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/config/JacksonParserTests.java b/spring-zero-core/src/test/java/org/springframework/zero/config/JacksonParserTests.java index 8203d859521..271de278aef 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/config/JacksonParserTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/config/JacksonParserTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/config/SimpleJsonParserTests.java b/spring-zero-core/src/test/java/org/springframework/zero/config/SimpleJsonParserTests.java index 2012dd972c9..5beea86618e 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/config/SimpleJsonParserTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/config/SimpleJsonParserTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/config/YamlParserTests.java b/spring-zero-core/src/test/java/org/springframework/zero/config/YamlJsonParserTests.java similarity index 82% rename from spring-zero-core/src/test/java/org/springframework/zero/config/YamlParserTests.java rename to spring-zero-core/src/test/java/org/springframework/zero/config/YamlJsonParserTests.java index 81357d56414..1cda3586e54 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/config/YamlParserTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/config/YamlJsonParserTests.java @@ -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() { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/config/YamlMapFactoryBeanTests.java b/spring-zero-core/src/test/java/org/springframework/zero/config/YamlMapFactoryBeanTests.java index 4ef7cff4914..ea7afe8dc1a 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/config/YamlMapFactoryBeanTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/config/YamlMapFactoryBeanTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/config/YamlPropertiesFactoryBeanTests.java b/spring-zero-core/src/test/java/org/springframework/zero/config/YamlPropertiesFactoryBeanTests.java index a9d6898bbf3..8b31b027483 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/config/YamlPropertiesFactoryBeanTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/config/YamlPropertiesFactoryBeanTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnClassConditionTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnClassConditionTests.java index e7f97ce9ee6..cfffc9d6dbd 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnClassConditionTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnClassConditionTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnExpressionConditionTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnExpressionConditionTests.java index a9e5eae562f..fb4f208f377 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnExpressionConditionTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnExpressionConditionTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnMissingClassConditionTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnMissingClassConditionTests.java index 9b1622e660e..b2696b7b077 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnMissingClassConditionTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnMissingClassConditionTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/NotWebApplicationConditionTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnNotWebApplicationConditionTests.java similarity index 95% rename from spring-zero-core/src/test/java/org/springframework/zero/context/condition/NotWebApplicationConditionTests.java rename to spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnNotWebApplicationConditionTests.java index 7f8fc6f1863..dce56319071 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/NotWebApplicationConditionTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnNotWebApplicationConditionTests.java @@ -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(); diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnResourceConditionTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnResourceConditionTests.java index d83a15fa7f2..493c23d6819 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnResourceConditionTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnResourceConditionTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/WebApplicationConditionTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnWebApplicationConditionTests.java similarity index 95% rename from spring-zero-core/src/test/java/org/springframework/zero/context/condition/WebApplicationConditionTests.java rename to spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnWebApplicationConditionTests.java index 4ac8d68774a..ad729822b2e 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/condition/WebApplicationConditionTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/condition/OnWebApplicationConditionTests.java @@ -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(); diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java index ee17be4f4df..d1e8485929b 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java @@ -80,7 +80,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { try { this.container.stop(); } - catch (Exception e) { + catch (Exception ex) { } } } diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/initializer/ContextIdApplicationContextInitializerTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/initializer/ContextIdApplicationContextInitializerTests.java index a2c799597a8..3c805295209 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/initializer/ContextIdApplicationContextInitializerTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/initializer/ContextIdApplicationContextInitializerTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/context/initializer/VcapApplicationContextInitializerTests.java b/spring-zero-core/src/test/java/org/springframework/zero/context/initializer/VcapApplicationContextInitializerTests.java index 04e393f9855..0d57fcc6366 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/context/initializer/VcapApplicationContextInitializerTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/context/initializer/VcapApplicationContextInitializerTests.java @@ -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 { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/logging/JavaLoggerConfigurerTests.java b/spring-zero-core/src/test/java/org/springframework/zero/logging/JavaLoggerConfigurerTests.java index bdbe34b1ffb..0d0048cb321 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/logging/JavaLoggerConfigurerTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/logging/JavaLoggerConfigurerTests.java @@ -25,11 +25,12 @@ import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.zero.logging.JavaLoggerConfigurer; import static org.junit.Assert.assertTrue; /** + * Tests for {@link JavaLoggerConfigurer}. + * * @author Dave Syer */ public class JavaLoggerConfigurerTests { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/logging/LogbackConfigurerTests.java b/spring-zero-core/src/test/java/org/springframework/zero/logging/LogbackConfigurerTests.java index 8f4c77181cc..8accbccc7ce 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/logging/LogbackConfigurerTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/logging/LogbackConfigurerTests.java @@ -29,6 +29,8 @@ import org.junit.Test; import static org.junit.Assert.assertTrue; /** + * Tests for {@link LogbackConfigurer}. + * * @author Dave Syer */ public class LogbackConfigurerTests { diff --git a/spring-zero-core/src/test/java/org/springframework/zero/logging/LoggingInitializerTests.java b/spring-zero-core/src/test/java/org/springframework/zero/logging/LoggingApplicationContextInitializerTests.java similarity index 90% rename from spring-zero-core/src/test/java/org/springframework/zero/logging/LoggingInitializerTests.java rename to spring-zero-core/src/test/java/org/springframework/zero/logging/LoggingApplicationContextInitializerTests.java index 434939baa3c..200f49c1c7f 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/logging/LoggingInitializerTests.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/logging/LoggingApplicationContextInitializerTests.java @@ -32,9 +32,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** + * Tests for {@link LoggingApplicationContextInitializer}. + * * @author Dave Syer */ -public class LoggingInitializerTests { +public class LoggingApplicationContextInitializerTests { private LoggingApplicationContextInitializer initializer = new LoggingApplicationContextInitializer(); @@ -65,7 +67,7 @@ public class LoggingInitializerTests { public void testDefaultConfigLocation() { GenericApplicationContext context = new GenericApplicationContext(); this.initializer.initialize(context); - Log logger = LogFactory.getLog(LoggingInitializerTests.class); + Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class); logger.info("Hello world"); String output = getOutput().trim(); assertTrue("Wrong output:\n" + output, output.contains("Hello world")); @@ -87,7 +89,7 @@ public class LoggingInitializerTests { } }); this.initializer.initialize(context); - Log logger = LogFactory.getLog(LoggingInitializerTests.class); + Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class); logger.info("Hello world"); String output = getOutput().trim(); assertTrue("Wrong output:\n" + output, output.contains("Hello world")); @@ -112,7 +114,7 @@ public class LoggingInitializerTests { } }); this.initializer.initialize(context); - Log logger = LogFactory.getLog(LoggingInitializerTests.class); + Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class); logger.info("Hello world"); String output = getOutput().trim(); assertTrue("Wrong output:\n" + output, output.startsWith("foo.log")); @@ -135,7 +137,7 @@ public class LoggingInitializerTests { } }); this.initializer.initialize(context); - Log logger = LogFactory.getLog(LoggingInitializerTests.class); + Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class); logger.info("Hello world"); String output = getOutput().trim(); assertTrue("Wrong output:\n" + output, output.startsWith("foo/springzero.log")); diff --git a/spring-zero-core/src/test/java/org/springframework/zero/logging/TestFormatter.java b/spring-zero-core/src/test/java/org/springframework/zero/logging/TestFormatter.java index 317ade89dcd..5ab6d99b48c 100644 --- a/spring-zero-core/src/test/java/org/springframework/zero/logging/TestFormatter.java +++ b/spring-zero-core/src/test/java/org/springframework/zero/logging/TestFormatter.java @@ -20,6 +20,8 @@ import java.util.logging.Formatter; import java.util.logging.LogRecord; /** + * Simple test {@link Formatter}. + * * @author Dave Syer */ public class TestFormatter extends Formatter { diff --git a/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/Launcher.java b/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/Launcher.java index fd80577b298..70df2f2808d 100644 --- a/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/Launcher.java +++ b/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/Launcher.java @@ -56,8 +56,8 @@ public abstract class Launcher { try { launch(args, getClass().getProtectionDomain()); } - catch (Exception e) { - e.printStackTrace(); + catch (Exception ex) { + ex.printStackTrace(); System.exit(1); } } diff --git a/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/MainMethodRunner.java b/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/MainMethodRunner.java index e09a68e8499..61f1a7029c8 100644 --- a/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/MainMethodRunner.java +++ b/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/MainMethodRunner.java @@ -37,23 +37,23 @@ public class MainMethodRunner implements Runnable { */ public MainMethodRunner(String mainClass, String[] args) { this.mainClassName = mainClass; - this.args = args; + this.args = (args == null ? null : args.clone()); } @Override public void run() { try { Class mainClass = Thread.currentThread().getContextClassLoader() - .loadClass(mainClassName); + .loadClass(this.mainClassName); Method mainMethod = mainClass.getDeclaredMethod("main", String[].class); if (mainMethod == null) { - throw new IllegalStateException(mainClassName + throw new IllegalStateException(this.mainClassName + " does not have a main method"); } - mainMethod.invoke(null, new Object[] { args }); + mainMethod.invoke(null, new Object[] { this.args }); } - catch (Exception e) { - e.printStackTrace(); + catch (Exception ex) { + ex.printStackTrace(); System.exit(1); } } diff --git a/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/data/RandomAccessDataFile.java b/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/data/RandomAccessDataFile.java index 01e6897133f..b9df11001e5 100644 --- a/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/data/RandomAccessDataFile.java +++ b/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/data/RandomAccessDataFile.java @@ -225,8 +225,8 @@ public class RandomAccessDataFile implements RandomAccessData { return (file == null ? new RandomAccessFile( RandomAccessDataFile.this.file, "r") : file); } - catch (InterruptedException e) { - throw new IOException(e); + catch (InterruptedException ex) { + throw new IOException(ex); } } @@ -249,8 +249,8 @@ public class RandomAccessDataFile implements RandomAccessData { this.available.release(size); } } - catch (InterruptedException e) { - throw new IOException(e); + catch (InterruptedException ex) { + throw new IOException(ex); } } } diff --git a/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/jar/RandomAccessJarFile.java b/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/jar/RandomAccessJarFile.java index dc499e3bf53..9d4f2f84010 100644 --- a/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/jar/RandomAccessJarFile.java +++ b/spring-zero-launcher/src/main/java/org/springframework/zero/launcher/jar/RandomAccessJarFile.java @@ -82,7 +82,7 @@ public class RandomAccessJarFile extends JarFile { * @throws IOException */ public RandomAccessJarFile(File file, JarEntryFilter... filters) throws IOException { - this(new RandomAccessDataFile(file)); + this(new RandomAccessDataFile(file), filters); } /** @@ -93,7 +93,7 @@ public class RandomAccessJarFile extends JarFile { */ public RandomAccessJarFile(RandomAccessDataFile file, JarEntryFilter... filters) throws IOException { - this(file, file.getFile().getPath(), file); + this(file, file.getFile().getPath(), file, filters); } /** @@ -204,32 +204,40 @@ public class RandomAccessJarFile extends JarFile { if (ze == null) { throw new IllegalArgumentException("ZipEntry must not be null"); } + if (ze.isDirectory()) { - final String directoryName = ze.getName(); - JarEntryFilter[] filtersToUse = new JarEntryFilter[filters.length + 1]; - System.arraycopy(filters, 0, filtersToUse, 1, filters.length); - filtersToUse[0] = new JarEntryFilter() { - @Override - public String apply(String entryName, JarEntry entry) { - if (entryName.startsWith(directoryName) - && !entryName.equals(directoryName)) { - return entryName.substring(ze.getName().length()); - } - return null; + return getNestedJarFileFromDirectoryEntry(ze, filters); + } + + return getNestedJarFileFromFileEntry(ze, filters); + } + + private RandomAccessJarFile getNestedJarFileFromDirectoryEntry(final ZipEntry entry, + JarEntryFilter... filters) throws IOException { + final String name = entry.getName(); + JarEntryFilter[] filtersToUse = new JarEntryFilter[filters.length + 1]; + System.arraycopy(filters, 0, filtersToUse, 1, filters.length); + filtersToUse[0] = new JarEntryFilter() { + @Override + public String apply(String entryName, JarEntry ze) { + if (entryName.startsWith(name) && !entryName.equals(name)) { + return entryName.substring(entry.getName().length()); } - }; - return new RandomAccessJarFile(this.rootJarFile, getName() + "!/" - + directoryName.substring(0, directoryName.length() - 1), this.data, - filtersToUse); - } - else { - if (ze.getMethod() != ZipEntry.STORED) { - throw new IllegalStateException("Unable to open nested compressed entry " - + ze.getName()); + return null; } - return new RandomAccessJarFile(this.rootJarFile, getName() + "!/" - + ze.getName(), getData(ze), filters); + }; + return new RandomAccessJarFile(this.rootJarFile, getName() + "!/" + + name.substring(0, name.length() - 1), this.data, filtersToUse); + } + + private RandomAccessJarFile getNestedJarFileFromFileEntry(ZipEntry entry, + JarEntryFilter... filters) throws IOException { + if (entry.getMethod() != ZipEntry.STORED) { + throw new IllegalStateException("Unable to open nested compressed entry " + + entry.getName()); } + return new RandomAccessJarFile(this.rootJarFile, getName() + "!/" + + entry.getName(), getData(entry), filters); } /** @@ -414,7 +422,7 @@ public class RandomAccessJarFile extends JarFile { return (int) (this.jarEntry == null ? this.jarFile.size() : this.jarEntry .getSize()); } - catch (IOException e) { + catch (IOException ex) { return -1; } } diff --git a/spring-zero-maven-plugin/src/main/java/org/springframework/zero/maven/MainClassFinder.java b/spring-zero-maven-plugin/src/main/java/org/springframework/zero/maven/MainClassFinder.java index 630a6648154..c93c6d60b85 100644 --- a/spring-zero-maven-plugin/src/main/java/org/springframework/zero/maven/MainClassFinder.java +++ b/spring-zero-maven-plugin/src/main/java/org/springframework/zero/maven/MainClassFinder.java @@ -39,7 +39,7 @@ import org.objectweb.asm.Type; * * @author Phillip Webb */ -class MainClassFinder { +abstract class MainClassFinder { private static final String DOT_CLASS = ".class"; diff --git a/spring-zero-maven-plugin/src/main/java/org/springframework/zero/maven/PropertiesMergingResourceTransformer.java b/spring-zero-maven-plugin/src/main/java/org/springframework/zero/maven/PropertiesMergingResourceTransformer.java index 1006e74c6c5..b3013e596f5 100644 --- a/spring-zero-maven-plugin/src/main/java/org/springframework/zero/maven/PropertiesMergingResourceTransformer.java +++ b/spring-zero-maven-plugin/src/main/java/org/springframework/zero/maven/PropertiesMergingResourceTransformer.java @@ -37,7 +37,8 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer // FIXME move out of core - String resource; // Set this in pom configuration with ... + private String resource; // Set this in pom configuration with + // ... private Properties data = new Properties(); @@ -84,4 +85,12 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer this.data.clear(); } + public String getResource() { + return this.resource; + } + + public void setResource(String resource) { + this.resource = resource; + } + } diff --git a/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/MainClassFinderTests.java b/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/MainClassFinderTests.java index 3dbbf70eee0..796d1f20290 100644 --- a/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/MainClassFinderTests.java +++ b/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/MainClassFinderTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.zero.maven; import java.io.File; @@ -25,7 +26,6 @@ import org.codehaus.plexus.util.IOUtil; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.springframework.zero.maven.MainClassFinder; import org.springframework.zero.maven.sample.ClassWithMainMethod; import org.springframework.zero.maven.sample.ClassWithoutMainMethod; diff --git a/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/PropertiesMergingResourceTransformerTests.java b/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/PropertiesMergingResourceTransformerTests.java index e0d4573bb7e..79a035f3c72 100644 --- a/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/PropertiesMergingResourceTransformerTests.java +++ b/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/PropertiesMergingResourceTransformerTests.java @@ -21,7 +21,6 @@ import java.io.ByteArrayOutputStream; import java.util.jar.JarOutputStream; import org.junit.Test; -import org.springframework.zero.maven.PropertiesMergingResourceTransformer; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -29,6 +28,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** + * Tests for {@link PropertiesMergingResourceTransformer}. + * * @author Dave Syer */ public class PropertiesMergingResourceTransformerTests { @@ -54,7 +55,7 @@ public class PropertiesMergingResourceTransformerTests { @Test public void testOutput() throws Exception { - this.transformer.resource = "foo"; + this.transformer.setResource("foo"); this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null); ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/sample/ClassWithoutMainMethod.java b/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/sample/ClassWithoutMainMethod.java index ad6e5423b35..6560f33e2e4 100644 --- a/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/sample/ClassWithoutMainMethod.java +++ b/spring-zero-maven-plugin/src/test/java/org/springframework/zero/maven/sample/ClassWithoutMainMethod.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.zero.maven.sample; /** diff --git a/spring-zero-samples/spring-zero-sample-actuator-ui/src/main/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplication.java b/spring-zero-samples/spring-zero-sample-actuator-ui/src/main/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplication.java index ae7c95711b7..e60a2bfd413 100644 --- a/spring-zero-samples/spring-zero-sample-actuator-ui/src/main/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplication.java +++ b/spring-zero-samples/spring-zero-sample-actuator-ui/src/main/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplication.java @@ -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.sample.actuator.ui; import java.util.Date; diff --git a/spring-zero-samples/spring-zero-sample-actuator-ui/src/test/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-zero-samples/spring-zero-sample-actuator-ui/src/test/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java index 52ad4bc01e0..42f5cc4aab6 100644 --- a/spring-zero-samples/spring-zero-sample-actuator-ui/src/test/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator-ui/src/test/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java @@ -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.sample.actuator.ui; import java.io.IOException; @@ -18,7 +34,6 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.actuator.ui.SampleActuatorUiApplication; import static org.junit.Assert.assertEquals; @@ -26,14 +41,13 @@ import static org.junit.Assert.assertEquals; * Integration tests for separate management and main service ports. * * @author Dave Syer - * */ public class SampleActuatorUiApplicationPortTests { private static ConfigurableApplicationContext context; - private static int port = 9000; - private static int managementPort = 9001; + private static int port = 9010; + private static int managementPort = 9011; @BeforeClass public static void start() throws Exception { diff --git a/spring-zero-samples/spring-zero-sample-actuator-ui/src/test/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-zero-samples/spring-zero-sample-actuator-ui/src/test/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplicationTests.java index 81443973f5f..f30e81befd7 100644 --- a/spring-zero-samples/spring-zero-sample-actuator-ui/src/test/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator-ui/src/test/java/org/springframework/zero/sample/actuator/ui/SampleActuatorUiApplicationTests.java @@ -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.sample.actuator.ui; import java.io.IOException; diff --git a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index 59f06479880..4084397b145 100644 --- a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -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.sample.actuator; import java.io.IOException; @@ -24,7 +40,6 @@ import org.springframework.security.crypto.codec.Base64; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.actuator.SampleActuatorApplication; import static org.junit.Assert.assertEquals; diff --git a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ManagementAddressSampleActuatorApplicationTests.java b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ManagementAddressSampleActuatorApplicationTests.java index 9f036daed44..0c98e44e43e 100644 --- a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ManagementAddressSampleActuatorApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ManagementAddressSampleActuatorApplicationTests.java @@ -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.sample.actuator; import java.io.IOException; @@ -26,7 +42,6 @@ import org.springframework.security.crypto.codec.Base64; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.actuator.SampleActuatorApplication; import static org.junit.Assert.assertEquals; @@ -39,8 +54,8 @@ public class ManagementAddressSampleActuatorApplicationTests { private static ConfigurableApplicationContext context; - private static int port = 9000; - private static int managementPort = 9001; + private static int port = 9010; + private static int managementPort = 9011; @BeforeClass public static void start() throws Exception { diff --git a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ManagementSampleActuatorApplicationTests.java b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ManagementSampleActuatorApplicationTests.java index e96fa66b081..6d4aa163015 100644 --- a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ManagementSampleActuatorApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ManagementSampleActuatorApplicationTests.java @@ -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.sample.actuator; import java.io.IOException; @@ -17,7 +33,6 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.actuator.SampleActuatorApplication; import static org.junit.Assert.assertEquals; @@ -25,14 +40,13 @@ import static org.junit.Assert.assertEquals; * Integration tests for separate management and main service ports. * * @author Dave Syer - * */ public class ManagementSampleActuatorApplicationTests { private static ConfigurableApplicationContext context; - private static int port = 9000; - private static int managementPort = 9001; + private static int port = 9010; + private static int managementPort = 9011; @BeforeClass public static void start() throws Exception { diff --git a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/NoManagementSampleActuatorApplicationTests.java index ec00119ab96..d6dd397904b 100644 --- a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/NoManagementSampleActuatorApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/NoManagementSampleActuatorApplicationTests.java @@ -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.sample.actuator; import java.io.IOException; @@ -26,7 +42,6 @@ import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.actuator.SampleActuatorApplication; import static org.junit.Assert.assertEquals; @@ -34,7 +49,6 @@ import static org.junit.Assert.assertEquals; * Integration tests for switching off management endpoints. * * @author Dave Syer - * */ public class NoManagementSampleActuatorApplicationTests { diff --git a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/SampleActuatorApplicationTests.java b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/SampleActuatorApplicationTests.java index 9070afa4dd4..9888c6cc089 100644 --- a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/SampleActuatorApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/SampleActuatorApplicationTests.java @@ -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.sample.actuator; import java.io.IOException; @@ -25,7 +41,6 @@ import org.springframework.security.crypto.codec.Base64; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.actuator.SampleActuatorApplication; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -35,7 +50,6 @@ import static org.junit.Assert.assertTrue; * Basic integration tests for service demo application. * * @author Dave Syer - * */ public class SampleActuatorApplicationTests { diff --git a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ShutdownSampleActuatorApplicationTests.java index 24840007f7e..a4e92246ee3 100644 --- a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ShutdownSampleActuatorApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/ShutdownSampleActuatorApplicationTests.java @@ -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.sample.actuator; import java.io.IOException; @@ -25,7 +41,6 @@ import org.springframework.security.crypto.codec.Base64; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.actuator.SampleActuatorApplication; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -34,7 +49,6 @@ import static org.junit.Assert.assertTrue; * Integration tests for separate management and main service ports. * * @author Dave Syer - * */ public class ShutdownSampleActuatorApplicationTests { diff --git a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/UnsecureSampleActuatorApplicationTests.java b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/UnsecureSampleActuatorApplicationTests.java index 0890cb2c68d..1a3d5e45400 100644 --- a/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/UnsecureSampleActuatorApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-actuator/src/test/java/org/springframework/zero/sample/actuator/UnsecureSampleActuatorApplicationTests.java @@ -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.sample.actuator; import java.io.IOException; diff --git a/spring-zero-samples/spring-zero-sample-batch/src/test/java/org/springframework/zero/sample/batch/SampleBatchApplicationTests.java b/spring-zero-samples/spring-zero-sample-batch/src/test/java/org/springframework/zero/sample/batch/SampleBatchApplicationTests.java index 4e42a6f0756..46ef39e090a 100644 --- a/spring-zero-samples/spring-zero-sample-batch/src/test/java/org/springframework/zero/sample/batch/SampleBatchApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-batch/src/test/java/org/springframework/zero/sample/batch/SampleBatchApplicationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.zero.sample.batch; import java.io.ByteArrayOutputStream; @@ -22,7 +23,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.batch.SampleBatchApplication; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/spring-zero-samples/spring-zero-sample-data-jpa/src/main/resources/application.properties b/spring-zero-samples/spring-zero-sample-data-jpa/src/main/resources/application.properties index 04e13807d5b..2793254e4ef 100644 --- a/spring-zero-samples/spring-zero-sample-data-jpa/src/main/resources/application.properties +++ b/spring-zero-samples/spring-zero-sample-data-jpa/src/main/resources/application.properties @@ -1 +1 @@ -spring.jpa.ddl_auto: create_drop \ No newline at end of file +spring.jpa.ddl_auto: create-drop \ No newline at end of file diff --git a/spring-zero-samples/spring-zero-sample-data-jpa/src/test/java/org/springframework/zero/sample/data/jpa/SampleDataJpaApplicationTests.java b/spring-zero-samples/spring-zero-sample-data-jpa/src/test/java/org/springframework/zero/sample/data/jpa/SampleDataJpaApplicationTests.java index 0d9d3239bac..187d2a3f162 100644 --- a/spring-zero-samples/spring-zero-sample-data-jpa/src/test/java/org/springframework/zero/sample/data/jpa/SampleDataJpaApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-data-jpa/src/test/java/org/springframework/zero/sample/data/jpa/SampleDataJpaApplicationTests.java @@ -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.sample.data.jpa; import java.io.IOException; @@ -16,7 +32,6 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.data.jpa.SampleDataJpaApplication; import static org.junit.Assert.assertEquals; diff --git a/spring-zero-samples/spring-zero-sample-integration/src/test/java/org/springframework/zero/sample/integration/consumer/SampleIntegrationApplicationTests.java b/spring-zero-samples/spring-zero-sample-integration/src/test/java/org/springframework/zero/sample/integration/consumer/SampleIntegrationApplicationTests.java index e2e25fcc087..2728be0718a 100644 --- a/spring-zero-samples/spring-zero-sample-integration/src/test/java/org/springframework/zero/sample/integration/consumer/SampleIntegrationApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-integration/src/test/java/org/springframework/zero/sample/integration/consumer/SampleIntegrationApplicationTests.java @@ -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.sample.integration.consumer; import java.util.concurrent.Callable; diff --git a/spring-zero-samples/spring-zero-sample-integration/src/test/java/org/springframework/zero/sample/integration/producer/ProducerApplication.java b/spring-zero-samples/spring-zero-sample-integration/src/test/java/org/springframework/zero/sample/integration/producer/ProducerApplication.java index 71d245c4997..4eda4280f8d 100644 --- a/spring-zero-samples/spring-zero-sample-integration/src/test/java/org/springframework/zero/sample/integration/producer/ProducerApplication.java +++ b/spring-zero-samples/spring-zero-sample-integration/src/test/java/org/springframework/zero/sample/integration/producer/ProducerApplication.java @@ -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.sample.integration.producer; import java.io.File; diff --git a/spring-zero-samples/spring-zero-sample-jetty/src/test/java/org/springframework/zero/sample/jetty/SampleJettyApplicationTests.java b/spring-zero-samples/spring-zero-sample-jetty/src/test/java/org/springframework/zero/sample/jetty/SampleJettyApplicationTests.java index 72c93991b97..3b8e138aa0f 100644 --- a/spring-zero-samples/spring-zero-sample-jetty/src/test/java/org/springframework/zero/sample/jetty/SampleJettyApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-jetty/src/test/java/org/springframework/zero/sample/jetty/SampleJettyApplicationTests.java @@ -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.sample.jetty; import java.io.IOException; diff --git a/spring-zero-samples/spring-zero-sample-profile/src/test/java/org/springframework/zero/sample/profile/SampleProfileApplicationTests.java b/spring-zero-samples/spring-zero-sample-profile/src/test/java/org/springframework/zero/sample/profile/SampleProfileApplicationTests.java index 08095a6e886..03eb7460582 100644 --- a/spring-zero-samples/spring-zero-sample-profile/src/test/java/org/springframework/zero/sample/profile/SampleProfileApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-profile/src/test/java/org/springframework/zero/sample/profile/SampleProfileApplicationTests.java @@ -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.sample.profile; import java.io.ByteArrayOutputStream; @@ -8,7 +24,6 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.zero.sample.profile.SampleProfileApplication; import static org.junit.Assert.assertTrue; diff --git a/spring-zero-samples/spring-zero-sample-simple/src/test/java/org/springframework/zero/sample/simple/SampleSimpleApplicationTests.java b/spring-zero-samples/spring-zero-sample-simple/src/test/java/org/springframework/zero/sample/simple/SampleSimpleApplicationTests.java index a4bb5d3264a..f9459132b80 100644 --- a/spring-zero-samples/spring-zero-sample-simple/src/test/java/org/springframework/zero/sample/simple/SampleSimpleApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-simple/src/test/java/org/springframework/zero/sample/simple/SampleSimpleApplicationTests.java @@ -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.sample.simple; import java.io.ByteArrayOutputStream; diff --git a/spring-zero-samples/spring-zero-sample-tomcat/src/test/java/org/springframework/zero/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-zero-samples/spring-zero-sample-tomcat/src/test/java/org/springframework/zero/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java index e804d812190..196c712f017 100644 --- a/spring-zero-samples/spring-zero-sample-tomcat/src/test/java/org/springframework/zero/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-tomcat/src/test/java/org/springframework/zero/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -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.sample.tomcat; import java.io.IOException; @@ -22,7 +38,6 @@ import org.springframework.zero.SpringApplication; import org.springframework.zero.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.zero.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.zero.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.zero.sample.tomcat.SampleTomcatApplication; import org.springframework.zero.sample.tomcat.service.HelloWorldService; import org.springframework.zero.sample.tomcat.web.SampleController; diff --git a/spring-zero-samples/spring-zero-sample-tomcat/src/test/java/org/springframework/zero/sample/tomcat/SampleTomcatApplicationTests.java b/spring-zero-samples/spring-zero-sample-tomcat/src/test/java/org/springframework/zero/sample/tomcat/SampleTomcatApplicationTests.java index 856d7b5c0bc..41b969527bb 100644 --- a/spring-zero-samples/spring-zero-sample-tomcat/src/test/java/org/springframework/zero/sample/tomcat/SampleTomcatApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-tomcat/src/test/java/org/springframework/zero/sample/tomcat/SampleTomcatApplicationTests.java @@ -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.sample.tomcat; import java.io.IOException; diff --git a/spring-zero-samples/spring-zero-sample-traditional/src/test/java/org/springframework/zero/sample/traditional/SampleTraditionalApplicationTests.java b/spring-zero-samples/spring-zero-sample-traditional/src/test/java/org/springframework/zero/sample/traditional/SampleTraditionalApplicationTests.java index 46019181c5a..b8a7b960bff 100644 --- a/spring-zero-samples/spring-zero-sample-traditional/src/test/java/org/springframework/zero/sample/traditional/SampleTraditionalApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-traditional/src/test/java/org/springframework/zero/sample/traditional/SampleTraditionalApplicationTests.java @@ -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.sample.traditional; import java.io.IOException; @@ -16,7 +32,6 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.zero.SpringApplication; -import org.springframework.zero.sample.traditional.SampleTraditionalApplication; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/spring-zero-samples/spring-zero-sample-xml/src/test/java/org/springframework/zero/sample/xml/SampleSpringXmlApplicationTests.java b/spring-zero-samples/spring-zero-sample-xml/src/test/java/org/springframework/zero/sample/xml/SampleSpringXmlApplicationTests.java index 64a2e334cb4..1e5f33ce998 100644 --- a/spring-zero-samples/spring-zero-sample-xml/src/test/java/org/springframework/zero/sample/xml/SampleSpringXmlApplicationTests.java +++ b/spring-zero-samples/spring-zero-sample-xml/src/test/java/org/springframework/zero/sample/xml/SampleSpringXmlApplicationTests.java @@ -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.sample.xml; import java.io.ByteArrayOutputStream; @@ -6,7 +22,6 @@ import java.io.PrintStream; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.zero.sample.xml.SampleSpringXmlApplication; import static org.junit.Assert.assertTrue;