Skip to content

Instantly share code, notes, and snippets.

@asdf913
Created June 28, 2023 22:52
Show Gist options
  • Save asdf913/3f5e4937a37306ab8251615229235fca to your computer and use it in GitHub Desktop.
Save asdf913/3f5e4937a37306ab8251615229235fca to your computer and use it in GitHub Desktop.
Detect the method is run under Eclipse or Maven
import java.util.Arrays;
public class IsUnderDebugOrMaven {
public static void main(final String[] args) {
//
System.out.println(isUnderDebugOrMaven());
//
}
private static boolean isUnderDebugOrMaven() {
//
return Arrays.stream(new Throwable().getStackTrace())
.anyMatch(x -> Arrays
.asList("org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference",
"org.apache.maven.surefire.junitplatform.JUnitPlatformProvider")
.contains(getClassName(x)));
//
}
private static String getClassName(final StackTraceElement instance) {
return instance != null ? instance.getClassName() : null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment