public Config loadConfig(URL url) throws ConfigException { try { logger.info("Loading config from {}", url); byte[] configBytes; try (InputStream is = url.openStream()) { configBytes = IOUtils.toByteArray(is); } catch (IOException e) { // getConfigURL should have ruled this out throw new AssertionError(e); } Constructor configConstructor = new Constructor(getConfigClass()); addTypeDescription(configConstructor); MissingPropertiesChecker propertiesChecker = new MissingPropertiesChecker(); configConstructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(configConstructor); Config result = (Config) yaml.loadAs(new ByteArrayInputStream(configBytes), getConfigClass()); propertiesChecker.check(); return result; } catch (YAMLException e) { throw new ConfigException("Invalid yaml", e); } }
@SuppressWarnings("unchecked") public PluginManager(ProxyServer proxy) { this.proxy = proxy; // Ignore unknown entries in the plugin descriptions Constructor yamlConstructor = new Constructor(); PropertyUtils propertyUtils = yamlConstructor.getPropertyUtils(); propertyUtils.setSkipMissingProperties( true ); yamlConstructor.setPropertyUtils( propertyUtils ); yaml = new Yaml( yamlConstructor ); eventBus = new EventBus( proxy.getLogger() ); }
constructor.setPropertyUtils(new PropertyUtils() { @Override public Property getProperty(Class<? extends Object> type, String name) throws IntrospectionException {
constructor.setPropertyUtils(new PropertyUtils() { @Override public Property getProperty(Class<? extends Object> type, String name) throws IntrospectionException {
public PluginManager(ProxyServer proxy) { this.proxy = proxy; // Ignore unknown entries in the plugin descriptions Constructor yamlConstructor = new Constructor(); PropertyUtils propertyUtils = yamlConstructor.getPropertyUtils(); propertyUtils.setSkipMissingProperties( true ); yamlConstructor.setPropertyUtils( propertyUtils ); yaml = new Yaml( yamlConstructor ); eventBus = new EventBus( proxy.getLogger() ); }
constructor.addTypeDescription(seedDesc); MissingPropertiesChecker propertiesChecker = new MissingPropertiesChecker(); constructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(constructor); Config result = yaml.loadAs(new ByteArrayInputStream(configBytes), Config.class);
public Config loadConfig(URL url) throws ConfigurationException { try { logger.debug("Loading settings from {}", url); byte[] configBytes; try (InputStream is = url.openStream()) { configBytes = ByteStreams.toByteArray(is); } catch (IOException e) { // getStorageConfigURL should have ruled this out throw new AssertionError(e); } Constructor constructor = new CustomConstructor(Config.class); PropertiesChecker propertiesChecker = new PropertiesChecker(); constructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(constructor); Config result = loadConfig(yaml, configBytes); propertiesChecker.check(); return result; } catch (YAMLException e) { throw new ConfigurationException("Invalid yaml: " + url + SystemUtils.LINE_SEPARATOR + " Error: " + e.getMessage(), false); } }
public Config loadConfig(URL url) throws ConfigurationException { try { logger.debug("Loading settings from {}", url); byte[] configBytes; try (InputStream is = url.openStream()) { configBytes = ByteStreams.toByteArray(is); } catch (IOException e) { // getStorageConfigURL should have ruled this out throw new AssertionError(e); } Constructor constructor = new CustomConstructor(Config.class); PropertiesChecker propertiesChecker = new PropertiesChecker(); constructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(constructor); Config result = loadConfig(yaml, configBytes); propertiesChecker.check(); return result; } catch (YAMLException e) { throw new ConfigurationException("Invalid yaml: " + url + SystemUtils.LINE_SEPARATOR + " Error: " + e.getMessage(), false); } }
public Config loadConfig(URL url) throws ConfigurationException { try { logger.debug("Loading settings from {}", url); byte[] configBytes; try (InputStream is = url.openStream()) { configBytes = ByteStreams.toByteArray(is); } catch (IOException e) { // getStorageConfigURL should have ruled this out throw new AssertionError(e); } Constructor constructor = new CustomConstructor(Config.class); PropertiesChecker propertiesChecker = new PropertiesChecker(); constructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(constructor); Config result = loadConfig(yaml, configBytes); propertiesChecker.check(); return result; } catch (YAMLException e) { throw new ConfigurationException("Invalid yaml: " + url + SystemUtils.LINE_SEPARATOR + " Error: " + e.getMessage(), false); } }
public Config loadConfig(URL url) throws ConfigurationException { try { logger.debug("Loading settings from {}", url); byte[] configBytes; try (InputStream is = url.openStream()) { configBytes = ByteStreams.toByteArray(is); } catch (IOException e) { // getStorageConfigURL should have ruled this out throw new AssertionError(e); } Constructor constructor = new CustomConstructor(Config.class); PropertiesChecker propertiesChecker = new PropertiesChecker(); constructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(constructor); Config result = loadConfig(yaml, configBytes); propertiesChecker.check(); return result; } catch (YAMLException e) { throw new ConfigurationException("Invalid yaml: " + url + SystemUtils.LINE_SEPARATOR + " Error: " + e.getMessage(), false); } }
constructor.addTypeDescription(seedDesc); MissingPropertiesChecker propertiesChecker = new MissingPropertiesChecker(); constructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(constructor); Config result = yaml.loadAs(new ByteArrayInputStream(configBytes), Config.class);
@Override public <T extends ExecutableRule<?>> Result<T> execute(T executableRule, Map<String, Object> ruleParameters, Severity severity, AnalyzerContext context) throws RuleException { SourceExecutable<String> executable = (SourceExecutable<String>) executableRule.getExecutable(); String source = executable.getSource(); Constructor c = new Constructor(YamlRuleSource.class); c.setPropertyUtils(new PropertyUtils() { @Override public Property getProperty(Class<? extends Object> type, String name) { return super.getProperty(type, LOWER_HYPHEN.to(LOWER_CAMEL, name)); } }); YamlRuleSource yamlRuleSource = new Yaml(c).loadAs(source, YamlRuleSource.class); String javaRuleClass = yamlRuleSource.getJavaRule(); if (javaRuleClass == null) { throw new RuleException("'java-rule-class' is required."); } JavaRule javaRule = getJavaRule(javaRuleClass); return javaRule.execute(executableRule, yamlRuleSource.getConfiguration(), ruleParameters, severity, context); }