play.Environment类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(169)

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

Environment介绍

[英]The environment for the application. Captures concerns relating to the classloader and the filesystem for the application.
[中]应用程序的环境。捕获与应用程序的类加载器和文件系统相关的问题。

代码示例

代码示例来源:origin: com.typesafe.play/play_2.12

  1. @Override
  2. public void configure(Environment env) {
  3. delegate.configure(env.asScala());
  4. }

代码示例来源:origin: com.typesafe.play/play_2.11

  1. /**
  2. * A simple environment.
  3. *
  4. * Uses the same classloader that the environment classloader is defined in,
  5. * the current working directory as the path and test mode.
  6. *
  7. * @return the environment
  8. */
  9. public static Environment simple() {
  10. return new Environment(new File("."), Environment.class.getClassLoader(), Mode.TEST);
  11. }

代码示例来源:origin: com.typesafe.play/play_2.12

  1. /**
  2. * Convert the given exception to an exception that Play can report more information about.
  3. * <p>
  4. * This will generate an id for the exception, and in dev mode, will load the source code for the code that threw the
  5. * exception, making it possible to report on the location that the exception was thrown from.
  6. */
  7. protected final UsefulException throwableToUsefulException(final Throwable throwable) {
  8. return HttpErrorHandlerExceptions.throwableToUsefulException(sourceMapper.sourceMapper(), environment.isProd(), throwable);
  9. }

代码示例来源:origin: com.typesafe.play/play_2.10

  1. /**
  2. * Returns `true` if the application is `DEV` mode.
  3. */
  4. public boolean isDev() {
  5. return mode().equals(Mode.DEV);
  6. }

代码示例来源:origin: com.typesafe.play/play-ebean

  1. @Override
  2. public Map<String, List<String>> apply(ClassLoader classLoader) {
  3. // Using TEST mode is the only way to load configuration without failing if application.conf doesn't exist
  4. Environment env = new Environment(new File("."), classLoader, Mode.TEST);
  5. Config config = ConfigFactory.load(env.classLoader());
  6. return EbeanParsedConfig.parseFromConfig(config).getDatasourceModels();
  7. }
  8. }

代码示例来源:origin: stackoverflow.com

  1. public class CustomApplicationLoader extends GuiceApplicationLoader {
  2. @Override
  3. public GuiceApplicationBuilder builder(ApplicationLoader.Context context) {
  4. final Environment environment = context.environment();
  5. GuiceApplicationBuilder builder = initialBuilder.in(environment);
  6. Configuration config = context.initialConfiguration();
  7. if (environment.isTest()) {
  8. config = merge("test.conf", config);
  9. builder = builder.bindings(new TestModule());
  10. } else if (environment.isDev()) {
  11. config = merge("dev.conf", config);
  12. builder = builder.bindings(new DevModule());
  13. } else if (environment.isProd()) {
  14. config = merge("prod.conf", config);
  15. builder = builder.bindings(new DevModule());
  16. } else {
  17. throw new IllegalStateException("No such mode.");
  18. }
  19. return builder.in(environment).loadConfig(config);
  20. }
  21. private Configuration merge(String configName, Configuration currentConfig) {
  22. return new Configuration(currentConfig.getWrappedConfiguration().$plus$plus(new play.api.Configuration(ConfigFactory.load(configName))));
  23. }
  24. }

代码示例来源:origin: com.typesafe.play/play-ebean

  1. private static Reflections getReflections(Environment env, String packageName) {
  2. // This is not supposed to happen very often, but just when starting the application.
  3. // So it should be okay to not have a cache.
  4. return new Reflections(getReflectionsConfiguration(packageName, env.classLoader()));
  5. }

代码示例来源:origin: com.typesafe.play/play-ebean

  1. /**
  2. * Generate evolutions.
  3. */
  4. @Override
  5. public void create() {
  6. if (!environment.isProd()) {
  7. config.serverConfigs().forEach((key, serverConfig) -> {
  8. String evolutionScript = generateEvolutionScript(servers.get(key));
  9. if (evolutionScript != null) {
  10. File evolutions = environment.getFile("conf/evolutions/" + key + "/1.sql");
  11. try {
  12. String content = "";
  13. if (evolutions.exists()) {
  14. content = new String(Files.readAllBytes(evolutions.toPath()), "utf-8");
  15. }
  16. if (content.isEmpty() || content.startsWith("# --- Created by Ebean DDL")) {
  17. environment.getFile("conf/evolutions/" + key).mkdirs();
  18. if (!content.equals(evolutionScript)) {
  19. Files.write(evolutions.toPath(), evolutionScript.getBytes("utf-8"));
  20. }
  21. }
  22. } catch (IOException e) {
  23. throw new RuntimeException(e);
  24. }
  25. }
  26. });
  27. }
  28. }

