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

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

Introduction

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

Prototype

public Set<String> getSubsections(String section) 

Source Link

Document

Get set of all subsections of specified section within this configuration and its base configuration

Usage

From source file:com.google.gerrit.server.git.PushReplication.java

License:Apache License

private List<RemoteConfig> allRemotes(final FileBasedConfig cfg) throws ConfigInvalidException {
    List<String> names = new ArrayList<String>(cfg.getSubsections("remote"));
    Collections.sort(names);/*from   w w w. j av a2  s  . co  m*/

    final List<RemoteConfig> result = new ArrayList<RemoteConfig>(names.size());
    for (final String name : names) {
        try {
            result.add(new RemoteConfig(cfg, name));
        } catch (URISyntaxException e) {
            throw new ConfigInvalidException("remote " + name + " has invalid URL in " + cfg.getFile());
        }
    }
    return result;
}

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  ww  w. j  a va2s  . c o  m
    }
    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:com.googlesource.gerrit.plugins.github.replication.GitHubDestinations.java

License:Apache License

private static List<RemoteConfig> allRemotes(FileBasedConfig cfg) throws ConfigInvalidException {
    Set<String> names = cfg.getSubsections("remote");
    List<RemoteConfig> result = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
        try {/*from w ww .j  ava2  s . c  om*/
            if (name.equalsIgnoreCase(GITHUB_DESTINATION)) {
                result.add(new RemoteConfig(cfg, name));
            }
        } catch (URISyntaxException e) {
            throw new ConfigInvalidException(
                    String.format("remote %s has invalid URL in %s", name, cfg.getFile()));
        }
    }
    return result;
}

From source file:com.googlesource.gerrit.plugins.hooks.workflow.GerritHookFilterChangeState.java

License:Apache License

private List<Transition> loadTransitions() {
    File configFile = new File(sitePath, "etc/issue-state-transition.config");
    FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED);
    try {/*from ww  w. j a va2 s . co  m*/
        cfg.load();
    } catch (IOException e) {
        log.error("Cannot load transitions configuration file " + cfg, e);
        return Collections.emptyList();
    } catch (ConfigInvalidException e) {
        log.error("Invalid transitions configuration file" + cfg, e);
        return Collections.emptyList();
    }

    List<Transition> transitions = new ArrayList<Transition>();
    Set<String> sections = cfg.getSubsections("action");
    for (String section : sections) {
        List<Condition> conditions = new ArrayList<Condition>();
        Set<String> keys = cfg.getNames("action", section);
        for (String key : keys) {
            String val = cfg.getString("action", section, key);
            conditions.add(new Condition(key.trim(), val.trim().split(",")));
        }
        transitions.add(new Transition(toAction(section), conditions));
    }
    return transitions;
}

From source file:com.googlesource.gerrit.plugins.hooks.workflow.RuleBase.java

License:Apache License

/**
 * Loads the rules for the RuleBase./*from  w  ww.j  a  v a2  s.  com*/
 *
 * Consider using {@link #loadRules()@}, as that method only loads the rules,
 * if they have not yet been loaded.
 */
private void forceLoadRules() throws Exception {
    File configFile = new File(sitePath, ITS_CONFIG_FILE);
    if (configFile.exists()) {
        FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED);
        cfg.load();

        rules = Lists.newArrayList();
        Collection<String> subsections = cfg.getSubsections(RULE_SECTION);
        for (String subsection : subsections) {
            Rule rule = ruleFactory.create(subsection);
            Collection<String> keys = cfg.getNames(RULE_SECTION, subsection);
            for (String key : keys) {
                String values[] = cfg.getStringList(RULE_SECTION, subsection, key);
                if (ACTION_KEY.equals(key)) {
                    for (String value : values) {
                        ActionRequest actionRequest = actionRequestFactory.create(value);
                        rule.addActionRequest(actionRequest);
                    }
                } else {
                    for (String value : values) {
                        Condition condition = conditionFactory.create(key, value);
                        rule.addCondition(condition);
                    }
                }
            }
            rules.add(rule);
        }
    } else {
        // configFile does not exist.
        log.warn("ITS actions configuration file (" + configFile + ") does not exist.");
        rules = Collections.emptySet();
    }
}

From source file:com.googlesource.gerrit.plugins.motd.MotdFileBasedConfig.java

License:Apache License

private static List<SubnetConfig> allSubnets(FileBasedConfig cfg) {
    Set<String> names = cfg.getSubsections("subnet");
    List<SubnetConfig> result = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
        result.add(new SubnetConfig(cfg, name));
    }//w w w  . ja  v  a 2  s.  c  o m
    return result;
}

From source file:com.googlesource.gerrit.plugins.replication.ReplicationFileBasedConfig.java

License:Apache License

