Commits

Samuel Le Berrigaud committed 11debb4

Created Atlassian OSGi.

Change-Id: I02dee7644f7ece0584317e617a22555c7912ca39

Comments (0)

Files changed (13)

osgi/pom.xml

-<?xml version="1.0" encoding="UTF-8"?>
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>com.atlassian.labs</groupId>
-        <artifactId>remoteapps-parent</artifactId>
-        <version>${VERSION_NUMBER}</version>
-    </parent>
-
-    <artifactId>remoteapps-util-osgi</artifactId>
-    <name>Atlassian Remote Apps - OSGI</name>
-
-    <dependencies>
-        <dependency>
-            <groupId>com.atlassian.labs</groupId>
-            <artifactId>remoteapps-util-concurrent</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.atlassian.plugins</groupId>
-            <artifactId>atlassian-plugins-osgi</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-context</artifactId>
-        </dependency>
-    </dependencies>
-</project>

osgi/src/main/java/com/atlassian/labs/remoteapps/plugin/util/tracker/WaitableServiceTracker.java

-package com.atlassian.labs.remoteapps.plugin.util.tracker;
-
-import com.atlassian.util.concurrent.Promise;
-import com.atlassian.util.concurrent.Promises;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.util.concurrent.AbstractFuture;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import static com.google.common.collect.Maps.*;
-
-/**
- * Service tracker that aggregates locally-defined services in the application context as well as
- * external osgi service implementations.  The other key function is the ability to wait until key
- * services have been tracked.
- */
-public class WaitableServiceTracker<K, T>
-{
-    private final Map<K, T> services;
-    private final ServiceTracker serviceTracker;
-    private static final Logger log = LoggerFactory.getLogger(WaitableServiceTracker.class);
-    private final Class serviceClass;
-    private final Function<T, K> extractor;
-    private final Set<ServiceFuture<K,T>> futures = new CopyOnWriteArraySet<ServiceFuture<K, T>>();
-    private final WaitableServiceTrackerCustomizer<T> customizer;
-
-    public WaitableServiceTracker(final BundleContext bundleContext, Class<T> serviceClass,
-            final Function<T, K> extractor,
-            final WaitableServiceTrackerCustomizer<T> customizer)
-    {
-        this.extractor = extractor;
-        this.customizer = customizer;
-        this.services = newHashMap();
-
-        this.serviceTracker = new ServiceTracker(bundleContext, serviceClass.getName(), new ServiceTrackerCustomizer()
-            
-        {
-            @Override
-            public Object addingService(ServiceReference reference)
-            {
-                T service = (T) bundleContext.getService(reference);
-                addIfKeyNotNull(extractor, customizer, service);
-                updateFutures();
-                return service;
-            }
-
-            @Override
-            public void modifiedService(ServiceReference reference, Object service)
-            {
-                removedService(reference, service);
-                addingService(reference);
-            }
-
-            @Override
-            public void removedService(ServiceReference reference, Object service)
-            {
-                for (Iterator<T> i = services.values().iterator(); i.hasNext(); )
-                {
-                    if (service == i.next())
-                    {
-                        i.remove();
-                    }
-                }
-                customizer.removed((T) service);
-                updateFutures();
-            }
-        });
-        this.serviceTracker.open();
-        this.serviceClass = serviceClass;
-    }
-
-    private void updateFutures()
-    {
-        // todo: should this be in its own thread/executor?
-        for (ServiceFuture<K,T> future : futures)
-        {
-            if (future.servicesUpdated(services))
-            {
-                futures.remove(future);
-            }
-        }
-    }
-
-    private void addIfKeyNotNull(Function<T, K> extractor,
-            WaitableServiceTrackerCustomizer<T> customizer, T service)
-    {
-        K key = extractor.apply(service);
-        if (key != null)
-        {
-            this.services.put(key, customizer.adding(service));
-        }
-    }
-
-    public Promise<Map<K,T>> waitFor(Predicate<Map<K, T>> predicate)
-    {
-        ServiceFuture<K,T> future = new ServiceFuture<K, T>(predicate);
-        if (!future.servicesUpdated(services))
-        {
-            futures.add(future);
-        }
-        return Promises.forListenableFuture(future);
-    }
-
-    void close()
-    {
-        this.serviceTracker.close();
-    }
-    
-    public T get(K key)
-    {
-        return services.get(key);
-    }
-    
-    public Set<K> getKeys()
-    {
-        return services.keySet();
-    }
-    
-    public Iterable<T> getAll()
-    {
-        return services.values();
-    }
-
-    Class getServiceClass()
-    {
-        return serviceClass;
-    }
-
-    void loadLocalServices(Collection<T> localServices)
-    {
-        for (T service : localServices)
-        {
-            addIfKeyNotNull(extractor, customizer, service);
-        }
-        updateFutures();
-    }
-
-    private static class ServiceFuture<K, T> extends AbstractFuture<Map<K,T>>
-    {
-        private Predicate<Map<K, T>> condition;
-
-        private ServiceFuture(Predicate<Map<K, T>> condition)
-        {
-            this.condition = condition;
-        }
-
-        public boolean servicesUpdated(Map<K, T> services)
-        {
-            if (condition.apply(services))
-            {
-                set(services);
-                return true;
-            }
-            return false;
-        }
-    }
-}

