本文整理了Java中org.jooby.Env.name()
方法的一些代码示例,展示了Env.name()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Env.name()
方法的具体详情如下:
包路径:org.jooby.Env
类名称:Env
方法名:name
暂无
代码示例来源:origin: jooby-project/jooby
/**
* Runs the callback function if the current env matches the given name.
*
* @param name A name to test for.
* @param fn A callback function.
* @param <T> A resulting type.
* @return A resulting object.
*/
@Nonnull
default <T> Optional<T> ifMode(final String name, final Supplier<T> fn) {
if (name().equals(name)) {
return Optional.of(fn.get());
}
return Optional.empty();
}
代码示例来源:origin: jooby-project/jooby
public RouteMetadata(final Env env) {
CacheLoader<Class<?>, Map<String, Object>> loader = CacheLoader
.from(RouteMetadata::extractMetadata);
cache = env.name().equals("dev")
? CacheBuilder.newBuilder().maximumSize(0).build(loader)
: CacheBuilder.newBuilder().build(loader);
}
代码示例来源:origin: jooby-project/jooby
private static List<Object> processEnvDep(final Set<Object> src, final Env env) {
List<Object> result = new ArrayList<>();
List<Object> bag = new ArrayList<>(src);
bag.forEach(it -> {
if (it instanceof EnvDep) {
EnvDep envdep = (EnvDep) it;
if (envdep.predicate.test(env.name())) {
int from = src.size();
envdep.callback.accept(env.config());
int to = src.size();
result.addAll(new ArrayList<>(src).subList(from, to));
}
} else {
result.add(it);
}
});
return result;
}
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
boolean whoops = conf.hasPath("whoops.enabled")
? conf.getBoolean("whoops.enabled")
: "dev".equals(env.name());
if (whoops) {
ClassLoader loader = env.router().getClass().getClassLoader();
Handler handler = prettyPage(loader, SourceLocator.local(), maxFrameSize, log);
env.router().err(tryPage(handler, log));
}
}
代码示例来源:origin: jooby-project/jooby
@Override public void configure(final Env env, final Config conf, final Binder binder)
throws Exception {
boolean useFile = Stream.of(swaggerOptions, ramlOptions)
.filter(Objects::nonNull)
.filter(it -> it.file != null)
.findFirst()
.isPresent();
Throwing.Function<Set<Route.Definition>, List<RouteMethod>> provider = null;
if (!useFile) {
Path dir = Optional.ofNullable(basedir).orElse(Paths.get(conf.getString("user.dir")));
ApiParser parser = new ApiParser(dir, filter);
customizer.forEach(parser::modify);
provider = routes -> parser
.parseFully(conf.getString("application.class"), new ArrayList<>(routes));
if (!env.name().equals("dev")) {
provider = provider.memoized();
}
binder.bind(ApiParser.class).toInstance(parser);
}
String contextPath = conf.getString("application.path");
if (swaggerOptions != null) {
swagger(contextPath, env.router(), swaggerOptions, conf, swagger, provider);
}
if (ramlOptions != null) {
raml(contextPath, env.router(), ramlOptions, raml, provider);
}
}
代码示例来源:origin: jooby-project/jooby
if ("dev".equals(env.name()) || config.getString("hbs.cache").isEmpty()) {
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config conf, final Binder binder) throws Throwable {
ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
boolean cacheable = !env.name().equals("dev");
/** Defaults: */
resolver.setCacheable(cacheable);
resolver.setPrefix(prefix);
resolver.setSuffix(suffix);
resolver.setTemplateMode(TemplateMode.HTML);
TemplateEngine engine = new TemplateEngine();
engine.setTemplateResolver(resolver);
if (callback != null) {
callback.accept(engine, conf);
}
binder.bind(TemplateEngine.class).toInstance(engine);
binder.bind(ITemplateEngine.class).toInstance(engine);
Multibinder.newSetBinder(binder, Renderer.class)
.addBinding()
.toInstance(new ThlEngine(engine, env));
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
JadeConfiguration jadeconf = new JadeConfiguration();
boolean dev = env.name().equals("dev");
boolean caching = conf.hasPath("jade.caching")
? conf.getBoolean("jade.caching")
: !dev;
boolean prettyPrint = conf.hasPath("jade.prettyprint")
? conf.getBoolean("jade.prettyprint")
: dev;
jadeconf.setCaching(caching);
jadeconf.setPrettyPrint(prettyPrint);
Map<String, Object> sharedVariables = new HashMap<>(2);
sharedVariables.put("env", env);
sharedVariables.put("xss", new XssHelper(env));
jadeconf.setSharedVariables(sharedVariables);
String ext = suffix.startsWith(".") ? suffix.substring(1) : suffix;
jadeconf.setTemplateLoader(new ClasspathTemplateLoader("UTF-8", ext));
if (callback != null) {
callback.accept(jadeconf, conf);
}
// rewrite template loader avoid NPE
jadeconf.setTemplateLoader(new IOTemplateLoader(jadeconf.getTemplateLoader()));
binder.bind(JadeConfiguration.class)
.toInstance(jadeconf);
Multibinder.newSetBinder(binder, Renderer.class).addBinding()
.toInstance(new Engine(jadeconf, suffix));
}
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config config, final Binder binder)
throws TemplateException {
Configuration freemarker = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
log.debug("Freemarker: {}", Configuration.getVersion());
freemarker.setSettings(properties(config));
freemarker.setTemplateLoader(new ClassTemplateLoader(getClass().getClassLoader(), prefix));
// cache
if ("dev".equals(env.name()) || config.getString("freemarker.cache").isEmpty()) {
// noop cache
freemarker.setCacheStorage(NullCacheStorage.INSTANCE);
} else {
freemarker.setCacheStorage(
new GuavaCacheStorage(
CacheBuilder
.from(config.getString("freemarker.cache"))
.build()));
}
freemarker.setOutputFormat(HTMLOutputFormat.INSTANCE);
if (configurer != null) {
configurer.accept(freemarker, config);
}
binder.bind(Configuration.class).toInstance(freemarker);
Engine engine = new Engine(freemarker, suffix, new XssDirective(env));
Multibinder.newSetBinder(binder, Renderer.class)
.addBinding().toInstance(engine);
}
代码示例来源:origin: jooby-project/jooby
String mode = env.name();
Function<String, Cache> cache = path -> {
if (conf.hasPath(path)) {
代码示例来源:origin: jooby-project/jooby
String envname = env.name();
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config config, final Binder binder) throws Throwable {
String envname = env.name();
boolean dev = "dev".equals(envname);
ClassLoader loader = getClass().getClassLoader();
代码示例来源:origin: jooby-project/jooby
boolean enabled = conf.hasPath("livereload.enabled")
? conf.getBoolean("livereload.enabled")
: "dev".equals(env.name());
if (enabled) {
Router router = env.router();
代码示例来源:origin: jooby-project/jooby
String ddl_auto = env.name().equals("dev") ? "update" : "none";
代码示例来源:origin: jooby-project/jooby
@Override
public void handle(final Request req, final Response rsp, final Err ex) throws Throwable {
log.error("execution of: {}{} resulted in exception\nRoute:\n{}\n\nStacktrace:",
req.method(), req.path(), req.route().print(6), ex);
Config conf = req.require(Config.class);
boolean stackstrace = Try.apply(() -> conf.getBoolean("err.stacktrace"))
.orElse(req.require(Env.class).name().equals("dev"));
rsp.send(
Results
.when(MediaType.html, () -> Results.html(VIEW).put("err", ex.toMap(stackstrace)))
.when(MediaType.all, () -> ex.toMap(stackstrace)));
}
代码示例来源:origin: jooby-project/jooby
if (!env.name().equals("dev")) {
List<RequestParam> params = provider.parameters(method);
paramProvider = (h) -> params;
代码示例来源:origin: org.jooby/jooby
public RouteMetadata(final Env env) {
CacheLoader<Class<?>, Map<String, Object>> loader = CacheLoader
.from(RouteMetadata::extractMetadata);
cache = env.name().equals("dev")
? CacheBuilder.newBuilder().maximumSize(0).build(loader)
: CacheBuilder.newBuilder().build(loader);
}
代码示例来源:origin: org.jooby/jooby-less
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
Configuration options = options(env.name().equals("dev"), conf.getConfig("less"));
if (configurer != null) {
configurer.accept(options);
}
LessCompiler compiler = new ForwardingLessCompiler(new DefaultLessCompiler(), options);
binder.bind(LessCompiler.class).toInstance(compiler);
LessHandler handler = new LessHandler(location, compiler);
handler.cdn(conf.getString("assets.cdn"));
handler.etag(conf.getBoolean("assets.etag"));
Multibinder.newSetBinder(binder, Route.Definition.class)
.addBinding()
.toInstance(new Route.Definition("GET", pattern, handler));
}
代码示例来源:origin: org.jooby/jooby-whoops
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
boolean whoops = conf.hasPath("whoops.enabled")
? conf.getBoolean("whoops.enabled")
: "dev".equals(env.name());
if (whoops) {
ClassLoader loader = env.router().getClass().getClassLoader();
Handler handler = prettyPage(loader, SourceLocator.local(), maxFrameSize, log);
env.router().err(tryPage(handler, log));
}
}
代码示例来源:origin: org.jooby/jooby
@Override
public void handle(final Request req, final Response rsp, final Err ex) throws Throwable {
log.error("execution of: {}{} resulted in exception\nRoute:\n{}\n\nStacktrace:",
req.method(), req.path(), req.route().print(6), ex);
Config conf = req.require(Config.class);
boolean stackstrace = Try.apply(() -> conf.getBoolean("err.stacktrace"))
.orElse(req.require(Env.class).name().equals("dev"));
rsp.send(
Results
.when(MediaType.html, () -> Results.html(VIEW).put("err", ex.toMap(stackstrace)))
.when(MediaType.all, () -> ex.toMap(stackstrace)));
}
内容来源于网络,如有侵权,请联系作者删除!