private static List<RemoteConfig> allRemotes(FileBasedConfig cfg) throws ConfigInvalidException {
    Set<String> names = cfg.getSubsections("remote");
    List<RemoteConfig> result = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
        try {/* ww  w .  j  a  v  a 2 s .c  o  m*/
            result.add(new RemoteConfig(cfg, name));
        } catch (URISyntaxException e) {
            throw new ConfigInvalidException(
                    String.format("remote %s has invalid URL in %s", name, cfg.getFile()));
        }
    }
    return result;
}

From source file:net.polydawn.mdm.Plumbing.java

License:Open Source License

/**
 * Copy in `url` git config keys from the parent repo config into the submodule config.
 * This allows for easily having per-project 'insteadof' url rewrites which apply even
 * when mdm is doing the creation of new repos (which is otherwise a tad hard to get at with git submodules).
 * @return true if module.getRepo().getConfig() has been modified and should be saved.
 * @throws ConfigInvalidException//from   w w w. j a  v a  2s  .c  o m
 * @throws IOException
 */
public static boolean initModuleConfig(Repository repo, MdmModule module)
        throws IOException, ConfigInvalidException {
    Config moduleConfig = module.getRepo().getConfig();
    // have to explicitly load the parent repo config in isolate, because `repo.getConfig` includes views of the system and user gitconfig, which we won't want to proxy here.
    FileBasedConfig parentConfig = new FileBasedConfig(new File(repo.getDirectory(), "config"), repo.getFS());
    try {
        parentConfig.load();
    } catch (IOException e) {
        throw new MdmRepositoryIOException(false, "the local git configuration file", e);
    }

    // copy any url_insteadof patterns from the parent repo's git config into the module's git config.
    // note that we do not strip out any additional insteadof's the module may have; if you've added those, it's none of our business (though at this point, we do overwrite).
    // see org.eclipse.jgit.transport.RemoteConfig for how these actually get used.
    for (String url : parentConfig.getSubsections(ConfigConstants.CONFIG_KEY_URL))
        for (String insteadOf : parentConfig.getStringList(ConfigConstants.CONFIG_KEY_URL, url, "insteadof"))
            moduleConfig.setString(ConfigConstants.CONFIG_KEY_URL, url, "insteadof", insteadOf);
    for (String url : parentConfig.getSubsections(ConfigConstants.CONFIG_KEY_URL))
        for (String insteadOf : parentConfig.getStringList(ConfigConstants.CONFIG_KEY_URL, url,
                "pushinsteadof"))
            moduleConfig.setString(ConfigConstants.CONFIG_KEY_URL, url, "pushinsteadof", insteadOf);
    return true;
}

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

License:Mozilla Public License

private List<BuildbotProject> allProjects(BuildbotConfig config, FileBasedConfig cfg) {
    Set<String> names = cfg.getSubsections(SECTION_PROJECT);
    List<BuildbotProject> result = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
        result.add(parseProject(config, cfg, name));
    }/*from   w ww . j a v a 2  s . c  o  m*/
    return result;
}

From source file:org.ms123.common.store.StoreServiceImpl.java

License:Open Source License

protected static Map _getStoreDescriptions(String namespace) throws Exception {
    String gitSpace = System.getProperty("git.repos");
    File dir = new File(gitSpace);
    String storeFileName = "store.cfg";
    File storeCfgFile = new File(gitSpace + "/" + namespace, storeFileName);
    if (!storeCfgFile.exists()) {
        throw new RuntimeException("StoreServiceImpl.storeCfg not exists:" + storeCfgFile);
    }//from  www  .ja  va  2 s.  c o  m
    FS fs = FS.detect();
    FileBasedConfig fbc = new FileBasedConfig(storeCfgFile, fs);
    fbc.load();
    Set<String> subList = fbc.getSubsections("store");
    Map storeMap = new HashMap();
    for (String storeId : subList) {
        String pack = fbc.getString("store", storeId, "pack");
        String ns = fbc.getString("store", storeId, "namespace");
        String db = fbc.getString("store", storeId, "database");
        String dbn = fbc.getString("store", storeId, "databasename");
        String dbh = fbc.getString("store", storeId, "databasehost");
        String repo = fbc.getString("store", storeId, "repository");
        if (repo == null) {
            repo = ns;
        }
        Map m = new HashMap();
        m.put(StoreDesc.PACK, pack);
        m.put(StoreDesc.STORE, db);
        m.put(StoreDesc.NAMESPACE, ns);
        m.put(StoreDesc.REPOSITORY, repo);
        m.put(StoreDesc.DATABASENAME, dbn);
        m.put(StoreDesc.DATABASEHOST, dbh);
        m.put(StoreDesc.STORE_ID, namespace + "_" + storeId);
        storeMap.put(namespace + "_" + storeId, m);
    }
    debug("storeMap:" + storeMap);
    return storeMap;
}