Skip to content

Commit 496bf62

Browse files
committed
Fix test
Signed-off-by: Bernát Gábor <gaborjbernat@gmail.com>
1 parent 389d766 commit 496bf62

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/search/SearchEngineTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
package org.opengrok.indexer.search;
2525

2626
import java.io.File;
27+
import java.net.URL;
28+
import java.nio.file.Path;
2729
import java.util.ArrayList;
2830
import java.util.Collections;
2931
import java.util.List;
@@ -59,7 +61,9 @@ class SearchEngineTest {
5961
@BeforeAll
6062
static void setUpClass() throws Exception {
6163
repository = new TestRepository();
62-
repository.create(HistoryGuru.class.getResource("/repositories"));
64+
URL url = HistoryGuru.class.getResource("/repositories");
65+
repository.createEmpty();
66+
repository.copyDirectoryWithUniqueModifiedTime(Path.of(url.toURI()), Path.of(repository.getSourceRoot()));
6367

6468
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
6569
env.setSourceRoot(repository.getSourceRoot());

opengrok-indexer/src/test/java/org/opengrok/indexer/util/TestRepository.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,35 @@ public void create(@NotNull final URL url) throws IOException, URISyntaxExceptio
112112
* @throws IOException on error
113113
*/
114114
public void copyDirectory(Path src, Path dest) throws IOException {
115+
try (Stream<Path> stream = Files.walk(src)) {
116+
stream.forEach(sourceFile -> {
117+
if (sourceFile.equals(src)) {
118+
return;
119+
}
120+
try {
121+
Path destRelativePath = getDestinationRelativePath(src, sourceFile);
122+
Path destPath = dest.resolve(destRelativePath);
123+
if (Files.isDirectory(sourceFile)) {
124+
if (!Files.exists(destPath)) {
125+
Files.createDirectory(destPath);
126+
}
127+
return;
128+
}
129+
Files.copy(sourceFile, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES);
130+
} catch (Exception e) {
131+
throw new RuntimeException(e);
132+
}
133+
});
134+
}
135+
}
136+
137+
/**
138+
* Assumes the destination directory exists.
139+
* @param src source directory
140+
* @param dest destination directory
141+
* @throws IOException on error
142+
*/
143+
public void copyDirectoryWithUniqueModifiedTime(Path src, Path dest) throws IOException {
115144
// Create a deterministic order of paths for creation time, so last modified time indexing is stable in tests
116145
// note we cannot use Files.copy(sourceFile, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES)
117146
// as the original creation time is the user checkout and not different accross files

0 commit comments

Comments
 (0)