提交 279f12d0 编写于 作者: T tfennelly

Call ExtensionListListener.onChange for add and remove (as well as refresh).

上级 cad0fdab
......@@ -199,6 +199,7 @@ public class ExtensionList<T> extends AbstractList<T> {
List<ExtensionComponent<T>> r = new ArrayList<ExtensionComponent<T>>(extensions);
removed |= removeComponent(r,o);
extensions = sort(r);
fireOnChangeListeners();
}
return removed;
}
......@@ -235,6 +236,7 @@ public class ExtensionList<T> extends AbstractList<T> {
List<ExtensionComponent<T>> r = new ArrayList<ExtensionComponent<T>>(extensions);
r.add(new ExtensionComponent<T>(t));
extensions = sort(r);
fireOnChangeListeners();
}
return true;
}
......@@ -293,13 +295,17 @@ public class ExtensionList<T> extends AbstractList<T> {
List<ExtensionComponent<T>> l = Lists.newArrayList(extensions);
l.addAll(found);
extensions = sort(l);
for (ExtensionListListener listener : listeners) {
try {
listener.onRefresh();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error firing ExtensionListListener.onRefresh().", e);
}
}
fireOnChangeListeners();
}
}
}
private void fireOnChangeListeners() {
for (ExtensionListListener listener : listeners) {
try {
listener.onChange();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error firing ExtensionListListener.onChange().", e);
}
}
}
......
......@@ -31,11 +31,11 @@ package hudson;
public abstract class ExtensionListListener {
/**
* {@link ExtensionList} has been refreshed.
* {@link ExtensionList} contents has changed.
* <p>
* This would be called when a dynamically loaded plugin introduces a new
* {@link ExtensionPoint} implementation that adds an entry to the {@link ExtensionList}
* being listened to.
* This would be called when an entry gets added to or removed from the list for any reason e.g.
* when a dynamically loaded plugin introduces a new {@link ExtensionPoint} implementation
* that adds an entry to the {@link ExtensionList} being listened to.
*/
public abstract void onRefresh();
public abstract void onChange();
}
......@@ -29,8 +29,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import java.io.IOException;
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
......@@ -40,7 +38,7 @@ public class ExtensionListListenerTest {
public JenkinsRule r = PluginManagerUtil.newJenkinsRule();
@Test
public void test_onRefresh() throws Exception {
public void test_onChange() throws Exception {
ExtensionList<TransientActionFactory> extensionList = ExtensionList.lookup(TransientActionFactory.class);
// force ExtensionList.ensureLoaded, otherwise the refresh will be ignored because
......@@ -52,17 +50,17 @@ public class ExtensionListListenerTest {
extensionList.addListener(listListener);
// magiext.hpi has a TransientActionFactory @Extension impl in it. The loading of that
// plugin should trigger onRefresh in the MyExtensionListListener instance.
// plugin should trigger onChange in the MyExtensionListListener instance.
PluginManagerUtil.dynamicLoad("magicext.hpi", r.jenkins);
Assert.assertTrue(listListener.refreshed);
Assert.assertEquals(1, listListener.onChangeCallCount);
}
private class MyExtensionListListener extends ExtensionListListener {
private boolean refreshed = false;
private int onChangeCallCount = 0;
@Override
public void onRefresh() {
refreshed = true;
public void onChange() {
onChangeCallCount++;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册