public static boolean isIdeaRunningTheTest() {
try {
final Class<?> aClass = Class.forName("com.intellij.rt.execution.junit.JUnitStarter");
} catch (ClassNotFoundException e) {
return false;
}
return true;
}
在确定想法版本时。。。
只要安装目录遵循安装程序中的标准(在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;
}