Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/RepoUtils.java @ 637:4a0bab2c6da1
HgInitCommand: expose repo init functionality
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 07 Jun 2013 12:32:15 +0200 |
parents | 4ec2d44e2bf3 |
children | 629a7370554c |
comparison
equal
deleted
inserted
replaced
636:ffce73efa2c2 | 637:4a0bab2c6da1 |
---|---|
16 */ | 16 */ |
17 package org.tmatesoft.hg.test; | 17 package org.tmatesoft.hg.test; |
18 | 18 |
19 import static org.junit.Assert.assertEquals; | 19 import static org.junit.Assert.assertEquals; |
20 import static org.junit.Assert.assertTrue; | 20 import static org.junit.Assert.assertTrue; |
21 import static org.tmatesoft.hg.internal.RequiresFile.*; | |
22 import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; | 21 import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; |
23 | 22 |
24 import java.io.File; | 23 import java.io.File; |
25 import java.io.FileOutputStream; | 24 import java.io.FileOutputStream; |
26 import java.io.FileWriter; | 25 import java.io.FileWriter; |
27 import java.io.IOException; | 26 import java.io.IOException; |
28 import java.util.ArrayList; | 27 import java.util.ArrayList; |
29 import java.util.Arrays; | 28 import java.util.Arrays; |
30 import java.util.Iterator; | 29 import java.util.Iterator; |
31 import java.util.LinkedList; | 30 import java.util.LinkedList; |
31 import java.util.List; | |
32 | 32 |
33 import junit.framework.Assert; | 33 import junit.framework.Assert; |
34 | 34 |
35 import org.tmatesoft.hg.core.HgException; | 35 import org.tmatesoft.hg.core.HgException; |
36 import org.tmatesoft.hg.core.HgIOException; | 36 import org.tmatesoft.hg.core.HgInitCommand; |
37 import org.tmatesoft.hg.internal.FileUtils; | 37 import org.tmatesoft.hg.internal.FileUtils; |
38 import org.tmatesoft.hg.internal.RepoInitializer; | |
39 import org.tmatesoft.hg.internal.StreamLogFacility; | 38 import org.tmatesoft.hg.internal.StreamLogFacility; |
40 import org.tmatesoft.hg.repo.HgRepository; | 39 import org.tmatesoft.hg.repo.HgRepository; |
40 import org.tmatesoft.hg.util.CancelledException; | |
41 | 41 |
42 /** | 42 /** |
43 * | 43 * |
44 * @author Artem Tikhomirov | 44 * @author Artem Tikhomirov |
45 * @author TMate Software Ltd. | 45 * @author TMate Software Ltd. |
46 */ | 46 */ |
47 public class RepoUtils { | 47 public class RepoUtils { |
48 | 48 |
49 static File initEmptyTempRepo(String dirName) throws IOException, HgIOException { | 49 static File initEmptyTempRepo(String dirName) throws IOException, HgException { |
50 File dest = createEmptyDir(dirName); | 50 File dest = createEmptyDir(dirName); |
51 RepoInitializer ri = new RepoInitializer(); | 51 try { |
52 ri.setRequires(STORE | FNCACHE | DOTENCODE); | 52 new HgInitCommand().location(dest).revlogV1().execute(); |
53 ri.initEmptyRepository(new File(dest, ".hg")); | 53 } catch (CancelledException ex) { |
54 Assert.fail(ex.toString()); | |
55 } | |
54 return dest; | 56 return dest; |
55 } | 57 } |
56 | 58 |
57 static File createEmptyDir(String dirName) throws IOException { | 59 static File createEmptyDir(String dirName) throws IOException { |
58 File dest = new File(Configuration.get().getTempDir(), dirName); | 60 File dest = new File(Configuration.get().getTempDir(), dirName); |
59 if (dest.exists()) { | 61 if (dest.exists()) { |
60 TestClone.rmdir(dest); | 62 rmdir(dest); |
61 } | 63 } |
62 dest.mkdirs(); | 64 dest.mkdirs(); |
63 return dest; | 65 return dest; |
64 } | 66 } |
65 | 67 |
168 } catch (Exception ex) { | 170 } catch (Exception ex) { |
169 System.err.println(s.result()); | 171 System.err.println(s.result()); |
170 throw ex; | 172 throw ex; |
171 } | 173 } |
172 } | 174 } |
175 | |
176 static void rmdir(File dest) throws IOException { | |
177 LinkedList<File> queue = new LinkedList<File>(); | |
178 queue.addAll(Arrays.asList(dest.listFiles())); | |
179 while (!queue.isEmpty()) { | |
180 File next = queue.removeFirst(); | |
181 if (next.isDirectory()) { | |
182 List<File> files = Arrays.asList(next.listFiles()); | |
183 if (!files.isEmpty()) { | |
184 queue.addAll(files); | |
185 queue.add(next); | |
186 } | |
187 // fall through | |
188 } | |
189 next.delete(); | |
190 } | |
191 dest.delete(); | |
192 } | |
173 } | 193 } |