Hi,

I have a simple plugin that use the pluginFirstClassLoader with the 
following Plugin and ItemListener classes:

public class PluginImpl extends Plugin {
    private final static Logger logger = 
Logger.getLogger(PluginImpl.class.getName());
    private String attribute;
    @Override
    public void start() throws Exception {
        logger.log(Level.INFO, "PluginImpl started");
        attribute = "someValue";
    }
    public String getAttribute(){
        return attribute;
    }
}

public class ItemListenerImpl extends ItemListener {
    private final static Logger logger = 
Logger.getLogger(ItemListenerImpl.class.getName());
    @Override
    public void onLoaded() {
        String value = 
Jenkins.getInstance().getPlugin(PluginImpl.class).getAttribute();
        logger.log(Level.INFO, "pluginImpl attribute value is: " + value);
    }
}

If I deploy this plugin in Jenkins, it works as expected: PluginImpl start 
method get called and set "someValue" in the attribute, ItemListemerImpl 
get called when all the jobs are loaded and it is able to retrieve the 
PluginImpl singleton and print the value of the attribute.

The problem is that if I use HusdonTestCase or JenkinsRule, I get a NPE in 
the ItemListener.onLoaded method because 
Jenkins.getInstance().getPlugin(PluginImpl.class) return null. I inspected 
the pluginManager while debugging the test and it contain my plugin. The 
reason why the method is not returning my plugin is that PluginImpl.class 
is loaded by 2 different class loaders. 

When Jenkins test instance initialize my plugin, PluginImpl is loaded by 
PluginFirstClassLoader but when ItemListenerImpl.onLoaded is called, 
PluginImpl is loaded with by sun.misc.Launcher$AppClassLoader.

Any idea on how to fix Jenkins tests harness to use proper classloader?

Thanks


-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to