Merge branch '1.5.x'

pull/7614/merge
Phillip Webb 8 years ago
commit a90bad37bd

@ -161,20 +161,31 @@ public class EnableAutoConfigurationImportSelector
private void checkExcludedClasses(List<String> configurations, private void checkExcludedClasses(List<String> configurations,
Set<String> exclusions) { Set<String> exclusions) {
StringBuilder message = new StringBuilder(); List<String> invalidExcludes = new ArrayList<String>();
for (String exclusion : exclusions) { for (String exclusion : exclusions) {
if (ClassUtils.isPresent(exclusion, getClass().getClassLoader()) if (ClassUtils.isPresent(exclusion, getClass().getClassLoader())
&& !configurations.contains(exclusion)) { && !configurations.contains(exclusion)) {
message.append("\t- ").append(exclusion).append(String.format("%n")); invalidExcludes.add(exclusion);
} }
} }
if (!message.toString().isEmpty()) { if (!invalidExcludes.isEmpty()) {
throw new IllegalStateException(String.format( handleInvalidExcludes(invalidExcludes);
"The following classes could not be excluded because they are"
+ " not auto-configuration classes:%n%s",
message.toString()));
} }
}
/**
* 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<String> 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));
} }
/** /**

@ -146,4 +146,9 @@ class ImportAutoConfigurationImportSelector
return super.getOrder() - 1; return super.getOrder() - 1;
} }
@Override
protected void handleInvalidExcludes(List<String> invalidExcludes) {
// Ignore for test
}
} }

@ -116,6 +116,15 @@ public class ImportAutoConfigurationImportSelectorTests {
assertThat(imports).containsOnly(FreeMarkerAutoConfiguration.class.getName()); 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 @Test
public void exclusionsAliasesAreApplied() throws Exception { public void exclusionsAliasesAreApplied() throws Exception {
AnnotationMetadata annotationMetadata = new SimpleMetadataReaderFactory() AnnotationMetadata annotationMetadata = new SimpleMetadataReaderFactory()
@ -149,6 +158,12 @@ public class ImportAutoConfigurationImportSelectorTests {
} }
@ImportOne
@ImportAutoConfiguration(exclude = ThymeleafAutoConfiguration.class)
static class ExclusionWithoutImport {
}
@SelfAnnotating @SelfAnnotating
static class ImportWithSelfAnnotatingAnnotation { static class ImportWithSelfAnnotatingAnnotation {

@ -83,9 +83,8 @@ public class LiveReloadServerTests {
@Test @Test
public void triggerReload() throws Exception { public void triggerReload() throws Exception {
LiveReloadWebSocketHandler handler = connect(); LiveReloadWebSocketHandler handler = connect();
handler.setExpectedMessageCount(1);
this.server.triggerReload(); this.server.triggerReload();
handler.awaitMessages(); Thread.sleep(200);
this.server.stop(); this.server.stop();
assertThat(handler.getMessages().get(0)) assertThat(handler.getMessages().get(0))
.contains("http://livereload.com/protocols/official-7"); .contains("http://livereload.com/protocols/official-7");
@ -208,8 +207,6 @@ public class LiveReloadServerTests {
private final CountDownLatch helloLatch = new CountDownLatch(2); private final CountDownLatch helloLatch = new CountDownLatch(2);
private CountDownLatch messagesLatch;
private final List<String> messages = new ArrayList<String>(); private final List<String> messages = new ArrayList<String>();
private int pongCount; private int pongCount;
@ -229,19 +226,12 @@ public class LiveReloadServerTests {
Thread.sleep(200); Thread.sleep(200);
} }
public void setExpectedMessageCount(int count) {
this.messagesLatch = new CountDownLatch(count);
}
@Override @Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) protected void handleTextMessage(WebSocketSession session, TextMessage message)
throws Exception { throws Exception {
if (message.getPayload().contains("hello")) { if (message.getPayload().contains("hello")) {
this.helloLatch.countDown(); this.helloLatch.countDown();
} }
if (this.messagesLatch != null) {
this.messagesLatch.countDown();
}
this.messages.add(message.getPayload()); this.messages.add(message.getPayload());
} }
@ -265,10 +255,6 @@ public class LiveReloadServerTests {
this.session.close(); this.session.close();
} }
public void awaitMessages() throws InterruptedException {
this.messagesLatch.await(1, TimeUnit.MINUTES);
}
public List<String> getMessages() { public List<String> getMessages() {
return this.messages; return this.messages;
} }

@ -212,9 +212,9 @@ force_stop() {
do_force_stop() { do_force_stop() {
kill -9 "$1" &> /dev/null || { echoRed "Unable to kill process $1"; return 1; } 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; } 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 sleep 1
done done
echoRed "Unable to kill process $1"; echoRed "Unable to kill process $1";
@ -271,7 +271,7 @@ status)
run) run)
run "$@"; exit $?;; 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 esac
exit 0 exit 0

Loading…
Cancel
Save