annotate test/org/tmatesoft/hg/test/Configuration.java @ 147:a05145db4d0c

Bring test repos along with us to recreate testbench
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 22 Feb 2011 15:49:26 +0100
parents
children a736f42ed75b
rev   line source
147
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.junit.Assert.*;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.File;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.tmatesoft.hg.repo.HgLookup;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.repo.HgRepository;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 /**
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 *
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 * @author Artem Tikhomirov
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 * @author TMate Software Ltd.
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 */
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 public class Configuration {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 private static Configuration inst;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 private final File root;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 private final HgLookup lookup;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 private Configuration(File reposRoot) {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 root = reposRoot;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 lookup = new HgLookup();
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 public static Configuration get() {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 if (inst == null) {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 String repo2 = System.getProperty("hg4j.tests.repos");
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 assertNotNull(repo2);
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 File rr = new File(repo2);
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 assertTrue(rr.exists());
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 inst = new Configuration(rr);
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 return inst;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 public HgRepository own() throws Exception {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 return lookup.detectFromWorkingDir();
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 // fails if repo not found
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 public HgRepository find(String key) throws Exception {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 HgRepository rv = lookup.detect(new File(root, key));
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 assertNotNull(rv);
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 assertFalse(rv.isInvalid());
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 return rv;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }