From 12045598152aa56f3e74e4a5dd227c205d9b2ee9 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 11 Nov 2015 21:33:54 -0800 Subject: [PATCH] Refine agent reloader detection Fixes gh-4366 --- .../boot/devtools/restart/AgentReloader.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/AgentReloader.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/AgentReloader.java index b4f348053b..f54e9c080f 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/AgentReloader.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/AgentReloader.java @@ -16,6 +16,10 @@ package org.springframework.boot.devtools.restart; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + import org.springframework.util.ClassUtils; /** @@ -26,6 +30,15 @@ import org.springframework.util.ClassUtils; */ public abstract class AgentReloader { + private static final Set AGENT_CLASSES; + + static { + Set agentClasses = new LinkedHashSet(); + agentClasses.add("org.zeroturnaround.javarebel.Integration"); + agentClasses.add("org.zeroturnaround.javarebel.ReloaderFactory"); + AGENT_CLASSES = Collections.unmodifiableSet(agentClasses); + } + private AgentReloader() { } @@ -34,15 +47,17 @@ public abstract class AgentReloader { * @return true if agent reloading is active */ public static boolean isActive() { - return isJRebelActive(); + return isActive(null) || isActive(AgentReloader.class.getClassLoader()) + || isActive(ClassLoader.getSystemClassLoader()); } - /** - * Determine if JRebel is active. - * @return true if JRebel is active - */ - public static boolean isJRebelActive() { - return ClassUtils.isPresent("org.zeroturnaround.javarebel.ReloaderFactory", null); + private static boolean isActive(ClassLoader classLoader) { + for (String agentClass : AGENT_CLASSES) { + if (ClassUtils.isPresent(agentClass, classLoader)) { + return true; + } + } + return false; } }