View Javadoc

1   package com.atlassian.sal.core.lifecycle;
2   
3   import com.google.common.base.Function;
4   import com.google.common.base.Joiner;
5   import com.google.common.collect.Iterables;
6   import org.osgi.framework.Bundle;
7   import org.osgi.framework.ServiceReference;
8   
9   import javax.annotation.Nonnull;
10  import javax.annotation.Nullable;
11  import java.util.Collection;
12  
13  import static com.atlassian.plugin.osgi.util.OsgiHeaderUtil.getPluginKey;
14  
15  /**
16   * A collection of methods to make lifecycle logging easier
17   */
18  class LifecycleLog {
19      @Nonnull
20      static String getPluginKeyFromBundle(@Nullable final Bundle bundle) {
21          return (bundle == null) ? "<stale service reference>" : getPluginKey(bundle);
22      }
23  
24      @Nonnull
25      static <T> String listPluginKeys(@Nonnull Collection<ServiceReference<T>> services) {
26          @SuppressWarnings("unchecked")
27          Iterable<String> pluginKeys = Iterables.transform(services, new Function<ServiceReference<T>, String>() {
28              @Nullable
29              @Override
30              public String apply(@Nonnull final ServiceReference<T> service) {
31  
32                  return getPluginKeyFromBundle(service.getBundle());
33              }
34          });
35  
36          return "[" + Joiner.on(", ").join(pluginKeys) + "]";
37      }
38  }