Skip to content

Commit

Permalink
Merge branch '7.0.x' into feature/7.0.0/13655-dot-notation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdaugherty authored Nov 22, 2024
2 parents 98aa050 + 7c71d9f commit def80d0
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 38 deletions.
245 changes: 245 additions & 0 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions UPGRADE7.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ Experienced while upgrading modules for Grails 7
- Fields with a public modifier were not returned with MetaClassImpl#getProperties() in groovy 3, but are now.

## NOTE: This document is a draft and the explanations are only highlights and will be expanded further prior to release of 7.0.

### Cool New Features
- You can now @Scaffold Controllers and Services and virtually eliminate any boiler plate code.
- Hello Exterminator, Good by bugs! Lot's of things started working... and working well! For instance, use of controller namespaces now work seemlessly.
- Bootstrap 5.3.3 support. Saffolding and Fields tags now optionally support boostrap classes.
- Priortization of AutoConfiguration over bean overriding.
- Lightweight, Removal of numerous dependencies.
- grails-bom overhaul for keeping depedencies up to date and in sync.
- g:form now automatically provides csrf protection when Spring Security CSRF is enabled.
- Massive decoupling of dependencies and cleanup between modules. SiteMesh dependencies are no longer compiled into controllers fused between numerous modules. SiteMesh isn't even required to use Grails!
- SiteMesh ahs been upgrade to SiteMesh 3!
- Completely up to date modern stack that has been optimized for easier future transitions.
- GSP can now be used OUTSIDE of Grails! see grails-boot
- Works with Spring Security 6 out of the box. No plugin needed!
- Tested and works with Java [17-23](https://github.com/grails/grails-core/blob/0549617f27aeb5b90b64797fa4147dde40fc9c86/.github/workflows/gradle.yml#L18)
2 changes: 1 addition & 1 deletion grails-bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
// when used by grails-gradle-plugin
// see: https://docs.gradle.org/current/userguide/compatibility.html#groovy
implementation "org.springframework:spring-context"
api "org.springframework.boot:spring-boot-autoconfigure"
implementation "org.springframework.boot:spring-boot-autoconfigure"


compileOnly "org.codehaus.groovy:groovy:$GroovySystem.version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import grails.config.Settings;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.Filter;
import org.grails.spring.config.http.GrailsFilters;
import org.grails.web.config.http.GrailsFilters;
import org.grails.web.filters.HiddenHttpMethodFilter;
import org.grails.web.servlet.mvc.GrailsWebRequestFilter;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -16,7 +16,6 @@
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.web.filter.CharacterEncodingFilter;

import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.grails.plugins.i18n;

import grails.config.Settings;
import grails.core.GrailsApplication;
import grails.plugins.GrailsPluginManager;
import grails.util.Environment;
import org.grails.spring.context.support.PluginAwareResourceBundleMessageSource;
import org.grails.web.i18n.ParamsAwareLocaleChangeInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

@AutoConfiguration(before = { MessageSourceAutoConfiguration.class, WebMvcAutoConfiguration.class })
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class I18nAutoConfiguration {

@Value("${" + Settings.GSP_VIEW_ENCODING + ":UTF-8}")
private String encoding;

@Value("${" + Settings.GSP_ENABLE_RELOAD + ":false}")
private boolean gspEnableReload;

@Value("${" + Settings.I18N_CACHE_SECONDS + ":5}")
private int cacheSeconds;

@Value("${" + Settings.I18N_FILE_CACHE_SECONDS + ":5}")
private int fileCacheSeconds;

@Bean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME)
public LocaleResolver localeResolver() {
return new SessionLocaleResolver();
}

@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
ParamsAwareLocaleChangeInterceptor localeChangeInterceptor = new ParamsAwareLocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
return localeChangeInterceptor;
}

