Created
June 28, 2023 22:52
-
-
Save asdf913/3f5e4937a37306ab8251615229235fca to your computer and use it in GitHub Desktop.
Detect the method is run under Eclipse or Maven
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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