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);
}
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);
}
}
}
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;
}
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;
}
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));
}
Aggregations