Skip to content

Commit

Permalink
[JENKINS-26535] tiger-types to the rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Mar 6, 2016
1 parent 6fe58e6 commit f467a82
Showing 1 changed file with 11 additions and 11 deletions.
Expand Up @@ -15,6 +15,7 @@
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.reflection.ReflectionCache;
import org.jvnet.tiger_types.Types;
import org.kohsuke.stapler.ClassDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -302,19 +303,20 @@ private Object coerce(String context, Type type, Object o) throws Exception {
* Signature of the type that the resolved class should be assignable to.
*/
private Class<?> resolveClass(Type type, String name) throws ClassNotFoundException {
Class<?> clazz;
Class base = Types.erasure(type);

if (name == null) {
if (Modifier.isAbstract(((Class) type).getModifiers())) {
if (Modifier.isAbstract(base.getModifiers())) {
throw new UnsupportedOperationException("must specify " + CLAZZ + " with an implementation of " + type);
}
clazz = (Class) type;
} else if (name.contains(".")) {
return base;
} else if (name.contains(".")) {// a fully qualified name
Jenkins j = Jenkins.getInstance();
ClassLoader loader = j != null ? j.getPluginManager().uberClassLoader : Thread.currentThread().getContextClassLoader();
clazz = Class.forName(name,true,loader);
} else if (type instanceof Class) {
clazz = null;
for (Class<?> c : findSubtypes((Class<?>) type)) {
return Class.forName(name,true,loader);
} else {
Class<?> clazz = null;
for (Class<?> c : findSubtypes(base)) {
if (c.getSimpleName().equals(name)) {
if (clazz != null) {
throw new UnsupportedOperationException(name + " as a " + type + " could mean either " + clazz.getName() + " or " + c.getName());
Expand All @@ -325,10 +327,8 @@ private Class<?> resolveClass(Type type, String name) throws ClassNotFoundExcept
if (clazz == null) {
throw new UnsupportedOperationException("no known implementation of " + type + " is named " + name);
}
} else {
throw new UnsupportedOperationException("JENKINS-26535: do not know how to handle " + type);
return clazz;
}
return clazz;
}

private List<Object> mapList(String context, Type type, List<?> list) throws Exception {
Expand Down

2 comments on commit f467a82

@lrodrigueza
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix the wilcard issue when trying to publish JUnit reports with the pipeline plugin?

@kohsuke
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lrodrigueza I don't know. Do you have a stack trace?

Please sign in to comment.