Skip to content

Commit 3d4a22d

Browse files
committed
build(flagd): Fix resource loading issue on windows
Signed-off-by: Guido Breitenhuber <[email protected]>
1 parent cf28cc9 commit 3d4a22d

File tree

1 file changed

+16
-11
lines changed
  • providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process

1 file changed

+16
-11
lines changed

Diff for: providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/TestUtils.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import dev.openfeature.contrib.providers.flagd.resolver.process.model.FlagParser;
44

55
import java.io.IOException;
6+
import java.net.URISyntaxException;
67
import java.net.URL;
78
import java.nio.file.Files;
9+
import java.nio.file.Path;
810
import java.nio.file.Paths;
11+
import java.util.Objects;
912

1013
public class TestUtils {
1114
public static final String VALID_SIMPLE = "flagConfigurations/valid-simple.json";
@@ -15,21 +18,23 @@ public class TestUtils {
1518
public static final String INVALID_CFG = "flagConfigurations/invalid-configuration.json";
1619
public static final String UPDATABLE_FILE = "flagConfigurations/updatableFlags.json";
1720

18-
1921
public static String getFlagsFromResource(final String file) throws IOException {
20-
final URL url = FlagParser.class.getClassLoader().getResource(file);
21-
if (url == null) {
22-
throw new IllegalStateException(String.format("Resource %s not found", file));
23-
} else {
24-
return new String(Files.readAllBytes(Paths.get(url.getPath())));
25-
}
22+
final Path resourcePath = getResourcePathInternal(file);
23+
return new String(Files.readAllBytes(resourcePath));
2624
}
2725

2826
public static String getResourcePath(final String relativePath) {
29-
final URL url = FlagParser.class.getClassLoader().getResource(relativePath);
30-
if (url == null) {
31-
throw new IllegalStateException(String.format("Resource %s not found", relativePath));
27+
return getResourcePathInternal(relativePath).toString();
28+
}
29+
30+
private static Path getResourcePathInternal(String file) {
31+
try {
32+
URL url = Objects.requireNonNull(FlagParser.class.getClassLoader().getResource(file));
33+
return Paths.get(url.toURI());
34+
} catch (NullPointerException e) {
35+
throw new IllegalStateException(String.format("Resource %s not found", file), e);
36+
} catch (URISyntaxException e) {
37+
throw new IllegalStateException("Invalid resource path", e);
3238
}
33-
return url.getPath();
3439
}
3540
}

0 commit comments

Comments
 (0)