use of java.net.URLClassLoader in project lucene-solr by apache.
the class SolrResourceLoader method addURLsToClassLoader.
private static URLClassLoader addURLsToClassLoader(final URLClassLoader oldLoader, List<URL> urls) {
if (urls.size() == 0) {
return oldLoader;
}
List<URL> allURLs = new ArrayList<>();
allURLs.addAll(Arrays.asList(oldLoader.getURLs()));
allURLs.addAll(urls);
for (URL url : urls) {
log.debug("Adding '{}' to classloader", url.toString());
}
ClassLoader oldParent = oldLoader.getParent();
IOUtils.closeWhileHandlingException(oldLoader);
return URLClassLoader.newInstance(allURLs.toArray(new URL[allURLs.size()]), oldParent);
}
use of java.net.URLClassLoader in project lucene-solr by apache.
the class SolrResourceLoader method addToClassLoader.
/**
* Adds URLs to the ResourceLoader's internal classloader. This method <b>MUST</b>
* only be called prior to using this ResourceLoader to get any resources, otherwise
* its behavior will be non-deterministic. You also have to {link @reloadLuceneSPI}
* before using this ResourceLoader.
*
* @param urls the URLs of files to add
*/
void addToClassLoader(List<URL> urls) {
URLClassLoader newLoader = addURLsToClassLoader(classLoader, urls);
if (newLoader != classLoader) {
this.classLoader = newLoader;
}
log.info("[{}] Added {} libs to classloader, from paths: {}", getCoreName("null"), urls.size(), urls.stream().map(u -> u.getPath().substring(0, u.getPath().lastIndexOf("/"))).sorted().distinct().collect(Collectors.toList()));
}
use of java.net.URLClassLoader in project SpaciousLib by anhcraft.
the class SPlugin method unloadPlugin.
public static boolean unloadPlugin(Plugin plugin) throws NoSuchFieldException, IllegalAccessException, IOException {
String name = plugin.getName();
PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = null;
List<Plugin> plugins = null;
Map<String, Plugin> names = null;
Map<String, Command> commands = null;
disablePlugin(plugin);
if (pluginManager != null) {
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames");
Field commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
Field commandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
commandsField.setAccessible(true);
pluginsField.setAccessible(true);
commandMapField.setAccessible(true);
lookupNamesField.setAccessible(true);
commandMap = (SimpleCommandMap) commandMapField.get(pluginManager);
commands = (Map<String, Command>) commandsField.get(commandMap);
plugins = (List<Plugin>) pluginsField.get(pluginManager);
names = (Map<String, Plugin>) lookupNamesField.get(pluginManager);
}
if (plugins != null && plugins.contains(plugin)) {
plugins.remove(plugin);
}
if (names != null && names.containsKey(name)) {
names.remove(name);
}
if (commandMap != null) {
for (Iterator<Map.Entry<String, Command>> it = commands.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Command> entry = it.next();
if (entry.getValue() instanceof PluginCommand) {
PluginCommand c = (PluginCommand) entry.getValue();
if (c.getPlugin() == plugin) {
c.unregister(commandMap);
it.remove();
}
}
}
}
ClassLoader cl = plugin.getClass().getClassLoader();
if (cl instanceof URLClassLoader) {
((URLClassLoader) cl).close();
}
System.gc();
return true;
}
use of java.net.URLClassLoader in project beam by apache.
the class DataflowRunnerTest method detectClassPathResourceWithNonFileResources.
@Test
public void detectClassPathResourceWithNonFileResources() throws Exception {
String url = "http://www.google.com/all-the-secrets.jar";
URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL(url) });
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unable to convert url (" + url + ") to file.");
DataflowRunner.detectClassPathResourcesToStage(classLoader);
}
use of java.net.URLClassLoader in project beam by apache.
the class DataflowRunnerTest method detectClassPathResourceWithFileResources.
@Test
public void detectClassPathResourceWithFileResources() throws Exception {
File file = tmpFolder.newFile("file");
File file2 = tmpFolder.newFile("file2");
URLClassLoader classLoader = new URLClassLoader(new URL[] { file.toURI().toURL(), file2.toURI().toURL() });
assertEquals(ImmutableList.of(file.getAbsolutePath(), file2.getAbsolutePath()), DataflowRunner.detectClassPathResourcesToStage(classLoader));
}
Aggregations