Skip to content

Commit

Permalink
Fix by consultation!!
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Dec 9, 2024
1 parent a612c9a commit e69ef14
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
21 changes: 7 additions & 14 deletions ant_task/src/zserio/ant/ToolWrapper.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package zserio.ant;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
Expand Down Expand Up @@ -40,25 +42,16 @@ public ToolWrapper(String className, Iterable<Path> classPath, boolean ignoreErr
String [] files = p.list();
for (String f : files)
{
String u = null;
try
{
if (f.endsWith(".jar"))
{
u = "jar:file:"+f+"!/";
}
else
{
u = "file:"+f+"/";
}

System.out.println("Adding " + u + " to classpath");
urls.add(new URL(u));
final URL pathUrl = new File(f).toURI().toURL();
System.out.println("Adding " + pathUrl + " to classpath");
urls.add(pathUrl);

}
catch (MalformedURLException e)
catch (MalformedURLException | RuntimeException e)
{
throw new BuildException("Malformed URL: " + u);
throw new BuildException("Malformed URL from file: " + f + " (" + e + ")");
}
}
}
Expand Down
42 changes: 14 additions & 28 deletions compiler/core/src/zserio/tools/ExtensionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -123,14 +123,16 @@ private ClassLoader getClassLoader()
System.out.println("Found file: " + file);
if (isFileZserioExtension(file))
{
urlArray.add(new URL("jar:file:" + file.getPath() + "!/"));
System.out.println("file.toURI() = " + file.toURI());
System.out.println("file.toURI().toURL() = " + file.toURI().toURL());
urlArray.add(file.toURI().toURL());
urlArray.addAll(getDependentJarsFromManifest(file));
}
}
}
catch (MalformedURLException excpt)
{
System.out.println("Exception!");
System.out.println("Exception!" + excpt.toString());
return currentClassLoader;
}

Expand All @@ -144,32 +146,16 @@ private File getWorkingDirectory()
{
try
{
final String execUrlPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
final String decodedExecUrlPath = URLDecoder.decode(execUrlPath, "UTF-8");
// check if decodedExecUrlPath is really URL, newer Java versions 11 or 17 returns normal path
System.out.println("decodedExecUrlPath = " + decodedExecUrlPath);
File decodedExecFile = null;
try
{
decodedExecFile = new File(new URI(decodedExecUrlPath));
}
catch (URISyntaxException | IllegalArgumentException excpt)
{
decodedExecFile = new File(decodedExecUrlPath);
}
if (decodedExecFile.getPath().startsWith("file:"))
{
decodedExecFile = new File(decodedExecFile.getPath().replaceFirst("^file:", ""));
}

System.out.println("decodedExecFile = " + decodedExecFile);
System.out.println("decodedExecFile.getParentFile() = " + decodedExecFile.getParentFile());
System.out.println(
"decodedExecFile.getParentFile().exist = " + decodedExecFile.getParentFile().exists());
final URI execUri = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
System.out.println("execUri = " + execUri);
final Path execPath = Paths.get(execUri);
System.out.println("execPath = " + execPath);
final Path execParentPath = execPath.getParent();
System.out.println("execParentPath = " + execParentPath);

return decodedExecFile.getParentFile();
return execParentPath.toFile();
}
catch (SecurityException | UnsupportedEncodingException excpt)
catch (SecurityException | URISyntaxException excpt)
{
return null;
}
Expand Down

0 comments on commit e69ef14

Please sign in to comment.