Refine agent reloader detection

Fixes gh-4366
This commit is contained in:
Phillip Webb 2015-11-11 21:33:54 -08:00
parent 6ae021969b
commit 1204559815
1 changed files with 22 additions and 7 deletions

View File

@ -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<String> AGENT_CLASSES;
static {
Set<String> agentClasses = new LinkedHashSet<String>();
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;
}
}