Search in sources :

Example 1 with Ini

use of org.ini4j.Ini in project intellij-community by JetBrains.

the class GitConfig method read.

/**
   * Creates an instance of GitConfig by reading information from the specified {@code .git/config} file.
   * <p/>
   * If some section is invalid, it is skipped, and a warning is reported.
   */
@NotNull
static GitConfig read(@NotNull File configFile) {
    GitConfig emptyConfig = new GitConfig(Collections.<Remote>emptyList(), Collections.<Url>emptyList(), Collections.<BranchConfig>emptyList());
    if (!configFile.exists()) {
        LOG.info("No .git/config file at " + configFile.getPath());
        return emptyConfig;
    }
    Ini ini = new Ini();
    // duplicate keys (e.g. url in [remote])
    ini.getConfig().setMultiOption(true);
    // don't need tree structure: it corrupts url in section name (e.g. [url "http://github.com/"]
    ini.getConfig().setTree(false);
    try {
        ini.load(configFile);
    } catch (IOException e) {
        LOG.warn("Couldn't load .git/config file at " + configFile.getPath(), e);
        return emptyConfig;
    }
    IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginManagerCore.getPluginByClassName(GitConfig.class.getName()));
    ClassLoader classLoader = plugin == null ? // null e.g. if IDEA is started from IDEA
    GitConfig.class.getClassLoader() : plugin.getPluginClassLoader();
    Pair<Collection<Remote>, Collection<Url>> remotesAndUrls = parseRemotes(ini, classLoader);
    Collection<BranchConfig> trackedInfos = parseTrackedInfos(ini, classLoader);
    return new GitConfig(remotesAndUrls.getFirst(), remotesAndUrls.getSecond(), trackedInfos);
}
Also used : Ini(org.ini4j.Ini) IOException(java.io.IOException) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Ini

use of org.ini4j.Ini in project asterixdb by apache.

the class ConfigManager method parseIni.

private void parseIni() throws IOException {
    Ini ini = null;
    for (IOption option : iniPointerOptions) {
        Object pointer = get(option);
        if (pointer instanceof String) {
            ini = ConfigUtils.loadINIFile((String) pointer);
        } else if (pointer instanceof URL) {
            ini = ConfigUtils.loadINIFile((URL) pointer);
        } else if (pointer != null) {
            throw new IllegalArgumentException("config file pointer options must be of type String (for file) or " + "URL, instead of " + option.type().targetType());
        }
    }
    if (ini == null) {
        LOGGER.info("no INI file specified; skipping parsing");
        return;
    }
    LOGGER.info("parsing INI file: " + ini);
    for (Profile.Section section : ini.values()) {
        allSections.add(section.getName());
        final Section rootSection = Section.parseSectionName(section.getParent() == null ? section.getName() : section.getParent().getName());
        String node;
        if (rootSection == Section.EXTENSION) {
            parseExtensionIniSection(section);
            continue;
        } else if (rootSection == Section.NC) {
            node = section.getName().equals(section.getSimpleName()) ? null : section.getSimpleName();
        } else if (Section.parseSectionName(section.getName()) != null) {
            node = null;
        } else {
            throw new HyracksException("Unknown section in ini: " + section.getName());
        }
        Map<String, IOption> optionMap = getSectionOptionMap(rootSection);
        for (Map.Entry<String, String> iniOption : section.entrySet()) {
            String name = iniOption.getKey();
            final IOption option = optionMap == null ? null : optionMap.get(name);
            if (option == null) {
                handleUnknownOption(section, name);
                return;
            }
            final String value = iniOption.getValue();
            LOGGER.fine("setting " + option.toIniString() + " to " + value);
            final Object parsed = option.type().parse(value);
            invokeSetters(option, parsed, node);
        }
    }
}
Also used : Ini(org.ini4j.Ini) IOption(org.apache.hyracks.api.config.IOption) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) Section(org.apache.hyracks.api.config.Section) URL(java.net.URL) Profile(org.ini4j.Profile) HashMap(java.util.HashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Map(java.util.Map) EnumMap(java.util.EnumMap) TreeMap(java.util.TreeMap) CompositeMap(org.apache.commons.collections4.map.CompositeMap) SortedMap(java.util.SortedMap)

Example 3 with Ini

use of org.ini4j.Ini in project asterixdb by apache.

the class ConfigUtils method loadINIFile.

public static Ini loadINIFile(String configFile) throws IOException {
    Ini ini = new Ini();
    File conffile = new File(configFile);
    if (!conffile.exists()) {
        throw new FileNotFoundException(configFile);
    }
    ini.load(conffile);
    return ini;
}
Also used : Ini(org.ini4j.Ini) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 4 with Ini

use of org.ini4j.Ini in project asterixdb by apache.

the class ConfigUtils method loadINIFile.

public static Ini loadINIFile(URL configURL) throws IOException {
    Ini ini = new Ini();
    ini.load(configURL);
    return ini;
}
Also used : Ini(org.ini4j.Ini)

Example 5 with Ini

use of org.ini4j.Ini in project buck by facebook.

the class TestDataHelper method overrideBuckconfig.

public static void overrideBuckconfig(ProjectWorkspace projectWorkspace, Map<String, ? extends Map<String, String>> buckconfigOverrides) throws IOException {
    String config = projectWorkspace.getFileContents(".buckconfig");
    Ini ini = new Ini(new StringReader(config));
    for (Map.Entry<String, ? extends Map<String, String>> section : buckconfigOverrides.entrySet()) {
        for (Map.Entry<String, String> entry : section.getValue().entrySet()) {
            ini.put(section.getKey(), entry.getKey(), entry.getValue());
        }
    }
    StringWriter writer = new StringWriter();
    ini.store(writer);
    Files.write(projectWorkspace.getPath(".buckconfig"), writer.toString().getBytes(UTF_8));
}
Also used : StringWriter(java.io.StringWriter) Ini(org.ini4j.Ini) StringReader(java.io.StringReader) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

Ini (org.ini4j.Ini)24 File (java.io.File)9 IOException (java.io.IOException)6 StringReader (java.io.StringReader)3 URL (java.net.URL)3 Map (java.util.Map)3 Profile (org.ini4j.Profile)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 EnumMap (java.util.EnumMap)2 HashMap (java.util.HashMap)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 CompositeMap (org.apache.commons.collections4.map.CompositeMap)2 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)2 IOption (org.apache.hyracks.api.config.IOption)2 Config (org.ini4j.Config)2 Hypervisor (com.cloud.hypervisor.Hypervisor)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1