View Javadoc

1   package com.atlassian.plugin.metadata;
2   
3   import com.atlassian.plugin.PluginAccessor;
4   import org.slf4j.Logger;
5   import org.slf4j.LoggerFactory;
6   
7   import java.util.ArrayList;
8   import java.util.Collection;
9   import java.util.HashSet;
10  
11  public class RequiredPluginValidator
12  {
13      private static final Logger log = LoggerFactory.getLogger(RequiredPluginValidator.class);
14  
15      private final PluginAccessor pluginAccessor;
16      private final RequiredPluginProvider requiredPluginProvider;
17      private final Collection<String> errors;
18  
19      public RequiredPluginValidator(final PluginAccessor pluginAccessor, final RequiredPluginProvider requiredPluginProvider)
20      {
21          this.pluginAccessor = pluginAccessor;
22          this.requiredPluginProvider = requiredPluginProvider;
23          errors = new HashSet<String>();
24      }
25  
26      /**
27       * Validates that the plugins specified in the {@link ClasspathFilePluginMetadata} are enabled.
28       *
29       * Returns a Collection of all of the keys that did not validate
30       *
31       * @return A Collection of plugin and module keys that did not validate.
32       */
33      public Collection<String> validate()
34      {
35          for (String key : requiredPluginProvider.getRequiredPluginKeys())
36          {
37              if (!pluginAccessor.isPluginEnabled(key))
38              {
39                  log.error("Plugin Not Enabled: " + key);
40                  errors.add(key);
41              }
42          }
43  
44          for (String key : requiredPluginProvider.getRequiredModuleKeys())
45          {
46              if (!pluginAccessor.isPluginModuleEnabled(key))
47              {
48                  log.error("Plugin Module Not Enabled: " + key);
49                  errors.add(key);
50              }
51          }
52  
53          return errors;
54      }
55  }