annotate src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java @ 453:7b883bf03b14

Artifacts upload using gradle build
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 13 Jun 2012 18:18:37 +0200
parents 31a89587eb04
children e31e85cf4d4c
rev   line source
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012 TMate Software Ltd
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.File;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.IOException;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.util.ArrayList;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.LinkedHashMap;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.List;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.util.Map;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.internal.ConfigFile;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.internal.Experimental;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.internal.Internals;
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
29 import org.tmatesoft.hg.repo.HgInternals;
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.repo.HgRepository;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 * WORK IN PROGRESS, DO NOT USE
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 *
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author Artem Tikhomirov
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author TMate Software Ltd.
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 @Experimental(reason="Investigating approaches to alter Hg configuration files")
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 public final class HgUpdateConfigCommand extends HgAbstractCommand<HgUpdateConfigCommand> {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 private final File configFile;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 private Map<String,List<String>> toRemove;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 private Map<String,Map<String,String>> toSet;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
46 private HgUpdateConfigCommand(File configurationFile) {
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 configFile = configurationFile;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public static HgUpdateConfigCommand forRepository(HgRepository hgRepo) {
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
51 // XXX HgRepository to implement SessionContextProvider (with getContext())?
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
52 return new HgUpdateConfigCommand(new File(HgInternals.getRepositoryDir(hgRepo), "hgrc"));
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
55 public static HgUpdateConfigCommand forUser(SessionContext ctx) {
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
56 return new HgUpdateConfigCommand(Internals.getUserConfigurationFileToWrite(ctx));
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
59 public static HgUpdateConfigCommand forInstallation(SessionContext ctx) {
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
60 return new HgUpdateConfigCommand(Internals.getInstallationConfigurationFileToWrite(ctx));
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 * Remove a property altogether
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 * @return <code>this</code> for convenience
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 public HgUpdateConfigCommand remove(String section, String key) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 if (toRemove == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 toRemove = new LinkedHashMap<String, List<String>>();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 List<String> s = toRemove.get(section);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 if (s == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 toRemove.put(section, s = new ArrayList<String>(5));
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 s.add(key);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 if (toSet != null && toSet.containsKey(section)) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 toSet.get(section).remove(key);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 return this;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 * Delete single attribute in a multi-valued property
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 * @return <code>this</code> for convenience
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 public HgUpdateConfigCommand remove(String section, String key, String value) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 throw new UnsupportedOperationException();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 * Set single-valued properties or update multi-valued with a single value
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 * @return <code>this</code> for convenience
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 public HgUpdateConfigCommand put(String section, String key, String value) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 if (toSet == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 toSet = new LinkedHashMap<String, Map<String,String>>();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 Map<String,String> s = toSet.get(section);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 if (s == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 toSet.put(section, s = new LinkedHashMap<String, String>());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 s.put(key, value);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 return this;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 * Multi-valued properties
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 * @return <code>this</code> for convenience
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 public HgUpdateConfigCommand add(String section, String key, String value) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 throw new UnsupportedOperationException();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
114 /**
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
115 * Perform config file update
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
116 *
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
117 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
118 */
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 public void execute() throws HgException {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 try {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 ConfigFile cfg = new ConfigFile();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 cfg.addLocation(configFile);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 if (toRemove != null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 for (Map.Entry<String,List<String>> s : toRemove.entrySet()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 for (String e : s.getValue()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 cfg.putString(s.getKey(), e, null);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 if (toSet != null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 for (Map.Entry<String,Map<String,String>> s : toSet.entrySet()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 for (Map.Entry<String, String> e : s.getValue().entrySet()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 cfg.putString(s.getKey(), e.getKey(), e.getValue());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 cfg.writeTo(configFile);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 } catch (IOException ex) {
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
139 String m = String.format("Failed to update configuration file %s", configFile);
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
140 throw new HgBadArgumentException(m, ex); // TODO [post-1.0] better exception, it's not bad argument case
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 public static void main(String[] args) throws Exception {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 HgUpdateConfigCommand cmd = HgUpdateConfigCommand.forUser(null);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 cmd.remove("test1", "sample1");
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 cmd.put("test2", "sample2", "value2");
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 cmd.put("ui", "user-name", "Another User <email@domain.com>");
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 cmd.execute();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 }