Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrameos committed Nov 28, 2024
1 parent 86c7878 commit a7197fb
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions native/java/org/jpype/classloader/DynamicClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DynamicClassLoader extends URLClassLoader
{
Expand All @@ -41,20 +39,30 @@ public DynamicClassLoader(ClassLoader parent)
super(launch(), parent);
}

/**
* Special routine for handling non-ascii paths.
*
* If we are loaded as the system ClassLoader, then we will use
* "jpype.class.path" rather than "java.class.path" during the load process.
* We will move it into the expected place after so no one is the wiser.
*
* @return
*/
private static URL[] launch()
{
String cp = System.getProperty("jpype.class.path");
if (cp == null)
return new URL[0];

ArrayList<URL> path = new ArrayList<>();
int off = 0, next;
do
int last = 0;
int next = 0;

while (next!=-1)
{
next = cp.indexOf(File.pathSeparator, off);
String element = (next == -1)
? cp.substring(off)
: cp.substring(off, next);
// Find the parts
next = cp.indexOf(File.pathSeparator, last);
String element = (next == -1) ? cp.substring(last) : cp.substring(last, next);
if (!element.isEmpty())
{
try
Expand All @@ -64,27 +72,18 @@ private static URL[] launch()
path.add(url);
} catch (MalformedURLException ex)
{
System.err.println("Malformed url "+ element);
} catch (IOException ex)
{
System.err.println("Unable to open "+ element);
System.err.println("Malformed url in classpath skipped " + element);
}
}
off = next + 1;
} while (next != -1);
last = next + 1;
}

System.out.println("jpype.class.path " + cp);
// Replace the path
System.clearProperty("jpype.class.path");
System.setProperty("java.class.path", cp);
return path.toArray(new URL[0]);
}

public void deferred()
{
System.getProperty("jpype.class.path");

}

// this is required to add a Java agent even if it is already in the path
@SuppressWarnings("unused")
private void appendToClassPathForInstrumentation(String path) throws Throwable
Expand Down

0 comments on commit a7197fb

Please sign in to comment.