Mercurial > hg4j
comparison src/org/tmatesoft/hg/core/HgRepoFacade.java @ 295:981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Fri, 16 Sep 2011 05:35:32 +0200 | 
| parents | cd3371670f0b | 
| children | 9c9c442b5f2e | 
   comparison
  equal
  deleted
  inserted
  replaced
| 294:32890bab7209 | 295:981f9f50bb6c | 
|---|---|
| 16 */ | 16 */ | 
| 17 package org.tmatesoft.hg.core; | 17 package org.tmatesoft.hg.core; | 
| 18 | 18 | 
| 19 import java.io.File; | 19 import java.io.File; | 
| 20 | 20 | 
| 21 import org.tmatesoft.hg.internal.BasicSessionContext; | |
| 21 import org.tmatesoft.hg.repo.HgRepository; | 22 import org.tmatesoft.hg.repo.HgRepository; | 
| 22 import org.tmatesoft.hg.repo.HgLookup; | 23 import org.tmatesoft.hg.repo.HgLookup; | 
| 23 | 24 | 
| 24 /** | 25 /** | 
| 25 * Starting point for the library. | 26 * Starting point for the library. | 
| 35 * @author Artem Tikhomirov | 36 * @author Artem Tikhomirov | 
| 36 * @author TMate Software Ltd. | 37 * @author TMate Software Ltd. | 
| 37 */ | 38 */ | 
| 38 public class HgRepoFacade { | 39 public class HgRepoFacade { | 
| 39 private HgRepository repo; | 40 private HgRepository repo; | 
| 41 private final SessionContext context; | |
| 40 | 42 | 
| 41 public HgRepoFacade() { | 43 public HgRepoFacade() { | 
| 44 this(new BasicSessionContext(null, null)); | |
| 45 } | |
| 46 | |
| 47 public HgRepoFacade(SessionContext ctx) { | |
| 48 if (ctx == null) { | |
| 49 throw new IllegalArgumentException(); | |
| 50 } | |
| 51 context = ctx; | |
| 42 } | 52 } | 
| 43 | 53 | 
| 44 /** | 54 /** | 
| 45 * @param hgRepo | 55 * @param hgRepo | 
| 46 * @return true on successful initialization | 56 * @return true on successful initialization | 
| 55 } | 65 } | 
| 56 | 66 | 
| 57 /** | 67 /** | 
| 58 * Tries to find repository starting from the current working directory. | 68 * Tries to find repository starting from the current working directory. | 
| 59 * @return <code>true</code> if found valid repository | 69 * @return <code>true</code> if found valid repository | 
| 60 * @throws HgException in case of errors during repository initialization | 70 * @throws HgInvalidFileException in case of errors during repository initialization | 
| 61 */ | 71 */ | 
| 62 public boolean init() throws HgException { | 72 public boolean init() throws HgInvalidFileException { | 
| 63 repo = new HgLookup().detectFromWorkingDir(); | 73 repo = new HgLookup(context).detectFromWorkingDir(); | 
| 64 return repo != null && !repo.isInvalid(); | 74 return repo != null && !repo.isInvalid(); | 
| 65 } | 75 } | 
| 66 | 76 | 
| 67 /** | 77 /** | 
| 68 * Looks up Mercurial repository starting from specified location and up to filesystem root. | 78 * Looks up Mercurial repository starting from specified location and up to filesystem root. | 
| 69 * | 79 * | 
| 70 * @param repoLocation path to any folder within structure of a Mercurial repository. | 80 * @param repoLocation path to any folder within structure of a Mercurial repository. | 
| 71 * @return <code>true</code> if found valid repository | 81 * @return <code>true</code> if found valid repository | 
| 72 * @throws HgException if there are errors accessing specified location | 82 * @throws HgInvalidFileException if there are errors accessing specified location | 
| 73 * @throws IllegalArgumentException if argument is <code>null</code> | 83 * @throws IllegalArgumentException if argument is <code>null</code> | 
| 74 */ | 84 */ | 
| 75 public boolean initFrom(File repoLocation) throws HgException { | 85 public boolean initFrom(File repoLocation) throws HgInvalidFileException { | 
| 76 if (repoLocation == null) { | 86 if (repoLocation == null) { | 
| 77 throw new IllegalArgumentException(); | 87 throw new IllegalArgumentException(); | 
| 78 } | 88 } | 
| 79 repo = new HgLookup().detect(repoLocation); | 89 repo = new HgLookup(context).detect(repoLocation); | 
| 80 return repo != null && !repo.isInvalid(); | 90 return repo != null && !repo.isInvalid(); | 
| 81 } | 91 } | 
| 82 | 92 | 
| 83 public HgRepository getRepository() { | 93 public HgRepository getRepository() { | 
| 84 if (repo == null) { | 94 if (repo == null) { | 
