View Javadoc

1   package com.atlassian.plugin.loaders;
2   
3   import com.atlassian.plugin.Plugin;
4   import com.atlassian.plugin.event.PluginEventManager;
5   import com.atlassian.plugin.factories.PluginFactory;
6   import com.atlassian.plugin.impl.AbstractDelegatingPlugin;
7   import com.atlassian.plugin.util.FileUtils;
8   
9   import java.io.File;
10  import java.net.URL;
11  import java.util.List;
12  
13  /**
14   * Plugin loader that unzips plugins from a zip file into a local directory, and ensures that directory only contains
15   * plugins from that zip file.  It also treats all plugins loaded from the directory as bundled plugins, meaning they
16   * can can be upgraded, but not deleted.
17   */
18  public class BundledPluginLoader extends DirectoryPluginLoader
19  {
20      public BundledPluginLoader(final URL zipUrl, final File pluginPath, final List<PluginFactory> pluginFactories, final PluginEventManager eventManager)
21      {
22          super(pluginPath, pluginFactories, eventManager);
23          if (zipUrl == null)
24          {
25              throw new IllegalArgumentException("Bundled zip url cannot be null");
26          }
27          FileUtils.conditionallyExtractZipFile(zipUrl, pluginPath);
28      }
29  
30      @Override
31      protected Plugin postProcess(final Plugin plugin)
32      {
33          return new BundledPluginDelegate(plugin);
34      }
35  
36      /**
37       * Delegate that overrides methods to enforce bundled plugin behavior
38       *
39       * @Since 2.2.0
40       */
41      private static class BundledPluginDelegate extends AbstractDelegatingPlugin
42      {
43  
44          public BundledPluginDelegate(Plugin delegate)
45          {
46              super(delegate);
47          }
48  
49          @Override
50          public boolean isBundledPlugin()
51          {
52              return true;
53          }
54  
55          @Override
56          public boolean isDeleteable()
57          {
58              return false;
59          }
60      }
61  }