Skip to content
Permalink
Browse files

[JENKINS-39520] ExtensionList.removeAll is unimplemented (#2612)

* Work around SUREFIRE-1226 just like jenkinsci/plugin-pom#33.

* [JENKINS-39520] Implement ExtensionList.removeAll.

* @oleg-nenashev suggests not notifying listeners unless we are actually removing something.
  • Loading branch information...
jglick authored and oleg-nenashev committed Nov 10, 2016
1 parent 643442a commit e6db919e5f70bb598de3235cbca00ef0a79302e9
Showing with 29 additions and 0 deletions.
  1. +15 −0 core/src/main/java/hudson/ExtensionList.java
  2. +1 −0 test/pom.xml
  3. +13 −0 test/src/test/java/hudson/ExtensionListTest.java
@@ -204,6 +204,21 @@ public boolean remove(Object o) {
}
}

@Override
public boolean removeAll(Collection<?> c) {
boolean removed = false;
try {
for (Object o : c) {
removed |= removeSync(o);
}
return removed;
} finally {
if (extensions != null && removed) {
fireOnChangeListeners();
}
}
}

private synchronized boolean removeSync(Object o) {
boolean removed = removeComponent(legacyInstances, o);
if(extensions!=null) {
@@ -40,6 +40,7 @@ THE SOFTWARE.
<concurrency>2</concurrency> <!-- may use e.g. 2C for 2 × (number of cores) -->
<mavenDebug>false</mavenDebug>
<jacocoSurefireArgs /><!-- empty by default -->
<trimStackTrace>false</trimStackTrace> <!-- SUREFIRE-1226 workaround -->
</properties>

<dependencies>
@@ -10,12 +10,14 @@
import hudson.model.Descriptor;
import hudson.model.Describable;
import hudson.util.DescriptorList;
import java.util.ArrayList;

import java.util.List;
import java.util.Collection;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.WithoutJenkins;

@@ -204,4 +206,15 @@ public void ordinals() {
assertEquals("mazda",list.get(1).name);
assertEquals("toyota",list.get(2).name);
}

@Issue("JENKINS-39520")
@Test
public void removeAll() {
ExtensionList<Animal> list = ExtensionList.lookup(Animal.class);
assertTrue(list.removeAll(new ArrayList<>(list)));
assertEquals(0, list.size());
assertFalse(list.removeAll(new ArrayList<>(list)));
assertEquals(0, list.size());
}

}

0 comments on commit e6db919

Please sign in to comment.
You can’t perform that action at this time.