DescribableModel implements Serializable { static Class<?> resolveClass(Class<?> base, @Nullable String name, @Nullable String symbol) throws ClassNotFoundException { if (name != null) { if (name.contains(".")) { Jenkins j = Jenkins.getInstanceOrNull(); ClassLoader loader = j != null ? j.getPluginManager().uberClassLoader : Thread.currentThread().getContextClassLoader(); 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 " + base + " could mean either " + clazz.getName() + " or " + c.getName()); } clazz = c; } } if (clazz == null) { throw new UnsupportedOperationException("no known implementation of " + base + " is named " + name); } return clazz; } } if (symbol != null) { Descriptor d = SymbolLookup.get().findDescriptor(base, symbol); if (d != null) { return d.clazz; } if (base == ParameterValue.class) { d = SymbolLookup.get().findDescriptor(ParameterDefinition.class, symbol); if (d != null) { Class<?> c = parameterValueClass(d.clazz); if (c != null) { return c; } } } throw new UnsupportedOperationException("no known implementation of " + base + " is using symbol ‘" + symbol + "’"); } if (Modifier.isAbstract(base.getModifiers())) { throw new UnsupportedOperationException("must specify " + CLAZZ + " with an implementation of " + base); } return base; } DescribableModel(Class<T> clazz); static DescribableModel<T> of(Class<T> clazz); Class<T> getType(); Collection<DescribableParameter> getParameters(); DescribableParameter getParameter(String name); boolean hasSingleRequiredParameter(); @CheckForNull DescribableParameter getSoleRequiredParameter(); @CheckForNull DescribableParameter getFirstRequiredParameter(); String getDisplayName(); @Deprecated T instantiate(Map<String,?> arguments); T instantiate(Map<String,?> arguments, @CheckForNull TaskListener listener); Map<String,Object> uninstantiate(T o); UninstantiatedDescribable uninstantiate2(T o); static Map<String,Object> uninstantiate_(Object o); @SuppressWarnings("unchecked") static UninstantiatedDescribable uninstantiate2_(Object o); boolean isDeprecated(); @CheckForNull String getHelp(); @Override String toString(); @SuppressFBWarnings("MS_SHOULD_BE_FINAL") // Used to control warnings that instantiate parameters will be ignored
    @Restricted(NoExternalUse.class)
    static boolean STRICT_PARAMETER_CHECKING; static final String CLAZZ; }
@Test public void resolveClass() throws Exception { assertEquals(FishingNet.class, DescribableModel.resolveClass(Fishing.class, null, "net")); assertEquals(FishingNet.class, DescribableModel.resolveClass(Fishing.class, "FishingNet", null)); assertEquals(Internet.class, DescribableModel.resolveClass(Tech.class, null, "net")); assertEquals(Internet.class, DescribableModel.resolveClass(Tech.class, "Internet", null)); }
@Issue("JENKINS-46122") @Test public void resolveSymbolOnWrongBaseClass() throws Exception { try { DescribableModel.resolveClass(Tech.class, null, "rod"); fail("No symbol for Tech should exist."); } catch (UnsupportedOperationException e) { assertEquals("no known implementation of " + Tech.class + " is using symbol ‘rod’", e.getMessage()); } }