Package com.typesafe.config

Examples of com.typesafe.config.Config


            } else if (!configFile.canRead()) {
                log.error("Your configuration at {} is not readable, cannot continue without it.", configFile.getAbsoluteFile());
                throw new IllegalStateException("Unreadable configuration file " + configFile.getAbsolutePath());
            }
        }
        final Config config = ConfigFactory.parseFileAnySyntax(configFile);
        if (config.isEmpty() && !isTest) {
            log.error("Your configuration file at {} is empty, cannot continue without content.", configFile.getAbsoluteFile());
            throw new IllegalStateException("Empty configuration file " + configFile.getAbsolutePath());
        /*
         *
         * This is merging the standard bundled application.conf with our graylog2-web-interface.conf.
         * The application.conf must always be empty when packaged so there is nothing hidden from the user.
         * We are merging, because the Configuration object already contains some information the web-interface needs.
         *
         */
        }
        return new Configuration(
                config.withFallback(configuration.getWrappedConfiguration().underlying())
        );
    }
View Full Code Here


        .setExceptionHandler(faultTolerance)
        .setMetricRegistry(SharedMetricRegistries.getOrCreate(morphlineFileAndId))
        .build();
    }
   
    Config override = ConfigFactory.parseMap(context.getSubProperties(MORPHLINE_VARIABLE_PARAM + "."));
    morphline = new Compiler().compile(new File(morphlineFile), morphlineId, morphlineContext, finalChild, override);     
   
    this.mappingTimer = morphlineContext.getMetricRegistry().timer(
        MetricRegistry.name("morphline.app", Metrics.ELAPSED_TIME));
    this.numRecords = morphlineContext.getMetricRegistry().meter(
View Full Code Here

    start(app);
  }

  protected static Map<String, String> configuration() {
    Map<String, String> conf = new HashMap<String, String>();
    Config config = ConfigFactory.parseFileAnySyntax(new File(
        "conf/application.conf"));
    config = config.resolve();
    for (Entry<String, ConfigValue> entry : config.entrySet()) {
      ConfigValue value = entry.getValue();
      conf.put(entry.getKey(), value.unwrapped().toString());
    }
    conf.putAll(inMemoryDatabase());
    return conf;
View Full Code Here

  public static DrillConfig create(String overrideFileName) {
   
    overrideFileName = overrideFileName == null ? CommonConstants.CONFIG_OVERRIDE : overrideFileName;
   
    // first we load defaults.
    Config fallback = ConfigFactory.load(CommonConstants.CONFIG_DEFAULT);
    Collection<URL> urls = PathScanner.getConfigURLs();
    logger.debug("Loading configs at the following URLs {}", urls);
    for (URL url : urls) {
      fallback = ConfigFactory.parseURL(url).withFallback(fallback);
    }

    Config c = ConfigFactory.load(overrideFileName).withFallback(fallback).resolve();
    return new DrillConfig(c);
  }
View Full Code Here

    this.config = config;
  }

  private ActorSystem applicationSystem() {
    applicationSystemEnabled = true;
    Config akkaConf = ConfigFactory.load(config);
    ActorSystem system = ActorSystem.create("application", akkaConf);
    logger.info("Starting application default Akka system.");
    return system;
  }
View Full Code Here

public class ConfigParserTest {
    @Test
    public void testSerialize() throws ConfigException {
        ConfigParser configParser = new ConfigParser();
        Config config = ConfigFactory.load("default").resolve();
        System.out.println(config.toString());
        GreedConfig greedConfig = configParser.parseAndCheck("greed", config.getConfig("greed"), GreedConfig.class);
        System.out.println(StringUtil.join(greedConfig.getLanguage().get("java").getTemplateDef().get("source").getTransformers(), ", "));
        System.out.println(Arrays.toString(greedConfig.getLanguage().get("java").getTemplateDef().get("source").getDependencies()));
        System.out.println(greedConfig.getLanguage().get("java").getTemplateDef().get("testcase").getOverwrite());
        System.out.println("done");
    }
View Full Code Here

import org.junit.Test;

public class ConfigTest {
    @Test
    public void configValidationTest() {
        Config conf = ConfigFactory.load("default");
        conf = conf.resolve();
        if (conf.hasPath("greed"))
            System.out.println(conf.getConfig("greed").toString());
    }
View Full Code Here

        if (!(obj instanceof Config) && !(obj instanceof ConfigObject)) {
            throw new ConfigException(String.format("Config object needed, %s found", obj.getClass().getSimpleName()));
        }

