View Javadoc

1   package com.atlassian.plugin.osgi.bridge;
2   
3   import org.osgi.framework.Bundle;
4   import org.osgi.framework.Constants;
5   
6   /**
7    * Utility methods for event bridge classes
8    *
9    * @since 2.2.1
10   */
11  class PluginBundleUtils
12  {
13      /**
14       * Gets the plugin key from the bundle
15       *
16       * WARNING: shamelessly copied from {@link com.atlassian.plugin.osgi.util.OsgiHeaderUtil}, which can't be imported
17       * due to creating a cyclic build dependency.  Ensure these two implementations are in sync.
18       *
19       * @param bundle The plugin bundle
20       * @return The plugin key, cannot be null
21       * @since 2.2.1
22       */
23      static String getPluginKey(Bundle bundle)
24      {
25          return getPluginKey(
26                  bundle.getSymbolicName(),
27                  bundle.getHeaders().get("Atlassian-Plugin-Key"),
28                  bundle.getHeaders().get(Constants.BUNDLE_VERSION)
29          );
30      }
31  
32      private static String getPluginKey(Object bundleName, Object atlKey, Object version)
33      {
34          Object key = atlKey;
35          if (key == null)
36          {
37              key = bundleName + "-" + version;
38          }
39          return key.toString();
40  
41      }
42  }