Skip to content

Commit

Permalink
Merge pull request spring-projects#14807 from Marcus Eisele
Browse files Browse the repository at this point in the history
* spring-projectsgh-14807:
  Polish "Add Log Output when DevTools restart is disabled"
  Add Log Output when DevTools restart is disabled
  • Loading branch information
wilkinsona committed Oct 29, 2018
2 parents 35bd4cf + 8ec9f23 commit cba89f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,9 @@

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.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
Expand All @@ -35,10 +38,12 @@
public class RestartApplicationListener
implements ApplicationListener<ApplicationEvent>, Ordered {

private int order = HIGHEST_PRECEDENCE;

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
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ApplicationStartingEvent) {
Expand All @@ -64,9 +69,15 @@ private void onApplicationStartingEvent(ApplicationStartingEvent event) {
String[] args = event.getArgs();
DefaultRestartInitializer initializer = new DefaultRestartInitializer();
boolean restartOnInitialize = !AgentReloader.isActive();
if (!restartOnInitialize) {
logger.info(
"Restart disabled due to an agent-based reloader being active");
}
Restarter.initialize(args, false, initializer, restartOnInitialize);
}
else {
logger.info("Restart disabled due to System property '" + ENABLED_PROPERTY
+ "' being set to false");
Restarter.disable();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.test.util.ReflectionTestUtils;
Expand All @@ -47,6 +49,9 @@ public class RestartApplicationListenerTests {

private static final String[] ARGS = new String[] { "a", "b", "c" };

@Rule
public final OutputCapture output = new OutputCapture();

@Before
@After
public void cleanup() {
Expand Down Expand Up @@ -81,8 +86,11 @@ public void initializeWithFail() {
@Test
public void disableWithSystemProperty() {
System.setProperty(ENABLED_PROPERTY, "false");
this.output.reset();
testInitialize(false);
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", false);
assertThat(this.output.toString())
.contains("Restart disabled due to System property");
}

private void testInitialize(boolean failed) {
Expand Down

0 comments on commit cba89f8

Please sign in to comment.