Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.slf4j.Logger;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.FileSystems;
Expand Down Expand Up @@ -222,13 +223,14 @@ private Map<String, List<String>> gatherCandidatePaths(GenerateSourceFileMapping
Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
if (pathPattern == null || pathMatcher.matches(path)) {
var relativePath = basePath.relativize(path);
if (pathPattern == null || pathMatcher.matches(relativePath)) {
String filename = path.getFileName().toString();
if (options.isLowercaseTemplate()) {
filename = filename.toLowerCase();
}
List<String> paths = candidatePaths.computeIfAbsent(filename, f -> new ArrayList<>());
paths.add(basePath.relativize(path).toString());
paths.add(relativePath.toString());
}
return FileVisitResult.CONTINUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ public void generateNestedMatchesTest() throws Exception {
assertMappedDatePresent();
}

@Test
public void generateBasePathMatchesTest() throws Exception {
testHelper.indexExportData("mini_gilmer");
GenerateSourceFileMappingOptions options = makeDefaultOptions();
// test source files are in the source subdirectory of the base path
options.setPathPattern("source/*.tif");
// add nested path
testHelper.addSourceFile("nested/path/276_182_E.tif");
Path basePath = testHelper.addSourceFile("276_183_E.tif");

service.generateMapping(options);

SourceFilesInfo info = service.loadMappings();
assertMappingPresent(info, "25", "276_182_E.tif", null);
assertMappingPresent(info, "26", "276_183_E.tif", basePath);
assertMappingPresent(info, "27", "276_203_E.tif", null);

assertMappedDatePresent();
}

@Test
public void generateTransformedNestedMatchTest() throws Exception {
testHelper.indexExportData("mini_gilmer");
Expand Down Expand Up @@ -822,11 +842,6 @@ private void assertExceptionContains(String expected, Exception e) {
"Expected message exception to contain '" + expected + "', but was: " + e.getMessage());
}

private void setIndexedDate() throws Exception {
project.getProjectProperties().setIndexedDate(Instant.now());
ProjectPropertiesSerialization.write(project);
}

private void assertMappedDatePresent() throws Exception {
MigrationProjectProperties props = ProjectPropertiesSerialization.read(project.getProjectPropertiesPath());
assertNotNull(props.getSourceFilesUpdatedDate());
Expand Down
Loading