From b76978ff7e68f15052dba8a82016ca1d545464cf Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 30 Dec 2016 12:22:37 -0800 Subject: [PATCH 1/4] Try to prevent Travis build failures Update LiveReloadServerTests which seems to be failing intermittently on Travis. --- .../livereload/LiveReloadServerTests.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java index 79df32a07f..5fd384e9f2 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java @@ -83,9 +83,8 @@ public class LiveReloadServerTests { @Test public void triggerReload() throws Exception { LiveReloadWebSocketHandler handler = connect(); - handler.setExpectedMessageCount(1); this.server.triggerReload(); - handler.awaitMessages(); + Thread.sleep(200); this.server.stop(); assertThat(handler.getMessages().get(0)) .contains("http://livereload.com/protocols/official-7"); @@ -208,8 +207,6 @@ public class LiveReloadServerTests { private final CountDownLatch helloLatch = new CountDownLatch(2); - private CountDownLatch messagesLatch; - private final List messages = new ArrayList(); private int pongCount; @@ -229,19 +226,12 @@ public class LiveReloadServerTests { Thread.sleep(200); } - public void setExpectedMessageCount(int count) { - this.messagesLatch = new CountDownLatch(count); - } - @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { if (message.getPayload().contains("hello")) { this.helloLatch.countDown(); } - if (this.messagesLatch != null) { - this.messagesLatch.countDown(); - } this.messages.add(message.getPayload()); } @@ -265,10 +255,6 @@ public class LiveReloadServerTests { this.session.close(); } - public void awaitMessages() throws InterruptedException { - this.messagesLatch.await(1, TimeUnit.MINUTES); - } - public List getMessages() { return this.messages; } From b27f4e23be39b39c6cd1d972b172a8865c6b77b1 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 30 Dec 2016 12:53:59 -0800 Subject: [PATCH 2/4] Ignore @ImportAutoConfiguration exclude errors Update `ImportAutoConfigurationImportSelector` to ignore excludes for classes that aren't loaded. Since the import classes for tests tend to be much more limited, the exception isn't really helpful. Closes gh-6809 --- ...EnableAutoConfigurationImportSelector.java | 25 +++++++++++++------ ...ImportAutoConfigurationImportSelector.java | 5 ++++ ...tAutoConfigurationImportSelectorTests.java | 15 +++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java index b8dab15000..e818bdc9d2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java @@ -161,20 +161,31 @@ public class EnableAutoConfigurationImportSelector private void checkExcludedClasses(List configurations, Set exclusions) { - StringBuilder message = new StringBuilder(); + List invalidExcludes = new ArrayList(); for (String exclusion : exclusions) { if (ClassUtils.isPresent(exclusion, getClass().getClassLoader()) && !configurations.contains(exclusion)) { - message.append("\t- ").append(exclusion).append(String.format("%n")); + invalidExcludes.add(exclusion); } } - if (!message.toString().isEmpty()) { - throw new IllegalStateException(String.format( - "The following classes could not be excluded because they are" - + " not auto-configuration classes:%n%s", - message.toString())); + if (!invalidExcludes.isEmpty()) { + handleInvalidExcludes(invalidExcludes); } + } + /** + * Handle any invalid excludes that have been specified. + * @param invalidExcludes the list of invalid excludes (will always have at least on + * element) + */ + protected void handleInvalidExcludes(List invalidExcludes) { + StringBuilder message = new StringBuilder(); + for (String exclude : invalidExcludes) { + message.append("\t- ").append(exclude).append(String.format("%n")); + } + throw new IllegalStateException(String + .format("The following classes could not be excluded because they are" + + " not auto-configuration classes:%n%s", message)); } /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java index 90abf076f8..44021075a9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java @@ -146,4 +146,9 @@ class ImportAutoConfigurationImportSelector return super.getOrder() - 1; } + @Override + protected void handleInvalidExcludes(List invalidExcludes) { + // Ignore for test + } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java index 60f274ecbb..bb0587b01c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java @@ -116,6 +116,15 @@ public class ImportAutoConfigurationImportSelectorTests { assertThat(imports).containsOnly(FreeMarkerAutoConfiguration.class.getName()); } + @Test + public void exclusionsWithoutImport() throws Exception { + AnnotationMetadata annotationMetadata = new SimpleMetadataReaderFactory() + .getMetadataReader(ExclusionWithoutImport.class.getName()) + .getAnnotationMetadata(); + String[] imports = this.importSelector.selectImports(annotationMetadata); + assertThat(imports).containsOnly(FreeMarkerAutoConfiguration.class.getName()); + } + @Test public void exclusionsAliasesAreApplied() throws Exception { AnnotationMetadata annotationMetadata = new SimpleMetadataReaderFactory() @@ -149,6 +158,12 @@ public class ImportAutoConfigurationImportSelectorTests { } + @ImportOne + @ImportAutoConfiguration(exclude = ThymeleafAutoConfiguration.class) + static class ExclusionWithoutImport { + + } + @SelfAnnotating static class ImportWithSelfAnnotatingAnnotation { From 40691d07f8e7e41f94b8d41b001d66ca54bd53dd Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Fri, 30 Dec 2016 16:13:57 +0900 Subject: [PATCH 3/4] Add force-stop to launch.script usage See gh-6223 Closes gh-7787 --- .../org/springframework/boot/loader/tools/launch.script | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script b/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script index cba5329854..36c57d8200 100755 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script @@ -271,7 +271,7 @@ status) run) run "$@"; exit $?;; *) - echo "Usage: $0 {start|stop|restart|force-reload|status|run}"; exit 1; + echo "Usage: $0 {start|stop|force-stop|restart|force-reload|status|run}"; exit 1; esac exit 0 From a35a1022c2e354873e4df5c4c4ac43204cc72d0e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 30 Dec 2016 13:23:47 -0800 Subject: [PATCH 4/4] Update force-stop to respect STOP_WAIT_TIME Closes gh-6223 --- .../org/springframework/boot/loader/tools/launch.script | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script b/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script index 36c57d8200..a36f3d3ba1 100755 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script @@ -212,9 +212,9 @@ force_stop() { do_force_stop() { kill -9 "$1" &> /dev/null || { echoRed "Unable to kill process $1"; return 1; } - for i in $(seq 1 60); do + for i in $(seq 1 $STOP_WAIT_TIME); do isRunning "$1" || { echoGreen "Stopped [$1]"; rm -f "$2"; return 0; } - [[ $i -eq 30 ]] && kill -9 "$1" &> /dev/null + [[ $i -eq STOP_WAIT_TIME/2 ]] && kill "$1" &> /dev/null sleep 1 done echoRed "Unable to kill process $1";