Search in sources :

Example 1 with LifeCycleListener

use of com.gitblit.extensions.LifeCycleListener in project gitblit by gitblit.

the class GitblitContext method startCore.

/**
	 * Prepare runtime settings and start all manager instances.
	 */
protected void startCore(ServletContext context) {
    Injector injector = (Injector) context.getAttribute(Injector.class.getName());
    // create the runtime settings object
    IStoredSettings runtimeSettings = injector.getInstance(IStoredSettings.class);
    final File baseFolder;
    if (goSettings != null) {
        // Gitblit GO
        baseFolder = configureGO(context, goSettings, goBaseFolder, runtimeSettings);
    } else {
        // servlet container
        WebXmlSettings webxmlSettings = new WebXmlSettings(context);
        String contextRealPath = context.getRealPath("/");
        File contextFolder = (contextRealPath != null) ? new File(contextRealPath) : null;
        // if the base folder dosen't match the default assume they don't want to use express,
        // this allows for other containers to customise the basefolder per context.
        String defaultBase = Constants.contextFolder$ + "/WEB-INF/data";
        String base = getBaseFolderPath(defaultBase);
        if (!StringUtils.isEmpty(System.getenv("OPENSHIFT_DATA_DIR")) && defaultBase.equals(base)) {
            // RedHat OpenShift
            baseFolder = configureExpress(context, webxmlSettings, contextFolder, runtimeSettings);
        } else {
            // standard WAR
            baseFolder = configureWAR(context, webxmlSettings, contextFolder, runtimeSettings);
        }
        // Test for Tomcat forward-slash/%2F issue and auto-adjust settings
        ContainerUtils.CVE_2007_0450.test(runtimeSettings);
    }
    // Manually configure IRuntimeManager
    logManager(IRuntimeManager.class);
    IRuntimeManager runtime = injector.getInstance(IRuntimeManager.class);
    runtime.setBaseFolder(baseFolder);
    runtime.getStatus().isGO = goSettings != null;
    runtime.getStatus().servletContainer = context.getServerInfo();
    runtime.start();
    managers.add(runtime);
    // create the plugin manager instance but do not start it
    loadManager(injector, IPluginManager.class);
    // start all other managers
    startManager(injector, INotificationManager.class);
    startManager(injector, IUserManager.class);
    startManager(injector, IAuthenticationManager.class);
    startManager(injector, IPublicKeyManager.class);
    startManager(injector, IRepositoryManager.class);
    startManager(injector, IProjectManager.class);
    startManager(injector, IFederationManager.class);
    startManager(injector, ITicketService.class);
    startManager(injector, IGitblit.class);
    startManager(injector, IServicesManager.class);
    startManager(injector, IFilestoreManager.class);
    // start the plugin manager last so that plugins can depend on
    // deterministic access to all other managers in their start() methods
    startManager(injector, IPluginManager.class);
    logger.info("");
    logger.info("All managers started.");
    logger.info("");
    IPluginManager pluginManager = injector.getInstance(IPluginManager.class);
    for (LifeCycleListener listener : pluginManager.getExtensions(LifeCycleListener.class)) {
        try {
            listener.onStartup();
        } catch (Throwable t) {
            logger.error(null, t);
        }
    }
}
Also used : IRuntimeManager(com.gitblit.manager.IRuntimeManager) Injector(com.google.inject.Injector) IStoredSettings(com.gitblit.IStoredSettings) WebXmlSettings(com.gitblit.WebXmlSettings) IPluginManager(com.gitblit.manager.IPluginManager) LifeCycleListener(com.gitblit.extensions.LifeCycleListener) File(java.io.File)

Example 2 with LifeCycleListener

use of com.gitblit.extensions.LifeCycleListener in project gitblit by gitblit.

the class GitblitContext method destroyContext.

/**
	 * Gitblit is being shutdown either because the servlet container is
	 * shutting down or because the servlet container is re-deploying Gitblit.
	 */
protected void destroyContext(ServletContext context) {
    logger.info("Gitblit context destroyed by servlet container.");
    IPluginManager pluginManager = getManager(IPluginManager.class);
    for (LifeCycleListener listener : pluginManager.getExtensions(LifeCycleListener.class)) {
        try {
            listener.onShutdown();
        } catch (Throwable t) {
            logger.error(null, t);
        }
    }
    for (IManager manager : managers) {
        logger.debug("stopping {}", manager.getClass().getSimpleName());
        manager.stop();
    }
}
Also used : IManager(com.gitblit.manager.IManager) IPluginManager(com.gitblit.manager.IPluginManager) LifeCycleListener(com.gitblit.extensions.LifeCycleListener)

Aggregations

LifeCycleListener (com.gitblit.extensions.LifeCycleListener)2 IPluginManager (com.gitblit.manager.IPluginManager)2 IStoredSettings (com.gitblit.IStoredSettings)1 WebXmlSettings (com.gitblit.WebXmlSettings)1 IManager (com.gitblit.manager.IManager)1 IRuntimeManager (com.gitblit.manager.IRuntimeManager)1 Injector (com.google.inject.Injector)1 File (java.io.File)1