Java Code Examples for com.typesafe.config.Config#checkValid()

The following examples show how to use com.typesafe.config.Config#checkValid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Compiler.java    From kite with Apache License 2.0 8 votes vote down vote up
/** Loads the given config file from the local file system */
public Config parse(File file, Config... overrides) throws IOException {
  if (file == null || file.getPath().trim().length() == 0) {
    throw new MorphlineCompilationException("Missing morphlineFile parameter", null);
  }
  if (!file.exists()) {
    throw new FileNotFoundException("File not found: " + file);
  }
  if (!file.canRead()) {
    throw new IOException("Insufficient permissions to read file: " + file);
  }
  Config config = ConfigFactory.parseFile(file);
  for (Config override : overrides) {
    config = override.withFallback(config);
  }
  
  synchronized (LOCK) {
    ConfigFactory.invalidateCaches();
    config = ConfigFactory.load(config);
    config.checkValid(ConfigFactory.defaultReference()); // eagerly validate aspects of tree config
  }
  return config;
}
 
Example 2
Source File: S2Controller.java    From ocraft-s2client with MIT License 6 votes vote down vote up
Config getGameConfiguration() {

            Config referenceConfig = cfg();

            Config customConfig = builderConfig();
            String customPath = customConfig.hasPath(GAME_EXE_PATH) ? customConfig.getString(GAME_EXE_PATH) : null;
            String customDataVersion = customConfig.hasPath(GAME_EXE_DATA_VER)
                    ? customConfig.getString(GAME_EXE_DATA_VER)
                    : null;
            String customBaseBuild = customConfig.hasPath(GAME_EXE_BUILD)
                    ? customConfig.getString(GAME_EXE_BUILD)
                    : null;

            Map<String, Object> executableConfig = ExecutableParser.loadSettings(
                    customPath, customDataVersion, customBaseBuild);

            Config gameConfig = ConfigFactory.parseMap(executableConfig).withFallback(customConfig);
            gameConfig.checkValid(referenceConfig);

            return gameConfig;
        }
 
Example 3
Source File: DremioConfig.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void check(){
  final Config inner = getInnerConfig();
  final Config ref = reference.resolve();

  // make sure types are right
  inner.checkValid(ref);

  // make sure we don't have any extra paths. these are typically typos.
  List<String> invalidPaths = new ArrayList<>();
  for(Entry<String, ConfigValue> entry : inner.entrySet()){
    if(!ref.hasPath(entry.getKey())){
      invalidPaths.add(entry.getKey());
    }
  }

  if(!invalidPaths.isEmpty()){
    StringBuilder sb = new StringBuilder();
    sb.append("Failure reading configuration file. The following properties were invalid:\n");
    for(String s : invalidPaths){
      sb.append("\t");
      sb.append(s);
      sb.append("\n");
    }

    throw new RuntimeException(sb.toString());
  }
}
 
Example 4
Source File: Settings.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
private static Config readConfig() {
  Config config = ConfigFactory.load();
  config.checkValid(ConfigFactory.defaultReference(), CONFIG_ROOT);

  return config.getConfig(CONFIG_ROOT);
}