mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 21:42:27 +00:00
Other languages on JVM may not be able to provide the type information.
This commit is contained in:
1 parent
d14ca2cec7
commit
237dbe3e2b
2 files changed
+24
-6
No files matched your search
@@ -38,6 +38,7 @@ import hudson.tasks.Publisher.DescriptorExtensionListImpl;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.lang.reflect.Type;
|
||||
@@ -156,13 +157,12 @@ public class DescriptorExtensionList<T extends Describable<T>, D extends Descrip
|
||||
List<ExtensionComponent<D>> r = new ArrayList<ExtensionComponent<D>>();
|
||||
for( ExtensionComponent<Descriptor> c : hudson.getExtensionList(Descriptor.class).getComponents() ) {
|
||||
Descriptor d = c.getInstance();
|
||||
Type subTyping = Types.getBaseClass(d.getClass(), Descriptor.class);
|
||||
if (!(subTyping instanceof ParameterizedType)) {
|
||||
LOGGER.severe(d.getClass()+" doesn't extend Descriptor with a type parameter");
|
||||
continue; // skip this one
|
||||
try {
|
||||
if(d.getT()==describableType)
|
||||
r.add((ExtensionComponent)c);
|
||||
} catch (IllegalStateException e) {
|
||||
LOGGER.log(Level.SEVERE, d.getClass() + " doesn't extend Descriptor with a type parameter", e); // skip this one
|
||||
}
|
||||
if(Types.erasure(Types.getTypeArgument(subTyping,0))==(Class)describableType)
|
||||
r.add((ExtensionComponent)c);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
*/
|
||||
package hudson.model;
|
||||
|
||||
import hudson.DescriptorExtensionList;
|
||||
import hudson.ExtensionComponent;
|
||||
import hudson.RelativePath;
|
||||
import hudson.XmlFile;
|
||||
import hudson.BulkChange;
|
||||
@@ -267,6 +269,22 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
|
||||
return clazz.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlike {@link #clazz}, return the parameter type 'T', which determines
|
||||
* the {@link DescriptorExtensionList} that this goes to.
|
||||
*
|
||||
* <p>
|
||||
* In those situations where subtypes cannot provide the type parameter,
|
||||
* this method can be overridden to provide it.
|
||||
*/
|
||||
public Class<T> getT() {
|
||||
Type subTyping = Types.getBaseClass(getClass(), Descriptor.class);
|
||||
if (!(subTyping instanceof ParameterizedType)) {
|
||||
throw new IllegalStateException(getClass()+" doesn't extend Descriptor with a type parameter.");
|
||||
}
|
||||
return Types.erasure(Types.getTypeArgument(subTyping, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL that this Descriptor is bound to, relative to the nearest {@link DescriptorByNameOwner}.
|
||||
* Since {@link Hudson} is a {@link DescriptorByNameOwner}, there's always one such ancestor to any request.
|
||||
|
||||
Reference in new issue
Block a user