Ting
2014-04-16 d0751dc352ef06c067593f31f5423fce357f8f1f
src/main/java/com/gitblit/manager/PluginManager.java
@@ -42,9 +42,10 @@
import ro.fortsoft.pf4j.PluginState;
import ro.fortsoft.pf4j.PluginStateEvent;
import ro.fortsoft.pf4j.PluginStateListener;
import ro.fortsoft.pf4j.PluginVersion;
import ro.fortsoft.pf4j.PluginWrapper;
import ro.fortsoft.pf4j.Version;
import com.gitblit.Constants;
import com.gitblit.Keys;
import com.gitblit.models.PluginRegistry;
import com.gitblit.models.PluginRegistry.InstallState;
@@ -63,6 +64,7 @@
 * the Dagger DI and retrieve extensions provided by active plugins.
 *
 * @author David Ostrovsky
 * @author James Moger
 *
 */
public class PluginManager implements IPluginManager, PluginStateListener {
@@ -82,7 +84,20 @@
      File dir = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins");
      dir.mkdirs();
      this.runtimeManager = runtimeManager;
      this.pf4j = new DefaultPluginManager(dir);
      try {
         Version systemVersion = Version.createVersion(Constants.getVersion());
         pf4j.setSystemVersion(systemVersion);
      } catch (Exception e) {
         logger.error(null, e);
      }
   }
   @Override
   public Version getSystemVersion() {
      return pf4j.getSystemVersion();
   }
   @Override
@@ -131,6 +146,30 @@
   }
   @Override
   public synchronized boolean upgradePlugin(String pluginId, String url, boolean verifyChecksum) throws IOException {
      // ensure we can download the update BEFORE we remove the existing one
      File file = download(url, verifyChecksum);
      if (file == null || !file.exists()) {
         logger.error("Failed to download plugin {}", url);
         return false;
      }
      if (deletePlugin(pluginId)) {
         String newPluginId = pf4j.loadPlugin(file);
         if (StringUtils.isEmpty(newPluginId)) {
            logger.error("Failed to load plugin {}", file);
            return false;
         }
         PluginState state = pf4j.startPlugin(newPluginId);
         return PluginState.STARTED.equals(state);
      } else {
         logger.error("Failed to delete plugin {}", pluginId);
      }
      return false;
   }
   @Override
   public synchronized boolean disablePlugin(String pluginId) {
      return pf4j.disablePlugin(pluginId);
   }
@@ -162,7 +201,6 @@
                     (file.getName().toLowerCase().endsWith(".sha1")
                           || file.getName().toLowerCase().endsWith(".md5"));
            }
         });
         if (checksums != null) {
@@ -296,9 +334,10 @@
            map.put(reg.id, reg);
         }
      }
      for (PluginWrapper pw : pf4j.getPlugins()) {
         String id = pw.getDescriptor().getPluginId();
         PluginVersion pv = pw.getDescriptor().getVersion();
         Version pv = pw.getDescriptor().getVersion();
         PluginRegistration reg = map.get(id);
         if (reg != null) {
            reg.installedRelease = pv.toString();
@@ -320,9 +359,9 @@
   }
   @Override
   public synchronized PluginRegistration lookupPlugin(String idOrName) {
   public synchronized PluginRegistration lookupPlugin(String pluginId) {
      for (PluginRegistration reg : getRegisteredPlugins()) {
         if (reg.id.equalsIgnoreCase(idOrName) || reg.name.equalsIgnoreCase(idOrName)) {
         if (reg.id.equalsIgnoreCase(pluginId)) {
            return reg;
         }
      }
@@ -330,8 +369,8 @@
   }
   @Override
   public synchronized PluginRelease lookupRelease(String idOrName, String version) {
      PluginRegistration reg = lookupPlugin(idOrName);
   public synchronized PluginRelease lookupRelease(String pluginId, String version) {
      PluginRegistration reg = lookupPlugin(pluginId);
      if (reg == null) {
         return null;
      }