Mercurial > hg4j
annotate 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 |
| rev | line source |
|---|---|
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.test; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.junit.Assert.assertEquals; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import static org.junit.Assert.assertTrue; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import static org.tmatesoft.hg.internal.RequiresFile.*; |
|
623
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
22 import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.io.File; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.io.FileOutputStream; |
|
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
26 import java.io.FileWriter; |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.io.IOException; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import java.util.ArrayList; |
|
623
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
29 import java.util.Arrays; |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
30 import java.util.Iterator; |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
31 import java.util.LinkedList; |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
|
623
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
33 import org.tmatesoft.hg.core.HgException; |
|
622
4e6179bde4fc
Update to comply with Java 1.5 target
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
34 import org.tmatesoft.hg.core.HgIOException; |
|
623
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
35 import org.tmatesoft.hg.internal.FileUtils; |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import org.tmatesoft.hg.internal.RepoInitializer; |
|
623
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
37 import org.tmatesoft.hg.internal.StreamLogFacility; |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 import org.tmatesoft.hg.repo.HgRepository; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 /** |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 * @author Artem Tikhomirov |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 * @author TMate Software Ltd. |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 */ |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 public class RepoUtils { |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 |
|
622
4e6179bde4fc
Update to comply with Java 1.5 target
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
47 static File initEmptyTempRepo(String dirName) throws IOException, HgIOException { |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 File dest = createEmptyDir(dirName); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 RepoInitializer ri = new RepoInitializer(); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 ri.setRequires(STORE | FNCACHE | DOTENCODE); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 ri.initEmptyRepository(new File(dest, ".hg")); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 return dest; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 } |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 static File createEmptyDir(String dirName) throws IOException { |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 File dest = new File(Configuration.get().getTempDir(), dirName); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 if (dest.exists()) { |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 TestClone.rmdir(dest); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 } |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 dest.mkdirs(); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 return dest; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 } |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 |
|
623
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
64 static File cloneRepoToTempLocation(String configRepoName, String name, boolean noupdate) throws HgException, IOException, InterruptedException { |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 return cloneRepoToTempLocation(Configuration.get().find(configRepoName), name, noupdate); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 } |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 static File cloneRepoToTempLocation(HgRepository repo, String name, boolean noupdate) throws IOException, InterruptedException { |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 File testRepoLoc = createEmptyDir(name); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 ExecHelper eh = new ExecHelper(new OutputParser.Stub(), testRepoLoc.getParentFile()); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 ArrayList<String> cmd = new ArrayList<String>(); |
|
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
72 cmd.add("hg"); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
73 cmd.add("clone"); |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 if (noupdate) { |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 cmd.add("--noupdate"); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 } |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 cmd.add(repo.getWorkingDir().toString()); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 cmd.add(testRepoLoc.getName()); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 eh.run(cmd.toArray(new String[cmd.size()])); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 assertEquals("[sanity]", 0, eh.getExitValue()); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 return testRepoLoc; |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
|
623
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
83 |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
84 static File copyRepoToTempLocation(String configRepoName, String newRepoName) throws HgException, IOException { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
85 File testRepoLoc = createEmptyDir(newRepoName); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
86 final File srcDir = Configuration.get().find(configRepoName).getWorkingDir(); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
87 Iterator<File> it = new Iterator<File>() { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
88 private final LinkedList<File> queue = new LinkedList<File>(); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
89 { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
90 queue.addAll(Arrays.asList(srcDir.listFiles())); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
91 } |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
92 public boolean hasNext() { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
93 return !queue.isEmpty(); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
94 } |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
95 public File next() { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
96 File n = queue.removeFirst(); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
97 if (n.isDirectory()) { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
98 queue.addAll(Arrays.asList(n.listFiles())); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
99 } |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
100 return n; |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
101 } |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
102 public void remove() { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
103 throw new UnsupportedOperationException(); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
104 } |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
105 }; |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
106 FileUtils fu = new FileUtils(new StreamLogFacility(Debug, true, System.err)); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
107 String srcPrefix = srcDir.getAbsolutePath(); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
108 while (it.hasNext()) { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
109 File next = it.next(); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
110 assert next.getAbsolutePath().startsWith(srcPrefix); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
111 String relPath = next.getAbsolutePath().substring(srcPrefix.length()); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
112 File dest = new File(testRepoLoc, relPath); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
113 if (next.isDirectory()) { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
114 dest.mkdir(); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
115 } else { |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
116 fu.copy(next, dest); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
117 dest.setLastModified(next.lastModified()); |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
118 } |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
119 } |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
120 return testRepoLoc; |
|
fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
622
diff
changeset
|
121 } |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 |
|
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
123 static void modifyFileAppend(File f, Object content) throws IOException { |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 assertTrue(f.isFile()); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 FileOutputStream fos = new FileOutputStream(f, true); |
|
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
126 if (content == null) { |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
127 content = "XXX".getBytes(); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
128 } |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
129 if (content instanceof byte[]) { |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
130 fos.write((byte[]) content); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
131 } else { |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
132 fos.write(String.valueOf(content).getBytes()); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
133 } |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 fos.close(); |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 } |
|
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 |
|
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
137 static void createFile(File f, Object content) throws IOException { |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
138 if (content == null) { |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
139 f.createNewFile(); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
140 return; |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
141 } |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
142 if (content instanceof byte[]) { |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
143 FileOutputStream fos = new FileOutputStream(f); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
144 fos.write((byte[]) content); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
145 fos.close(); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
146 } else { |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
147 FileWriter fw = new FileWriter(f); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
148 fw.write(String.valueOf(content)); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
149 fw.close(); |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
150 } |
|
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
536
diff
changeset
|
151 } |
|
536
2813a26b8999
Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 } |
