Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/Internals.java @ 456:909306e412e2
Refactor LogFacility and SessionContext, better API for both
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Mon, 18 Jun 2012 16:54:00 +0200 |
| parents | 48f993aa2f41 |
| children | e31e85cf4d4c |
comparison
equal
deleted
inserted
replaced
| 454:36fd1fd06492 | 456:909306e412e2 |
|---|---|
| 15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
| 18 | 18 |
| 19 import static org.tmatesoft.hg.internal.RequiresFile.*; | 19 import static org.tmatesoft.hg.internal.RequiresFile.*; |
| 20 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; | |
| 20 | 21 |
| 21 import java.io.File; | 22 import java.io.File; |
| 22 import java.io.FileOutputStream; | 23 import java.io.FileOutputStream; |
| 23 import java.io.IOException; | 24 import java.io.IOException; |
| 24 import java.nio.charset.Charset; | 25 import java.nio.charset.Charset; |
| 81 private final boolean shallCacheRevlogsInRepo; | 82 private final boolean shallCacheRevlogsInRepo; |
| 82 | 83 |
| 83 public Internals(SessionContext ctx) { | 84 public Internals(SessionContext ctx) { |
| 84 sessionContext = ctx; | 85 sessionContext = ctx; |
| 85 isCaseSensitiveFileSystem = !runningOnWindows(); | 86 isCaseSensitiveFileSystem = !runningOnWindows(); |
| 86 Object p = ctx.getProperty(CFG_PROPERTY_REVLOG_STREAM_CACHE, true); | 87 shallCacheRevlogsInRepo = new PropertyMarshal(ctx).getBoolean(CFG_PROPERTY_REVLOG_STREAM_CACHE, true); |
| 87 shallCacheRevlogsInRepo = p instanceof Boolean ? ((Boolean) p).booleanValue() : Boolean.parseBoolean(String.valueOf(p)); | |
| 88 } | 88 } |
| 89 | 89 |
| 90 public void parseRequires(HgRepository hgRepo, File requiresFile) throws HgInvalidControlFileException { | 90 public void parseRequires(HgRepository hgRepo, File requiresFile) throws HgInvalidControlFileException { |
| 91 try { | 91 try { |
| 92 new RequiresFile().parse(this, requiresFile); | 92 new RequiresFile().parse(this, requiresFile); |
| 171 public EncodingHelper buildFileNameEncodingHelper() { | 171 public EncodingHelper buildFileNameEncodingHelper() { |
| 172 return new EncodingHelper(getFileEncoding(), sessionContext); | 172 return new EncodingHelper(getFileEncoding(), sessionContext); |
| 173 } | 173 } |
| 174 | 174 |
| 175 private Charset getFileEncoding() { | 175 private Charset getFileEncoding() { |
| 176 Object altEncoding = sessionContext.getProperty(CFG_PROPERTY_FS_FILENAME_ENCODING, null); | 176 Object altEncoding = sessionContext.getConfigurationProperty(CFG_PROPERTY_FS_FILENAME_ENCODING, null); |
| 177 Charset cs; | 177 Charset cs; |
| 178 if (altEncoding == null) { | 178 if (altEncoding == null) { |
| 179 cs = Charset.defaultCharset(); | 179 cs = Charset.defaultCharset(); |
| 180 } else { | 180 } else { |
| 181 try { | 181 try { |
| 182 cs = Charset.forName(altEncoding.toString()); | 182 cs = Charset.forName(altEncoding.toString()); |
| 183 } catch (IllegalArgumentException ex) { | 183 } catch (IllegalArgumentException ex) { |
| 184 // both IllegalCharsetNameException and UnsupportedCharsetException are subclasses of IAE, too | 184 // both IllegalCharsetNameException and UnsupportedCharsetException are subclasses of IAE, too |
| 185 // not severe enough to throw an exception, imo. Just record the fact it's bad ad we ignore it | 185 // not severe enough to throw an exception, imo. Just record the fact it's bad ad we ignore it |
| 186 sessionContext.getLog().error(Internals.class, ex, String.format("Bad configuration value for filename encoding %s", altEncoding)); | 186 sessionContext.getLog().dump(Internals.class, Error, ex, String.format("Bad configuration value for filename encoding %s", altEncoding)); |
| 187 cs = Charset.defaultCharset(); | 187 cs = Charset.defaultCharset(); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 return cs; | 190 return cs; |
| 191 } | 191 } |
| 222 * For Windows, it's Mercurial installation directory itself | 222 * For Windows, it's Mercurial installation directory itself |
| 223 * @param ctx | 223 * @param ctx |
| 224 */ | 224 */ |
| 225 private static File findHgInstallRoot(SessionContext ctx) { | 225 private static File findHgInstallRoot(SessionContext ctx) { |
| 226 // let clients to override Hg install location | 226 // let clients to override Hg install location |
| 227 String p = (String) ctx.getProperty(CFG_PROPERTY_HG_INSTALL_ROOT, null); | 227 String p = (String) ctx.getConfigurationProperty(CFG_PROPERTY_HG_INSTALL_ROOT, null); |
| 228 if (p != null) { | 228 if (p != null) { |
| 229 return new File(p); | 229 return new File(p); |
| 230 } | 230 } |
| 231 StringTokenizer st = new StringTokenizer(System.getenv("PATH"), System.getProperty("path.separator"), false); | 231 StringTokenizer st = new StringTokenizer(System.getenv("PATH"), System.getProperty("path.separator"), false); |
| 232 final boolean runsOnWin = runningOnWindows(); | 232 final boolean runsOnWin = runningOnWindows(); |
