Mercurial > jhg
annotate src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java @ 485:cdd53e5884ae
Do not add anything to exception message in case no details are known
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 09 Aug 2012 15:45:18 +0200 |
parents | e31e85cf4d4c |
children | b3c16d1aede0 |
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 |
483
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
46 private final SessionContext sessionCtx; |
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
47 |
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
48 private HgUpdateConfigCommand(SessionContext sessionContext, File configurationFile) { |
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
49 sessionCtx = sessionContext; |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 configFile = configurationFile; |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 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
|
54 // XXX HgRepository to implement SessionContextProvider (with getContext())? |
483
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
55 return new HgUpdateConfigCommand(HgInternals.getContext(hgRepo), new File(HgInternals.getRepositoryDir(hgRepo), "hgrc")); |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 |
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
|
58 public static HgUpdateConfigCommand forUser(SessionContext ctx) { |
483
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
59 return new HgUpdateConfigCommand(ctx, Internals.getUserConfigurationFileToWrite(ctx)); |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 |
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
|
62 public static HgUpdateConfigCommand forInstallation(SessionContext ctx) { |
483
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
63 return new HgUpdateConfigCommand(ctx, Internals.getInstallationConfigurationFileToWrite(ctx)); |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 |
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 * Remove a property altogether |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 * @return <code>this</code> for convenience |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 */ |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 public HgUpdateConfigCommand remove(String section, String key) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 if (toRemove == null) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 toRemove = new LinkedHashMap<String, List<String>>(); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 List<String> s = toRemove.get(section); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 if (s == null) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 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
|
77 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 s.add(key); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 if (toSet != null && toSet.containsKey(section)) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 toSet.get(section).remove(key); |
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 return this; |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 |
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 * 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
|
87 * @return <code>this</code> for convenience |
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 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
|
90 throw new UnsupportedOperationException(); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 |
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 * 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
|
95 * @return <code>this</code> for convenience |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 */ |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 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
|
98 if (toSet == null) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 toSet = new LinkedHashMap<String, Map<String,String>>(); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 Map<String,String> s = toSet.get(section); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 if (s == null) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 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
|
104 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 s.put(key, value); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 return this; |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 |
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 * Multi-valued properties |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 * @return <code>this</code> for convenience |
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 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
|
114 throw new UnsupportedOperationException(); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 |
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
|
117 /** |
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 * 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
|
119 * |
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
|
120 * @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
|
121 */ |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 public void execute() throws HgException { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 try { |
483
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
124 ConfigFile cfg = new ConfigFile(sessionCtx); |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 cfg.addLocation(configFile); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 if (toRemove != null) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 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
|
128 for (String e : s.getValue()) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 cfg.putString(s.getKey(), e, null); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 if (toSet != null) { |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 cfg.writeTo(configFile); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 } 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
|
142 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
|
143 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
|
144 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 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
|
149 HgUpdateConfigCommand cmd = HgUpdateConfigCommand.forUser(null); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 cmd.remove("test1", "sample1"); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 cmd.put("test2", "sample2", "value2"); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 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
|
153 cmd.execute(); |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 } |