1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.spf4j.test.log;
17
18 import com.google.common.annotations.Beta;
19 import com.google.common.base.Ascii;
20 import java.util.List;
21 import org.spf4j.base.Env;
22
23
24
25
26 public final class TestUtils {
27 private TestUtils() { }
28
29 public static boolean isExecutedDuringMvnRelease() {
30 return Env.getValue("MAVEN_CMD_LINE_ARGS", "").contains("release:");
31 }
32
33 public static boolean isExecutedInCI() {
34 return isExecutedInTravis();
35 }
36
37 public static boolean isExecutedInTravis() {
38 return Ascii.equalsIgnoreCase("true", "TRAVIS");
39 }
40
41
42 public static boolean isExecutedFromNetbeans() {
43 String mvnNetbeansCP = System.getProperty("maven.ext.class.path");
44 return mvnNetbeansCP != null && mvnNetbeansCP.contains("netbeans");
45 }
46
47 @Beta
48 public static boolean isExecutedFromIntelij() {
49 for (StackTraceElement[] st : Thread.getAllStackTraces().values()) {
50 if (st != null) {
51 for (StackTraceElement ste : st) {
52 if (ste.getClassName().startsWith("com.intellij.rt.execution")) {
53 return true;
54 }
55 }
56 }
57 }
58 return false;
59 }
60
61
62 @Beta
63 public static boolean isExecutedFromEclipse() {
64 for (StackTraceElement[] st : Thread.getAllStackTraces().values()) {
65 if (st != null) {
66 for (StackTraceElement ste : st) {
67 if (ste.getClassName().startsWith("org.eclipse.jdt.internal")) {
68 return true;
69 }
70 }
71 }
72 }
73 return false;
74 }
75
76
77
78
79
80
81
82
83 public static boolean isExecutedFromIDE() {
84 return isExecutedFromNetbeans() || System.getProperty("spf4j.execFromIDE") != null
85 || isExecutedFromEclipse() || isExecutedFromIntelij();
86 }
87
88 public static boolean isExecutedFromIDEInvididually() {
89 return isExecutedFromIDE() && System.getProperty("test") != null;
90 }
91
92 public static boolean isExecutedWithDebuggerAgent() {
93 List<String> inputArguments = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments();
94 return inputArguments.stream()
95 .filter((arg) -> "-agentlib:jdwp".equals(arg) || "-Xdebug".equals(arg) || arg.startsWith("-Xrunjdwp"))
96 .count() > 0;
97
98 }
99
100 }