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       * Gets the plugin key from the bundle
14       *
15       * WARNING: shamelessly copied from {@code com.atlassian.plugin.osgi.util.OsgiHeaderUtil}, which can't be imported
16       * due to creating a cyclic build dependency. Ensure these two implementations are in sync.
17       *
18       * @param bundle The plugin bundle
19       * @return The plugin key, cannot be null
20       * @since 2.2.1
21       */
22      static String getPluginKey(Bundle bundle) {
23          return getPluginKey(
24                  bundle.getSymbolicName(),
25                  bundle.getHeaders().get("Atlassian-Plugin-Key"),
26                  bundle.getHeaders().get(Constants.BUNDLE_VERSION)
27          );
28      }
29  
30      private static String getPluginKey(Object bundleName, Object atlKey, Object version) {
31          Object key = atlKey;
32          if (key == null) {
33              key = bundleName + "-" + version;
34          }
35          return key.toString();
36  
37      }
38  }