Search in sources :

Example 1 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.

the class ProxyFilter method init.

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    filters.addAll(pluginManager.getExtensions(HttpRequestFilter.class));
    for (HttpRequestFilter f : filters) {
        // wrap the filter config for Gitblit settings retrieval
        PluginWrapper pluginWrapper = pluginManager.whichPlugin(f.getClass());
        FilterConfig runtimeConfig = new FilterRuntimeConfig(runtimeManager, pluginWrapper.getPluginId(), filterConfig);
        f.init(runtimeConfig);
    }
}
Also used : HttpRequestFilter(com.gitblit.extensions.HttpRequestFilter) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) FilterConfig(javax.servlet.FilterConfig)

Example 2 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper 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)

Example 3 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.

the class GitBlitWebApp method init.

@Override
public void init() {
    super.init();
    // Setup page authorization mechanism
    boolean useAuthentication = settings.getBoolean(Keys.web.authenticateViewPages, false) || settings.getBoolean(Keys.web.authenticateAdminPages, false);
    if (useAuthentication) {
        AuthorizationStrategy authStrategy = new AuthorizationStrategy(settings, homePageClass);
        getSecuritySettings().setAuthorizationStrategy(authStrategy);
        getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy);
    }
    // Grab Browser info (like timezone, etc)
    if (settings.getBoolean(Keys.web.useClientTimezone, false)) {
        getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
    }
    // configure the resource cache duration to 90 days for deployment
    if (!isDebugMode()) {
        getResourceSettings().setDefaultCacheDuration(90 * 86400);
    }
    // setup the standard gitweb-ish urls
    mount("/repositories", RepositoriesPage.class);
    mount("/overview", OverviewPage.class, "r");
    mount("/summary", SummaryPage.class, "r");
    mount("/reflog", ReflogPage.class, "r");
    mount("/commits", LogPage.class, "r", "h");
    mount("/log", LogPage.class, "r", "h");
    mount("/tags", TagsPage.class, "r");
    mount("/branches", BranchesPage.class, "r");
    mount("/commit", CommitPage.class, "r", "h");
    mount("/tag", TagPage.class, "r", "h");
    mount("/tree", TreePage.class, "r", "h", "f");
    mount("/blob", BlobPage.class, "r", "h", "f");
    mount("/blobdiff", BlobDiffPage.class, "r", "h", "f");
    mount("/commitdiff", CommitDiffPage.class, "r", "h");
    mount("/compare", ComparePage.class, "r", "h");
    mount("/patch", PatchPage.class, "r", "h", "f");
    mount("/history", HistoryPage.class, "r", "h", "f");
    mount("/search", GitSearchPage.class);
    mount("/metrics", MetricsPage.class, "r");
    mount("/blame", BlamePage.class, "r", "h", "f");
    mount("/users", UsersPage.class);
    mount("/teams", TeamsPage.class);
    mount("/logout", LogoutPage.class);
    // setup ticket urls
    mount("/tickets", TicketsPage.class, "r", "h");
    mount("/tickets/new", NewTicketPage.class, "r");
    mount("/tickets/edit", EditTicketPage.class, "r", "h");
    mount("/tickets/export", ExportTicketPage.class, "r", "h");
    mount("/milestones/new", NewMilestonePage.class, "r");
    mount("/milestones/edit", EditMilestonePage.class, "r", "h");
    mount("/mytickets", MyTicketsPage.class, "r", "h");
    // setup the markup document urls
    mount("/docs", DocsPage.class, "r", "h");
    mount("/doc", DocPage.class, "r", "h", "f");
    mount("/editfile", EditFilePage.class, "r", "h", "f");
    // federation urls
    mount("/proposal", ReviewProposalPage.class, "t");
    mount("/registration", FederationRegistrationPage.class, "u", "n");
    mount("/new", NewRepositoryPage.class);
    mount("/edit", EditRepositoryPage.class, "r");
    mount("/activity", ActivityPage.class, "r", "h");
    mount("/lucene", LuceneSearchPage.class);
    mount("/project", ProjectPage.class, "p");
    mount("/projects", ProjectsPage.class);
    mount("/user", UserPage.class, "user");
    mount("/forks", ForksPage.class, "r");
    mount("/fork", ForkPage.class, "r");
    // filestore URL
    mount("/filestore", FilestorePage.class);
    // allow started Wicket plugins to initialize
    for (PluginWrapper pluginWrapper : pluginManager.getPlugins()) {
        if (PluginState.STARTED != pluginWrapper.getPluginState()) {
            continue;
        }
        if (pluginWrapper.getPlugin() instanceof GitblitWicketPlugin) {
            GitblitWicketPlugin wicketPlugin = (GitblitWicketPlugin) pluginWrapper.getPlugin();
            wicketPlugin.init(this);
        }
    }
    // customize the Wicket class resolver to load from plugins
    IClassResolver coreResolver = getApplicationSettings().getClassResolver();
    PluginClassResolver classResolver = new PluginClassResolver(coreResolver, pluginManager);
    getApplicationSettings().setClassResolver(classResolver);
    getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
}
Also used : GitblitWicketPlugin(com.gitblit.extensions.GitblitWicketPlugin) IClassResolver(org.apache.wicket.application.IClassResolver) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper)