osgi/src/main/java/com/atlassian/labs/remoteapps/plugin/util/tracker/WaitableServiceTrackerCustomizer.java

-package com.atlassian.labs.remoteapps.plugin.util.tracker;
-
-/**
- * Callbacks for adding and removing services to the tracker
- */
-public interface WaitableServiceTrackerCustomizer<T>
-{
-    T adding(T service);
-    
-    void removed(T service);
-}

osgi/src/main/java/com/atlassian/labs/remoteapps/plugin/util/tracker/WaitableServiceTrackerFactory.java

-package com.atlassian.labs.remoteapps.plugin.util.tracker;
-
-import com.google.common.base.Function;
-import org.osgi.framework.BundleContext;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationEvent;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.event.ContextRefreshedEvent;
-import org.springframework.stereotype.Component;
-
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * Creates waitable service trackers.
- */
-@Component
-public class WaitableServiceTrackerFactory implements DisposableBean, ApplicationListener
-{
-    private final BundleContext bundleContext;
-    private final Set<WaitableServiceTracker<?,?>> serviceTrackers;
-
-    @Autowired
-    public WaitableServiceTrackerFactory(BundleContext bundleContext)
-    {
-        this.bundleContext = bundleContext;
-        this.serviceTrackers = new CopyOnWriteArraySet<WaitableServiceTracker<?,?>>();
-    }
-
-    public <K, T> WaitableServiceTracker<K,T> create(Class<T> serviceClass,
-            Function<T,K> keyExtractor)
-    {
-        return create(serviceClass, keyExtractor, new NoOpWaitableServiceTrackerCustomizer<T>());
-    }
-    public <K, T> WaitableServiceTracker<K,T> create(Class<T> serviceClass, 
-            Function<T,K> keyExtractor, WaitableServiceTrackerCustomizer<T> customizer)
-    {
-        WaitableServiceTracker<K,T> tracker = new WaitableServiceTracker<K,T>(bundleContext,
-                serviceClass, keyExtractor, customizer);
-        serviceTrackers.add(tracker);
-        return tracker;
-    }
-
-    @Override
-    public void destroy() throws Exception
-    {
-        for (WaitableServiceTracker<?,?> tracker : serviceTrackers)
-        {
-            tracker.close();
-        }
-    }
-
-    public <T> WaitableServiceTracker<T, T> create(Class<T> serviceClass)
-    {
-        return create(serviceClass, new ValueAsKeyFunction<T>());
-    }
-
-    public <T> WaitableServiceTracker<T, T> create(Class<T> serviceClass, WaitableServiceTrackerCustomizer<T> customizer)
-    {
-        return create(serviceClass, new ValueAsKeyFunction<T>(), customizer);
-    }
-
-    @Override
-    public void onApplicationEvent(ApplicationEvent event)
-    {
-        if (event instanceof ContextRefreshedEvent)
-        {
-            ApplicationContext ctx = ((ContextRefreshedEvent)event).getApplicationContext();
-            for (WaitableServiceTracker tracker : serviceTrackers)
-            {
-                tracker.loadLocalServices(ctx.getBeansOfType(tracker.getServiceClass()).values());
-            }
-        }
-    }
-
-    private static class NoOpWaitableServiceTrackerCustomizer<T> implements WaitableServiceTrackerCustomizer<T>
-    {
-
-        @Override
-        public T adding(T service)
-        {
-            return service;
-        }
-
-        @Override
-        public void removed(T service)
-        {
-        }
-    }
-
-    private static class ValueAsKeyFunction<T> implements Function<T, T>
-    {
-        @Override
-        public T apply(T from)
-        {
-            return from;
-        }
-    }
-}
             <artifactId>atlassian-uri</artifactId>
         </dependency>
         <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>remoteapps-util-osgi</artifactId>
-            <version>${project.version}</version>
+            <groupId>com.atlassian.osgi</groupId>
+            <artifactId>atlassian-osgi</artifactId>
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>

plugin/src/main/java/com/atlassian/labs/remoteapps/plugin/ModuleGeneratorManager.java

 package com.atlassian.labs.remoteapps.plugin;
 
-import com.atlassian.labs.remoteapps.plugin.module.applinks.ApplicationTypeModuleGenerator;
 import com.atlassian.labs.remoteapps.plugin.module.RemoteModuleGenerator;
-import com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTracker;
-import com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTrackerFactory;
+import com.atlassian.labs.remoteapps.plugin.module.applinks.ApplicationTypeModuleGenerator;
+import com.atlassian.osgi.tracker.WaitableServiceTracker;
+import com.atlassian.osgi.tracker.WaitableServiceTrackerFactory;
 import com.google.common.base.Function;
 import org.dom4j.Element;
 import org.springframework.beans.factory.annotation.Autowired;

plugin/src/main/java/com/atlassian/labs/remoteapps/plugin/descriptor/PluginDescriptorValidatorProvider.java

 import com.atlassian.labs.remoteapps.spi.InstallationFailedException;
 import com.atlassian.labs.remoteapps.spi.descriptor.DescribedModuleDescriptorFactory;
 import com.atlassian.labs.remoteapps.spi.schema.Schema;
-import com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTracker;
-import com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTrackerFactory;
+import com.atlassian.osgi.tracker.WaitableServiceTracker;
+import com.atlassian.osgi.tracker.WaitableServiceTrackerFactory;
 import com.atlassian.plugin.Plugin;
 import com.atlassian.plugin.osgi.bridge.external.PluginRetrievalService;
 import com.atlassian.sal.api.ApplicationProperties;

plugin/src/main/java/com/atlassian/labs/remoteapps/plugin/integration/plugins/DynamicDescriptorRegistration.java

 package com.atlassian.labs.remoteapps.plugin.integration.plugins;
 
 import com.atlassian.labs.remoteapps.host.common.util.BundleUtil;
-import com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTracker;
-import com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTrackerFactory;
+import com.atlassian.osgi.tracker.WaitableServiceTracker;
+import com.atlassian.osgi.tracker.WaitableServiceTrackerFactory;
 import com.atlassian.plugin.ModuleDescriptor;
 import com.atlassian.plugin.ModuleDescriptorFactory;
 import com.atlassian.plugin.Plugin;

plugin/src/main/resources/atlassian-plugin.xml

                interface="com.atlassian.labs.remoteapps.spi.webhook.PluginUriResolver" public="true"
                class="com.atlassian.labs.remoteapps.plugin.module.webhook.RemoteAppsPluginUriResolver" />
 
+    <component key="waitableServiceTrackerFactory" class="com.atlassian.osgi.tracker.WaitableServiceTrackerFactory" />
+
     <component key="webHookProvider"
                interface="com.atlassian.labs.remoteapps.spi.webhook.WebHookProvider" public="true"
                class="com.atlassian.labs.remoteapps.plugin.webhooks.PluginAppWebHookProvider" />
         <module>test</module>
         <module>universal-binary-test-plugin</module>
         <module>webhook-plugin</module>
-        <module>osgi</module>
     </modules>
 
     <build>
                 <version>0.1</version>
             </dependency>
             <dependency>
+                <groupId>com.atlassian.osgi</groupId>
+                <artifactId>atlassian-osgi</artifactId>
+                <version>0.1</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.osgi</groupId>
+                        <artifactId>org.osgi</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
                 <groupId>com.atlassian.event</groupId>
                 <artifactId>atlassian-event</artifactId>
                 <version>${event.version}</version>

webhook-plugin/pom.xml

             <artifactId>atlassian-uri</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.atlassian.labs</groupId>
-            <artifactId>remoteapps-util-osgi</artifactId>
-            <version>${project.version}</version>
+            <groupId>com.atlassian.osgi</groupId>
+            <artifactId>atlassian-osgi</artifactId>
         </dependency>
         <dependency>
             <groupId>com.atlassian.plugins</groupId>

webhook-plugin/src/main/java/com/atlassian/labs/remoteapps/plugin/webhook/WebHookRegistrationManager.java

 
 import com.atlassian.event.api.EventListener;
 import com.atlassian.event.api.EventPublisher;
-import com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTrackerCustomizer;
-import com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTrackerFactory;
 import com.atlassian.labs.remoteapps.plugin.webhook.impl.WebHookRegistrarImpl;
 import com.atlassian.labs.remoteapps.spi.webhook.WebHookProvider;
+import com.atlassian.osgi.tracker.WaitableServiceTrackerCustomizer;
+import com.atlassian.osgi.tracker.WaitableServiceTrackerFactory;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Multimaps;
 import com.google.common.collect.SetMultimap;

webhook-plugin/src/main/resources/atlassian-plugin.xml

     <component key="pluginUriResolver"
                class="com.atlassian.labs.remoteapps.plugin.webhook.impl.PluginUriResolverImpl" />
 
-    <component key="waitableServiceTrackerFactory" class="com.atlassian.labs.remoteapps.plugin.util.tracker.WaitableServiceTrackerFactory" />
+    <component key="waitableServiceTrackerFactory" class="com.atlassian.osgi.tracker.WaitableServiceTrackerFactory" />
 
     <component key="requestKiller"
                class="com.atlassian.labs.remoteapps.host.common.service.http.RequestKiller" />
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.