Example usage for org.eclipse.jgit.storage.file FileBasedConfig getBoolean

List of usage examples for org.eclipse.jgit.storage.file FileBasedConfig getBoolean

Introduction

In this page you can find the example usage for org.eclipse.jgit.storage.file FileBasedConfig getBoolean.

Prototype

public boolean getBoolean(final String section, String subsection, final String name,
        final boolean defaultValue) 

Source Link

Document

Get a boolean value from the git config

Usage

From source file:com.google.gitiles.GitilesFilter.java

License:Open Source License

private void setDefaultFields(FilterConfig config) throws ServletException {
    if (renderer != null && urls != null && accessFactory != null && resolver != null
            && visibilityCache != null) {
        return;//from  www.  ja  v a2  s  .  com
    }
    String configPath = config.getInitParameter(CONFIG_PATH_PARAM);
    if (configPath == null) {
        throw new ServletException("Missing required parameter " + configPath);
    }
    FileBasedConfig jgitConfig = new FileBasedConfig(new File(configPath), FS.DETECTED);
    try {
        jgitConfig.load();
    } catch (IOException e) {
        throw new ServletException(e);
    } catch (ConfigInvalidException e) {
        throw new ServletException(e);
    }

    if (renderer == null) {
        String staticPrefix = config.getServletContext().getContextPath() + STATIC_PREFIX;
        String customTemplates = jgitConfig.getString("gitiles", null, "customTemplates");
        // TODO(dborowitz): Automatically set to true when run with mvn jetty:run.
        if (jgitConfig.getBoolean("gitiles", null, "reloadTemplates", false)) {
            renderer = new DebugRenderer(staticPrefix, customTemplates,
                    Joiner.on(File.separatorChar).join(System.getProperty("user.dir"), "gitiles-servlet", "src",
                            "main", "resources", "com", "google", "gitiles", "templates"));
        } else {
            renderer = new DefaultRenderer(staticPrefix, Renderer.toFileURL(customTemplates));
        }
    }
    if (urls == null) {
        try {
            urls = new DefaultUrls(jgitConfig.getString("gitiles", null, "canonicalHostName"),
                    getBaseGitUrl(jgitConfig), getGerritUrl(jgitConfig));
        } catch (UnknownHostException e) {
            throw new ServletException(e);
        }
    }
    linkifier = new Linkifier(urls);
    if (accessFactory == null || resolver == null) {
        String basePath = jgitConfig.getString("gitiles", null, "basePath");
        if (basePath == null) {
            throw new ServletException("gitiles.basePath not set");
        }
        boolean exportAll = jgitConfig.getBoolean("gitiles", null, "exportAll", false);

        FileResolver<HttpServletRequest> fileResolver;
        if (resolver == null) {
            fileResolver = new FileResolver<HttpServletRequest>(new File(basePath), exportAll);
            resolver = wrapResolver(fileResolver);
        } else if (resolver instanceof FileResolver) {
            fileResolver = (FileResolver<HttpServletRequest>) resolver;
        } else {
            fileResolver = null;
        }
        if (accessFactory == null) {
            checkState(fileResolver != null, "need a FileResolver when GitilesAccess.Factory not set");
            try {
                accessFactory = new DefaultAccess.Factory(new File(basePath), getBaseGitUrl(jgitConfig),
                        fileResolver);
            } catch (IOException e) {
                throw new ServletException(e);
            }
        }
    }
    if (visibilityCache == null) {
        if (jgitConfig.getSubsections("cache").contains("visibility")) {
            visibilityCache = new VisibilityCache(false, ConfigUtil.getCacheBuilder(jgitConfig, "visibility"));
        } else {
            visibilityCache = new VisibilityCache(false);
        }
    }
}

From source file:org.libreoffice.ci.gerrit.buildbot.config.BuildbotConfigProvider.java

License:Mozilla Public License

@Override
public BuildbotConfig get() {
    File file = new File(site.etc_dir, "buildbot.config");
    FileBasedConfig cfg = new FileBasedConfig(file, FS.DETECTED);
    if (!cfg.getFile().exists()) {
        throw new IllegalStateException(String.format("can not find config file: %s", file.getAbsolutePath()));
    }/*from   w  ww.j a  v  a 2  s .c o  m*/

    if (cfg.getFile().length() == 0) {
        throw new IllegalStateException(String.format("empty config file: %s", file.getAbsolutePath()));
    }

    try {
        cfg.load();
    } catch (ConfigInvalidException e) {
        throw new IllegalStateException(
                String.format("config file %s is invalid: %s", cfg.getFile(), e.getMessage()), e);
    } catch (IOException e) {
        throw new IllegalStateException(String.format("cannot read %s: %s", cfg.getFile(), e.getMessage()), e);
    }

    BuildbotConfig config = new BuildbotConfig();
    config.setEmail(cfg.getString(SECTION_USER, null, KEY_MAIL));
    config.setForgeReviewerIdentity(cfg.getBoolean(SECTION_USER, null, KEY_FORGE_REVIEWER_IDENTITY, true));
    String buildbotAdminGroupName = cfg.getString(SECTION_USER, null, KEY_BUILDBOT_ADMIN_GROUP_NAME);
    Preconditions.checkNotNull(buildbotAdminGroupName,
            String.format("%s must not be null", KEY_BUILDBOT_ADMIN_GROUP_NAME));
    config.setBuildbotAdminGroupId(getGroup(buildbotAdminGroupName));

    String buildbotUserGroupName = cfg.getString(SECTION_USER, null, KEY_BUILDBOT_USER_GROUP_NAME);
    Preconditions.checkNotNull(buildbotUserGroupName,
            String.format("%s must not be null", KEY_BUILDBOT_USER_GROUP_NAME));
    config.setBuildbotUserGroupId(getGroup(buildbotUserGroupName));

    String publisherModeStr = cfg.getString(SECTION_LOG, null, KEY_MODE);
    Preconditions.checkNotNull(publisherModeStr, "log.mode must not be null");
    LogPublisherMode publisherMode = LogPublisherMode.valueOf(publisherModeStr.toUpperCase());
    Preconditions.checkNotNull(publisherMode, " log.mode has wrong value");
    config.setLogDir(cfg.getString(SECTION_LOG, null, KEY_DIRECTORY));
    if (publisherMode == LogPublisherMode.INTERN) {
        config.setlogPublisher(buildbotLogPublisher);
    } else {
        config.setExternalLogViewer(true);
        config.setExternalLogViewerHost(cfg.getString(SECTION_LOG, null, KEY_HOST));
        config.setExternalLogViewerUrl(cfg.getString(SECTION_LOG, null, KEY_URL));
        config.setExternalLogViewerJob(cfg.getString(SECTION_LOG, null, KEY_JOB));
        config.setlogPublisher(jenkinsLogPublisher);
    }

    ImmutableList.Builder<BuildbotProject> dest = ImmutableList.builder();

    for (BuildbotProject p : allProjects(config, cfg)) {
        dest.add(p);
    }
    config.setProjects(dest.build());
    return config;
}