Skip to content

Commit

Permalink
Avoid class loader creation if not needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jan 3, 2023
1 parent cf84b72 commit a070a5d
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
throw new IllegalStateException("Source and target cannot be equal: " + source());
}
List<Transformation> transformations = new ArrayList<Transformation>(getTransformations());
ClassLoader classLoader = ByteBuddySkippingUrlClassLoader.of(getClass().getClassLoader(), discoverySet(), classPath());
ClassLoader classLoader = ByteBuddySkippingUrlClassLoader.of(getClass().getClassLoader(), discoverySet());
Plugin.Engine.Summary summary;
try {
if (discovery.isDiscover(transformations)) {
Expand Down Expand Up @@ -465,7 +465,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
classFileLocator.close();
}
} finally {
if (classLoader instanceof Closeable) {
if (classLoader instanceof Closeable && classLoader instanceof ByteBuddySkippingUrlClassLoader) {
((Closeable) classLoader).close();
}
}
Expand Down Expand Up @@ -580,21 +580,23 @@ protected ByteBuddySkippingUrlClassLoader(ClassLoader parent, URL[] url) {
*
* @param classLoader The class loader of the Byte Buddy plugin.
* @param discoverySet The source set to discover plugins from or {@code null} if no source set is used.
* @param classPath The configured class path.
* @return The resolved class loader.
*/
protected static ClassLoader of(ClassLoader classLoader, @MaybeNull Iterable<File> discoverySet, Iterable<File> classPath) {
protected static ClassLoader of(ClassLoader classLoader, @MaybeNull Iterable<File> discoverySet) {
if (discoverySet == null) {
return classLoader;
}
List<URL> urls = new ArrayList<URL>();
for (File file : discoverySet == null
? classPath
: discoverySet) {
for (File file : discoverySet) {
try {
urls.add(file.toURI().toURL());
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
}
return new ByteBuddySkippingUrlClassLoader(classLoader, urls.toArray(new URL[0]));
return urls.isEmpty()
? classLoader
: new ByteBuddySkippingUrlClassLoader(classLoader, urls.toArray(new URL[0]));
}

@Override
Expand Down

0 comments on commit a070a5d

Please sign in to comment.