本文整理汇总了Java中groovy.util.ConfigSlurper类的典型用法代码示例。如果您正苦于以下问题:Java ConfigSlurper类的具体用法?Java ConfigSlurper怎么用?Java ConfigSlurper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigSlurper类属于groovy.util包,在下文中一共展示了ConfigSlurper类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setClientProperties
import groovy.util.ConfigSlurper; //导入依赖的package包/类
/**
* Set the client properties, such as brokerURL, from a pre-loaded groovy config file.
*
* @param leoClient Client object to configure.
* @return Reference to the configured Client.
* @throws MalformedURLException if the configuration file url that was set is invalid.
* @throws InvocationTargetException if the groovy config refers to objects not in the classpath.
* @throws IllegalAccessException if there is a rights issue accessing settings from the groovy config.
*/
protected Client setClientProperties(Client leoClient) throws MalformedURLException, InvocationTargetException, IllegalAccessException {
if (clientConfigFile.length != 1) {
return leoClient;
}
ConfigSlurper configSlurper = new ConfigSlurper();
ConfigObject o = configSlurper.parse(clientConfigFile[0].toURI().toURL());
Set<Map.Entry> entries = o.entrySet();
for (Map.Entry e : entries) {
System.out.println("Setting property " + e.getKey() + " on client to " + e.getValue() + ".");
BeanUtils.setProperty(leoClient, e.getKey().toString(), e.getValue());
}
return leoClient;
}
开发者ID:department-of-veterans-affairs,项目名称:Leo,代码行数:26,代码来源:CommandLineClient.java
示例2: loadFromResource
import groovy.util.ConfigSlurper; //导入依赖的package包/类
private ConfigObject loadFromResource(final ConfigSlurper slurper, final String location) {
final Resource res = resourceLoader.getResource(location);
if (!res.exists()) {
LOG.warn("Skip non-existence resource: {}", res);
return null;
}
if (!res.isReadable()) {
LOG.warn("Resource not readable: {}", res);
return null;
}
final URL url;
try {
url = res.getURL();
}
catch (IOException e) {
throw new ConfigException("Not expecting a bad URL from a redable resource: " + res, e);
}
return slurper.parse(url);
}
开发者ID:ctzen,项目名称:slurper-configuration,代码行数:20,代码来源:Config.java
示例3: getProperties
import groovy.util.ConfigSlurper; //导入依赖的package包/类
public static Properties getProperties() {
Properties profileProperties = new Properties();
String profile = System.getProperty("profile", "test");
try {
profileProperties = new ConfigSlurper(profile).parse(new File("src/main/resources/config.groovy").toURI().toURL()).toProperties();
} catch (MalformedURLException e) {
e.printStackTrace();
}
Properties systemProperties = System.getProperties();
System.out.println("\n[Properties reading] ---------------------------------------------------------");
for (Map.Entry entry : profileProperties.entrySet()) {
String key = String.valueOf(entry.getKey());
System.out.println(key + " = " + entry.getValue());
if (systemProperties.containsKey(key)) {
String value = systemProperties.getProperty(key);
if (!value.isEmpty()) {
profileProperties.setProperty(key, value);
System.out.println(key + " = " + entry.getValue() + " !!! corrected");
}
}
}
System.out.println("[Properties reading] ---------------------------------------------------------\n");
return profileProperties;
}
开发者ID:automician,项目名称:snippets,代码行数:32,代码来源:Helpers.java
示例4: parseConfiguration
import groovy.util.ConfigSlurper; //导入依赖的package包/类
/**
* Parse the groovy configuration file to retrieve the parameters for the annotator.
*
* @param configurationFile
* @throws IOException
*/
protected void parseConfiguration(File configurationFile) throws IOException {
ConfigSlurper configSlurper = new ConfigSlurper();
ConfigObject configObject = new ConfigSlurper().parse(FileUtils.readFileToString(configurationFile));
//Get the name and base configuration
annotatorName =(String)configObject.get("name");
ConfigObject configuration = (ConfigObject) configObject.get("configuration");
//Get the default parameters if specified
if(configuration.get("defaults") != null) {
this.defaults = (ConfigObject) configuration.get("defaults");
}
// Create the configuration maps and merge in any defaults. .
for (Object configurationKey: configuration.keySet()) {
String configurationName = (String)configurationKey;
// Defaults are handled outside of this loop.
if ("defaults".equals(configurationName)) {
continue;
}
if (configurationNameParametersMap.containsKey(configurationName)) {
throw new IllegalArgumentException("ConText configuration file has multiple configurations of the same name: '" + configurationName + "'.");
}
ConfigObject contextConfigObject = (ConfigObject) configuration.get(configurationName);
ConfigObject mergedConfigObject = contextConfigObject.clone();
mergeDefaults(mergedConfigObject, this.defaults);
configurationNameParametersMap.put(configurationName, mergedConfigObject);
}
}
开发者ID:Blulab-Utah,项目名称:ConText,代码行数:38,代码来源:AnnotatorConfiguration.java
示例5: createCompilerConfiguration
import groovy.util.ConfigSlurper; //导入依赖的package包/类
private CompilerConfiguration createCompilerConfiguration(ClassLoader cl) {
Closure customizer = null;
Properties properties = new Properties();
URL url = findConfigurationResource(cl);
if(url != null) {
log.trace("Configuring groovy compiler with ${url}");
try {
if(url.getFile().toLowerCase().endsWith(".groovy")) {
ConfigSlurper slurper = new ConfigSlurper();
slurper.setClassLoader(new GroovyClassLoader(cl));
ConfigObject cObject = slurper.parse(url);
Object c = cObject.remove("customizer");
if (c instanceof Closure<?>) {
customizer = (Closure) c;
}
properties.putAll(cObject.toProperties());
} else {
InputStream stream = url.openStream();
properties.load(stream);
}
} catch(Exception e) {
log.error("Error loading Groovy CompilerConfiguration properties from $url", e);
}
} else {
log.trace("No groovy configuration file found.");
}
CompilerConfiguration compilerCfg = new CompilerConfiguration(CompilerConfiguration.DEFAULT);
if(properties.size() != 0){
compilerCfg.configure(properties);
}
if (customizer != null) {
Object result = customizer.call(compilerCfg);
// Expectation: If result isn't a CompilerConfiguration, the original one has been modified
if(result instanceof CompilerConfiguration)
compilerCfg = (CompilerConfiguration) result;
}
return compilerCfg;
}
开发者ID:vert-x3,项目名称:vertx-lang-groovy,代码行数:41,代码来源:GroovyVerticleFactory.java
示例6: getListeners
import groovy.util.ConfigSlurper; //导入依赖的package包/类
/**
* Parse the groovy config files, and return the listener objects that are defined in them.
*
* @param configs the groovy config files to slurp
* @return the list of listeners that are defined in the groovy configs.
* @throws MalformedURLException if the configuration file url that was set is invalid.
*/
public static List<UimaAsBaseCallbackListener> getListeners(File...configs) throws MalformedURLException {
ConfigSlurper configSlurper = new ConfigSlurper();
List<UimaAsBaseCallbackListener> listeners = new ArrayList<UimaAsBaseCallbackListener>();
for (File config: configs) {
ConfigObject configObject = configSlurper.parse(config.toURI().toURL());
if (configObject.get("listener") != null ) {
listeners.add((UimaAsBaseCallbackListener) configObject.get("listener"));
}
}
return listeners;
}
开发者ID:department-of-veterans-affairs,项目名称:Leo,代码行数:20,代码来源:CommandLineClient.java
示例7: getReader
import groovy.util.ConfigSlurper; //导入依赖的package包/类
/**
* Parse the groovy config file, and return the reader object. This must be a BaseLeoCollectionReader.
*
* @param config the groovy config file to slurp
* @return the reader defined in the groovy config.
* @throws MalformedURLException if the configuration file url that was set is invalid.
*/
public static BaseLeoCollectionReader getReader(File config) throws MalformedURLException {
ConfigSlurper configSlurper = new ConfigSlurper();
ConfigObject configObject = configSlurper.parse(config.toURI().toURL());
if (configObject.get("reader") != null ) {
return (BaseLeoCollectionReader) configObject.get("reader");
}
return null;
}
开发者ID:department-of-veterans-affairs,项目名称:Leo,代码行数:17,代码来源:CommandLineClient.java
示例8: loadConfigFile
import groovy.util.ConfigSlurper; //导入依赖的package包/类
/**
* Load the config file(s).
*
* @param environment name of the environment to load
* @param configFilePaths paths the config files to load, local or remote
* @return ConfigObject with accumulated variables representing the environment
* @throws IOException if there is a problem reading the config files
*/
public static ConfigObject loadConfigFile(String environment, String... configFilePaths) throws IOException {
ConfigSlurper slurper = new ConfigSlurper(environment);
ConfigObject config = new ConfigObject();
ClassLoader cl = ClassLoader.getSystemClassLoader();
for (String filePath : configFilePaths) {
InputStream in = cl.getResourceAsStream(filePath);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
String resourceAsString = out.toString();
config.merge(slurper.parse(resourceAsString));
}
return config;
}
开发者ID:department-of-veterans-affairs,项目名称:Leo,代码行数:22,代码来源:LeoUtils.java
示例9: loadFromLocation
import groovy.util.ConfigSlurper; //导入依赖的package包/类
private void loadFromLocation(final ConfigSlurper slurper, final ConfigObject configObject, final String location) {
LOG.info("Load from: {}", location);
final ConfigObject cobj;
if (location.startsWith(LOCATION_PREFIX_CLASS)) {
cobj = loadFromClass(slurper, location.substring(LOCATION_PREFIX_CLASS.length()));
}
else {
cobj = loadFromResource(slurper, location);
}
if (cobj != null) {
resolveScriptValues(configObject, cobj);
configObject.merge(cobj);
}
}
开发者ID:ctzen,项目名称:slurper-configuration,代码行数:15,代码来源:Config.java
示例10: loadFromClass
import groovy.util.ConfigSlurper; //导入依赖的package包/类
private ConfigObject loadFromClass(final ConfigSlurper slurper, final String classname) {
final Class<?> scriptClass;
try {
scriptClass = resourceLoader.getClassLoader().loadClass(classname);
}
catch (final ClassNotFoundException e) {
LOG.warn("Class not found: {}", classname);
return null;
}
return slurper.parse(scriptClass);
}
开发者ID:ctzen,项目名称:slurper-configuration,代码行数:12,代码来源:Config.java
示例11: getConfig
import groovy.util.ConfigSlurper; //导入依赖的package包/类
public static Config getConfig(String env, File config) throws IOException {
ConfigObject configObject = new ConfigSlurper(env).parse(readGroovyConfigScript(config));
Config stormConf = new Config();
Map flatten = configObject.flatten();
stormConf.putAll(flatten);
Map<String, Class> dataTypes = new HashMap<String, Class>();
dataTypes.put("topology.workers", Integer.class);
dataTypes.put("topology.acker.executors", Integer.class);
dataTypes.put("topology.message.timeout.secs", Integer.class);
dataTypes.put("topology.max.task.parallelism", Integer.class);
dataTypes.put("topology.stats.sample.rate", Double.class);
// this will convert built in properties as storm uses old school properties
for (Field field : stormConf.getClass().getFields()) {
if (Modifier.isStatic(field.getModifiers())
&& Modifier.isPublic(field.getModifiers())) {
String property = field.getName().toLowerCase().replace('_', '.');
if (property.startsWith("java.")) {
// don't mess with Java system properties here
continue;
}
Object override = flatten.get(property);
if (override != null) {
stormConf.put(property, override);
System.out.println("Overrode property '" + property + "' with value [" + override + "] from Config.groovy of type " + override.getClass().getName());
}
String system = System.getProperty(property, null);
if (system != null) {
if (dataTypes.containsKey(property)) {
Class aClass = dataTypes.get(property);
try {
Method valueOf = aClass.getMethod("valueOf", String.class);
stormConf.put(property, valueOf.invoke(aClass, system));
System.out.println("Overrode property '" + property + "' with value [" + stormConf.get(property) + "] from -D System property of type " + aClass.getName());
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
} else {
stormConf.put(property, system);
System.out.println("Overrode property '" + property + "' with String value [" + system + "] from -D System property");
}
}
}
}
return stormConf;
}
开发者ID:lucidworks,项目名称:storm-solr,代码行数:50,代码来源:StreamingApp.java
注:本文中的groovy.util.ConfigSlurper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论