Skip to content

Commit 40f77f3

Browse files
fix(go-feature-flag): fix loading wasm files in a jar mode. (#1595)
Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
1 parent 1c3e1e8 commit 40f77f3

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

providers/go-feature-flag/download-wasm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
# This script copy the wasm module from the git submodule repository and adds it to the build.
44
wasm_version="v1.45.4" # {{wasm_version}}
5-
mv ./wasm-releases/evaluation/gofeatureflag-evaluation_$wasm_version.wasi ./src/main/resources/wasm/gofeatureflag-evaluation_$wasm_version.wasi
5+
cp ./wasm-releases/evaluation/gofeatureflag-evaluation_$wasm_version.wasi ./src/main/resources/wasm/gofeatureflag-evaluation.wasi

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/wasm/EvaluationWasm.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616
import dev.openfeature.contrib.providers.gofeatureflag.wasm.bean.WasmInput;
1717
import dev.openfeature.sdk.ErrorCode;
1818
import dev.openfeature.sdk.Reason;
19-
import java.io.File;
20-
import java.net.URL;
19+
import java.io.InputStream;
2120
import java.nio.charset.StandardCharsets;
22-
import java.nio.file.Files;
23-
import java.nio.file.Path;
24-
import java.nio.file.Paths;
2521
import java.util.Collections;
2622
import lombok.val;
2723

@@ -58,27 +54,21 @@ public EvaluationWasm() throws WasmFileNotFound {
5854
/**
5955
* getWasmFile is a function that returns the path to the WASM file.
6056
* It looks for the file in the classpath under the directory "wasm".
57+
* This method handles both file system resources and JAR-packaged resources.
6158
*
6259
* @return the path to the WASM file
6360
* @throws WasmFileNotFound - if the file is not found
6461
*/
65-
private File getWasmFile() throws WasmFileNotFound {
62+
private InputStream getWasmFile() throws WasmFileNotFound {
6663
try {
67-
ClassLoader classLoader = EvaluationWasm.class.getClassLoader();
68-
URL directoryUrl = classLoader.getResource("wasm");
69-
if (directoryUrl == null) {
70-
throw new RuntimeException("Directory not found");
71-
}
72-
Path dirPath = Paths.get(directoryUrl.toURI());
73-
try (val files = Files.list(dirPath)) {
74-
return files.filter(path -> path.getFileName().toString().startsWith("gofeatureflag-evaluation")
75-
&& (path.getFileName().toString().endsWith(".wasi")
76-
|| path.getFileName().toString().endsWith(".wasm")))
77-
.findFirst()
78-
.map(Path::toFile)
79-
.orElseThrow(
80-
() -> new RuntimeException("No file starting with 'gofeatureflag-evaluation' found"));
64+
final String wasmResourcePath = "wasm/gofeatureflag-evaluation.wasi";
65+
InputStream inputStream = EvaluationWasm.class.getClassLoader().getResourceAsStream(wasmResourcePath);
66+
if (inputStream == null) {
67+
throw new WasmFileNotFound("WASM resource not found in classpath: " + wasmResourcePath);
8168
}
69+
return inputStream;
70+
} catch (WasmFileNotFound e) {
71+
throw e;
8272
} catch (Exception e) {
8373
throw new WasmFileNotFound(e);
8474
}
840 KB
Binary file not shown.

0 commit comments

Comments
 (0)