Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/RepoUtils.java @ 623:fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 20 May 2013 18:35:13 +0200 |
parents | 4e6179bde4fc |
children | 8a5cdcb27b8f |
comparison
equal
deleted
inserted
replaced
622:4e6179bde4fc | 623:fedc54356091 |
---|---|
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.*; | 21 import static org.tmatesoft.hg.internal.RequiresFile.*; |
22 import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; | |
22 | 23 |
23 import java.io.File; | 24 import java.io.File; |
24 import java.io.FileOutputStream; | 25 import java.io.FileOutputStream; |
25 import java.io.FileWriter; | 26 import java.io.FileWriter; |
26 import java.io.IOException; | 27 import java.io.IOException; |
27 import java.util.ArrayList; | 28 import java.util.ArrayList; |
29 import java.util.Arrays; | |
30 import java.util.Iterator; | |
31 import java.util.LinkedList; | |
28 | 32 |
33 import org.tmatesoft.hg.core.HgException; | |
29 import org.tmatesoft.hg.core.HgIOException; | 34 import org.tmatesoft.hg.core.HgIOException; |
35 import org.tmatesoft.hg.internal.FileUtils; | |
30 import org.tmatesoft.hg.internal.RepoInitializer; | 36 import org.tmatesoft.hg.internal.RepoInitializer; |
37 import org.tmatesoft.hg.internal.StreamLogFacility; | |
31 import org.tmatesoft.hg.repo.HgRepository; | 38 import org.tmatesoft.hg.repo.HgRepository; |
32 | 39 |
33 /** | 40 /** |
34 * | 41 * |
35 * @author Artem Tikhomirov | 42 * @author Artem Tikhomirov |
52 } | 59 } |
53 dest.mkdirs(); | 60 dest.mkdirs(); |
54 return dest; | 61 return dest; |
55 } | 62 } |
56 | 63 |
57 static File cloneRepoToTempLocation(String configRepoName, String name, boolean noupdate) throws Exception, InterruptedException { | 64 static File cloneRepoToTempLocation(String configRepoName, String name, boolean noupdate) throws HgException, IOException, InterruptedException { |
58 return cloneRepoToTempLocation(Configuration.get().find(configRepoName), name, noupdate); | 65 return cloneRepoToTempLocation(Configuration.get().find(configRepoName), name, noupdate); |
59 } | 66 } |
60 | 67 |
61 static File cloneRepoToTempLocation(HgRepository repo, String name, boolean noupdate) throws IOException, InterruptedException { | 68 static File cloneRepoToTempLocation(HgRepository repo, String name, boolean noupdate) throws IOException, InterruptedException { |
62 File testRepoLoc = createEmptyDir(name); | 69 File testRepoLoc = createEmptyDir(name); |
69 } | 76 } |
70 cmd.add(repo.getWorkingDir().toString()); | 77 cmd.add(repo.getWorkingDir().toString()); |
71 cmd.add(testRepoLoc.getName()); | 78 cmd.add(testRepoLoc.getName()); |
72 eh.run(cmd.toArray(new String[cmd.size()])); | 79 eh.run(cmd.toArray(new String[cmd.size()])); |
73 assertEquals("[sanity]", 0, eh.getExitValue()); | 80 assertEquals("[sanity]", 0, eh.getExitValue()); |
81 return testRepoLoc; | |
82 } | |
83 | |
84 static File copyRepoToTempLocation(String configRepoName, String newRepoName) throws HgException, IOException { | |
85 File testRepoLoc = createEmptyDir(newRepoName); | |
86 final File srcDir = Configuration.get().find(configRepoName).getWorkingDir(); | |
87 Iterator<File> it = new Iterator<File>() { | |
88 private final LinkedList<File> queue = new LinkedList<File>(); | |
89 { | |
90 queue.addAll(Arrays.asList(srcDir.listFiles())); | |
91 } | |
92 public boolean hasNext() { | |
93 return !queue.isEmpty(); | |
94 } | |
95 public File next() { | |
96 File n = queue.removeFirst(); | |
97 if (n.isDirectory()) { | |
98 queue.addAll(Arrays.asList(n.listFiles())); | |
99 } | |
100 return n; | |
101 } | |
102 public void remove() { | |
103 throw new UnsupportedOperationException(); | |
104 } | |
105 }; | |
106 FileUtils fu = new FileUtils(new StreamLogFacility(Debug, true, System.err)); | |
107 String srcPrefix = srcDir.getAbsolutePath(); | |
108 while (it.hasNext()) { | |
109 File next = it.next(); | |
110 assert next.getAbsolutePath().startsWith(srcPrefix); | |
111 String relPath = next.getAbsolutePath().substring(srcPrefix.length()); | |
112 File dest = new File(testRepoLoc, relPath); | |
113 if (next.isDirectory()) { | |
114 dest.mkdir(); | |
115 } else { | |
116 fu.copy(next, dest); | |
117 dest.setLastModified(next.lastModified()); | |
118 } | |
119 } | |
74 return testRepoLoc; | 120 return testRepoLoc; |
75 } | 121 } |
76 | 122 |
77 static void modifyFileAppend(File f, Object content) throws IOException { | 123 static void modifyFileAppend(File f, Object content) throws IOException { |
78 assertTrue(f.isFile()); | 124 assertTrue(f.isFile()); |