代码示例来源:origin: com.typesafe.play/play-java_2.10

  1. private static Reflections getReflections(Environment env, String packageName) {
  2. if (env.isTest()) {
  3. return ReflectionsCache$.MODULE$.getReflections(env.classLoader(), packageName);
  4. } else {
  5. return new Reflections(getReflectionsConfiguration(packageName, env.classLoader()));
  6. }
  7. }

代码示例来源:origin: com.typesafe.play/play_2.10

  1. /**
  2. * Load a new configuration from an environment.
  3. */
  4. public static Configuration load(Environment env) {
  5. return new Configuration(play.api.Configuration.load(env.underlying()));
  6. }

代码示例来源:origin: com.typesafe.play/play_2.11

  1. /**
  2. * Returns `true` if the application is `TEST` mode.
  3. *
  4. * @return `true` if the application is `TEST` mode.
  5. */
  6. public boolean isTest() {
  7. return mode().equals(Mode.TEST);
  8. }

代码示例来源:origin: com.github.rmannibucau/playx-servlet

  1. @Override
  2. public ClassLoader getClassLoader() {
  3. return injector.instanceOf(Environment.class).classLoader();
  4. }

代码示例来源:origin: com.typesafe.play/play_2.10

  1. /**
  2. * The context for loading an application.
  3. *
  4. * @param environment the application environment
  5. * @param initialSettings the initial settings. These settings are merged with the settings from the loaded
  6. * configuration files, and together form the initialConfiguration provided by the context. It
  7. * is intended for use in dev mode, to allow the build system to pass additional configuration
  8. * into the application.
  9. */
  10. public Context(Environment environment, Map<String,Object> initialSettings) {
  11. this.underlying = new play.api.ApplicationLoader.Context(
  12. environment.underlying(),
  13. scala.Option.empty(),
  14. new play.core.DefaultWebCommands(),
  15. play.api.Configuration.load(environment.underlying(), play.libs.Scala.asScala(initialSettings)));
  16. }

代码示例来源:origin: com.typesafe.play/play_2.11

  1. @Override
  2. public void configure(Environment env) {
  3. delegate.configure(env.asScala());
  4. }

代码示例来源:origin: com.typesafe.play/play

  1. /**
  2. * A simple environment.
  3. *
  4. * Uses the same classloader that the environment classloader is defined in,
  5. * the current working directory as the path and test mode.
  6. *
  7. * @return the environment
  8. */
  9. public static Environment simple() {
  10. return new Environment(new File("."), Environment.class.getClassLoader(), Mode.TEST);
  11. }

代码示例来源:origin: com.typesafe.play/play_2.12

  1. /**
  2. * Convert the given exception to an exception that Play can report more information about.
  3. * <p>
  4. * This will generate an id for the exception, and in dev mode, will load the source code for the code that threw the
  5. * exception, making it possible to report on the location that the exception was thrown from.
  6. */
  7. protected final UsefulException throwableToUsefulException(final Throwable throwable) {
  8. return HttpErrorHandlerExceptions.throwableToUsefulException(sourceMapper.sourceMapper(), environment.isProd(), throwable);
  9. }

代码示例来源:origin: com.typesafe.play/play_2.11

  1. /**
  2. * Returns `true` if the application is `PROD` mode.
  3. *
  4. * @return `true` if the application is `PROD` mode.
  5. */
  6. public boolean isProd() {
  7. return mode().equals(Mode.PROD);
  8. }

代码示例来源:origin: com.typesafe.play/play-ebean

  1. private void addModelClassesToServerConfig(String key, ServerConfig serverConfig, Set<String> classes) {
  2. for (String clazz: classes) {
  3. try {
  4. serverConfig.addClass(Class.forName(clazz, true, environment.classLoader()));
  5. } catch (Exception e) {
  6. throw new ConfigException.BadValue(
  7. "ebean." + key,
  8. "Cannot register class [" + clazz + "] in Ebean server",
  9. e
  10. );
  11. }
  12. }
  13. }

代码示例来源:origin: com.typesafe.play/play_2.10

  1. /**
  2. * Create a new context with a different environment.
  3. */
  4. public Context withEnvironment(Environment environment) {
  5. play.api.ApplicationLoader.Context scalaContext = new play.api.ApplicationLoader.Context(
  6. environment.underlying(),
  7. underlying.sourceMapper(),
  8. underlying.webCommands(),
  9. underlying.initialConfiguration());
  10. return new Context(scalaContext);
  11. }

代码示例来源:origin: com.typesafe.play/play

  1. @Override
  2. public void configure(Environment env) {
  3. delegate.configure(env.asScala());
  4. }

相关文章