@Bean(AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME)
public MessageSource messageSource(GrailsApplication grailsApplication, GrailsPluginManager pluginManager) {
PluginAwareResourceBundleMessageSource messageSource = new PluginAwareResourceBundleMessageSource(grailsApplication, pluginManager);
messageSource.setDefaultEncoding(encoding);
messageSource.setFallbackToSystemLocale(false);
if (Environment.getCurrent().isReloadEnabled() || gspEnableReload) {
messageSource.setCacheSeconds(cacheSeconds);
messageSource.setFileCacheSeconds(fileCacheSeconds);
}
return messageSource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@
*/
package org.grails.plugins.i18n

import grails.config.Config
import grails.config.Settings
import grails.core.GrailsApplication
import grails.plugins.Plugin
import grails.util.BuildSettings
import grails.util.Environment
import grails.util.GrailsUtil
import groovy.util.logging.Slf4j
import org.grails.spring.context.support.PluginAwareResourceBundleMessageSource
import org.grails.web.i18n.ParamsAwareLocaleChangeInterceptor
import org.springframework.context.support.ReloadableResourceBundleMessageSource
import org.springframework.core.io.Resource
import org.springframework.web.servlet.i18n.SessionLocaleResolver

import java.nio.file.Files

Expand All @@ -44,29 +37,6 @@ class I18nGrailsPlugin extends Plugin {
String version = GrailsUtil.getGrailsVersion()
String watchedResources = "file:./${baseDir}/**/*.properties".toString()

@Override
Closure doWithSpring() {{->
GrailsApplication application = grailsApplication
Config config = application.config
boolean gspEnableReload = config.getProperty(Settings.GSP_ENABLE_RELOAD, Boolean, false)
String encoding = config.getProperty(Settings.GSP_VIEW_ENCODING, 'UTF-8')

messageSource(PluginAwareResourceBundleMessageSource, application, pluginManager) {
fallbackToSystemLocale = false
if (Environment.current.isReloadEnabled() || gspEnableReload) {
cacheSeconds = config.getProperty(Settings.I18N_CACHE_SECONDS, Integer, 5)
fileCacheSeconds = config.getProperty(Settings.I18N_FILE_CACHE_SECONDS, Integer, 5)
}
defaultEncoding = encoding
}

localeChangeInterceptor(ParamsAwareLocaleChangeInterceptor) {
paramName = "lang"
}

localeResolver(SessionLocaleResolver)
}}

@Override
void onChange(Map<String, Object> event) {
def ctx = applicationContext
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.grails.plugins.i18n.I18nAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package grails.boot
import grails.artefact.Artefact
import grails.boot.config.GrailsAutoConfiguration
import grails.web.Controller
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory
Expand Down Expand Up @@ -31,7 +31,7 @@ class EmbeddedContainerWithGrailsSpec extends Specification {
new URL("http://localhost:${context.webServer.port}/foos").text == 'all foos'
}

@SpringBootApplication
@EnableAutoConfiguration
static class Application extends GrailsAutoConfiguration {
@Bean
ConfigurableServletWebServerFactory webServerFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package grails.boot

import grails.boot.config.GrailsAutoConfiguration
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory
Expand Down Expand Up @@ -32,7 +32,7 @@ class GrailsSpringApplicationSpec extends Specification{
}


@SpringBootApplication
@EnableAutoConfiguration
static class Application extends GrailsAutoConfiguration {
@Bean
ConfigurableServletWebServerFactory webServerFactory() {
Expand Down
2 changes: 2 additions & 0 deletions grails-web-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dependencies {
compileOnly "jakarta.servlet:jakarta.servlet-api"
testCompileOnly "org.springframework:spring-test"

// now used by plugins for autoconfiguration
api "org.springframework.boot:spring-boot-autoconfigure"
api "org.springframework:spring-webmvc"
api "org.springframework:spring-context-support"
implementation "com.github.ben-manes.caffeine:caffeine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package org.grails.spring.config.http;
package org.grails.web.config.http;

import org.springframework.boot.autoconfigure.security.SecurityProperties;

Expand Down

0 comments on commit def80d0

Please sign in to comment.