com.typesafe.config.Config.root()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(277)

本文整理了Java中com.typesafe.config.Config.root()方法的一些代码示例,展示了Config.root()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.root()方法的具体详情如下:
包路径:com.typesafe.config.Config
类名称:Config
方法名:root

Config.root介绍

[英]Gets the Config as a tree of ConfigObject. This is a constant-time operation (it is not proportional to the number of values in the Config).
[中]将配置作为ConfigObject的树获取。这是一个恒定时间操作(与配置中的值数量不成正比)。

代码示例

代码示例来源:origin: apache/incubator-pinot

public ConfigObject include(ConfigIncludeContext context, String what) {
 File file = new File(what);
 // Attempt to locate the file
 if (!file.exists()) {
  file = new File("profiles", what);
 }
 return ConfigFactory.parseFileAnySyntax(file).root();
}

代码示例来源:origin: apache/incubator-pinot

public ConfigObject include(ConfigIncludeContext context, String what) {
 return ConfigFactory.parseFileAnySyntax(new File(what)).root();
}

代码示例来源:origin: jooby-project/jooby

@Override
public Set<Entry<String, Object>> propertySet(final Object context) {
 if (context instanceof Config) {
  return ((Config) context).root().unwrapped().entrySet();
 }
 return Collections.emptySet();
}

代码示例来源:origin: apache/incubator-pinot

public ConfigObject include(ConfigIncludeContext context, String what) {
 return ConfigFactory.parseFileAnySyntax(new File(what)).root();
}

代码示例来源:origin: mpusher/mpush

static boolean init() {
  if (logInit) return true;
  System.setProperty("log.home", CC.mp.log_dir);
  System.setProperty("log.root.level", CC.mp.log_level);
  System.setProperty("logback.configurationFile", CC.mp.log_conf_path);
  LoggerFactory
      .getLogger("console")
      .info(CC.mp.cfg.root().render(ConfigRenderOptions.concise().setFormatted(true)));
  return true;
}

代码示例来源:origin: OryxProject/oryx

static List<String> buildPropertiesLines() {
 ConfigObject config = (ConfigObject) ConfigUtils.getDefault().root().get("oryx");
 Map<String,String> keyValueMap = new TreeMap<>();
 add(config, "oryx", keyValueMap);
 return keyValueMap.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.toList());
}

代码示例来源:origin: jooby-project/jooby

private Iterable<String> names(final Config conf) {
 Set<String> result = new LinkedHashSet<>();
 conf.root().forEach((k, v) -> result.add(ConfigUtil.splitPath(k).get(0)));
 return result;
}

代码示例来源:origin: mpusher/mpush

@Test
public void testLoad2() {
  Map<String, String> map = new HashMap<>();
  System.out.println("public interface mp {");
  System.out.printf("  Config cfg = ConfigManager.I.mp().toConfig();%n%n");
  CC.mp.cfg.root().forEach((s, configValue) -> print2(s, configValue, "mp", 1));
  System.out.println("}");
}

代码示例来源:origin: apache/incubator-gobblin

@SuppressWarnings("unchecked")
 private VersionSelectionPolicy<T> createSelectionPolicy(String className, Config config, Properties jobProps) {
  try {
   this.log.debug(String.format("Configuring selection policy %s for %s with %s", className, this.datasetRoot,
     config.root().render(ConfigRenderOptions.concise())));
   return (VersionSelectionPolicy<T>) GobblinConstructorUtils.invokeFirstConstructor(Class.forName(className),
     ImmutableList.<Object> of(config), ImmutableList.<Object> of(config, jobProps),
     ImmutableList.<Object> of(jobProps));
  } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException
    | ClassNotFoundException e) {
   throw new IllegalArgumentException(e);
  }
 }
}

代码示例来源:origin: jooby-project/jooby

