提交 ff005a68 编写于 作者: K kohsuke

Fixed a regression in 1.286 about handling form field validations in some plugins.

    (<a href="http://www.nabble.com/1.286-version-and-description-The-requested-resource-%28%29-is-not--available.-td22233801.html">report</a>)


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15826 71c3de6d-444a-0410-be80-ed276b4c234a
上级 87c74aaa
......@@ -29,12 +29,15 @@ import hudson.model.Hudson;
import hudson.model.ViewDescriptor;
import hudson.model.Descriptor.FormException;
import hudson.util.Memoizer;
import hudson.util.Iterators;
import hudson.util.Iterators.FlattenIterator;
import hudson.slaves.NodeDescriptor;
import hudson.tasks.Publisher;
import hudson.tasks.Publisher.DescriptorExtensionListImpl;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Logger;
import java.util.concurrent.CopyOnWriteArrayList;
import java.lang.reflect.Type;
......@@ -138,7 +141,7 @@ public class DescriptorExtensionList<T extends Describable<T>, D extends Descrip
}
/**
* Stores manually registered Descriptor instances.
* Stores manually registered Descriptor instances. Keyed by the {@link Describable} type.
*/
private static final Memoizer<Class,CopyOnWriteArrayList> legacyDescriptors = new Memoizer<Class,CopyOnWriteArrayList>() {
public CopyOnWriteArrayList compute(Class key) {
......@@ -146,5 +149,20 @@ public class DescriptorExtensionList<T extends Describable<T>, D extends Descrip
}
};
/**
* List up all the legacy instances currently in use.
*/
public static Iterable<Descriptor> listLegacyInstances() {
return new Iterable<Descriptor>() {
public Iterator<Descriptor> iterator() {
return new FlattenIterator<Descriptor,CopyOnWriteArrayList>(legacyDescriptors.values()) {
protected Iterator expand(CopyOnWriteArrayList v) {
return v.iterator();
}
};
}
};
}
private static final Logger LOGGER = Logger.getLogger(DescriptorExtensionList.class.getName());
}
......@@ -103,6 +103,7 @@ import hudson.util.HudsonIsRestarting;
import hudson.util.DescribableList;
import hudson.util.Futures;
import hudson.util.Memoizer;
import hudson.util.Iterators;
import hudson.widgets.Widget;
import net.sf.json.JSONObject;
import org.acegisecurity.*;
......@@ -691,7 +692,8 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
* this just doesn't scale.
*/
public Descriptor getDescriptor(String fullyQualifiedClassName) {
for( Descriptor d : getExtensionList(Descriptor.class) )
// legacy descriptors that are reigstered manually doesn't show up in getExtensionList, so check them explicitly.
for( Descriptor d : Iterators.sequence(getExtensionList(Descriptor.class),DescriptorExtensionList.listLegacyInstances()) )
if(d.clazz.getName().equals(fullyQualifiedClassName))
return d;
return null;
......
......@@ -219,5 +219,10 @@ public interface BuildStep {
public Iterator<Descriptor<Publisher>> iterator() {
return core.iterator();
}
@Override
public boolean remove(Object o) {
return core.remove(o);
}
}
}
......@@ -130,6 +130,11 @@ public final class DescriptorList<T extends Describable<T>> extends AbstractList
add(element); // order is ignored
}
@Override
public boolean remove(Object o) {
return store().remove(o);
}
/**
* Gets the actual data store. This is the key to control the dual-mode nature of {@link DescriptorList}
*/
......
......@@ -65,4 +65,11 @@ public abstract class Memoizer<K,V> {
public void clear() {
store.clear();
}
/**
* Provides a snapshot view of all {@code V}s.
*/
public Iterable<V> values() {
return store.values();
}
}
......@@ -36,6 +36,7 @@ import hudson.search.SearchTest;
import hudson.security.AuthorizationStrategy;
import hudson.security.SecurityRealm;
import hudson.tasks.Ant;
import hudson.tasks.BuildStep;
import hudson.tasks.Ant.AntInstallation;
import hudson.tasks.Ant.DescriptorImpl;
import org.jvnet.hudson.test.Email;
......@@ -145,4 +146,22 @@ public class HudsonTest extends HudsonTestCase {
// the master computer object should be still here
wc.goTo("computer/(master)/");
}
/**
* Legacy descriptors should be visible in the /descriptor/xyz URL.
*/
@Email("http://www.nabble.com/1.286-version-and-description-The-requested-resource-%28%29-is-not--available.-td22233801.html")
public void testLegacyDescriptorLookup() throws Exception {
Descriptor dummy = new Descriptor(HudsonTest.class) {
public String getDisplayName() {
return "dummy";
}
};
BuildStep.PUBLISHERS.addRecorder(dummy);
assertSame(dummy,hudson.getDescriptor(HudsonTest.class.getName()));
BuildStep.PUBLISHERS.remove(dummy);
assertNull(hudson.getDescriptor(HudsonTest.class.getName()));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册