Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
getting info on whether JVM started in debug mode.
/**
*
* -----------------------------------------------------------------------------------
* From : org.junit.rules.DisableOnDebug#isDebugging(java.util.List<java.lang.String>)
* -----------------------------------------------------------------------------------
*
* Parses arguments passed to the runtime environment for debug flags
* <p>
* Options specified in:
* <ul>
* <li>
* <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/jpda/conninv.html#Invocation"
* >javase-6</a></li>
* <li><a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html#Invocation"
* >javase-7</a></li>
* <li><a href="http://docs.oracle.com/javase/8/docs/technotes/guides/jpda/conninv.html#Invocation"
* >javase-8</a></li>
*
*
* @param arguments
* the arguments passed to the runtime environment, usually this
* will be {@link RuntimeMXBean#getInputArguments()}
* @return true if the current JVM was started in debug mode, false
* otherwise.
*/
private static boolean isDebugging(List<String> arguments) {
for (final String argument : arguments) {
if ("-Xdebug".equals(argument)) {
return true;
} else if (argument.startsWith("-agentlib:jdwp")) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment