com.servicerocket.confluence.plugin.utility.library.EnvironmentAssistantWithModuleTracker Maven / Gradle / Ivy
The newest version!
package com.servicerocket.confluence.plugin.utility.library;
import com.atlassian.plugin.PluginAccessor;
import com.atlassian.plugin.event.PluginEventManager;
import com.atlassian.plugin.tracker.DefaultPluginModuleTracker;
import com.atlassian.plugin.tracker.PluginModuleTracker;
import com.servicerocket.confluence.randombits.support.core.env.EnvironmentProvider;
import com.servicerocket.confluence.randombits.support.core.impl.DefaultEnvironmentAssistant;
import org.springframework.beans.factory.DisposableBean;
/**
* Temporary class to re-introduce module descriptor back into the plugin.
* Should be merge with parent class once `randombits core` runtime library is consolidate into this plugin.
*
* @author Kai Ming
* @since 2.1.1.20161207
*/
public class EnvironmentAssistantWithModuleTracker extends DefaultEnvironmentAssistant implements DisposableBean {
private final PluginModuleTracker providerTracker;
public EnvironmentAssistantWithModuleTracker(PluginAccessor pluginAccessor, PluginEventManager pluginEventManager) {
this.providerTracker = new DefaultPluginModuleTracker<>(
pluginAccessor, pluginEventManager, EnvironmentProviderModuleDescriptor.class, new CachingCustomizer()
);
}
private class CachingCustomizer implements PluginModuleTracker.Customizer {
@Override
public EnvironmentProviderModuleDescriptor adding(EnvironmentProviderModuleDescriptor descriptor) {
addProvider(descriptor.getModule());
return descriptor;
}
@Override
public void removed(EnvironmentProviderModuleDescriptor descriptor) {
removeProvider(descriptor.getModule());
}
}
@Override
public void destroy() throws Exception {
providerTracker.close();
}
}