Skip to content

Commit 7635572

Browse files
committed
Log resolved path for debugging. (hbz/lobid-resources#1527)
Incidentally also changes paths to normalized and absolute, which _might_ affect behaviour.
1 parent 7a2e224 commit 7635572

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

metafix/src/main/java/org/metafacture/metafix/Metafix.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.io.Reader;
3737
import java.io.StringReader;
3838
import java.io.UncheckedIOException;
39+
import java.nio.file.Path;
3940
import java.nio.file.Paths;
4041
import java.util.ArrayList;
4142
import java.util.Collection;
@@ -145,17 +146,28 @@ public void literal(final String name, final String value) {
145146
}
146147

147148
public String resolvePath(final String path) {
149+
final Path basePath;
150+
148151
if (path.startsWith(".")) {
149152
if (fixFile != null) {
150-
return Paths.get(fixFile).resolveSibling(path).toString();
153+
basePath = getPath(fixFile).getParent();
151154
}
152155
else {
153156
throw new IllegalArgumentException("Cannot resolve relative path: " + path);
154157
}
155158
}
156159
else {
157-
return path;
160+
basePath = getPath("");
158161
}
162+
163+
final String resolvedPath = basePath.resolve(path).normalize().toString();
164+
LOG.debug("Resolved path: path = '{}', result = '{}', base = '{}'", path, resolvedPath, basePath);
165+
166+
return resolvedPath;
167+
}
168+
169+
private Path getPath(final String path) {
170+
return Paths.get(path).toAbsolutePath().normalize();
159171
}
160172

161173
public RecordTransformer getRecordTransformer(final String fixDef) {

metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ public void shouldIncludeLocationAndTextInProcessExceptionInConditional() {
10841084
final String text2 = "nothing()";
10851085
final String message = "Error while executing Fix expression (at FILE, line 3): " + text1 + " " + text2;
10861086

1087-
MetafixTestHelpers.assertThrows(FixProcessException.class, s -> s.replaceAll("file:/.+?\\.fix", "FILE"), message, () ->
1087+
MetafixTestHelpers.assertProcessException(/*BasicIndexOutOfBoundsException.class*/null, s -> s.replaceAll("file:/.+?\\.fix", "FILE"), message, () ->
10881088
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
10891089
"if exists('animal')",
10901090
"nothing()",
@@ -1112,7 +1112,7 @@ public void shouldIncludeLocationAndTextInProcessExceptionInBody() {
11121112
final String text = "add_field()";
11131113
final String message = "Error while executing Fix expression (at FILE, line 4): " + text;
11141114

1115-
MetafixTestHelpers.assertThrows(FixProcessException.class, s -> s.replaceAll("file:/.+?\\.fix", "FILE"), message, () ->
1115+
MetafixTestHelpers.assertProcessException(/*BasicIndexOutOfBoundsException.class*/null, s -> s.replaceAll("file:/.+?\\.fix", "FILE"), message, () ->
11161116
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
11171117
"if exists('animal')",
11181118
"nothing()",

metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ public void shouldLookupInCopiedNestedArrays() {
830830

831831
@Test
832832
public void shouldFailLookupInUnknownExternalMap() {
833-
MetafixTestHelpers.assertProcessException(MorphExecutionException.class, "File not found: testMap.csv", () ->
833+
MetafixTestHelpers.assertProcessException(MorphExecutionException.class, s -> s.replaceAll(": /.+?/testMap\\.csv", ": FILE"), "File not found: FILE", () ->
834834
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
835835
LOOKUP + " 'testMap.csv')"
836836
),

metafix/src/test/java/org/metafacture/metafix/MetafixTestHelpers.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public static void assertExecutionException(final Class<?> expectedClass, final
5555
}
5656

5757
public static void assertProcessException(final Class<?> expectedClass, final String expectedMessage, final Executable executable) {
58-
assertThrows(FixProcessException.class, expectedClass, expectedMessage, executable, UnaryOperator.identity());
58+
assertProcessException(expectedClass, UnaryOperator.identity(), expectedMessage, executable);
59+
}
60+
61+
public static void assertProcessException(final Class<?> expectedClass, final UnaryOperator<String> operator, final String expectedMessage, final Executable executable) {
62+
assertThrows(FixProcessException.class, expectedClass, expectedMessage, executable, operator);
5963
}
6064

6165
public static void assertThrows(final Class<? extends Throwable> expectedClass, final String expectedMessage, final Executable executable) {

0 commit comments

Comments
 (0)