View Javadoc

1   package com.atlassian.plugin.loaders;
2   
3   import com.atlassian.plugin.util.FileUtils;
4   import com.atlassian.plugin.Plugin;
5   import com.atlassian.plugin.ModuleDescriptorFactory;
6   import com.atlassian.plugin.PluginParseException;
7   import com.atlassian.plugin.factories.PluginFactory;
8   import com.atlassian.plugin.event.PluginEventManager;
9   import com.atlassian.plugin.impl.DynamicPlugin;
10  import com.atlassian.plugin.loaders.classloading.DeploymentUnit;
11  
12  import java.io.File;
13  import java.util.List;
14  import java.net.URL;
15  
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  
19  /**
20   * Plugin loader that unzips plugins from a zip file into a local directory, and ensures that directory only contains
21   * plugins from that zip file.  It also treats all plugins loaded from the directory as bundled plugins, meaning they
22   * can can be upgraded, but not deleted.
23   */
24  public class BundledPluginLoader extends DirectoryPluginLoader {
25  
26      private static final Log log = LogFactory.getLog(BundledPluginLoader.class);
27      public BundledPluginLoader(URL zipUrl, File pluginPath, List<PluginFactory> pluginFactories, PluginEventManager eventManager)
28      {
29          super(pluginPath, pluginFactories, eventManager);
30          if (zipUrl == null)
31              throw new IllegalArgumentException("Bundled zip url cannot be null");
32          FileUtils.conditionallyExtractZipFile(zipUrl, pluginPath);
33      }
34  
35      /**
36       * Just like the {@link DirectoryPluginLoader#deployPluginFromUnit(DeploymentUnit,ModuleDescriptorFactory)} method
37       * but changes the plugin to not be deletable
38       * @param deploymentUnit The plugin to deploy
39       * @param moduleDescriptorFactory The descriptor factory
40       * @return The created plugin
41       * @throws PluginParseException If there is a problem parsing the configuration
42       */
43      protected Plugin deployPluginFromUnit(DeploymentUnit deploymentUnit, ModuleDescriptorFactory moduleDescriptorFactory) throws PluginParseException
44      {
45          Plugin plugin = super.deployPluginFromUnit(deploymentUnit, moduleDescriptorFactory);
46          if (plugin instanceof DynamicPlugin)
47          {
48              DynamicPlugin dplugin = (DynamicPlugin) plugin;
49              dplugin.setDeletable(false);
50              dplugin.setBundled(true);
51          }
52  
53          if (log.isDebugEnabled())
54              log.debug("Deployed bundled plugin: "+plugin.getName());
55          return plugin;
56      }
57  }