static Config flyway(Config conf) {
 Config flyway = conf.root().entrySet().stream()
   .filter(it -> isFlywayProperty(it.getKey()))
   .reduce(empty(), (seed, entry) -> seed.withValue(entry.getKey(), entry.getValue()),
     Config::withFallback);
 return flyway;
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public MultiAccessControlAction createRetentionAction(Config config, FileSystem fs, Config jobConfig) {
 Preconditions.checkArgument(this.canCreateWithConfig(config),
   "Can not create MultiAccessControlAction with config " + config.root().render(ConfigRenderOptions.concise()));
 if (config.hasPath(LEGACY_ACCESS_CONTROL_KEY)) {
  return new MultiAccessControlAction(config.getConfig(LEGACY_ACCESS_CONTROL_KEY), fs, jobConfig);
 } else if (config.hasPath(ACCESS_CONTROL_KEY)) {
  return new MultiAccessControlAction(config.getConfig(ACCESS_CONTROL_KEY), fs, jobConfig);
 }
 throw new IllegalStateException(
   "RetentionActionFactory.canCreateWithConfig returned true but could not create MultiAccessControlAction");
}

代码示例来源:origin: apache/incubator-gobblin

public void saveConfigToFile(final Config config, final Path destPath)
  throws IOException {
 final String configAsHoconString = config.root().render();
 this.fileUtils.saveToFile(configAsHoconString, destPath);
}

代码示例来源:origin: apache/drill

@VisibleForTesting
public DrillConfig(Config config) {
 super(config);
 logger.debug("Setting up DrillConfig object.");
 // we need to exclude sun.java.command config node while logging, because
 // it contains user password along with other parameters
 logger.trace("Given Config object is:\n{}", config.withoutPath("password").withoutPath("sun.java.command")
        .root().render(ConfigRenderOptions.defaults()));
 RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
 this.startupArguments = ImmutableList.copyOf(bean.getInputArguments());
 logger.debug("DrillConfig object initialized.");
}

代码示例来源:origin: OryxProject/oryx

/**
 * @param config {@link Config} to print
 * @return pretty-printed version of config values, excluding those
 *  inherited from the local JVM environment
 */
public static String prettyPrint(Config config) {
 return redact(config.root().withOnlyKey("oryx").render(RENDER_OPTS));
}

代码示例来源:origin: OryxProject/oryx

/**
 * @param config {@link Config} to serialize to a String
 * @return JSON-like representation of properties in the configuration, excluding those
 *  inherited from the local JVM environment
 */
public static String serialize(Config config) {
 return config.root().withOnlyKey("oryx").render(ConfigRenderOptions.concise());
}

代码示例来源:origin: ethereum/ethereumj

public String dump() {
  return config.root().render(ConfigRenderOptions.defaults().setComments(false));
}

代码示例来源:origin: apache/incubator-gobblin

private void writeJobConf(String jobName, Config jobConfig) throws IOException {
 String targetPath = this.jobConfigPath + "/" + jobName + ".conf";
 String renderedConfig = jobConfig.root().render(ConfigRenderOptions.defaults());
 try (DataOutputStream os = new DataOutputStream(new FileOutputStream(targetPath));
   Writer writer = new OutputStreamWriter(os, Charsets.UTF_8)) {
  writer.write(renderedConfig);
 }
}

代码示例来源:origin: spotify/apollo

@Override
public synchronized Model.LoadedConfig loadedConfig() {
 return new LoadedConfigBuilder()
   .spNode(filteredConfig().root())
   .build();
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public void run(String[] args) throws Exception {
 CliObjectFactory<Command> factory = new ConstructorAndPublicMethodsCliObjectFactory<>(Command.class);
 Command command = factory.buildObject(args, 1, true, args[0]);
 ConfigClient configClient = ConfigClient.createConfigClient(VersionStabilityPolicy.READ_FRESHEST);
 if (command.resolvedConfig) {
  Config resolvedConfig = configClient.getConfig(command.uri);
  System.out.println(resolvedConfig.root().render(ConfigRenderOptions.defaults()));
 }
}

代码示例来源:origin: apache/incubator-pinot

public static <T> String serializeToString(T object) {
 Config config = ConfigFactory.parseMap(serialize(object).toJavaMap());
 return config.root().render(ConfigRenderOptions.defaults().setJson(false).setOriginComments(false));
}

相关文章