Search in sources :

Example 1 with FileSettings

use of com.gitblit.FileSettings in project gitblit by gitblit.

the class GitblitAuthority method loadUsers.

private IUserService loadUsers(File folder) {
    File file = new File(folder, "gitblit.properties");
    if (!file.exists()) {
        return null;
    }
    gitblitSettings = new FileSettings(file.getAbsolutePath());
    mail = new MailService(gitblitSettings);
    String us = gitblitSettings.getString(Keys.realm.userService, "${baseFolder}/users.conf");
    String ext = us.substring(us.lastIndexOf(".") + 1).toLowerCase();
    IUserService service = null;
    if (!ext.equals("conf") && !ext.equals("properties") && ext.contains("userservice")) {
        String realm = ext.substring(0, ext.indexOf("userservice"));
        us = gitblitSettings.getString(MessageFormat.format("realm.{0}.backingUserService", realm), "${baseFolder}/users.conf");
    }
    if (us.endsWith(".conf")) {
        service = new ConfigUserService(FileUtils.resolveParameter(Constants.baseFolder$, folder, us));
    } else {
        throw new RuntimeException("Unsupported user service: " + us);
    }
    service = new ConfigUserService(FileUtils.resolveParameter(Constants.baseFolder$, folder, us));
    return service;
}
Also used : MailService(com.gitblit.service.MailService) FileSettings(com.gitblit.FileSettings) IUserService(com.gitblit.IUserService) ConfigUserService(com.gitblit.ConfigUserService) File(java.io.File)

Example 2 with FileSettings

use of com.gitblit.FileSettings in project gitblit by gitblit.

the class CoreModule method configure.

@Override
protected void configure() {
    bind(IStoredSettings.class).toInstance(new FileSettings());
    bind(XssFilter.class).to(JSoupXssFilter.class);
    // bind complex providers
    bind(IPublicKeyManager.class).toProvider(IPublicKeyManagerProvider.class);
    bind(ITicketService.class).toProvider(ITicketServiceProvider.class);
    bind(WorkQueue.class).toProvider(WorkQueueProvider.class);
    // core managers
    bind(IRuntimeManager.class).to(RuntimeManager.class);
    bind(IPluginManager.class).to(PluginManager.class);
    bind(INotificationManager.class).to(NotificationManager.class);
    bind(IUserManager.class).to(UserManager.class);
    bind(IAuthenticationManager.class).to(AuthenticationManager.class);
    bind(IRepositoryManager.class).to(RepositoryManager.class);
    bind(IProjectManager.class).to(ProjectManager.class);
    bind(IFederationManager.class).to(FederationManager.class);
    bind(IFilestoreManager.class).to(FilestoreManager.class);
    // the monolithic manager
    bind(IGitblit.class).to(GitBlit.class);
    // manager for long-running daemons and services
    bind(IServicesManager.class).to(ServicesManager.class);
}
Also used : ITicketService(com.gitblit.tickets.ITicketService) IAuthenticationManager(com.gitblit.manager.IAuthenticationManager) IUserManager(com.gitblit.manager.IUserManager) IStoredSettings(com.gitblit.IStoredSettings) FileSettings(com.gitblit.FileSettings) IFederationManager(com.gitblit.manager.IFederationManager) IRepositoryManager(com.gitblit.manager.IRepositoryManager) WorkQueue(com.gitblit.utils.WorkQueue) IRuntimeManager(com.gitblit.manager.IRuntimeManager) IProjectManager(com.gitblit.manager.IProjectManager) IServicesManager(com.gitblit.manager.IServicesManager) IGitblit(com.gitblit.manager.IGitblit) INotificationManager(com.gitblit.manager.INotificationManager) JSoupXssFilter(com.gitblit.utils.JSoupXssFilter) XssFilter(com.gitblit.utils.XssFilter) IPluginManager(com.gitblit.manager.IPluginManager) IPublicKeyManager(com.gitblit.transport.ssh.IPublicKeyManager) IFilestoreManager(com.gitblit.manager.IFilestoreManager)

