Search in sources :

Example 1 with PluginRegistry

use of com.gitblit.models.PluginRegistry in project gitblit by gitblit.

the class PluginManager method getRegistries.

protected List<PluginRegistry> getRegistries() {
    List<PluginRegistry> list = new ArrayList<PluginRegistry>();
    File folder = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins");
    FileFilter jsonFilter = new FileFilter() {

        @Override
        public boolean accept(File file) {
            return !file.isDirectory() && file.getName().toLowerCase().endsWith(".json");
        }
    };
    File[] files = folder.listFiles(jsonFilter);
    if (files == null || files.length == 0) {
        // automatically retrieve the registry if we don't have a local copy
        refreshRegistry(true);
        files = folder.listFiles(jsonFilter);
    }
    if (files == null || files.length == 0) {
        return list;
    }
    for (File file : files) {
        PluginRegistry registry = null;
        try {
            String json = FileUtils.readContent(file, "\n");
            registry = JsonUtils.fromJsonString(json, PluginRegistry.class);
            registry.setup();
        } catch (Exception e) {
            logger.error("Failed to deserialize " + file, e);
        }
        if (registry != null) {
            list.add(registry);
        }
    }
    return list;
}
Also used : PluginRegistry(com.gitblit.models.PluginRegistry) ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) File(java.io.File) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with PluginRegistry

use of com.gitblit.models.PluginRegistry in project gitblit by gitblit.

the class PluginManager method getRegisteredPlugins.

@Override
public synchronized List<PluginRegistration> getRegisteredPlugins() {
    List<PluginRegistration> list = new ArrayList<PluginRegistration>();
    Map<String, PluginRegistration> map = new TreeMap<String, PluginRegistration>();
    for (PluginRegistry registry : getRegistries()) {
        list.addAll(registry.registrations);
        for (PluginRegistration reg : list) {
            reg.installedRelease = null;
            map.put(reg.id, reg);
        }
    }
    for (PluginWrapper pw : pf4j.getPlugins()) {
        String id = pw.getDescriptor().getPluginId();
        Version pv = pw.getDescriptor().getVersion();
        PluginRegistration reg = map.get(id);
        if (reg != null) {
            reg.installedRelease = pv.toString();
        }
    }
    return list;
}
Also used : Version(ro.fortsoft.pf4j.Version) PluginRegistry(com.gitblit.models.PluginRegistry) ArrayList(java.util.ArrayList) PluginRegistration(com.gitblit.models.PluginRegistry.PluginRegistration) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) TreeMap(java.util.TreeMap)

Aggregations

PluginRegistry (com.gitblit.models.PluginRegistry)2 ArrayList (java.util.ArrayList)2 PluginRegistration (com.gitblit.models.PluginRegistry.PluginRegistration)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 TreeMap (java.util.TreeMap)1 PluginWrapper (ro.fortsoft.pf4j.PluginWrapper)1 Version (ro.fortsoft.pf4j.Version)1