public AliveDashboardMediator(Shell shell, DashboardPart dashboardPart) {
    this.dashboardPart = dashboardPart;
    state = new AliveDashboardState();
    locations = new HashMap<String, ActionContainer>();
    contributions = new HashMap<DashboardActionDescriptor, IFigure>();
    this.shell = shell;

    IConfigurationElement[] config =
        Platform.getExtensionRegistry()
            .getConfigurationElementsFor("net.sf.ictalive.aliveclipse.dashboard.actions");
    for (IConfigurationElement ce : config)
      try {

        Object o = ce.createExecutableExtension("class");
        if (o instanceof PluggedInDashboardAction<?>) {
          PluggedInDashboardAction<AliveDashboardState> pluggedInAction =
              (PluggedInDashboardAction<AliveDashboardState>) o;
          if (pluggedInAction.dashboardActionId() == null)
            Plugin.getDefault()
                .getLog()
                .log(
                    Plugin.createError(
                        "IDashboardAction plugin has null dashboardActionId.", null));
          else pluggedInActions.put(pluggedInAction.dashboardActionId(), pluggedInAction);
        }
      } catch (CoreException e1) {
        e1.printStackTrace();
      }
  }
 public Collection<Class<? extends CloseableIndexComponent>> indexServices() {
   List<Class<? extends CloseableIndexComponent>> services = Lists.newArrayList();
   for (Plugin plugin : plugins.values()) {
     services.addAll(plugin.indexServices());
   }
   return services;
 }
  public static void modalityChanged(int paramInt, boolean paramBoolean) {
    PerPluginInfo localPerPluginInfo = (PerPluginInfo) pluginInfoMap.get(new Integer(paramInt));
    if (localPerPluginInfo == null) return;
    final AppletID localAppletID = new AppletID(paramInt);
    if (paramBoolean) {
      final int i = localPerPluginInfo.modalityPushed();
      final Plugin localPlugin = localPerPluginInfo.getPlugin();
      localPlugin.invokeLater(
          new Runnable() {
            private final ModalitySupport.PerPluginInfo val$info;
            private final AppletID val$id;
            private final int val$depth;
            private final Plugin val$plugin;

            public void run() {
              if (this.val$info.getPlugin().getActiveJSCounter() > 0) {
                this.val$info.modalityPopped();
                return;
              }
              while ((!JVMManager.getManager().appletExited(localAppletID))
                  && (this.val$info.getModalityDepth() >= i))
                localPlugin.waitForSignalWithModalBlocking();
              localPlugin.notifyMainThread();
            }
          });
    } else {
      localPerPluginInfo.modalityPopped();
    }
  }
 public Collection<Class<? extends Module>> indexModules() {
   List<Class<? extends Module>> modules = Lists.newArrayList();
   for (Plugin plugin : plugins.values()) {
     modules.addAll(plugin.indexModules());
   }
   return modules;
 }
 public Collection<Class<? extends LifecycleComponent>> services() {
   List<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
   for (Plugin plugin : plugins.values()) {
     services.addAll(plugin.services());
   }
   return services;
 }
 private Map<String, Plugin> loadPluginsFromClasspath(Settings settings) {
   Map<String, Plugin> plugins = newHashMap();
   Enumeration<URL> pluginUrls = null;
   try {
     pluginUrls = settings.getClassLoader().getResources("es-plugin.properties");
   } catch (IOException e) {
     logger.warn("Failed to find plugins from classpath", e);
   }
   while (pluginUrls.hasMoreElements()) {
     URL pluginUrl = pluginUrls.nextElement();
     Properties pluginProps = new Properties();
     InputStream is = null;
     try {
       is = pluginUrl.openStream();
       pluginProps.load(is);
       String sPluginClass = pluginProps.getProperty("plugin");
       Class<?> pluginClass = settings.getClassLoader().loadClass(sPluginClass);
       Plugin plugin = (Plugin) pluginClass.newInstance();
       plugins.put(plugin.name(), plugin);
     } catch (Exception e) {
       logger.warn("Failed to load plugin from [" + pluginUrl + "]", e);
     } finally {
       if (is != null) {
         try {
           is.close();
         } catch (IOException e) {
           // ignore
         }
       }
     }
   }
   return plugins;
 }
