diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-08-25 16:00:18 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-08-25 17:39:13 +0200 |
commit | 70dfdc0bdcff5bfd6924c2832c5fdff69d1f201a (patch) | |
tree | 18f7664ac3756d9f99266622d2d9cae222d3803c /server/process | |
parent | 8eceec4c11715b83faf6a7bff745b3f5e383fd11 (diff) | |
download | sonarqube-70dfdc0bdcff5bfd6924c2832c5fdff69d1f201a.tar.gz sonarqube-70dfdc0bdcff5bfd6924c2832c5fdff69d1f201a.zip |
Disable process monitoring when in debug with agentlib:jdwt
Diffstat (limited to 'server/process')
4 files changed, 38 insertions, 3 deletions
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java index 23cb5dfe3a0..6d75bece303 100644 --- a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java +++ b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java @@ -32,9 +32,10 @@ public abstract class MonitoredProcess implements ProcessMXBean { private final static Logger LOGGER = LoggerFactory.getLogger(MonitoredProcess.class); - public static final String NAME_PROPERTY = "pName"; + private static final String DEBUG_AGENT = "-agentlib:jdwp"; private static final long AUTOKILL_TIMEOUT_MS = 30000L; private static final long AUTOKILL_CHECK_DELAY_MS = 2000L; + public static final String NAME_PROPERTY = "pName"; public static final String MISSING_NAME_ARGUMENT = "Missing Name argument"; private Long lastPing; @@ -50,7 +51,7 @@ public abstract class MonitoredProcess implements ProcessMXBean { private final boolean isMonitored; protected MonitoredProcess(Props props) { - this(props, false); + this(props, !props.containsValue(DEBUG_AGENT)); } protected MonitoredProcess(Props props, boolean monitor) { @@ -154,6 +155,10 @@ public abstract class MonitoredProcess implements ProcessMXBean { return terminated && monitor == null; } + public boolean isMonitored() { + return this.isMonitored; + } + @Override public final boolean isReady() { try { diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/Props.java b/server/process/sonar-process/src/main/java/org/sonar/process/Props.java index d6e2795a597..f8112ea6423 100644 --- a/server/process/sonar-process/src/main/java/org/sonar/process/Props.java +++ b/server/process/sonar-process/src/main/java/org/sonar/process/Props.java @@ -40,6 +40,15 @@ public class Props { return properties.containsKey(key); } + public boolean containsValue(String value) { + for (Object propertyValue : properties.values()) { + if (propertyValue.toString().contains(value)) { + return true; + } + } + return false; + } + @CheckForNull public String of(String key) { String value = properties.getProperty(key); diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/DummyProcess.java b/server/process/sonar-process/src/test/java/org/sonar/process/DummyProcess.java index 15d3ec7af09..f16c61fd93c 100644 --- a/server/process/sonar-process/src/test/java/org/sonar/process/DummyProcess.java +++ b/server/process/sonar-process/src/test/java/org/sonar/process/DummyProcess.java @@ -43,7 +43,7 @@ public class DummyProcess extends MonitoredProcess { } protected DummyProcess(Props props) throws Exception { - this(props, false); + super(props); } @Override diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java index 515d3c1ea3d..f3e4d2a78db 100644 --- a/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java +++ b/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java @@ -44,6 +44,27 @@ public class MonitoredProcessTest { assertThat(dummyProcess).isNotNull(); } + @Test + public void should_not_monitor_debug() throws Exception { + Properties properties = new Properties(); + properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME); + properties.setProperty("sonar.search.javaOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"); + DummyProcess dummyProcess = new DummyProcess(new Props(properties)); + + assertThat(dummyProcess.isMonitored()).isFalse(); + } + + @Test + public void should_monitor_by_default() throws Exception { + Properties properties = new Properties(); + properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME); + properties.setProperty("sonar.search.javaOpts", "hello world"); + DummyProcess dummyProcess = new DummyProcess(new Props(properties)); + + assertThat(dummyProcess.isMonitored()).isTrue(); + } + + @Test(timeout = 3000L) public void monitor_dies_when_no_pings() throws Exception { Properties properties = new Properties(); |