-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kaklakariada
committed
Jun 16, 2024
1 parent
65bb574
commit 7d49032
Showing
8 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
.../src/main/java/org/itsallcode/openfasttrace/core/serviceloader/ChildFirstClassLoader.java
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,49 @@ | ||
package org.itsallcode.openfasttrace.core.serviceloader; | ||
|
||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
|
||
/** | ||
* This class loader will first try to load the class from the given URLs and | ||
* then from the parent class loader, unlike {@link URLClassLoader} which does | ||
* it the other way around. | ||
* <p> | ||
* This is based on | ||
* https://medium.com/@isuru89/java-a-child-first-class-loader-cbd9c3d0305 | ||
* <p> | ||
*/ | ||
class ChildFirstClassLoader extends URLClassLoader | ||
{ | ||
ChildFirstClassLoader(final String name, final URL[] urls, final ClassLoader parent) | ||
{ | ||
super(name, urls, parent); | ||
} | ||
|
||
@Override | ||
protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException | ||
{ | ||
// has the class loaded already? | ||
Class<?> loadedClass = findLoadedClass(name); | ||
if (loadedClass == null) | ||
{ | ||
try | ||
{ | ||
// find the class from given jar urls | ||
loadedClass = findClass(name); | ||
} | ||
catch (final ClassNotFoundException ignore) | ||
{ | ||
// Hmmm... class does not exist in the given urls. | ||
// Let's try finding it in our parent classloader. | ||
// this'll throw ClassNotFoundException in failure. | ||
loadedClass = super.loadClass(name, resolve); | ||
} | ||
} | ||
|
||
if (resolve) | ||
{ // marked to resolve | ||
resolveClass(loadedClass); | ||
} | ||
return loadedClass; | ||
} | ||
} |
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
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
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
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,10 @@ | ||
handlers = java.util.logging.ConsoleHandler org.itsallcode.openfasttrace.testutil.log.NoOpLoggingHandler | ||
.level = INFO | ||
java.util.logging.ConsoleHandler.level = ALL | ||
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter | ||
java.util.logging.ConsoleHandler.encoding = UTF-8 | ||
java.util.logging.SimpleFormatter.format = %1$tF %1$tT [%4$s] %2$s - %5$s %6$s%n | ||
|
||
org.itsallcode.openfasttrace.testutil.log.NoOpLoggingHandler.level = ALL | ||
|
||
org.itsallcode.openfasttrace.level = INFO |