Beispiel #7
0
  public void logSevere(String message) {

    uLogger.severe(String.format("[%d] %s", Thread.currentThread().getId(), message));

    final int maxSevereLogsToDump = 10; // could consider settings, but nah!

    if (currentSevereCnt.incrementAndGet() < maxSevereLogsToDump) {

      final String dumpLogFilename = String.format("%d.dump.log", new Date().getTime());
      final String dumpLogFilePath =
          plugin.getDataFolder().toString() + File.separator + dumpLogFilename;

      try {
        PrintWriter out = new PrintWriter(dumpLogFilePath);
        out.println(String.format("[%d] %s", Thread.currentThread().getId(), message));
        out.flush();
        out.close();
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }

    if (plugin.settings.devUser == null) {
      return;
    }

    final Player player = plugin.getServer().getPlayer(plugin.settings.devUser);

    if (player != null && player.isOnline()) {
      player.sendMessage(
          "Omniscient error: " + message.substring(0, Math.min(message.length() - 1, 30)));
    }
  }
Beispiel #8
0
  /*
   * (non-Javadoc)
   *
   * @see jframe.core.plugin.PluginContext#regPlugins(java.util.Collection,
   * java.util.Comparator)
   */
  public void regPlugins(Collection<Plugin> plugins, Comparator<? super Plugin> comparator) {
    if (plugins == null || plugins.size() == 0) return;

    if (comparator == null) {
      comparator = new PluginComparator(PluginComparator.TYPE.START);
    }
    TreeSet<Plugin> set = new TreeSet<Plugin>(comparator);
    for (Plugin p : plugins) {
      if (!set.add(p)) _LOG.warn("Found repeated plugin: " + p.getName());
    }
    Iterator<Plugin> iter = set.iterator();
    Plugin p = null;
    while (iter.hasNext()) {
      p = iter.next();
      try {
        regPlugin(p);
      } catch (Exception e) {
        _LOG.error(
            "When invoke pluginContext.regPlugin(), plugin name is "
                + p.getName()
                + " "
                + e.getMessage());
        unregPlugin(p);
      }
      iter.remove();
    }
  }
  private void resolveDeleteByDependency() {
    // delete by depend
    boolean hasModifications = true;
    while (hasModifications) {
      log.debug("Check uninstall dependencies");
      hasModifications = false;
      for (Plugin plugin : deletions) {
        if (!additions.contains(plugin)) {
          for (Plugin dep : getDependants(plugin)) {
            if (!deletions.contains(dep) && dep.isInstalled()) {
              log.debug("Add to deletions: " + dep);
              deletions.add(dep);
              hasModifications = true;
            }
            if (additions.contains(dep)) {
              log.debug("Remove from additions: " + dep);
              additions.remove(dep);
              hasModifications = true;
            }
          }
        }

        if (hasModifications) {
          break; // prevent ConcurrentModificationException
        }
      }
    }
  }
  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);
  }
  public void enablePlugin(final Plugin plugin) {
    if (!(plugin instanceof JavaPlugin)) {
      throw new IllegalArgumentException("Plugin is not associated with this PluginLoader");
    }

    if (!plugin.isEnabled()) {
      JavaPlugin jPlugin = (JavaPlugin) plugin;

      String pluginName = jPlugin.getDescription().getName();

      if (!loaders.containsKey(pluginName)) {
        loaders.put(pluginName, (PluginClassLoader) jPlugin.getClassLoader());
      }

      try {
        jPlugin.setEnabled(true);
      } catch (Throwable ex) {
        server
            .getLogger()
            .log(
                Level.SEVERE,
                "Error occurred while enabling "
                    + plugin.getDescription().getFullName()
                    + " (Is it up to date?): "
                    + ex.getMessage(),
                ex);
      }

      // Perhaps abort here, rather than continue going, but as it stands,
      // an abort is not possible the way it's currently written
      server.getPluginManager().callEvent(new PluginEnableEvent(plugin));
    }
  }
  private void resolveInstallByDependency() {
    // resolve dependencies
    boolean hasModifications = true;
    while (hasModifications) {
      log.debug("Check install dependencies: " + additions);
      hasModifications = false;
      for (Plugin plugin : additions) {
        for (String pluginID : plugin.getDepends()) {
          Plugin depend = getPluginByID(pluginID);

          if (!depend.isInstalled() || deletions.contains(depend)) {
            if (!additions.contains(depend)) {
              log.debug("Add to install: " + depend);
              additions.add(depend);
              hasModifications = true;
            }
          }
        }

        if (hasModifications) {
          break; // prevent ConcurrentModificationException
        }
      }
    }
  }
    /** Create worker-specific fileinstall.cfg file for the master. */
    public void confCreate(final String worker) {
      ensureConf();
      final Conf conf = conf();

      if (!ResourceUtil.hasProject(worker)) {
        Plugin.logWarn("Project#confCreate: missing project: " + worker);
        return;
      }

      final Map<String, String> variables = //
          Conf.variables(ResourceUtil.workspacePath(), worker, ResourceUtil.projectPath(worker));

      final String path =
          ConfUtil.replace( //
              conf.fileinstallPath(), variables);

      final String tempalte =
          ConfUtil.replace( //
              conf.fileinstallTemplate(), variables);

      final File file = ProjectUtil.file(project(), path);

      try {
        FileUtil.writeTextFile(file, tempalte);
        Plugin.logOK("Project#confCreate file: " + file);
      } catch (final Throwable e) {
        Plugin.logErrr("Project#confCreate failure", e);
      }
    }
  @UnsafeMethod
  public synchronized void enablePlugin(Plugin plugin) {
    if (!CommonPlugin.class.isAssignableFrom(plugin.getClass())) {
      throw new IllegalArgumentException(
          "Cannot enable plugin with this PluginLoader as it is of the wrong type!");
    }
    if (!plugin.isEnabled()) {
      CommonPlugin cp = (CommonPlugin) plugin;
      String name = cp.getDescription().getName();

      if (!loaders.containsKey(name)) {
        loaders.put(name, (CommonClassLoader) cp.getClassLoader());
      }

      try {
        cp.setEnabled(true);
        cp.onEnable();
      } catch (Throwable e) {
        engine
            .getLogger()
            .log(
                Level.SEVERE,
                "An error occured when enabling '"
                    + plugin.getDescription().getFullName()
                    + "': "
                    + e.getMessage(),
                e);
      }

      engine.getEventManager().callEvent(new PluginEnableEvent(cp));
    }
  }
  /**
   * Loads the plugin in the specified file
   *
   * <p>File must be valid according to the current enabled Plugin interfaces
   *
   * @param file File containing the plugin to load
   * @return The Plugin loaded, or null if it was invalid
   * @throws InvalidPluginException Thrown when the specified file is not a valid plugin
   * @throws UnknownDependencyException If a required dependency could not be found
   */
  public synchronized Plugin loadPlugin(File file)
      throws InvalidPluginException, UnknownDependencyException {
    Validate.notNull(file, "File cannot be null");

    checkUpdate(file);

    Set<Pattern> filters = fileAssociations.keySet();
    Plugin result = null;

    for (Pattern filter : filters) {
      String name = file.getName();
      Matcher match = filter.matcher(name);

      if (match.find()) {
        PluginLoader loader = fileAssociations.get(filter);

        result = loader.loadPlugin(file);
      }
    }

    if (result != null) {
      plugins.add(result);
      lookupNames.put(result.getDescription().getName(), result);
    }

    return result;
  }
  /** Loads all plugins, calling onLoad, &c. */
  private void loadPlugins() {
    // clear the map
    commandMap.clearCommands();
    commandMap.register("glowstone", new ColorCommand("colors"));
    commandMap.register("glowstone", new TellrawCommand());

    File folder = new File(config.getString(ServerConfig.Key.PLUGIN_FOLDER));
    if (!folder.isDirectory() && !folder.mkdirs()) {
      logger.log(Level.SEVERE, "Could not create plugins directory: " + folder);
    }

    // clear plugins and prepare to load
    pluginManager.clearPlugins();
    pluginManager.registerInterface(JavaPluginLoader.class);
    Plugin[] plugins = pluginManager.loadPlugins(folder);

    // call onLoad methods
    for (Plugin plugin : plugins) {
      try {
        plugin.onLoad();
      } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex);
      }
    }
  }
Beispiel #17
0
  /** 从配置文件装载系统配置信息 */
  public void initialize() throws PluginException {
    try {
      Element sysconfig = Plugin.getRoot().getElement("sysconfig");
      DEBUG = Boolean.valueOf(sysconfig.getAttributeValue("debug"));
      ERROR_PAGE = sysconfig.getElementText("error-page");
      CACHE_PATH = sysconfig.getElementText("cache-path");

      MvcPlugin.getMvcs().clear();
      Element mvc = Plugin.getRoot().getElement("mvc");

      // autoInject=Boolean.valueOf(mvc.getAttributeValue("auto-inject"));
      // paramIntercept=Boolean.valueOf(mvc.getAttributeValue("param-intercept"));
      String _useDao = mvc.getAttributeValue("use-dao");
      USE_DAO = !(_useDao == null || _useDao.equalsIgnoreCase("false"));
      if (USE_DAO) {
        DAOFactory.getInstance().createDAO().close();
      }
      Element modules = mvc.getElement("modules");
      for (int i = 0; i < modules.getChildCount(); i++) {
        Element module = (Element) modules.getElement(i);
        if (module != null) {
          MvcPlugin.getMvcs().add(module.getText());
        }
      }

    } catch (UtilException e) {
      throw new PluginException(e);
    }
  }
 /** Called when Plugin is destroyed. */
 public void onDestroy() {
   Enumeration e = this.plugins.elements();
   while (e.hasMoreElements()) {
     Plugin plugin = (Plugin) e.nextElement();
     plugin.onDestroy();
   }
 }
