Permalink
Browse files

Merge branch 'master' of github.com:grails/grails-core

  • Loading branch information...
2 parents 32646fd + cb4c5f5 commit af484a89de432272bb24dc667a56273471035b00 @lhotari lhotari committed Oct 1, 2011
@@ -26,6 +26,8 @@ import org.codehaus.groovy.grails.cli.parsing.ParseException
import org.codehaus.groovy.grails.cli.support.MetaClassRegistryCleaner
import org.codehaus.groovy.grails.cli.parsing.CommandLine
import java.awt.Desktop
+import org.codehaus.groovy.grails.cli.support.UaaIntegration
+import grails.util.PluginBuildSettings
/**
* Provides the implementation of interactive mode in Grails.
@@ -69,6 +71,9 @@ class InteractiveMode {
console.reader.addCompletor(new GrailsInteractiveCompletor(settings, scriptRunner.availableScripts))
interactiveModeActive = true
+ if(UaaIntegration.isAvailable() && !UaaIntegration.isEnabled()) {
+ UaaIntegration.enable(settings, new PluginBuildSettings(settings), true)
+ }
addStatus("Enter a script name to run. Use TAB for completion: ")
while (interactiveModeActive) {
def scriptName = showPrompt()
@@ -54,12 +54,18 @@
+ "To consent to the Terms of Use, please enter 'Y'. Enter 'N' to indicate your do not consent and anonymous data collection will remain disabled.\n"
+ "##########################################################.\n"
+ "Enter Y or N:";
+
+ private static boolean enabled = false;
public static final int ONE_MINUTE = 180000;
public static boolean isAvailable() {
return ClassUtils.isPresent("org.springframework.uaa.client.UaaServiceFactory", UaaIntegration.class.getClassLoader());
}
+ public static boolean isEnabled() {
+ return enabled;
+ }
+
public static void enable(final BuildSettings settings, final PluginBuildSettings pluginSettings, boolean interactive) {
final UaaService uaaService = UaaServiceFactory.getUaaService();
@@ -82,7 +88,8 @@ else if ("n".equalsIgnoreCase(selection)) {
}
}
}
- else if (isUaaAccepted(privacyLevel)) {
+
+ if (isUaaAccepted(privacyLevel)) {
Runnable r = new Runnable() {
public void run() {
final UaaClient.Product product = VersionHelper.getProduct("Grails", settings.getGrailsVersion());
@@ -117,6 +124,7 @@ public void run() {
ConcurrentTaskScheduler scheduler = new ConcurrentTaskScheduler();
scheduler.schedule(r, new Date(System.currentTimeMillis() + ONE_MINUTE));
+ enabled = true;
}
}
@@ -29,6 +29,7 @@
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import com.opensymphony.module.sitemesh.Config;
@@ -82,6 +83,7 @@ public RequestDispatcher getRequestDispatcher(String path) {
*/
public void testGetDecoratorHttpServletRequestPage() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
+ webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/test.gsp", "<html><body><g:layoutBody /></body></html>");
@@ -104,6 +106,7 @@ public void testGetDecoratorHttpServletRequestPage() throws Exception {
public void testDecoratedByApplicationConventionForViewsNotRenderedByAController() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
+ webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/application.gsp", "<html><body><h1>Default Layout</h1><g:layoutBody /></body></html>");
@@ -128,6 +131,7 @@ public void testDecoratedByApplicationConventionForViewsNotRenderedByAController
public void testDecoratedByApplicationConvention() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
+ webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/application.gsp", "<html><body><h1>Default Layout</h1><g:layoutBody /></body></html>");
@@ -160,6 +164,7 @@ public void testDecoratedByApplicationConvention() throws Exception {
public void testOverridingDefaultTemplateViaConfig() throws Exception {
ConfigObject config = new ConfigSlurper().parse("grails.sitemesh.default.layout='otherApplication'");
GrailsWebRequest webRequest = buildMockRequest(config);
+ webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/application.gsp", "<html><body><h1>Default Layout</h1><g:layoutBody /></body></html>");
appCtx.registerMockResource("/grails-app/views/layouts/otherApplication.gsp", "<html><body><h1>Other Default Layout</h1><g:layoutBody /></body></html>");
@@ -192,6 +197,7 @@ public void testOverridingDefaultTemplateViaConfig() throws Exception {
public void testDecoratedByControllerConvention() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
+ webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/test.gsp", "<html><body><g:layoutBody /></body></html>");
@@ -223,6 +229,7 @@ public void testDecoratedByControllerConvention() throws Exception {
public void testDecoratedByActionConvention() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
+ webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/test2/testAction.gsp", "<html><body><g:layoutBody /></body></html>");
@@ -253,6 +260,7 @@ public void testDecoratedByActionConvention() throws Exception {
public void testDecoratedByLayoutPropertyInController() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
+ webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/test.gsp", "<html><body><g:layoutBody /></body></html>");
appCtx.registerMockResource("/grails-app/views/layouts/mylayout.gsp", "<html><body><g:layoutBody /></body></html>");
@@ -29,6 +29,7 @@
import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine;
import org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException;
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest;
+import org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutDecoratorMapper;
import org.springframework.core.io.Resource;
import org.springframework.scripting.ScriptSource;
import org.springframework.util.Assert;
@@ -140,7 +141,7 @@ public void setAttribute(String name, Object o) {
@SuppressWarnings({ "rawtypes", "unused" })
protected void renderWithTemplateEngine(GroovyPagesTemplateEngine engine, Map model,
HttpServletResponse response, HttpServletRequest request) throws IOException {
-
+ request.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE);
GSPResponseWriter out = null;
try {
out = createResponseWriter(response);
@@ -38,6 +38,7 @@
public class GrailsLayoutDecoratorMapper extends AbstractDecoratorMapper implements DecoratorMapper {
private GroovyPageLayoutFinder groovyPageLayoutFinder;
public static final String LAYOUT_ATTRIBUTE = GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE;
+ public static final String RENDERING_VIEW = GroovyPageLayoutFinder.RENDERING_VIEW_ATTRIBUTE;
@Override
public void init(Config c, Properties properties, DecoratorMapper parentMapper) throws InstantiationException {
@@ -48,6 +48,7 @@
public class GroovyPageLayoutFinder {
public static final String LAYOUT_ATTRIBUTE = "org.grails.layout.name";
+ public static final String RENDERING_VIEW_ATTRIBUTE = "org.grails.rendering.view";
private static final Log LOG = LogFactory.getLog(GrailsLayoutDecoratorMapper.class);
private static final long LAYOUT_CACHE_EXPIRATION_MILLIS = Long.getLong("grails.gsp.reload.interval", 5000)
.longValue();
@@ -90,58 +91,60 @@ public Decorator findLayout(HttpServletRequest request, Page page) {
if (LOG.isDebugEnabled()) {
LOG.debug("Evaluating layout for request: " + request.getRequestURI());
}
- Object layoutAttribute = request.getAttribute(LAYOUT_ATTRIBUTE);
- String layoutName = layoutAttribute != null ? layoutAttribute.toString() : null;
+ final Object layoutAttribute = request.getAttribute(LAYOUT_ATTRIBUTE);
+ if(request.getAttribute(RENDERING_VIEW_ATTRIBUTE) != null || layoutAttribute != null) {
+ String layoutName = layoutAttribute != null ? layoutAttribute.toString() : null;
- if (layoutName == null) {
- layoutName = page.getProperty("meta.layout");
- }
+ if (layoutName == null) {
+ layoutName = page.getProperty("meta.layout");
+ }
- Decorator d = null;
+ Decorator d = null;
- if (StringUtils.isBlank(layoutName)) {
- GroovyObject controller = (GroovyObject)request.getAttribute(GrailsApplicationAttributes.CONTROLLER);
- if (controller != null) {
- String controllerName = (String)controller
- .getProperty(ControllerDynamicMethods.CONTROLLER_NAME_PROPERTY);
- String actionUri = (String)controller.getProperty(ControllerDynamicMethods.ACTION_URI_PROPERTY);
+ if (StringUtils.isBlank(layoutName)) {
+ GroovyObject controller = (GroovyObject)request.getAttribute(GrailsApplicationAttributes.CONTROLLER);
+ if (controller != null) {
+ String controllerName = (String)controller
+ .getProperty(ControllerDynamicMethods.CONTROLLER_NAME_PROPERTY);
+ String actionUri = (String)controller.getProperty(ControllerDynamicMethods.ACTION_URI_PROPERTY);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Found controller in request, location layout for controller [" + controllerName
- + "] and action [" + actionUri + "]");
- }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Found controller in request, location layout for controller [" + controllerName
+ + "] and action [" + actionUri + "]");
+ }
- LayoutCacheKey cacheKey = null;
- boolean cachedIsNull = false;
+ LayoutCacheKey cacheKey = null;
+ boolean cachedIsNull = false;
- if (cacheEnabled) {
- cacheKey = new LayoutCacheKey(controllerName, actionUri);
- DecoratorCacheValue cacheValue = layoutDecoratorCache.get(cacheKey);
- if (cacheValue != null && (!gspReloadEnabled || !cacheValue.isExpired())) {
- d = cacheValue.getDecorator();
- if (d == null) {
- cachedIsNull = true;
+ if (cacheEnabled) {
+ cacheKey = new LayoutCacheKey(controllerName, actionUri);
+ DecoratorCacheValue cacheValue = layoutDecoratorCache.get(cacheKey);
+ if (cacheValue != null && (!gspReloadEnabled || !cacheValue.isExpired())) {
+ d = cacheValue.getDecorator();
+ if (d == null) {
+ cachedIsNull = true;
+ }
}
}
- }
- if (d == null && !cachedIsNull) {
- d = resolveDecorator(request, controller, controllerName, actionUri);
- if (cacheEnabled) {
- layoutDecoratorCache.put(cacheKey, new DecoratorCacheValue(d));
+ if (d == null && !cachedIsNull) {
+ d = resolveDecorator(request, controller, controllerName, actionUri);
+ if (cacheEnabled) {
+ layoutDecoratorCache.put(cacheKey, new DecoratorCacheValue(d));
+ }
}
}
+ else {
+ d = getApplicationDefaultDecorator(request);
+ }
}
else {
- d = getApplicationDefaultDecorator(request);
+ d = getNamedDecorator(request, layoutName);
}
- }
- else {
- d = getNamedDecorator(request, layoutName);
- }
- if (d != null) {
- return d;
+ if (d != null) {
+ return d;
+ }
}
return null;
}

0 comments on commit af484a8

Please sign in to comment.