예제 #1
0
  /**
   * Build a list of installed plugins.
   *
   * @return a list of plugin names and version numbers.
   */
  public static EventList<NameAndVersion> findInstalledPlugins() {
    EventList<NameAndVersion> plugins = new BasicEventList<NameAndVersion>();
    if (!PluginCore.userPluginDir.exists()) return plugins;
    String[] files =
        PluginCore.userPluginDir.list(
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return name.endsWith(".jar");
              }
            });

    HashMap<String, PluginDescriptor> urls = new HashMap<String, PluginDescriptor>();
    Collection<PluginDescriptor> descriptors =
        PluginCore.getManager().getRegistry().getPluginDescriptors();
    for (PluginDescriptor desc : descriptors) {
      if ((desc.getPluginClassName() == null)
          || !desc.getPluginClassName().equals("net.sf.jabref.plugin.core.JabRefPlugin")) {
        urls.put(desc.getId(), desc);
      }
    }

    for (String file1 : files) {
      File file = new File(PluginCore.userPluginDir, file1);
      String[] nav = getNameAndVersion(file);
      if (nav != null) {
        VersionNumber vn = nav[1] != null ? new VersionNumber(nav[1]) : null;
        NameAndVersion nameAndVersion = new NameAndVersion(nav[0], vn, true, file);
        for (Iterator<String> it = urls.keySet().iterator(); it.hasNext(); ) {
          String loc = it.next();
          if (loc.contains(nav[0])) {
            PluginDescriptor desc = urls.get(loc);
            // System.out.println("Accounted for: "+desc.getId()+" "+desc.getVersion().toString());
            if (!PluginCore.getManager().isPluginEnabled(urls.get(loc)))
              nameAndVersion.setStatus(BAD);
            else nameAndVersion.setStatus(LOADED);
            it.remove();
          }
        }
        plugins.add(nameAndVersion);
      }
    }

    for (String url : urls.keySet()) {
      PluginDescriptor desc = urls.get(url);
      File location = new File(desc.getLocation().getFile());
      if (location.getPath().contains(PluginCore.userPluginDir.getPath()))
        continue; // This must be a loaded user dir plugin that's been deleted.
      // System.out.println("File: "+desc.getLocation().getFile());
      NameAndVersion nameAndVersion =
          new NameAndVersion(
              desc.getId(), new VersionNumber(desc.getVersion().toString()), false, location);
      if (!PluginCore.getManager().isPluginEnabled(urls.get(url))) nameAndVersion.setStatus(BAD);
      else nameAndVersion.setStatus(LOADED);
      plugins.add(nameAndVersion);
    }
    return plugins;
  }