Exemple #1
0
  /** Creates a hudson.PluginStrategy, looking at the corresponding system property. */
  protected PluginStrategy createPluginStrategy() {
    String strategyName = System.getProperty(PluginStrategy.class.getName());
    if (strategyName != null) {
      try {
        Class<?> klazz = getClass().getClassLoader().loadClass(strategyName);
        Object strategy = klazz.getConstructor(PluginManager.class).newInstance(this);
        if (strategy instanceof PluginStrategy) {
          LOGGER.info("Plugin strategy: " + strategyName);
          return (PluginStrategy) strategy;
        } else {
          LOGGER.warning(
              "Plugin strategy (" + strategyName + ") is not an instance of hudson.PluginStrategy");
        }
      } catch (ClassNotFoundException e) {
        LOGGER.warning("Plugin strategy class not found: " + strategyName);
      } catch (Exception e) {
        LOGGER.log(
            WARNING,
            "Could not instantiate plugin strategy: "
                + strategyName
                + ". Falling back to ClassicPluginStrategy",
            e);
      }
      LOGGER.info("Falling back to ClassicPluginStrategy");
    }

    // default and fallback
    return new ClassicPluginStrategy(this);
  }
Exemple #2
0
 /**
  * Get the plugin instances that extend a specific class, use to find similar plugins. Note:
  * beware the classloader fun.
  *
  * @param pluginSuperclass The class that your plugin is derived from.
  * @return The list of plugins implementing the specified class.
  */
 public List<PluginWrapper> getPlugins(Class<? extends Plugin> pluginSuperclass) {
   List<PluginWrapper> result = new ArrayList<PluginWrapper>();
   for (PluginWrapper p : plugins) {
     if (pluginSuperclass.isInstance(p.getPlugin())) result.add(p);
   }
   return Collections.unmodifiableList(result);
 }
Exemple #3
0
 /**
  * Return the {@link PluginWrapper} that loaded the given class 'c'.
  *
  * @since 1.402.
  */
 public PluginWrapper whichPlugin(Class c) {
   PluginWrapper oneAndOnly = null;
   ClassLoader cl = c.getClassLoader();
   for (PluginWrapper p : activePlugins) {
     if (p.classLoader == cl) {
       if (oneAndOnly != null) return null; // ambigious
       oneAndOnly = p;
     }
   }
   return oneAndOnly;
 }
Exemple #4
0
 /**
  * Get the plugin instance that implements a specific class, use to find your plugin singleton.
  * Note: beware the classloader fun.
  *
  * @param pluginClazz The class that your plugin implements.
  * @return The plugin singleton or <code>null</code> if for some reason the plugin is not loaded.
  */
 public PluginWrapper getPlugin(Class<? extends Plugin> pluginClazz) {
   for (PluginWrapper p : plugins) {
     if (pluginClazz.isInstance(p.getPlugin())) return p;
   }
   return null;
 }