在我的案例中,我运行的是一个 Eclipse 衍生产品,所以 Neeme 的回答只是给了我该产品的版本。OP 询问如何找到 日食版本,这正是我所追求的。因此,我需要做出一些改变,让我做到这一点:
/**
* Attempts to get the version of the eclipse ide we're running in.
* @return the version, or null if it couldn't be detected.
*/
static Version getEclipseVersion() {
String product = "org.eclipse.platform.ide";
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint("org.eclipse.core.runtime.products");
if (point != null) {
IExtension[] extensions = point.getExtensions();
for (IExtension ext : extensions) {
if (product.equals(ext.getUniqueIdentifier())) {
IContributor contributor = ext.getContributor();
if (contributor != null) {
Bundle bundle = Platform.getBundle(contributor.getName());
if (bundle != null) {
return bundle.getVersion();
}
}
}
}
}
return null;
}
这将返回一个方便的 Version,可以这样比较:
private static final Version DESIRED_MINIMUM_VERSION = new Version("4.9"); //other constructors are available
boolean haveAtLeastMinimumDesiredVersion()
Version thisVersion = getEclipseVersion();
if (thisVersion == null) {
//we might have a problem
}
//returns a positive number if thisVersion is greater than the given parameter (desiredVersion)
return thisVersion.compareTo(DESIRED_MINIMUM_VERSION) >= 0;
}