From 3a3228fc707e112cf4d8448b3e76b60e7512a4f4 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Thu, 17 Nov 2016 16:55:16 -0800 Subject: [PATCH 1/4] Add CORS interceptor for Cloud Foundry actuators This interceptor processes the response with CORS headers and apepars before the Cloud Foundry security interceptor. See gh-7108 --- .../CloudFoundryEndpointHandlerMapping.java | 25 +++++++++++++++++++ ...oudFoundryEndpointHandlerMappingTests.java | 24 +++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMapping.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMapping.java index 6a9555f53d..ebee4c2a81 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMapping.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMapping.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.mvc.AbstractEndpointHandlerMapping; @@ -34,6 +35,7 @@ import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.servlet.HandlerExecutionChain; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerMapping; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; /** * {@link HandlerMapping} to map {@link Endpoint}s to Cloud Foundry specific URLs. @@ -45,10 +47,13 @@ class CloudFoundryEndpointHandlerMapping private final HandlerInterceptor securityInterceptor; + private final CorsConfiguration corsConfiguration; + CloudFoundryEndpointHandlerMapping(Set endpoints, CorsConfiguration corsConfiguration, HandlerInterceptor securityInterceptor) { super(endpoints, corsConfiguration); this.securityInterceptor = securityInterceptor; + this.corsConfiguration = corsConfiguration; } @Override @@ -97,6 +102,7 @@ class CloudFoundryEndpointHandlerMapping private HandlerInterceptor[] addSecurityInterceptor(HandlerInterceptor[] existing) { List interceptors = new ArrayList(); + interceptors.add(new CorsInterceptor(this.corsConfiguration)); interceptors.add(this.securityInterceptor); if (existing != null) { interceptors.addAll(Arrays.asList(existing)); @@ -104,4 +110,23 @@ class CloudFoundryEndpointHandlerMapping return interceptors.toArray(new HandlerInterceptor[interceptors.size()]); } + /** + * {@link HandlerInterceptor} that processes the response for CORS. + * + */ + class CorsInterceptor extends HandlerInterceptorAdapter { + private final CorsConfiguration config; + + CorsInterceptor(CorsConfiguration config) { + this.config = config; + } + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) throws Exception { + return getCorsProcessor().processRequest(this.config, request, response); + } + + } + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMappingTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMappingTests.java index a83559390e..08e029686d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMappingTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMappingTests.java @@ -33,6 +33,9 @@ import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.OrderedHealthAggregator; import org.springframework.context.support.StaticApplicationContext; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsProcessor; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerExecutionChain; import org.springframework.web.servlet.HandlerInterceptor; @@ -47,6 +50,25 @@ import static org.assertj.core.api.Assertions.assertThat; public class CloudFoundryEndpointHandlerMappingTests extends AbstractEndpointHandlerMappingTests { + @Test + public void corsInterceptorShouldBeFirstAndCallCorsProcessor() throws Exception { + TestMvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("a")); + CorsConfiguration corsConfiguration = new CorsConfiguration(); + CloudFoundryEndpointHandlerMapping handlerMapping = new CloudFoundryEndpointHandlerMapping( + Collections.singleton(endpoint), corsConfiguration, null); + CorsProcessor corsProcessor = Mockito.mock(CorsProcessor.class); + handlerMapping.setCorsProcessor(corsProcessor); + MockHttpServletRequest request = new MockHttpServletRequest(); + HandlerExecutionChain handlerExecutionChain = handlerMapping + .getHandlerExecutionChain(endpoint, request); + HandlerInterceptor[] interceptors = handlerExecutionChain.getInterceptors(); + CloudFoundryEndpointHandlerMapping.CorsInterceptor corsInterceptor = (CloudFoundryEndpointHandlerMapping.CorsInterceptor) interceptors[0]; + MockHttpServletResponse response = new MockHttpServletResponse(); + corsInterceptor.preHandle(request, response, new Object()); + Mockito.verify(corsProcessor).processRequest(corsConfiguration, request, + response); + } + @Test public void getHandlerExecutionChainShouldHaveSecurityInterceptor() throws Exception { CloudFoundrySecurityInterceptor securityInterceptor = Mockito @@ -57,7 +79,7 @@ public class CloudFoundryEndpointHandlerMappingTests HandlerExecutionChain handlerExecutionChain = handlerMapping .getHandlerExecutionChain(endpoint, new MockHttpServletRequest()); HandlerInterceptor[] interceptors = handlerExecutionChain.getInterceptors(); - assertThat(interceptors).contains(securityInterceptor); + assertThat(interceptors[1]).isEqualTo(securityInterceptor); } @Test From fce17ca6d9a5736140e200af4c888e9b5000233c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 18 Nov 2016 15:50:19 -0800 Subject: [PATCH 2/4] Polish --- .../autoconfigure/web/ServerProperties.java | 4 +- ...assLoaderFilesResourcePatternResolver.java | 66 +++++++++---------- .../boot/devtools/restart/Restarter.java | 8 ++- .../ClassLoaderFileURLStreamHandler.java | 1 + .../tests/DevToolsIntegrationTests.java | 6 +- 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 9f9c4afeef..ae4a553491 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -964,8 +964,8 @@ public class ServerProperties private boolean renameOnRotate; /** - * Set request attributes for IP address, Hostname, protocol and port used - * for the request. + * Set request attributes for IP address, Hostname, protocol and port used for + * the request. */ private boolean requestAttributesEnabled; diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java index 2bbb7ebf30..51f24e3131 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java @@ -21,12 +21,8 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map.Entry; -import java.util.Set; import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind; @@ -48,9 +44,8 @@ import org.springframework.util.AntPathMatcher; */ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternResolver { - private static final Set LOCATION_PATTERN_PREFIXES = Collections - .unmodifiableSet(new HashSet( - Arrays.asList(CLASSPATH_ALL_URL_PREFIX, CLASSPATH_URL_PREFIX))); + private static final String[] LOCATION_PATTERN_PREFIXES = { CLASSPATH_ALL_URL_PREFIX, + CLASSPATH_URL_PREFIX }; private final ResourcePatternResolver delegate = new PathMatchingResourcePatternResolver(); @@ -62,26 +57,26 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe this.classLoaderFiles = classLoaderFiles; } + @Override + public ClassLoader getClassLoader() { + return this.delegate.getClassLoader(); + } + @Override public Resource getResource(String location) { Resource candidate = this.delegate.getResource(location); - if (isExcludedResource(candidate)) { + if (isDeleted(candidate)) { return new DeletedClassLoaderFileResource(location); } return candidate; } - @Override - public ClassLoader getClassLoader() { - return this.delegate.getClassLoader(); - } - @Override public Resource[] getResources(String locationPattern) throws IOException { List resources = new ArrayList(); Resource[] candidates = this.delegate.getResources(locationPattern); for (Resource candidate : candidates) { - if (!isExcludedResource(candidate)) { + if (!isDeleted(candidate)) { resources.add(candidate); } } @@ -89,38 +84,43 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe return resources.toArray(new Resource[resources.size()]); } - private String trimLocationPattern(String locationPattern) { - for (String prefix : LOCATION_PATTERN_PREFIXES) { - if (locationPattern.startsWith(prefix)) { - return locationPattern.substring(prefix.length()); - } - } - return locationPattern; - } - private List getAdditionalResources(String locationPattern) throws MalformedURLException { List additionalResources = new ArrayList(); String trimmedLocationPattern = trimLocationPattern(locationPattern); for (SourceFolder sourceFolder : this.classLoaderFiles.getSourceFolders()) { for (Entry entry : sourceFolder.getFilesEntrySet()) { - if (entry.getValue().getKind() == Kind.ADDED && this.antPathMatcher - .match(trimmedLocationPattern, entry.getKey())) { - additionalResources.add(new UrlResource(new URL("reloaded", null, -1, - "/" + entry.getKey(), - new ClassLoaderFileURLStreamHandler(entry.getValue())))); + String name = entry.getKey(); + ClassLoaderFile file = entry.getValue(); + if (file.getKind() == Kind.ADDED + && this.antPathMatcher.match(trimmedLocationPattern, name)) { + URL url = new URL("reloaded", null, -1, "/" + name, + new ClassLoaderFileURLStreamHandler(file)); + UrlResource resource = new UrlResource(url); + additionalResources.add(resource); } } } return additionalResources; } - private boolean isExcludedResource(Resource resource) { + private String trimLocationPattern(String pattern) { + for (String prefix : LOCATION_PATTERN_PREFIXES) { + if (pattern.startsWith(prefix)) { + return pattern.substring(prefix.length()); + } + } + return pattern; + } + + private boolean isDeleted(Resource resource) { for (SourceFolder sourceFolder : this.classLoaderFiles.getSourceFolders()) { for (Entry entry : sourceFolder.getFilesEntrySet()) { try { - if (entry.getValue().getKind() == Kind.DELETED && resource.exists() - && resource.getURI().toString().endsWith(entry.getKey())) { + String name = entry.getKey(); + ClassLoaderFile file = entry.getValue(); + if (file.getKind() == Kind.DELETED && resource.exists() + && resource.getURI().toString().endsWith(name)) { return true; } } @@ -136,8 +136,6 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe /** * A {@link Resource} that represents a {@link ClassLoaderFile} that has been * {@link Kind#DELETED deleted}. - * - * @author Andy Wilkinson */ private final class DeletedClassLoaderFileResource extends AbstractResource { @@ -161,5 +159,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe public InputStream getInputStream() throws IOException { throw new IOException(this.name + " has been deleted"); } + } + } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java index 6137a29a53..c66d9bb8fa 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java @@ -420,12 +420,16 @@ public class Restarter { return; } if (applicationContext instanceof GenericApplicationContext) { - ((GenericApplicationContext) applicationContext).setResourceLoader( - new ClassLoaderFilesResourcePatternResolver(this.classLoaderFiles)); + prepare((GenericApplicationContext) applicationContext); } this.rootContext = applicationContext; } + private void prepare(GenericApplicationContext applicationContext) { + applicationContext.setResourceLoader( + new ClassLoaderFilesResourcePatternResolver(this.classLoaderFiles)); + } + private LeakSafeThread getLeakSafeThread() { try { return this.leakSafeThreads.takeFirst(); diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFileURLStreamHandler.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFileURLStreamHandler.java index cd4da3c642..9ae99c8b55 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFileURLStreamHandler.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFileURLStreamHandler.java @@ -27,6 +27,7 @@ import java.net.URLStreamHandler; * {@link URLStreamHandler} for the contents of a {@link ClassLoaderFile}. * * @author Phillip Webb + * @since 1.5.0 */ public class ClassLoaderFileURLStreamHandler extends URLStreamHandler { diff --git a/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java b/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java index 8c6ef0e9ed..34ae3f8eb4 100644 --- a/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java +++ b/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java @@ -146,8 +146,8 @@ public class DevToolsIntegrationTests { } Thread.sleep(100); } - int port = Integer - .valueOf(FileCopyUtils.copyToString(new FileReader(this.serverPortFile))); + FileReader portReader = new FileReader(this.serverPortFile); + int port = Integer.valueOf(FileCopyUtils.copyToString(portReader)); this.serverPortFile.delete(); return port; } @@ -187,5 +187,7 @@ public class DevToolsIntegrationTests { } builder.make().saveIn(this.classesDirectory); } + } + } From c2c5611f7762638b78e31d62e77ba736d4615c5e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 18 Nov 2016 15:58:56 -0800 Subject: [PATCH 3/4] Polish --- .../cloudfoundry/CloudFoundryEndpointHandlerMapping.java | 2 +- .../CloudFoundryEndpointHandlerMappingTests.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMapping.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMapping.java index ebee4c2a81..8a2ecf1984 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMapping.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMapping.java @@ -112,9 +112,9 @@ class CloudFoundryEndpointHandlerMapping /** * {@link HandlerInterceptor} that processes the response for CORS. - * */ class CorsInterceptor extends HandlerInterceptorAdapter { + private final CorsConfiguration config; CorsInterceptor(CorsConfiguration config) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMappingTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMappingTests.java index 08e029686d..b3d13d326f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMappingTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryEndpointHandlerMappingTests.java @@ -41,6 +41,8 @@ import org.springframework.web.servlet.HandlerExecutionChain; import org.springframework.web.servlet.HandlerInterceptor; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /** * Tests for {@link CloudFoundryEndpointHandlerMapping}. @@ -56,7 +58,7 @@ public class CloudFoundryEndpointHandlerMappingTests CorsConfiguration corsConfiguration = new CorsConfiguration(); CloudFoundryEndpointHandlerMapping handlerMapping = new CloudFoundryEndpointHandlerMapping( Collections.singleton(endpoint), corsConfiguration, null); - CorsProcessor corsProcessor = Mockito.mock(CorsProcessor.class); + CorsProcessor corsProcessor = mock(CorsProcessor.class); handlerMapping.setCorsProcessor(corsProcessor); MockHttpServletRequest request = new MockHttpServletRequest(); HandlerExecutionChain handlerExecutionChain = handlerMapping @@ -65,8 +67,7 @@ public class CloudFoundryEndpointHandlerMappingTests CloudFoundryEndpointHandlerMapping.CorsInterceptor corsInterceptor = (CloudFoundryEndpointHandlerMapping.CorsInterceptor) interceptors[0]; MockHttpServletResponse response = new MockHttpServletResponse(); corsInterceptor.preHandle(request, response, new Object()); - Mockito.verify(corsProcessor).processRequest(corsConfiguration, request, - response); + verify(corsProcessor).processRequest(corsConfiguration, request, response); } @Test From 165712028604b1b7c9431764c4655510de34b5ca Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 18 Nov 2016 17:27:54 -0800 Subject: [PATCH 4/4] Move ModifiedClassPathRunner to its own module Migrate `ModifiedClassPathRunner` from `spring-boot` test source to its own module. Fixes gh-7420 --- pom.xml | 1 + spring-boot-actuator/pom.xml | 5 + ...rtiesAutoConfigurationNoSecurityTests.java | 4 +- ...rityHealthMvcEndpointIntegrationTests.java | 4 +- spring-boot-autoconfigure/pom.xml | 5 + ...eanConditionTypeDeductionFailureTests.java | 4 +- ...ourceBeanCreationFailureAnalyzerTests.java | 4 +- spring-boot-dependencies/pom.xml | 7 +- spring-boot-devtools/pom.xml | 5 + ...eddedDataSourceAutoConfigurationTests.java | 4 +- spring-boot-docs/pom.xml | 5 + .../SpringApplicationBuilderExampleTests.java | 4 +- spring-boot-full-build/pom.xml | 1 + spring-boot-junit-runners/pom.xml | 99 +++++++++++++++++++ .../classpath}/ClassPathExclusions.java | 2 +- .../runner/classpath}/ClassPathOverrides.java | 2 +- .../classpath}/ModifiedClassPathRunner.java | 2 +- .../junit/runner/classpath/package-info.java | 20 ++++ .../boot/junit/runner/package-info.java | 20 ++++ ...odifiedClassPathRunnerExclusionsTests.java | 2 +- ...ModifiedClassPathRunnerOverridesTests.java | 2 +- .../spring-boot-sample-ant/pom.xml | 9 +- spring-boot-test/pom.xml | 5 + .../test/mock/mockito/Mockito21Tests.java | 4 +- .../test/mock/mockito/Mockito22Tests.java | 4 +- spring-boot/pom.xml | 63 +----------- ...lidationExceptionFailureAnalyzerTests.java | 4 +- 27 files changed, 204 insertions(+), 87 deletions(-) create mode 100644 spring-boot-junit-runners/pom.xml rename {spring-boot/src/test/java/org/springframework/boot/testutil => spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath}/ClassPathExclusions.java (96%) rename {spring-boot/src/test/java/org/springframework/boot/testutil => spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath}/ClassPathOverrides.java (95%) rename {spring-boot/src/test/java/org/springframework/boot/testutil => spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath}/ModifiedClassPathRunner.java (99%) create mode 100644 spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/package-info.java create mode 100644 spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/package-info.java rename {spring-boot/src/test/java/org/springframework/boot/testutil => spring-boot-junit-runners/src/test/java/org/springframework/boot/junit/runner/classpath}/ModifiedClassPathRunnerExclusionsTests.java (96%) rename {spring-boot/src/test/java/org/springframework/boot/testutil => spring-boot-junit-runners/src/test/java/org/springframework/boot/junit/runner/classpath}/ModifiedClassPathRunnerOverridesTests.java (96%) diff --git a/pom.xml b/pom.xml index f65fe87bdd..9c8a4e7ae7 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,7 @@ spring-boot-dependencies spring-boot-parent spring-boot-tools + spring-boot-junit-runners spring-boot spring-boot-test spring-boot-autoconfigure diff --git a/spring-boot-actuator/pom.xml b/spring-boot-actuator/pom.xml index 984b8cbf5d..f845fe9335 100644 --- a/spring-boot-actuator/pom.xml +++ b/spring-boot-actuator/pom.xml @@ -286,6 +286,11 @@ test-jar test + + org.springframework.boot + spring-boot-junit-runners + test + org.springframework.boot spring-boot-test diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationNoSecurityTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationNoSecurityTests.java index 1060636db4..aa66780544 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationNoSecurityTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationNoSecurityTests.java @@ -20,9 +20,9 @@ import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.junit.runner.classpath.ClassPathExclusions; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.boot.testutil.ClassPathExclusions; -import org.springframework.boot.testutil.ModifiedClassPathRunner; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java index 0feaf7f230..b6e52904dc 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java @@ -30,8 +30,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.testutil.ClassPathExclusions; -import org.springframework.boot.testutil.ModifiedClassPathRunner; +import org.springframework.boot.junit.runner.classpath.ClassPathExclusions; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.mock.web.MockServletContext; diff --git a/spring-boot-autoconfigure/pom.xml b/spring-boot-autoconfigure/pom.xml index fd311054d8..79c324793a 100755 --- a/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-autoconfigure/pom.xml @@ -605,6 +605,11 @@ test-jar test + + org.springframework.boot + spring-boot-junit-runners + test + org.springframework.boot spring-boot-test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java index 0236b94ddf..7d72947f59 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java @@ -21,8 +21,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.autoconfigure.condition.OnBeanCondition.BeanTypeDeductionException; -import org.springframework.boot.testutil.ClassPathExclusions; -import org.springframework.boot.testutil.ModifiedClassPathRunner; +import org.springframework.boot.junit.runner.classpath.ClassPathExclusions; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBeanCreationFailureAnalyzerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBeanCreationFailureAnalyzerTests.java index 5a044d4143..c1086780a7 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBeanCreationFailureAnalyzerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBeanCreationFailureAnalyzerTests.java @@ -22,8 +22,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.diagnostics.FailureAnalysis; -import org.springframework.boot.testutil.ClassPathExclusions; -import org.springframework.boot.testutil.ModifiedClassPathRunner; +import org.springframework.boot.junit.runner.classpath.ClassPathExclusions; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index e4f3db7254..0512aea8d8 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -203,6 +203,11 @@ test-jar 1.5.0.BUILD-SNAPSHOT + + org.springframework.boot + spring-boot-junit-runners + 1.5.0.BUILD-SNAPSHOT + org.springframework.boot spring-boot-test @@ -2613,4 +2618,4 @@ integration-test - + \ No newline at end of file diff --git a/spring-boot-devtools/pom.xml b/spring-boot-devtools/pom.xml index 7d62b1bef0..55965acc0d 100644 --- a/spring-boot-devtools/pom.xml +++ b/spring-boot-devtools/pom.xml @@ -92,6 +92,11 @@ test-jar test + + org.springframework.boot + spring-boot-junit-runners + test + org.springframework.boot spring-boot-test diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java index 9fc1a9eddf..52b2a53eeb 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java @@ -25,8 +25,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.testutil.ClassPathExclusions; -import org.springframework.boot.testutil.ModifiedClassPathRunner; +import org.springframework.boot.junit.runner.classpath.ClassPathExclusions; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import org.springframework.context.ConfigurableApplicationContext; import static org.mockito.Mockito.times; diff --git a/spring-boot-docs/pom.xml b/spring-boot-docs/pom.xml index 00c64be0bd..5c5b4b4598 100644 --- a/spring-boot-docs/pom.xml +++ b/spring-boot-docs/pom.xml @@ -722,6 +722,11 @@ test-jar test + + org.springframework.boot + spring-boot-junit-runners + test + diff --git a/spring-boot-docs/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderExampleTests.java b/spring-boot-docs/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderExampleTests.java index 9927cf0912..2774836a42 100644 --- a/spring-boot-docs/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderExampleTests.java +++ b/spring-boot-docs/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderExampleTests.java @@ -20,9 +20,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.junit.runner.classpath.ClassPathExclusions; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import org.springframework.boot.test.rule.OutputCapture; -import org.springframework.boot.testutil.ClassPathExclusions; -import org.springframework.boot.testutil.ModifiedClassPathRunner; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot-full-build/pom.xml b/spring-boot-full-build/pom.xml index 0a4e5fca65..f552da11da 100644 --- a/spring-boot-full-build/pom.xml +++ b/spring-boot-full-build/pom.xml @@ -48,6 +48,7 @@ ../spring-boot-dependencies ../spring-boot-parent ../spring-boot-tools + ../spring-boot-junit-runners ../spring-boot ../spring-boot-test ../spring-boot-autoconfigure diff --git a/spring-boot-junit-runners/pom.xml b/spring-boot-junit-runners/pom.xml new file mode 100644 index 0000000000..d0c5525f37 --- /dev/null +++ b/spring-boot-junit-runners/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-parent + 1.5.0.BUILD-SNAPSHOT + ../spring-boot-parent + + spring-boot-junit-runners + Spring Boot JUnit Runners + Spring Boot JUnit Runners + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/.. + + + + + junit + junit + provided + + + + org.apache.maven + maven-aether-provider + + + org.eclipse.sisu.plexus + org.eclipse.sisu + + + + + org.apache.maven + maven-settings-builder + + + org.codehaus.plexus + plexus-component-api + + + * + * + + + + + org.eclipse.aether + aether-api + + + org.eclipse.aether + aether-connector-basic + + + org.eclipse.aether + aether-impl + + + org.eclipse.aether + aether-spi + + + org.eclipse.aether + aether-transport-file + + + org.eclipse.aether + aether-transport-http + + + jcl-over-slf4j + org.slf4j + + + + + org.eclipse.aether + aether-util + + + org.springframework + spring-core + + + + io.projectreactor.spring + reactor-spring-context + test + + + diff --git a/spring-boot/src/test/java/org/springframework/boot/testutil/ClassPathExclusions.java b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ClassPathExclusions.java similarity index 96% rename from spring-boot/src/test/java/org/springframework/boot/testutil/ClassPathExclusions.java rename to spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ClassPathExclusions.java index b42c053a64..ab05e17854 100644 --- a/spring-boot/src/test/java/org/springframework/boot/testutil/ClassPathExclusions.java +++ b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ClassPathExclusions.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.testutil; +package org.springframework.boot.junit.runner.classpath; import java.io.File; import java.lang.annotation.ElementType; diff --git a/spring-boot/src/test/java/org/springframework/boot/testutil/ClassPathOverrides.java b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ClassPathOverrides.java similarity index 95% rename from spring-boot/src/test/java/org/springframework/boot/testutil/ClassPathOverrides.java rename to spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ClassPathOverrides.java index 93af3c074e..ad3ccbf083 100644 --- a/spring-boot/src/test/java/org/springframework/boot/testutil/ClassPathOverrides.java +++ b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ClassPathOverrides.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.testutil; +package org.springframework.boot.junit.runner.classpath; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunner.java b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunner.java similarity index 99% rename from spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunner.java rename to spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunner.java index c7f05b4866..85656ac3b3 100644 --- a/spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunner.java +++ b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunner.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.testutil; +package org.springframework.boot.junit.runner.classpath; import java.io.File; import java.lang.annotation.Annotation; diff --git a/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/package-info.java b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/package-info.java new file mode 100644 index 0000000000..6764178349 --- /dev/null +++ b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/classpath/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2016 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. + */ + +/** + * Custom JUnit runner to change the classpath. + */ +package org.springframework.boot.junit.runner.classpath; diff --git a/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/package-info.java b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/package-info.java new file mode 100644 index 0000000000..5e4237e267 --- /dev/null +++ b/spring-boot-junit-runners/src/main/java/org/springframework/boot/junit/runner/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2016 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. + */ + +/** + * Custom JUnit runners used in Spring Boot's own tests. + */ +package org.springframework.boot.junit.runner; diff --git a/spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunnerExclusionsTests.java b/spring-boot-junit-runners/src/test/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunnerExclusionsTests.java similarity index 96% rename from spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunnerExclusionsTests.java rename to spring-boot-junit-runners/src/test/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunnerExclusionsTests.java index 40803d8e4b..5628cb8046 100644 --- a/spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunnerExclusionsTests.java +++ b/spring-boot-junit-runners/src/test/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunnerExclusionsTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.testutil; +package org.springframework.boot.junit.runner.classpath; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunnerOverridesTests.java b/spring-boot-junit-runners/src/test/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunnerOverridesTests.java similarity index 96% rename from spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunnerOverridesTests.java rename to spring-boot-junit-runners/src/test/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunnerOverridesTests.java index 8d51b23034..a7ce73a3ee 100644 --- a/spring-boot/src/test/java/org/springframework/boot/testutil/ModifiedClassPathRunnerOverridesTests.java +++ b/spring-boot-junit-runners/src/test/java/org/springframework/boot/junit/runner/classpath/ModifiedClassPathRunnerOverridesTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.testutil; +package org.springframework.boot.junit.runner.classpath; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-boot-samples/spring-boot-sample-ant/pom.xml b/spring-boot-samples/spring-boot-sample-ant/pom.xml index c681c3e232..47e3e96500 100644 --- a/spring-boot-samples/spring-boot-sample-ant/pom.xml +++ b/spring-boot-samples/spring-boot-sample-ant/pom.xml @@ -1,5 +1,4 @@ - - + 4.0.0 @@ -60,8 +59,8 @@ package - - + + @@ -101,4 +100,4 @@ - + \ No newline at end of file diff --git a/spring-boot-test/pom.xml b/spring-boot-test/pom.xml index d9f03e8234..eb1af9b776 100644 --- a/spring-boot-test/pom.xml +++ b/spring-boot-test/pom.xml @@ -118,6 +118,11 @@ test-jar test + + org.springframework.boot + spring-boot-junit-runners + test + org.jetbrains.kotlin kotlin-runtime diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito21Tests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito21Tests.java index 495a772080..c6878dea47 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito21Tests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito21Tests.java @@ -21,8 +21,8 @@ import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.RunWith; -import org.springframework.boot.testutil.ClassPathOverrides; -import org.springframework.boot.testutil.ModifiedClassPathRunner; +import org.springframework.boot.junit.runner.classpath.ClassPathOverrides; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito22Tests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito22Tests.java index 57df08053a..967f1b79ba 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito22Tests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito22Tests.java @@ -21,8 +21,8 @@ import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.RunWith; -import org.springframework.boot.testutil.ClassPathOverrides; -import org.springframework.boot.testutil.ModifiedClassPathRunner; +import org.springframework.boot.junit.runner.classpath.ClassPathOverrides; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index 16b412cab1..16f001da68 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -246,6 +246,11 @@ true + + org.springframework.boot + spring-boot-junit-runners + test + com.google.appengine appengine-api-1.0-sdk @@ -290,64 +295,6 @@ org.apache.httpcomponents httpasyncclient test - - - org.apache.maven - maven-aether-provider - - - org.eclipse.sisu.plexus - org.eclipse.sisu - - - - - org.apache.maven - maven-settings-builder - - - org.codehaus.plexus - plexus-component-api - - - * - * - - - - - org.eclipse.aether - aether-api - - - org.eclipse.aether - aether-connector-basic - - - org.eclipse.aether - aether-impl - - - org.eclipse.aether - aether-spi - - - org.eclipse.aether - aether-transport-file - - - org.eclipse.aether - aether-transport-http - - - jcl-over-slf4j - org.slf4j - - - - - org.eclipse.aether - aether-util org.firebirdsql.jdbc diff --git a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/ValidationExceptionFailureAnalyzerTests.java b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/ValidationExceptionFailureAnalyzerTests.java index e70e949f96..1be55cf125 100644 --- a/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/ValidationExceptionFailureAnalyzerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/ValidationExceptionFailureAnalyzerTests.java @@ -22,8 +22,8 @@ import org.junit.runner.RunWith; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.diagnostics.FailureAnalysis; -import org.springframework.boot.testutil.ClassPathExclusions; -import org.springframework.boot.testutil.ModifiedClassPathRunner; +import org.springframework.boot.junit.runner.classpath.ClassPathExclusions; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.assertj.core.api.Assertions.assertThat;