本文整理了Java中play.Environment
类的一些代码示例,展示了Environment
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment
类的具体详情如下:
包路径:play.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
@Override
public void configure(Environment env) {
delegate.configure(env.asScala());
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* A simple environment.
*
* Uses the same classloader that the environment classloader is defined in,
* the current working directory as the path and test mode.
*
* @return the environment
*/
public static Environment simple() {
return new Environment(new File("."), Environment.class.getClassLoader(), Mode.TEST);
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Convert the given exception to an exception that Play can report more information about.
* <p>
* This will generate an id for the exception, and in dev mode, will load the source code for the code that threw the
* exception, making it possible to report on the location that the exception was thrown from.
*/
protected final UsefulException throwableToUsefulException(final Throwable throwable) {
return HttpErrorHandlerExceptions.throwableToUsefulException(sourceMapper.sourceMapper(), environment.isProd(), throwable);
}
代码示例来源:origin: com.typesafe.play/play_2.10
/**
* Returns `true` if the application is `DEV` mode.
*/
public boolean isDev() {
return mode().equals(Mode.DEV);
}
代码示例来源:origin: com.typesafe.play/play-ebean
@Override
public Map<String, List<String>> apply(ClassLoader classLoader) {
// Using TEST mode is the only way to load configuration without failing if application.conf doesn't exist
Environment env = new Environment(new File("."), classLoader, Mode.TEST);
Config config = ConfigFactory.load(env.classLoader());
return EbeanParsedConfig.parseFromConfig(config).getDatasourceModels();
}
}
代码示例来源:origin: stackoverflow.com
public class CustomApplicationLoader extends GuiceApplicationLoader {
@Override
public GuiceApplicationBuilder builder(ApplicationLoader.Context context) {
final Environment environment = context.environment();
GuiceApplicationBuilder builder = initialBuilder.in(environment);
Configuration config = context.initialConfiguration();
if (environment.isTest()) {
config = merge("test.conf", config);
builder = builder.bindings(new TestModule());
} else if (environment.isDev()) {
config = merge("dev.conf", config);
builder = builder.bindings(new DevModule());
} else if (environment.isProd()) {
config = merge("prod.conf", config);
builder = builder.bindings(new DevModule());
} else {
throw new IllegalStateException("No such mode.");
}
return builder.in(environment).loadConfig(config);
}
private Configuration merge(String configName, Configuration currentConfig) {
return new Configuration(currentConfig.getWrappedConfiguration().$plus$plus(new play.api.Configuration(ConfigFactory.load(configName))));
}
}
代码示例来源:origin: com.typesafe.play/play-ebean
private static Reflections getReflections(Environment env, String packageName) {
// This is not supposed to happen very often, but just when starting the application.
// So it should be okay to not have a cache.
return new Reflections(getReflectionsConfiguration(packageName, env.classLoader()));
}
代码示例来源:origin: com.typesafe.play/play-ebean
/**
* Generate evolutions.
*/
@Override
public void create() {
if (!environment.isProd()) {
config.serverConfigs().forEach((key, serverConfig) -> {
String evolutionScript = generateEvolutionScript(servers.get(key));
if (evolutionScript != null) {
File evolutions = environment.getFile("conf/evolutions/" + key + "/1.sql");
try {
String content = "";
if (evolutions.exists()) {
content = new String(Files.readAllBytes(evolutions.toPath()), "utf-8");
}
if (content.isEmpty() || content.startsWith("# --- Created by Ebean DDL")) {
environment.getFile("conf/evolutions/" + key).mkdirs();
if (!content.equals(evolutionScript)) {
Files.write(evolutions.toPath(), evolutionScript.getBytes("utf-8"));
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
}
代码示例来源:origin: com.typesafe.play/play-java_2.10
private static Reflections getReflections(Environment env, String packageName) {
if (env.isTest()) {
return ReflectionsCache$.MODULE$.getReflections(env.classLoader(), packageName);
} else {
return new Reflections(getReflectionsConfiguration(packageName, env.classLoader()));
}
}
代码示例来源:origin: com.typesafe.play/play_2.10
/**
* Load a new configuration from an environment.
*/
public static Configuration load(Environment env) {
return new Configuration(play.api.Configuration.load(env.underlying()));
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Returns `true` if the application is `TEST` mode.
*
* @return `true` if the application is `TEST` mode.
*/
public boolean isTest() {
return mode().equals(Mode.TEST);
}
代码示例来源:origin: com.github.rmannibucau/playx-servlet
@Override
public ClassLoader getClassLoader() {
return injector.instanceOf(Environment.class).classLoader();
}
代码示例来源:origin: com.typesafe.play/play_2.10
/**
* The context for loading an application.
*
* @param environment the application environment
* @param initialSettings the initial settings. These settings are merged with the settings from the loaded
* configuration files, and together form the initialConfiguration provided by the context. It
* is intended for use in dev mode, to allow the build system to pass additional configuration
* into the application.
*/
public Context(Environment environment, Map<String,Object> initialSettings) {
this.underlying = new play.api.ApplicationLoader.Context(
environment.underlying(),
scala.Option.empty(),
new play.core.DefaultWebCommands(),
play.api.Configuration.load(environment.underlying(), play.libs.Scala.asScala(initialSettings)));
}
代码示例来源:origin: com.typesafe.play/play_2.11
@Override
public void configure(Environment env) {
delegate.configure(env.asScala());
}
代码示例来源:origin: com.typesafe.play/play
/**
* A simple environment.
*
* Uses the same classloader that the environment classloader is defined in,
* the current working directory as the path and test mode.
*
* @return the environment
*/
public static Environment simple() {
return new Environment(new File("."), Environment.class.getClassLoader(), Mode.TEST);
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Convert the given exception to an exception that Play can report more information about.
* <p>
* This will generate an id for the exception, and in dev mode, will load the source code for the code that threw the
* exception, making it possible to report on the location that the exception was thrown from.
*/
protected final UsefulException throwableToUsefulException(final Throwable throwable) {
return HttpErrorHandlerExceptions.throwableToUsefulException(sourceMapper.sourceMapper(), environment.isProd(), throwable);
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Returns `true` if the application is `PROD` mode.
*
* @return `true` if the application is `PROD` mode.
*/
public boolean isProd() {
return mode().equals(Mode.PROD);
}
代码示例来源:origin: com.typesafe.play/play-ebean
private void addModelClassesToServerConfig(String key, ServerConfig serverConfig, Set<String> classes) {
for (String clazz: classes) {
try {
serverConfig.addClass(Class.forName(clazz, true, environment.classLoader()));
} catch (Exception e) {
throw new ConfigException.BadValue(
"ebean." + key,
"Cannot register class [" + clazz + "] in Ebean server",
e
);
}
}
}
代码示例来源:origin: com.typesafe.play/play_2.10
/**
* Create a new context with a different environment.
*/
public Context withEnvironment(Environment environment) {
play.api.ApplicationLoader.Context scalaContext = new play.api.ApplicationLoader.Context(
environment.underlying(),
underlying.sourceMapper(),
underlying.webCommands(),
underlying.initialConfiguration());
return new Context(scalaContext);
}
代码示例来源:origin: com.typesafe.play/play
@Override
public void configure(Environment env) {
delegate.configure(env.asScala());
}
内容来源于网络,如有侵权,请联系作者删除!