@Test public void testClassLoading() throws IOException { ClassLoader systemLoader = Thread.currentThread().getContextClassLoader(); String configName = "type.class.property"; String configNameDefault = ConfigUtils.class.getName(); ConfigDef configDef = new ConfigDef(); configDef.define(configName, Type.CLASS, configNameDefault, ConfigDef.Importance.MEDIUM, "system class"); AbstractConfig config = new AbstractConfig(configDef, new HashMap<>()); Class<?> systemKlass = config.getClass(configName); assertEquals(systemLoader, systemKlass.getClassLoader()); Set<String> allowedKlasses = Collections.singleton(configNameDefault); List<URL> pluginUrls = Collections.singletonList(Paths.get("target/classes/").toUri().toURL()); URLClassLoader pluginLoader = new PluginClassLoader(pluginUrls.toArray(new URL[0]), systemLoader, allowedKlasses); try { Thread.currentThread().setContextClassLoader(pluginLoader); configDef = new ConfigDef(); configDef.define(configName, Type.CLASS, configNameDefault, ConfigDef.Importance.MEDIUM, "plugin class"); config = new AbstractConfig(configDef, new HashMap<>()); Class<?> pluginKlass = config.getClass(configName); assertEquals(pluginLoader, pluginKlass.getClassLoader()); assertNotEquals(pluginKlass, systemKlass); assertEquals(pluginKlass.getName(), systemKlass.getName()); } finally { Thread.currentThread().setContextClassLoader(systemLoader); } }
public ConfigDef define(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation) { if (configKeys.containsKey(name)) { throw new ConfigException("Configuration " + name + " is defined twice."); } Object parsedDefault = NO_DEFAULT_VALUE.equals(defaultValue) ? NO_DEFAULT_VALUE : parseType(name, defaultValue, type); configKeys .put(name, new ConfigKey(name, type, parsedDefault, validator, importance, documentation)); return this; }
ConfigDef { public ConfigDef define(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation) { if (configKeys.containsKey(name)) { throw new ConfigException("Configuration " + name + " is defined twice."); } Object parsedDefault = NO_DEFAULT_VALUE.equals(defaultValue) ? NO_DEFAULT_VALUE : parseType(name, defaultValue, type); configKeys .put(name, new ConfigKey(name, type, parsedDefault, validator, importance, documentation)); return this; } }
ConfigDef { public ConfigDef define(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation) { if (configKeys.containsKey(name)) { throw new ConfigException("Configuration " + name + " is defined twice."); } Object parsedDefault = NO_DEFAULT_VALUE.equals(defaultValue) ? NO_DEFAULT_VALUE : parseType(name, defaultValue, type); configKeys .put(name, new ConfigKey(name, type, parsedDefault, validator, importance, documentation)); return this; } ConfigDef();  ConfigDef(ConfigDef configDef); }
ConfigDef { public ConfigDef define(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation) { if (configKeys.containsKey(name)) { throw new ConfigException("Configuration " + name + " is defined twice."); } Object parsedDefault = NO_DEFAULT_VALUE.equals(defaultValue) ? NO_DEFAULT_VALUE : parseType(name, defaultValue, type); configKeys .put(name, new ConfigKey(name, type, parsedDefault, validator, importance, documentation)); return this; } ConfigDef();  ConfigDef(ConfigDef configDef); Set<String> names(); ConfigDef define(String name, Type type, Object defaultValue, Validator validator,
                          Importance importance, String documentation); ConfigDef defineOverride(String name, Type type, Object defaultValue, Validator validator,
                                  Importance importance, String documentation); ConfigDef define(String name, Type type, Object defaultValue, Importance importance,
                          String documentation); ConfigDef defineOverride(String name, Type type, Object defaultValue, Importance importance,
                          String documentation); ConfigDef define(String name, Type type, Validator validator, Importance importance,
                          String documentation); ConfigDef defineOverride(String name, Type type, Validator validator, Importance importance,
                          String documentation); ConfigDef define(String name, Type type, Importance importance, String documentation); ConfigDef defineOverride(String name, Type type, Importance importance, String documentation); Map<String, Object> parse(Map<?, ?> props); String toHtmlTable(); String toRst(); }
ConfigDef { public ConfigDef define(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation) { if (configKeys.containsKey(name)) { throw new ConfigException("Configuration " + name + " is defined twice."); } Object parsedDefault = NO_DEFAULT_VALUE.equals(defaultValue) ? NO_DEFAULT_VALUE : parseType(name, defaultValue, type); configKeys .put(name, new ConfigKey(name, type, parsedDefault, validator, importance, documentation)); return this; } ConfigDef();  ConfigDef(ConfigDef configDef); Set<String> names(); ConfigDef define(String name, Type type, Object defaultValue, Validator validator,
                          Importance importance, String documentation); ConfigDef defineOverride(String name, Type type, Object defaultValue, Validator validator,
                                  Importance importance, String documentation); ConfigDef define(String name, Type type, Object defaultValue, Importance importance,
                          String documentation); ConfigDef defineOverride(String name, Type type, Object defaultValue, Importance importance,
                          String documentation); ConfigDef define(String name, Type type, Validator validator, Importance importance,
                          String documentation); ConfigDef defineOverride(String name, Type type, Validator validator, Importance importance,
                          String documentation); ConfigDef define(String name, Type type, Importance importance, String documentation); ConfigDef defineOverride(String name, Type type, Importance importance, String documentation); Map<String, Object> parse(Map<?, ?> props); String toHtmlTable(); String toRst();  }