private synchronized String doGetHawtioVersion()

in hawtio-system/src/main/java/io/hawt/jmx/About.java [71:139]


    private synchronized String doGetHawtioVersion() {
        // loading the version can be tricky depending on how hawtio has been started, so we try different strategies

        String version = Objects.getVersion(getClass(), "io.hawt", "hawtio-web");
        if (version == null) {
            version = Objects.getVersion(getClass(), "io.hawt", "hawtio-app");
        }
        if (version == null) {
            version = Objects.getVersion(getClass(), "io.hawt", "hawtio-default");
        }
        if (version != null) {
            return version;
        }

        InputStream is = null;
        try {
            Properties p = new Properties();

            // try to load from maven properties first as they have the version
            is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/META-INF/maven/io.hawt/hawtio-web/pom.properties");
            if (is == null) {
                is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/META-INF/maven/io.hawt/hawtio-default/pom.properties");
            }
            if (is == null) {
                is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/META-INF/maven/io.hawt/hawtio-app/pom.properties");
            }
            if (is == null) {
                is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/META-INF/maven/io.hawt/hawtio-embedded/pom.properties");
            }
            // then try the general manifest file
            is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/META-INF/MANIFEST.MF");
            if (is != null) {
                p.load(is);
                version = p.getProperty("Bundle-Version", null);
                if (version == null) {
                    version = p.getProperty("version", "");
                }
            }
        } catch (Exception e) {
            // ignore
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    // ignore
                }
            }
        }

        // fallback to using Java API
        if (version == null) {
            Package aPackage = Thread.currentThread().getContextClassLoader().getClass().getPackage();
            if (aPackage != null) {
                version = aPackage.getImplementationVersion();
                if (version == null) {
                    version = aPackage.getSpecificationVersion();
                }
            }
        }

        if (version == null) {
            // we could not compute the version so use a blank
            version = "";
        }

        return version;
    }