public ModuleContextImpl(Logger log, BridgeContext bridgeContext, ResourceResolver resolver) { // ModuleRuntime<?> lifeCycle; if (bridgeContext.getRunMode().isDynamic()) { ReadFileSystem<?> sourcePath = bridgeContext.getSourcePath(); log.info("Initializing live module at " + sourcePath.getDescription()); lifeCycle = new ModuleRuntime.Dynamic(log, Thread.currentThread().getContextClassLoader(), sourcePath); } else { log.info("Initializing module in " + bridgeContext.getRunMode().name().toLowerCase() + " mode"); ReadFileSystem<?> classPath = bridgeContext.getClassPath(); lifeCycle = new ModuleRuntime.Static(log, Thread.currentThread().getContextClassLoader(), classPath); } // this.bridgeContext = bridgeContext; this.resolver = resolver; this.runtime = lifeCycle; }
String getAssetURL(Asset asset) { StringBuilder sb = new StringBuilder(); try { renderAssetURL(asset.getLocation(), asset.resolveURI(bridge.getRunMode().getMinifyAssets()), sb); } catch (IOException e) { // Should not happen throw new UndeclaredIOException(e); } return sb.toString(); } }
public RunMode getRunMode() { if (runMode == null) { String runModeValue = getInitParameter("juzu.run_mode"); if (runModeValue != null) { runModeValue = Tools.interpolate(runModeValue, System.getProperties()); runMode = RunMode.parse(runModeValue); if (runMode == null) { // log.info("Unparseable run mode " + runModeValue + " will use prod instead"); runMode = RunMode.PROD; } } else { runMode = RunMode.PROD; } } return runMode; }
public static WebArchive createPortletDeployment(DescriptorBuilder config, Asset portletXML) { // WebArchive war = createDeployment(asDefault, config.getApplications()); AbstractWebTestCase.path = null; AbstractWebTestCase.servlet = false; // String sourcePath; try { sourcePath = config.getRunMode().isDynamic() ? getCompiler().getSourcePath().getRoot().getCanonicalFile().getAbsolutePath() : ""; } catch (IOException e) { throw failure("Could not read obtain source path", e); } // if (sourcePath != null) { config = config.sourcePath(sourcePath); } // web.xml descriptor config = config.embedPortletContainer(); war.setWebXML(new StringAsset(config.toWebXml())); war.addAsWebInfResource(portletXML, "portlet.xml"); // return war; }
private RunMode(boolean dynamic, boolean prettyFail, boolean cacheAssets, boolean minifyAssets) { this.dynamic = dynamic; this.prettyFail = prettyFail; this.value = name().toLowerCase(); this.cacheAssets = cacheAssets; this.minifyAssets = minifyAssets; }
@Override public Completion<Boolean> refresh(boolean recompile) { if (application == null) { // For now only works with CDI ProvidedCDIInjector injector = (ProvidedCDIInjector)this.injector; // Get App application = injector.getApplication(); // Complete application start applicationLifeCycle = application.getInjectionContext().get(Application.class); // Complete application start try { applicationLifeCycle.get(); } catch (InvocationTargetException e) { return Completion.failed(e); } // server.register(application, getRunMode().getCacheAssets()); } // return Completion.completed(false); }
} else if (response instanceof Response.Error) { Response.Error error = (Response.Error)response; if (bridge.getRunMode().getPrettyFail()) { resp.setContentType("text/html"); PrintWriter writer = resp.getWriter();
appendContextParam(buffer, "juzu.run_mode", runMode.getValue()); appendContextParam(buffer, "juzu.inject", injector.getValue()); appendContextParam(buffer, "juzu.request_encoding", requestEncoding.name());
public static WebArchive createPortletDeployment(DescriptorBuilder config, Asset portletXML) { // WebArchive war = createDeployment(asDefault, config.getApplications()); AbstractWebTestCase.path = null; AbstractWebTestCase.servlet = false; // String sourcePath; try { sourcePath = config.getRunMode().isDynamic() ? getCompiler().getSourcePath().getRoot().getCanonicalFile().getAbsolutePath() : ""; } catch (IOException e) { throw failure("Could not read obtain source path", e); } // if (sourcePath != null) { config = config.sourcePath(sourcePath); } // web.xml descriptor config = config.embedPortletContainer(); war.setWebXML(new StringAsset(config.toWebXml())); war.addAsWebInfResource(portletXML, "portlet.xml"); // return war; }
private RunMode(boolean dynamic, boolean prettyFail, boolean cacheAssets, boolean minifyAssets) { this.dynamic = dynamic; this.prettyFail = prettyFail; this.value = name().toLowerCase(); this.cacheAssets = cacheAssets; this.minifyAssets = minifyAssets; }
@Override public Completion<Boolean> refresh(boolean recompile) { if (application == null) { // For now only works with CDI ProvidedCDIInjector injector = (ProvidedCDIInjector)this.injector; // Get App application = injector.getApplication(); // Complete application start applicationLifeCycle = application.getInjectionContext().get(Application.class); // Complete application start try { applicationLifeCycle.get(); } catch (InvocationTargetException e) { return Completion.failed(e); } // server.register(application, getRunMode().getCacheAssets()); } // return Completion.completed(false); }
} else if (response instanceof Response.Error) { Response.Error error = (Response.Error)response; if (bridge.getRunMode().getPrettyFail()) { resp.setContentType("text/html"); PrintWriter writer = resp.getWriter();
appendContextParam(buffer, "juzu.run_mode", runMode.getValue()); appendContextParam(buffer, "juzu.inject", injector.getValue()); appendContextParam(buffer, "juzu.request_encoding", requestEncoding.name());
public ModuleContextImpl(Logger log, BridgeContext bridgeContext, ResourceResolver resolver) { // ModuleRuntime<?> lifeCycle; if (bridgeContext.getRunMode().isDynamic()) { ReadFileSystem<?> sourcePath = bridgeContext.getSourcePath(); log.info("Initializing live module at " + sourcePath.getDescription()); lifeCycle = new ModuleRuntime.Dynamic(log, Thread.currentThread().getContextClassLoader(), sourcePath); } else { log.info("Initializing module in " + bridgeContext.getRunMode().name().toLowerCase() + " mode"); ReadFileSystem<?> classPath = bridgeContext.getClassPath(); lifeCycle = new ModuleRuntime.Static(log, Thread.currentThread().getContextClassLoader(), classPath); } // this.bridgeContext = bridgeContext; this.resolver = resolver; this.runtime = lifeCycle; }
String getAssetURL(Asset asset) { StringBuilder sb = new StringBuilder(); try { renderAssetURL(asset.getLocation(), asset.resolveURI(bridge.getRunMode().getMinifyAssets()), sb); } catch (IOException e) { // Should not happen throw new UndeclaredIOException(e); } return sb.toString(); } }
/** * Parse the run mode * * @param s the string to parse * @return the corresponding run mode or null if none can be matched * @throws NullPointerException if the string argument is null */ public static RunMode parse(String s) throws NullPointerException { if (s == null) { throw new NullPointerException("No null string argument accepted"); } for (RunMode runMode : ALL) { String name = runMode.name(); if (name.equalsIgnoreCase(s)) { return runMode; } } return null; }
assetServer.register(application, runMode.getCacheAssets());
if (response instanceof Response.Error) { Response.Error error = (Response.Error)response; http.getRequestContext().send(error, bridge.getRunMode().getPrettyFail()); return true; } else if (response instanceof Response.View) {
public RunMode getRunMode() { if (runMode == null) { String runModeValue = getInitParameter("juzu.run_mode"); if (runModeValue != null) { runModeValue = Tools.interpolate(runModeValue, System.getProperties()); runMode = RunMode.parse(runModeValue); if (runMode == null) { // log.info("Unparseable run mode " + runModeValue + " will use prod instead"); runMode = RunMode.PROD; } } else { runMode = RunMode.PROD; } } return runMode; }
public static String renderAssetURLById(String id) throws NullPointerException { Request request = Request.getCurrent(); if (request != null) { AssetManager assetManager = request.getApplication().resolveBean(AssetManager.class); if (assetManager != null) { Asset asset = assetManager.getAsset(id); if (asset != null) { String uri = asset.resolveURI(request.getRunMode().getMinifyAssets()); return renderAssetURL(request, asset.getLocation(), uri); } } } return null; }