Skip to content

Commit

Permalink
fix(compiler): support file location containing special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
rbioteau committed Oct 8, 2024
1 parent 00b670c commit 966ae32
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -43,11 +45,16 @@ public class JDTCompiler {
private static final String PARAMETERS_NAME_ARG = "-parameters";

public static File lookupJarContaining(Class<?> clazz) {
var jarFile = new File(clazz.getProtectionDomain().getCodeSource().getLocation().getPath());
if (!jarFile.exists()) {
throw new IllegalArgumentException("Cannot find jar file for class " + clazz.getName());
try {
File jarFile = Path.of(clazz.getProtectionDomain().getCodeSource().getLocation().toURI()).toFile();
if (!jarFile.exists()) {
throw new IllegalArgumentException("Cannot find jar file for class " + clazz.getName() +". Resolved jar file: " + jarFile.getAbsolutePath() +" does not exist.");
}
return jarFile;
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Cannot find jar file for class " + clazz.getName(), e);
}
return jarFile;

}

public static File lookupJarContaining(String className) throws ClassNotFoundException {
Expand Down

0 comments on commit 966ae32

Please sign in to comment.