Commit cba89f88 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge pull request #14807 from Marcus Eisele

* gh-14807:
  Polish "Add Log Output when DevTools restart is disabled"
  Add Log Output when DevTools restart is disabled
parents 35bd4cfb 8ec9f237
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
package org.springframework.boot.devtools.restart; package org.springframework.boot.devtools.restart;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
...@@ -35,10 +38,12 @@ import org.springframework.core.Ordered; ...@@ -35,10 +38,12 @@ import org.springframework.core.Ordered;
public class RestartApplicationListener public class RestartApplicationListener
implements ApplicationListener<ApplicationEvent>, Ordered { implements ApplicationListener<ApplicationEvent>, Ordered {
private int order = HIGHEST_PRECEDENCE;
private static final String ENABLED_PROPERTY = "spring.devtools.restart.enabled"; private static final String ENABLED_PROPERTY = "spring.devtools.restart.enabled";
private static final Log logger = LogFactory.getLog(RestartApplicationListener.class);
private int order = HIGHEST_PRECEDENCE;
@Override @Override
public void onApplicationEvent(ApplicationEvent event) { public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ApplicationStartingEvent) { if (event instanceof ApplicationStartingEvent) {
...@@ -64,9 +69,15 @@ public class RestartApplicationListener ...@@ -64,9 +69,15 @@ public class RestartApplicationListener
String[] args = event.getArgs(); String[] args = event.getArgs();
DefaultRestartInitializer initializer = new DefaultRestartInitializer(); DefaultRestartInitializer initializer = new DefaultRestartInitializer();
boolean restartOnInitialize = !AgentReloader.isActive(); boolean restartOnInitialize = !AgentReloader.isActive();
if (!restartOnInitialize) {
logger.info(
"Restart disabled due to an agent-based reloader being active");
}
Restarter.initialize(args, false, initializer, restartOnInitialize); Restarter.initialize(args, false, initializer, restartOnInitialize);
} }
else { else {
logger.info("Restart disabled due to System property '" + ENABLED_PROPERTY
+ "' being set to false");
Restarter.disable(); Restarter.disable();
} }
} }
......
...@@ -20,6 +20,7 @@ import java.util.List; ...@@ -20,6 +20,7 @@ import java.util.List;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
...@@ -27,6 +28,7 @@ import org.springframework.boot.context.event.ApplicationFailedEvent; ...@@ -27,6 +28,7 @@ import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
...@@ -47,6 +49,9 @@ public class RestartApplicationListenerTests { ...@@ -47,6 +49,9 @@ public class RestartApplicationListenerTests {
private static final String[] ARGS = new String[] { "a", "b", "c" }; private static final String[] ARGS = new String[] { "a", "b", "c" };
@Rule
public final OutputCapture output = new OutputCapture();
@Before @Before
@After @After
public void cleanup() { public void cleanup() {
...@@ -81,8 +86,11 @@ public class RestartApplicationListenerTests { ...@@ -81,8 +86,11 @@ public class RestartApplicationListenerTests {
@Test @Test
public void disableWithSystemProperty() { public void disableWithSystemProperty() {
System.setProperty(ENABLED_PROPERTY, "false"); System.setProperty(ENABLED_PROPERTY, "false");
this.output.reset();
testInitialize(false); testInitialize(false);
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", false); assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", false);
assertThat(this.output.toString())
.contains("Restart disabled due to System property");
} }
private void testInitialize(boolean failed) { private void testInitialize(boolean failed) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment