Examples of ConfigFile


Examples of org.tmatesoft.hg.internal.ConfigFile

  @Rule
  public ErrorCollectorExt errorCollector = new ErrorCollectorExt();

  @Test
  public void testConfigFile() throws Exception {
    ConfigFile configFile = new ConfigFile(new BasicSessionContext(null));
    configFile.addLocation(new File(Configuration.get().getTestDataDir(), "sample.rc"));
    // section1 has key1 unset, key2 overridden from included, key4 from second occurence
    HashMap<String, String> section1 = new HashMap<String, String>();
    section1.put("key2", "alternative value 2");
    section1.put("key3", "value 3");
    section1.put("key4", "value 4");
    // section2 comes from included config
    HashMap<String, String> section2 = new HashMap<String, String>();
    section2.put("key1", "value 1-2");
    HashMap<String, String> section3 = new HashMap<String, String>();
    section3.put("key1", "value 1-3");
    HashMap<String, HashMap<String,String>> sections = new HashMap<String, HashMap<String,String>>();
    sections.put("section1", section1);
    sections.put("section2", section2);
    sections.put("section3", section3);
    //
    for (String s : configFile.getSectionNames()) {
//      System.out.printf("[%s]\n", s);
      final HashMap<String, String> m = sections.remove(s);
      errorCollector.assertTrue(m != null);
      for (Map.Entry<String, String> e : configFile.getSection(s).entrySet()) {
//        System.out.printf("%s = %s\n", e.getKey(), e.getValue());
        if (m.containsKey(e.getKey())) {
          errorCollector.assertEquals(m.remove(e.getKey()), e.getValue());
        } else {
          errorCollector.fail("Unexpected key:" + e.getKey());
View Full Code Here

Examples of org.tmatesoft.hg.internal.ConfigFile

   * @throws HgIOException when configuration file read/write attemt has failed
   * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
   */
  public void execute() throws HgMissingConfigElementException, HgIOException, HgException {
    try {
      ConfigFile cfgRead = new ConfigFile(sessionCtx);
      cfgRead.addLocation(configFile);
      ConfigFileParser cfgWrite = new ConfigFileParser();
      FileInputStream fis = new FileInputStream(configFile);
      cfgWrite.parse(fis);
      fis.close();
      for (Operation op : changes) {
        if (!ignoreMissingKeys && !cfgRead.hasSection(op.section)) {
          throw new HgMissingConfigElementException("Bad section name", op.section, op.key);
        }
        Map<String, String> sect = cfgRead.getSection(op.section);
        if (!ignoreMissingKeys && !sect.containsKey(op.key)) {
          throw new HgMissingConfigElementException("Bad key name", op.section, op.key);
        }
        String oldValue = sect.get(op.key);
        if (oldValue == null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.