Beispiel #19
0
 @SuppressWarnings("unchecked")
 private static void startPlugins() {
   logger.info("Loading available plugins");
   final Collection<File> botJars =
       FileUtils.listFiles(pluginsDirecotry, new String[] {"jar"}, false);
   for (File botJar : botJars) {
     try {
       JarFile jar = new JarFile(botJar);
       ZipEntry ze = jar.getEntry("plugin.yml");
       if (ze == null) throw new RuntimeException("Plugin has no plugin.yml file!");
       InputStream is = jar.getInputStream(ze);
       YAMLNode n = new YAMLNode(new Yaml().loadAs(is, Map.class), true);
       String mainClass = n.getString("mainClass");
       String name = n.getString("name");
       URLClassLoader loader =
           new URLClassLoader(new URL[] {botJar.toURI().toURL()}, Chatty.class.getClassLoader());
       Plugin plugin = loader.loadClass(mainClass).asSubclass(Plugin.class).newInstance();
       plugin.start();
       PLUGIN_INFO.put(name, new PluginInfo(name, plugin, n));
       logger.info("Loaded plugin '{}'", name);
     } catch (Exception e) {
       logger.error("Failed to load plugin from {}", botJar.getName());
       e.printStackTrace();
     }
   }
   logger.info("Loaded {} plugin(s)", PLUGIN_INFO.size());
 }
 private Plugin getPluginByID(String id) {
   for (Plugin plugin : allPlugins.keySet()) {
     if (plugin.getID().equals(id)) {
       return plugin;
     }
   }
   throw new RuntimeException("Plugin not found by ID: " + id);
 }
Beispiel #21
0
  public static void addOpenPort(int port, Protocol protocol, String service, String version) {
    Port p = new Port(port, protocol, service, version);

    getCurrentTarget().addOpenPort(p);

    for (Plugin plugin : getPluginsForTarget()) {
      plugin.onTargetNewOpenPort(getCurrentTarget(), p);
    }
  }
