private DetectorFactoryCollection(
      boolean loadCore,
      boolean forceLoad,
      @Nonnull Collection<Plugin> pluginsToLoad,
      @Nonnull Collection<Plugin> enabledPlugins) {
    if (loadCore) {
      loadCorePlugin();
    }
    for (Plugin plugin : pluginsToLoad) {
      if (forceLoad || plugin.isGloballyEnabled() && !plugin.isCorePlugin()) {
        loadPlugin(plugin);
        if (!enabledPlugins.contains(plugin)) {
          enabledPlugins.add(plugin);
        }
      }
    }
    setGlobalOptions();
    updateChecker = new UpdateChecker(this);
    pluginsToUpdate = combine(enabledPlugins);
    // There are too many places where the detector factory collection can be created,
    // and in many cases it has nothing to do with update checks, like Plugin#addCustomPlugin(URI).

    // Line below commented to allow custom plugins be loaded/registered BEFORE we
    // start to update something. The reason is that custom plugins
    // can disable update globally OR just will be NOT INCLUDED in the update check!
    // updateChecker.checkForUpdates(pluginsToUpdate, false);
  }
  private void setGlobalOptions() {
    globalOptions.clear();
    globalOptionsSetter.clear();

    for (Plugin p : plugins()) {
      if (p.isGloballyEnabled()) {
        for (Map.Entry<String, String> e : p.getMyGlobalOptions().entrySet()) {
          String key = e.getKey();
          String value = e.getValue();
          String oldValue = globalOptions.get(key);

          if (oldValue != null) {
            if (oldValue.equals(value)) {
              continue;
            }
            Plugin oldP = globalOptionsSetter.get(key);
            throw new RuntimeException(
                "Incompatible global options for "
                    + key
                    + "; conflict between "
                    + oldP.getPluginId()
                    + " and "
                    + p.getPluginId());
          }
          globalOptions.put(key, value);
          globalOptionsSetter.put(key, p);
        }
      }
    }
  }
Esempio n. 3
0
  /**
   * @param justPrintConfiguration
   * @throws InterruptedException
   */
  public static void printVersion(boolean justPrintConfiguration) throws InterruptedException {
    System.out.println("FindBugs " + Version.COMPUTED_RELEASE);
    if (justPrintConfiguration) {
      for (Plugin plugin : Plugin.getAllPlugins()) {
        System.out.printf(
            "Plugin %s, version %s, loaded from %s%n",
            plugin.getPluginId(), plugin.getVersion(), plugin.getPluginLoader().getURL());
        if (plugin.isCorePlugin()) System.out.println("  is core plugin");
        if (plugin.isInitialPlugin()) System.out.println("  is initial plugin");
        if (plugin.isEnabledByDefault()) System.out.println("  is enabled by default");
        if (plugin.isGloballyEnabled()) System.out.println("  is globally enabled");
        Plugin parent = plugin.getParentPlugin();
        if (parent != null) {
          System.out.println("  has parent plugin " + parent.getPluginId());
        }

        for (CloudPlugin cloudPlugin : plugin.getCloudPlugins()) {
          System.out.printf("  cloud %s%n", cloudPlugin.getId());
          System.out.printf("     %s%n", cloudPlugin.getDescription());
        }
        for (DetectorFactory factory : plugin.getDetectorFactories()) {
          System.out.printf("  detector %s%n", factory.getShortName());
        }
        System.out.println();
      }
      printPluginUpdates(true, 10);
    } else printPluginUpdates(false, 3);
  }