Navigation Menu

Skip to content

Commit

Permalink
[JENKINS-39520] ExtensionList.removeAll is unimplemented (#2612)
Browse files Browse the repository at this point in the history
* 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 e6db919
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/src/main/java/hudson/ExtensionList.java
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/pom.xml
Expand Up @@ -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>
Expand Down
13 changes: 13 additions & 0 deletions test/src/test/java/hudson/ExtensionListTest.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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.