Example 3 with FileSettings

use of com.gitblit.FileSettings in project gitblit by gitblit.

the class GitblitContext method configureWAR.

/**
	 * Configures a standard WAR instance of Gitblit.
	 *
	 * @param context
	 * @param webxmlSettings
	 * @param contextFolder
	 * @param runtimeSettings
	 * @return the base folder
	 */
protected File configureWAR(ServletContext context, WebXmlSettings webxmlSettings, File contextFolder, IStoredSettings runtimeSettings) {
    // Gitblit is running in a standard servlet container
    logger.debug("configuring Gitblit WAR");
    logger.info("WAR contextFolder is " + ((contextFolder != null) ? contextFolder.getAbsolutePath() : "<empty>"));
    String webXmlPath = webxmlSettings.getString(Constants.baseFolder, Constants.contextFolder$ + "/WEB-INF/data");
    if (webXmlPath.contains(Constants.contextFolder$) && contextFolder == null) {
        // warn about null contextFolder (issue-199)
        logger.error("");
        logger.error(MessageFormat.format("\"{0}\" depends on \"{1}\" but \"{2}\" is returning NULL for \"{1}\"!", Constants.baseFolder, Constants.contextFolder$, context.getServerInfo()));
        logger.error(MessageFormat.format("Please specify a non-parameterized path for <context-param> {0} in web.xml!!", Constants.baseFolder));
        logger.error(MessageFormat.format("OR configure your servlet container to specify a \"{0}\" parameter in the context configuration!!", Constants.baseFolder));
        logger.error("");
    }
    String baseFolderPath = getBaseFolderPath(webXmlPath);
    File baseFolder = com.gitblit.utils.FileUtils.resolveParameter(Constants.contextFolder$, contextFolder, baseFolderPath);
    baseFolder.mkdirs();
    // try to extract the data folder resource to the baseFolder
    extractResources(context, "/WEB-INF/data/", baseFolder);
    // delegate all config to baseFolder/gitblit.properties file
    File localSettings = new File(baseFolder, "gitblit.properties");
    FileSettings fileSettings = new FileSettings(localSettings.getAbsolutePath());
    // merge the stored settings into the runtime settings
    //
    // if runtimeSettings is also a FileSettings w/o a specified target file,
    // the target file for runtimeSettings is set to "localSettings".
    runtimeSettings.merge(fileSettings);
    return baseFolder;
}
Also used : FileSettings(com.gitblit.FileSettings) File(java.io.File)

Example 4 with FileSettings

use of com.gitblit.FileSettings in project gitblit by gitblit.

the class GitBlitTest method testFileSettings.

@Test
public void testFileSettings() throws Exception {
    FileSettings settings = new FileSettings("src/main/distrib/data/gitblit.properties");
    assertEquals(true, settings.getBoolean("missing", true));
    assertEquals("default", settings.getString("missing", "default"));
    assertEquals(10, settings.getInteger("missing", 10));
    assertEquals(5, settings.getInteger("realm.realmFile", 5));
    assertTrue(settings.getBoolean("git.enableGitServlet", false));
    assertEquals("${baseFolder}/users.conf", settings.getString("realm.userService", null));
    assertEquals(5, settings.getInteger("realm.minPasswordLength", 0));
    List<String> mdExtensions = settings.getStrings("web.markdownExtensions");
    assertTrue(mdExtensions.size() > 0);
    assertTrue(mdExtensions.contains("md"));
    List<String> keys = settings.getAllKeys("server");
    assertTrue(keys.size() > 0);
    assertTrue(keys.contains("server.httpsPort"));
    assertTrue(settings.getChar("web.forwardSlashCharacter", ' ') == '/');
}
Also used : FileSettings(com.gitblit.FileSettings) Test(org.junit.Test)

Example 5 with FileSettings

use of com.gitblit.FileSettings in project gitblit by gitblit.

