This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve #75 by adding DynamicClassLoader
- Loading branch information
1 parent
0ef7373
commit e8defdd
Showing
3 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.update4j; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.nio.file.Paths; | ||
|
||
public final class DynamicClassLoader extends URLClassLoader { | ||
|
||
static { | ||
registerAsParallelCapable(); | ||
} | ||
|
||
public DynamicClassLoader(String name, ClassLoader parent) { | ||
super(name, new URL[0], parent); | ||
} | ||
|
||
/* | ||
* Required when this classloader is used as the system classloader | ||
*/ | ||
public DynamicClassLoader(ClassLoader parent) { | ||
this("classpath", parent); | ||
} | ||
|
||
public DynamicClassLoader() { | ||
this(Thread.currentThread().getContextClassLoader()); | ||
} | ||
|
||
void add(URL url) { | ||
addURL(url); | ||
} | ||
|
||
public static DynamicClassLoader findAncestor(ClassLoader cl) { | ||
do { | ||
|
||
if(cl instanceof DynamicClassLoader) | ||
return (DynamicClassLoader) cl; | ||
|
||
cl = cl.getParent(); | ||
} while(cl != null); | ||
|
||
return null; | ||
} | ||
|
||
/* | ||
* Required for Java Agents when this classloader is used as the system classloader | ||
*/ | ||
@SuppressWarnings("unused") | ||
private void appendToClassPathForInstrumentation(String jarfile) { | ||
try { | ||
add(Paths.get(jarfile).toRealPath().toUri().toURL()); | ||
} catch (IOException e) { | ||
new AssertionError(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters