// Path: hawtio-log/src/main/java/io/hawt/log/support/MavenCoordinates.java
// public static void appendMavenCoordinateFromPomProperties(InputStream is, StringBuilder buffer) throws IOException {
//     Properties props = new Properties();
//     try {
//         props.load(is);
//         String groupId = props.getProperty("groupId");
//         String artifactId = props.getProperty("artifactId");
//         String version = props.getProperty("version");
//         if (groupId != null && artifactId != null & version != null) {
//             if (buffer.length() > 0) {
//                 buffer.append(" ");
//             }
//             buffer.append(groupId).append(":").append(artifactId).append(":").append(version);
//         }
//     } finally {
//         is.close();
//     }
// }


import java.net.URL;
import java.util.Enumeration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import static io.hawt.log.support.MavenCoordinates.appendMavenCoordinateFromPomProperties;
        try {
            bundleId = Long.parseLong(bundleIdStr);
        } catch (NumberFormatException e) {
            return null;
        }
        return getMavenCoordinates(bundleId);
    }

    public static Bundle getBundle(long bundleId) {
        Bundle logBundle = FrameworkUtil.getBundle(Logs.class);
        BundleContext bundleContext = logBundle != null ? logBundle.getBundleContext() : null;
        Bundle bundle = bundleContext != null ? bundleContext.getBundle(bundleId) : null;
        return bundle;
    }

    public static String getMavenCoordinates(long bundleId) {
        Bundle bundle = getBundle(bundleId);
        if (bundle == null) {
            // Not sure why can't we find the bundleId?
            return null;
        }
        String id = Long.toString(bundle.getBundleId()) + ":" + Long.toString(bundle.getLastModified());
        String maven = MAVEN_COORDINATES.get(id);
        if (maven == null) {
            if (bundle.getState() >= Bundle.RESOLVED) {
                try {
                    Enumeration<URL> e = bundle.findEntries("META-INF/maven/", "pom.properties", true);
                    StringBuilder buf = new StringBuilder();
                    while (e != null && e.hasMoreElements()) {
                        URL url = e.nextElement();
// Path: hawtio-log/src/main/java/io/hawt/log/support/MavenCoordinates.java
// public static void appendMavenCoordinateFromPomProperties(InputStream is, StringBuilder buffer) throws IOException {
//     Properties props = new Properties();
//     try {
//         props.load(is);
//         String groupId = props.getProperty("groupId");
//         String artifactId = props.getProperty("artifactId");
//         String version = props.getProperty("version");
//         if (groupId != null && artifactId != null & version != null) {
//             if (buffer.length() > 0) {
//                 buffer.append(" ");
//             }
//             buffer.append(groupId).append(":").append(artifactId).append(":").append(version);
//         }
//     } finally {
//         is.close();
//     }
// }


// Path: hawtio-log-osgi/src/main/java/io/hawt/log/osgi/MavenCoordinates.java
import java.net.URL;
import java.util.Enumeration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import static io.hawt.log.support.MavenCoordinates.appendMavenCoordinateFromPomProperties;

        try {
            bundleId = Long.parseLong(bundleIdStr);
        } catch (NumberFormatException e) {
            return null;
        }
        return getMavenCoordinates(bundleId);
    }

    public static Bundle getBundle(long bundleId) {
        Bundle logBundle = FrameworkUtil.getBundle(Logs.class);
        BundleContext bundleContext = logBundle != null ? logBundle.getBundleContext() : null;
        Bundle bundle = bundleContext != null ? bundleContext.getBundle(bundleId) : null;
        return bundle;
    }

    public static String getMavenCoordinates(long bundleId) {
        Bundle bundle = getBundle(bundleId);
        if (bundle == null) {
            // Not sure why can't we find the bundleId?
            return null;
        }
        String id = Long.toString(bundle.getBundleId()) + ":" + Long.toString(bundle.getLastModified());
        String maven = MAVEN_COORDINATES.get(id);
        if (maven == null) {
            if (bundle.getState() >= Bundle.RESOLVED) {
                try {
                    Enumeration<URL> e = bundle.findEntries("META-INF/maven/", "pom.properties", true);
                    StringBuilder buf = new StringBuilder();
                    while (e != null && e.hasMoreElements()) {
                        URL url = e.nextElement();
                        appendMavenCoordinateFromPomProperties(url.openStream(), buf);