        Config rawConf = (obj instanceof ConfigObject) ? ((ConfigObject) obj).toConfig() : (Config) obj;
        HashSet<String> hasSet = new HashSet<String>();
        try {
            T configObject = configClass.newInstance();
            for (Field field: configClass.getDeclaredFields()) {

                if (field.isSynthetic()) {
                    // ignore synthetic fields (e.g. eclEmma)
                    continue;
                }

                if (!rawConf.hasPath(field.getName())) {
                    if (field.isAnnotationPresent(Required.class))
                        throw new ConfigException(String.format("Missing required config key at %s.%s", path, field.getName()));
                    continue;
                }

                Method setter = ReflectionUtil.findSetter(configClass, field);
                if (setter == null) {
                    throw new ConfigException(String.format("FATAL: Unable to find setter for %s in class %s", field.getName(), configClass.getName()));
                }

                IParser parser = null;
                if (field.isAnnotationPresent(Parser.class)) {
                    Class<? extends IParser> parserClass = field.getAnnotation(Parser.class).value();
                    parser = parserClass.newInstance();
                }

                Class<?> fieldType = field.getType();
                hasSet.add(field.getName());
                if (fieldType.isPrimitive() || String.class.equals(fieldType) || fieldType.isEnum()) {
                    setter.invoke(configObject,
                            parser != null ? parser.apply(rawConf.getAnyRef(field.getName())) : parseAndCheck(path + "." + field.getName(), rawConf.getAnyRef(field.getName()), fieldType));
                }
                else if (fieldType.isArray()) {
                    Class<?> elementType = fieldType.getComponentType();
                    List<?> rawValues = rawConf.getAnyRefList(field.getName());
                    Object values = Array.newInstance(elementType, rawValues.size());
                    int idx = 0;
                    for (Object rv: rawValues) {
                        Array.set(values, idx,
                                parser != null ? parser.apply(rv) : parseAndCheck(String.format("%s.[%d]", path, idx), rv, elementType));
                        idx++;
                    }
                    setter.invoke(configObject, values);
                }
                else if (field.isAnnotationPresent(MapParam.class)) {
                    HashMap<Object, Object> map = new HashMap<Object, Object>();
                    Class<?> valueClass = field.getAnnotation(MapParam.class).value();
                    for (Map.Entry<String, ConfigValue> entry : rawConf.getObject(field.getName()).entrySet()) {
                        map.put(entry.getKey(),
                                parser != null ? parser.apply(entry.getValue()) : parseAndCheck(path + "." + field.getName() + "." + entry.getKey(), entry.getValue(), valueClass));
                    }
                    setter.invoke(configObject, map);
                }
                else if (fieldType.isAnnotationPresent(ConfigObjectClass.class)) {
                    setter.invoke(configObject, parseAndCheck(path + "." + field.getName(), rawConf.getConfig(field.getName()), fieldType));
                }
                else if (parser != null) {
                    setter.invoke(configObject, parser.apply(rawConf.getAnyRef(field.getName())));
                }
                else {
                    throw new ConfigException(String.format("Field %s with unknown type %s at path %s", field.getName(), fieldType.getSimpleName(), path));
                }
            }
View Full Code Here

    }

    private static final String DEFAULT_USER_CONFIG_FILENAME = "greed.conf";

    static GreedConfig loadConfig() throws ConfigException {
        Config conf = ConfigFactory.parseResources(Configuration.class.getClassLoader(), "default.conf");

        if (!Modes.testMode) {
            // User configuration will not be loaded in test mode
            String workspace = getWorkspace();
            File userConfFile = new File(workspace, DEFAULT_USER_CONFIG_FILENAME);
            if (userConfFile.exists()) {
                Config userConf = ConfigFactory.parseFile(userConfFile);
                conf = userConf.withFallback(conf);
            }
        }

        conf = conf.resolve();
        return new ConfigParser().parseAndCheck("greed", conf.getConfig("greed"), GreedConfig.class);
View Full Code Here

    String morphlineFile = context.getString(MORPHLINE_FILE_PARAM);
    String morphlineId = context.getString(MORPHLINE_ID_PARAM);
    if (morphlineFile == null || morphlineFile.trim().length() == 0) {
      throw new MorphlineCompilationException("Missing parameter: " + MORPHLINE_FILE_PARAM, null);
    }
    Config override = ConfigFactory.parseMap(context.getSubProperties(MORPHLINE_VARIABLE_PARAM + "."));
    morphline = new Compiler().compile(new File(morphlineFile), morphlineId, morphlineContext, finalChild, override);     
    morphlineFileAndId = morphlineFile + "@" + morphlineId;
  }
View Full Code Here

TOP

Related Classes of com.typesafe.config.Config

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.