關於「是IDEA測試始作俑者」的問題,答案很簡單:
public static boolean isIdeaRunningTheTest() {
try {
final Class<?> aClass = Class.forName("com.intellij.rt.execution.junit.JUnitStarter");
} catch (ClassNotFoundException e) {
return false;
}
return true;
}
作爲確定IDEA版...
下工作,只要安裝目錄遵循安裝程序的標準(在Windows上,我不知道它在Mac或Linux系統上的安裝位置)。
public static String getIdeaVersionTheDumbWay() {
String result="unknown";
final String binPath = System.getProperty("idea.launcher.bin.path");
if (binPath.contains("IntelliJ IDEA")) {
final String[] strings = binPath.split(System.getProperty("file.separator")+System.getProperty("file.separator"));
for (String s : strings) {
final int startIndex = s.indexOf("IntelliJ IDEA");
if (startIndex >= 0) {
result= s.substring(startIndex + 14);
}
}
}
return result;
}