Skip to content

Commit

Permalink
FORGE-2007: Added ClassLoaders.executeIn(URL[] urls, Callable<T> call…
Browse files Browse the repository at this point in the history
…able)
  • Loading branch information
gastaldi committed Sep 11, 2014
1 parent ca6ec66 commit 4e04c59
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.jboss.forge.furnace.util;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -49,6 +51,26 @@ public static <T> T executeIn(ClassLoader loader, Callable<T> task) throws Excep
}
}

/**
* Execute the given {@link Callable} by creating an {@link URLClassLoader} from the given {@link URL} array.
* <p/>
* Return the result, if any.
*/
public static <T> T executeIn(URL[] urls, Callable<T> callable) throws Exception
{
ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader();
URLClassLoader newClassLoader = null;
try
{
newClassLoader = new URLClassLoader(urls, savedClassLoader);
return executeIn(newClassLoader, callable);
}
finally
{
Streams.closeQuietly(newClassLoader);
}
}

public static boolean containsClass(ClassLoader loader, Class<?> type)
{
if (loader == null)
Expand Down

0 comments on commit 4e04c59

Please sign in to comment.