Example 4 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.

the class PluginClassResolver method getResources.

@Override
public Iterator<URL> getResources(final String name) {
    Set<URL> urls = new TreeSet<URL>(new UrlExternalFormComparator());
    for (PluginWrapper plugin : pluginManager.getPlugins()) {
        if (PluginState.STARTED != plugin.getPluginState()) {
            // ignore this plugin
            continue;
        }
        Iterator<URL> it = getResources(name, plugin);
        while (it.hasNext()) {
            URL url = it.next();
            urls.add(url);
        }
    }
    Iterator<URL> it = coreResolver.getResources(name);
    while (it.hasNext()) {
        URL url = it.next();
        urls.add(url);
    }
    return urls.iterator();
}
Also used : TreeSet(java.util.TreeSet) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) URL(java.net.URL)

Example 5 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.

the class PluginManager method upgradePlugin.

@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;
    }
    Version oldVersion = pf4j.getPlugin(pluginId).getDescriptor().getVersion();
    if (removePlugin(pluginId, false)) {
        String newPluginId = pf4j.loadPlugin(file);
        if (StringUtils.isEmpty(newPluginId)) {
            logger.error("Failed to load plugin {}", file);
            return false;
        }
        // the plugin to handle an upgrade
        PluginWrapper pluginWrapper = pf4j.getPlugin(newPluginId);
        if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
            ((GitblitPlugin) pluginWrapper.getPlugin()).onUpgrade(oldVersion);
        }
        PluginState state = pf4j.startPlugin(newPluginId);
        return PluginState.STARTED.equals(state);
    } else {
        logger.error("Failed to delete plugin {}", pluginId);
    }
    return false;
}
Also used : PluginState(ro.fortsoft.pf4j.PluginState) GitblitPlugin(com.gitblit.extensions.GitblitPlugin) Version(ro.fortsoft.pf4j.Version) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) File(java.io.File)

Aggregations

PluginWrapper (ro.fortsoft.pf4j.PluginWrapper)7 GitblitPlugin (com.gitblit.extensions.GitblitPlugin)3 File (java.io.File)3 PluginState (ro.fortsoft.pf4j.PluginState)2 Version (ro.fortsoft.pf4j.Version)2 GitblitWicketPlugin (com.gitblit.extensions.GitblitWicketPlugin)1 HttpRequestFilter (com.gitblit.extensions.HttpRequestFilter)1 PluginRegistry (com.gitblit.models.PluginRegistry)1 PluginRegistration (com.gitblit.models.PluginRegistry.PluginRegistration)1 FileFilter (java.io.FileFilter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 FilterConfig (javax.servlet.FilterConfig)1 IClassResolver (org.apache.wicket.application.IClassResolver)1