the class GitblitContext method configureExpress.

/**
	 * Configures an OpenShift instance of Gitblit.
	 *
	 * @param context
	 * @param webxmlSettings
	 * @param contextFolder
	 * @param runtimeSettings
	 * @return the base folder
	 */
private File configureExpress(ServletContext context, WebXmlSettings webxmlSettings, File contextFolder, IStoredSettings runtimeSettings) {
    // Gitblit is running in OpenShift/JBoss
    logger.debug("configuring Gitblit Express");
    String openShift = System.getenv("OPENSHIFT_DATA_DIR");
    File base = new File(openShift);
    logger.info("EXPRESS contextFolder is " + contextFolder.getAbsolutePath());
    // Copy the included scripts to the configured groovy folder
    String path = webxmlSettings.getString(Keys.groovy.scriptsFolder, "groovy");
    File localScripts = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, base, path);
    if (!localScripts.exists()) {
        File warScripts = new File(contextFolder, "/WEB-INF/data/groovy");
        if (!warScripts.equals(localScripts)) {
            try {
                com.gitblit.utils.FileUtils.copy(localScripts, warScripts.listFiles());
            } catch (IOException e) {
                logger.error(MessageFormat.format("Failed to copy included Groovy scripts from {0} to {1}", warScripts, localScripts));
            }
        }
    }
    // Copy the included gitignore files to the configured gitignore folder
    String gitignorePath = webxmlSettings.getString(Keys.git.gitignoreFolder, "gitignore");
    File localGitignores = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, base, gitignorePath);
    if (!localGitignores.exists()) {
        File warGitignores = new File(contextFolder, "/WEB-INF/data/gitignore");
        if (!warGitignores.equals(localGitignores)) {
            try {
                com.gitblit.utils.FileUtils.copy(localGitignores, warGitignores.listFiles());
            } catch (IOException e) {
                logger.error(MessageFormat.format("Failed to copy included .gitignore files from {0} to {1}", warGitignores, localGitignores));
            }
        }
    }
    // merge the WebXmlSettings into the runtime settings (for backwards-compatibilty)
    runtimeSettings.merge(webxmlSettings);
    // settings are to be stored in openshift/gitblit.properties
    File localSettings = new File(base, "gitblit.properties");
    FileSettings fileSettings = new FileSettings(localSettings.getAbsolutePath());
    // merge the stored settings into the runtime settings
    //
    // if runtimeSettings is also a FileSettings w/o a specified target file,
    // the target file for runtimeSettings is set to "localSettings".
    runtimeSettings.merge(fileSettings);
    return base;
}
Also used : FileSettings(com.gitblit.FileSettings) IOException(java.io.IOException) File(java.io.File)

Aggregations

FileSettings (com.gitblit.FileSettings)6 File (java.io.File)3 MailService (com.gitblit.service.MailService)2 Test (org.junit.Test)2 ConfigUserService (com.gitblit.ConfigUserService)1 IStoredSettings (com.gitblit.IStoredSettings)1 IUserService (com.gitblit.IUserService)1 IAuthenticationManager (com.gitblit.manager.IAuthenticationManager)1 IFederationManager (com.gitblit.manager.IFederationManager)1 IFilestoreManager (com.gitblit.manager.IFilestoreManager)1 IGitblit (com.gitblit.manager.IGitblit)1 INotificationManager (com.gitblit.manager.INotificationManager)1 IPluginManager (com.gitblit.manager.IPluginManager)1 IProjectManager (com.gitblit.manager.IProjectManager)1 IRepositoryManager (com.gitblit.manager.IRepositoryManager)1 IRuntimeManager (com.gitblit.manager.IRuntimeManager)1 IServicesManager (com.gitblit.manager.IServicesManager)1 IUserManager (com.gitblit.manager.IUserManager)1 Mailing (com.gitblit.models.Mailing)1 ITicketService (com.gitblit.tickets.ITicketService)1