How do I get the version of Xtend at runtime

71 Views Asked by At

When I want to get the runtime version of Java, i use:

String version = System.getProperty("java.version");

But there is no property "xtend.version". How do I get the runtime version in Xtend.

1

There are 1 best solutions below

0
kapex On BEST ANSWER

Since there is no such property, you could try to load the version from the Xtend Runtime Library's manifest.

If you are running in an OSGi environment (e.g. Eclipse plugins), it should be rather straight-forward:

val Bundle bundle = Platform.getBundle("org.eclipse.xtend.lib")
val Version version = bundle.getVersion()

If running as a regular Java application, then this works for me and prints something like 2.30.0.v20230227-1111:

val manifests = ClassLoader.systemClassLoader.getResources("META-INF/MANIFEST.MF")

for (manifestUrl : manifests.asIterator.toList) {
    try (val stream = manifestUrl.openStream) {
        val manifest = new Manifest(stream)
        val attributes = manifest.mainAttributes
        val bundleSymbolicName = attributes.getValue("Bundle-SymbolicName")
        
        if (bundleSymbolicName == "org.eclipse.xtend.lib") {
            println(attributes.getValue("Bundle-Version"))
        }
    }
}