Beispiel #22
0
 /** Returns a list of all the plugins with the given {@code pluginClass}. */
 public <T extends Plugin> List<T> findPlugins(Class<T> pluginClass) {
   List<T> plugins = new ArrayList<T>();
   for (Plugin plugin : getAllPlugins(getState().getDatabase())) {
     if (pluginClass.isInstance(plugin) && plugin.getTool() != null) {
       plugins.add((T) plugin);
     }
   }
   return plugins;
 }
Beispiel #23
0
 /**
  * Returns the {@link de.xirp.profile.Plugin plugins} for the specified plugin main class
  * associated with this robot.
  *
  * @param pluginMainClass The main class of the plugin.
  * @return The list of plugins or <code>null</code> if no plugin was found.
  * @see de.xirp.profile.Plugin
  */
 public List<Plugin> getPlugins(String pluginMainClass) {
   List<Plugin> lst = new ArrayList<Plugin>();
   for (Plugin plugin : getPlugins().getPlugins()) {
     if (plugin.getClassName().equalsIgnoreCase(pluginMainClass)) {
       lst.add(plugin);
     }
   }
   return lst;
 }
 private void appendPluginSettings(StringBuffer buffer) {
   if (plugins.size() > 0) {
     Iterator<Plugin> iterator = plugins.iterator();
     while (iterator.hasNext()) {
       Plugin plugin = iterator.next();
       plugin.definePluginSettings(buffer);
     }
   }
 }
Beispiel #25
0
  public static ArrayList<Plugin> getPluginsForTarget(Target target) {
    ArrayList<Plugin> filtered = new ArrayList<Plugin>();

    if (target != null) {
      for (Plugin plugin : mPlugins) if (plugin.isAllowedTarget(target)) filtered.add(plugin);
    }

    return filtered;
  }
Beispiel #26
0
 /**
  * Locate a plugin with the given name. Plugins are identified by their class names (without
  * package name).
  *
  * @param pluginName The name of the plugin (the base class name)
  * @return the Plugin instance or null if not found.
  */
 public Plugin getPlugin(String pluginName) {
   for (Plugin plugin : mPlugins) {
     String name = plugin.getClass().getSimpleName();
     if (name.equals(pluginName)) {
       return plugin;
     }
   }
   return null;
 }
 public static void startAll() {
   for (String pluginName : AppConfig.getPlugins()) {
     Plugin plugin = get(pluginName);
     if (plugin != null) {
       logger.warn("Starting plugin " + pluginName);
       plugin.start();
     }
   }
 }
 /**
  * Unloads the plugin. The effectively shuts the plugin down and removes it from the
  * PluginRegistry's resource loaders.
  *
  * @throws Exception
  */
 public synchronized void unload() throws Exception {
   if (plugin != null) {
     plugin.stop();
     // it's important that the plugin be removed from the resource loading system after shutdown
     // in
     // case the plugin needs to access the resource loader during shutdown
     registry.removeResourceLoader(plugin.getName());
   }
   loaded = false;
 }
 /**
  * Loads the plugin from the PluginLoader. This will also start the Plugin and add it to the
  * PluginRegistry's resoure loaders.
  */
 public synchronized void load() throws Exception {
   plugin = loader.load();
   plugin.setSuppressStartupFailure(suppressStartupFailure);
   // it's important that the plugin is added to the resource loading system prior to startup
   // because
   // startup may need to grab services
   registry.addResourceLoader(plugin);
   plugin.start();
   loaded = true;
 }
 private void resolveInstallLibs() {
   for (Plugin plugin : additions) {
     Map<String, String> libs = plugin.getLibs(plugin.getCandidateVersion());
     for (String lib : libs.keySet()) {
       if (Plugin.getLibInstallPath(lib) == null) {
         libAdditions.put(lib, libs.get(lib));
       }
     }
   }
 }