[FIXED JENKINS-19976] Merged #1054: fix class loading from dynamically installed optional dependencies.

This commit is contained in:
Jesse Glick committed 2014-03-24 09:52:32 -04:00
commit df8df45c27
6 files changed
+195

No files matched your search

@@ -377,6 +377,45 @@ public class ClassicPluginStrategy implements PluginStrategy {
plugin.getPlugin().start();
}
/**
* Called when a plugin is deployed, and there is a plugin optionally depending on that plugin.
* The class loader of the existing depending plugin should be updated
* to load classes from the newly deployed plugin.
*
* @param depender the plugin to update its class loader
* @param dependee
* @see hudson.PluginStrategy#updateDependency(hudson.PluginWrapper, hudson.PluginWrapper)
*/
@Override
public void updateDependency(PluginWrapper depender, PluginWrapper dependee) {
DependencyClassLoader classLoader = findAncestorDependencyClassLoader(depender.classLoader);
if (classLoader != null) {
classLoader.updateTransientDependencies();
LOGGER.log(Level.INFO, "Updated dependency of {0}", depender.getShortName());
}
}
private DependencyClassLoader findAncestorDependencyClassLoader(ClassLoader classLoader)
{
for (; classLoader != null; classLoader = classLoader.getParent()) {
if (classLoader instanceof DependencyClassLoader) {
return (DependencyClassLoader)classLoader;
}
if (classLoader instanceof AntClassLoader) {
// AntClassLoaders hold parents not only as AntClassLoader#getParent()
// but also as AntClassLoader#getConfiguredParent()
DependencyClassLoader ret = findAncestorDependencyClassLoader(
((AntClassLoader)classLoader).getConfiguredParent()
);
if (ret != null) {
return ret;
}
}
}
return null;
}
private static File resolve(File base, String relative) {
File rel = new File(relative);
if(rel.isAbsolute())
@@ -523,6 +562,11 @@ public class ClassicPluginStrategy implements PluginStrategy {
this.dependencies = dependencies;
}
private void updateTransientDependencies() {
// This will be recalculated at the next time.
transientDependencies = null;
}
private List<PluginWrapper> getTransitiveDependencies() {
if (transientDependencies==null) {
CyclicGraphDetector<PluginWrapper> cgd = new CyclicGraphDetector<PluginWrapper>() {