Skip to content

Commit

Permalink
Fix ExtensionManager to work with Java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Dec 4, 2024
1 parent a1ef31d commit 9de7f65
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions compiler/core/src/zserio/tools/ExtensionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
Expand Down Expand Up @@ -105,11 +106,11 @@ public void callExtensions(Root rootNode, ExtensionParameters parameters) throws
private ClassLoader getClassLoader()
{
final ClassLoader currentClassLoader = getClass().getClassLoader();
final String workingDirectory = getWorkingDirectory();
final File workingDirectory = getWorkingDirectory();
if (workingDirectory == null)
return currentClassLoader;

final File[] fileList = new File(workingDirectory).listFiles();
final File[] fileList = workingDirectory.listFiles();
if (fileList == null)
return currentClassLoader;

Expand All @@ -136,17 +137,19 @@ private ClassLoader getClassLoader()
return urlClassLoader;
}

private String getWorkingDirectory()
private File getWorkingDirectory()
{
try
{
final String execPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
final String decodedExecPath = URLDecoder.decode(execPath, "UTF-8");
final String workingDirectory = new File(decodedExecPath).getParent();
final String workingDirectoryUrl = new File(decodedExecPath).getParent();
final File workingDirectory = new File(new URL(workingDirectoryUrl).toURI());

return workingDirectory;
}
catch (SecurityException | UnsupportedEncodingException excpt)
catch (SecurityException | UnsupportedEncodingException | MalformedURLException |
URISyntaxException excpt)
{
return null;
}
Expand Down

0 comments on commit 9de7f65

Please sign in to comment.