diff --git a/sqrl-base/src/main/java/com/datasqrl/module/resolver/FileResourceResolver.java b/sqrl-base/src/main/java/com/datasqrl/module/resolver/FileResourceResolver.java index 09d732a23..9a3b2ad8a 100644 --- a/sqrl-base/src/main/java/com/datasqrl/module/resolver/FileResourceResolver.java +++ b/sqrl-base/src/main/java/com/datasqrl/module/resolver/FileResourceResolver.java @@ -21,10 +21,6 @@ public FileResourceResolver(Path baseDir) { this.baseDir = baseDir; } - public Optional resolve(Path path) { - return Optional.of(path.toFile().toURI()); - } - @Override public String toString() { return "FileResourceResolver[" + baseDir + ']'; @@ -51,4 +47,13 @@ public Optional resolveFile(NamePath namePath) { } return Optional.of(path); } + + @Override + public Optional resolve(Path relativePath) { + Path resolvedPath = baseDir.resolve(relativePath); + if (Files.exists(resolvedPath)) { + return Optional.of(resolvedPath); + } + return Optional.empty(); + } } diff --git a/sqrl-base/src/main/java/com/datasqrl/module/resolver/ResourceResolver.java b/sqrl-base/src/main/java/com/datasqrl/module/resolver/ResourceResolver.java index b5a336ff3..da68ef173 100644 --- a/sqrl-base/src/main/java/com/datasqrl/module/resolver/ResourceResolver.java +++ b/sqrl-base/src/main/java/com/datasqrl/module/resolver/ResourceResolver.java @@ -14,6 +14,8 @@ public interface ResourceResolver { Optional resolveFile(NamePath namePath); + Optional resolve(Path relativePath); + static URL toURL(URI uri) { try { return uri.toURL(); diff --git a/sqrl-planner/src/main/java/com/datasqrl/loaders/ObjectLoaderImpl.java b/sqrl-planner/src/main/java/com/datasqrl/loaders/ObjectLoaderImpl.java index 518fcdc72..bf00498d0 100644 --- a/sqrl-planner/src/main/java/com/datasqrl/loaders/ObjectLoaderImpl.java +++ b/sqrl-planner/src/main/java/com/datasqrl/loaders/ObjectLoaderImpl.java @@ -25,7 +25,6 @@ import com.datasqrl.util.StringUtil; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Preconditions; -import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Files; @@ -180,8 +179,9 @@ private List loadFunction(Path path, NamePath namePath) { String jarPath = json.get("jarPath").asText(); String functionClassName = json.get("functionClass").asText(); - URL jarUrl = new File(jarPath).toURI().toURL(); - Class functionClass = loadClass(jarPath, functionClassName); + Optional resolvedJarPath = resourceResolver.resolve(Path.of(jarPath)); + URL jarUrl = resolvedJarPath.get().toUri().toURL(); + Class functionClass = loadClass(jarUrl, functionClassName); Preconditions.checkArgument(UDF_FUNCTION_CLASS.isAssignableFrom(functionClass), "Class is not a UserDefinedFunction"); UserDefinedFunction udf = (UserDefinedFunction) functionClass.getDeclaredConstructor().newInstance(); @@ -191,8 +191,8 @@ private List loadFunction(Path path, NamePath namePath) { } @SneakyThrows - private Class loadClass(String jarPath, String functionClassName) { - URL[] urls = {new File(jarPath).toURI().toURL()}; + private Class loadClass(URL jarUrl, String functionClassName) { + URL[] urls = { jarUrl }; URLClassLoader classLoader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); return Class.forName(functionClassName, true, classLoader); } diff --git a/sqrl-tools/sqrl-packager/src/main/java/com/datasqrl/packager/preprocess/JarPreprocessor.java b/sqrl-tools/sqrl-packager/src/main/java/com/datasqrl/packager/preprocess/JarPreprocessor.java index 8ab04d60b..6e2b2b18a 100644 --- a/sqrl-tools/sqrl-packager/src/main/java/com/datasqrl/packager/preprocess/JarPreprocessor.java +++ b/sqrl-tools/sqrl-packager/src/main/java/com/datasqrl/packager/preprocess/JarPreprocessor.java @@ -89,8 +89,11 @@ private Void processJarEntry(JarEntry entry, JarFile file, processorContext.addLibrary(path); } + processorContext.addDependency(path); + return null; } + /** * Checks if the jar entry is valid */