View Javadoc
1   package com.atlassian.plugin.loaders;
2   
3   import com.atlassian.plugin.DefaultPluginArtifactFactory;
4   import com.atlassian.plugin.PluginArtifactFactory;
5   import com.atlassian.plugin.ReferenceMode;
6   import com.atlassian.plugin.event.PluginEventManager;
7   import com.atlassian.plugin.factories.PluginFactory;
8   import com.atlassian.plugin.util.EnumUtils;
9   
10  import java.io.File;
11  import java.util.List;
12  
13  /**
14   * A PluginLoader which manages plugins specified by a roster file.
15   *
16   * @see RosterFileScanner
17   * @since v3.0.24
18   */
19  public class RosterFilePluginLoader extends ScanningPluginLoader {
20      public static String getReferenceModePropertyName() {
21          return RosterFilePluginLoader.class.getName() + ".referenceMode";
22      }
23  
24      private static ReferenceMode referenceModeFromProperty() {
25          final String propertyName = getReferenceModePropertyName();
26          return EnumUtils.enumValueFromProperty(propertyName, ReferenceMode.values(), ReferenceMode.FORBID_REFERENCE);
27      }
28  
29      /**
30       * Create a RosterFilePluginLoader which loads a given roster file to locate plugins.
31       *
32       * @param rosterFile         the file to load the plugin roster from, as per {@link RosterFileScanner}.
33       * @param pluginFactories    the factories used to convert PluginArtifacts to Plugins.
34       * @param pluginEventManager the event manager for the plugin system.
35       */
36      public RosterFilePluginLoader(final File rosterFile,
37                                    final List<PluginFactory> pluginFactories,
38                                    final PluginEventManager pluginEventManager) {
39          this(rosterFile, pluginFactories, referenceModeFromProperty(), pluginEventManager);
40      }
41  
42      /**
43       * Create a RosterFilePluginLoader which loads a given roster file to locate plugins.
44       *
45       * @param rosterFile         the file to load the plugin roster from, as per {@link RosterFileScanner}.
46       * @param pluginFactories    the factories used to convert PluginArtifacts to Plugins.
47       * @param referenceMode      the ReferenceMode to use for the implicit {@link DefaultPluginArtifactFactory}.
48       * @param pluginEventManager the event manager for the plugin system.
49       */
50      public RosterFilePluginLoader(final File rosterFile,
51                                    final List<PluginFactory> pluginFactories,
52                                    final ReferenceMode referenceMode,
53                                    final PluginEventManager pluginEventManager) {
54          this(rosterFile, pluginFactories, new DefaultPluginArtifactFactory(referenceMode), pluginEventManager);
55      }
56  
57      /**
58       * Create a RosterFilePluginLoader which loads a given roster file to locate plugins.
59       *
60       * @param rosterFile            the file to load the plugin roster from, as per {@link RosterFileScanner}.
61       * @param pluginFactories       the factories used to convert PluginArtifacts to Plugins.
62       * @param pluginArtifactFactory the factory used to convert URIs to PluginArtifacts.
63       * @param pluginEventManager    the event manager for the plugin system.
64       */
65      public RosterFilePluginLoader(final File rosterFile,
66                                    final List<PluginFactory> pluginFactories,
67                                    final PluginArtifactFactory pluginArtifactFactory,
68                                    final PluginEventManager pluginEventManager) {
69          super(new RosterFileScanner(rosterFile), pluginFactories, pluginArtifactFactory, pluginEventManager);
70      }
71  }