Permalink
Browse files

Merge branch '2.2.x'

  • Loading branch information...
2 parents c53161e + 1eb2cb1 commit 08041fca6e4181a6d3f49da828fe15f23a7584d4 @lhotari lhotari committed Sep 27, 2012
View
@@ -27,7 +27,7 @@ ext {
datastoreVersion = "1.1.0.RELEASE"
gantVersion = "1.9.6"
gdocEngineVersion = "1.0.1"
- groovyVersion = "2.0.2"
+ groovyVersion = "2.0.4"
gradleGroovyVersion = groovyVersion
gradleGroovyVersion = "1.8.2"
ivyVersion = "2.2.0"
View
@@ -88,8 +88,8 @@ The following libraries are included in Grails because they are required either
- Gant 1.9.5 (http://gant.codehaus.org) Apache 2.0 License
- required for the command line tools (Gant)
-* groovy-all-2.0.2.jar
-- Groovy 2.0.2 (http://groovy.codehaus.org) Apache 2.0 License
+* groovy-all-2.0.4.jar
+- Groovy 2.0.4 (http://groovy.codehaus.org) Apache 2.0 License
- required for the command line tools (Gant)
- required for building Grails core
- required for running Grails applications
@@ -4,7 +4,9 @@ configurations {
uaa.extendsFrom compile
}
dependencies {
-
+ compile("org.springframework:spring-core:${springVersion}") {
+ exclude module:"commons-logging"
+ }
// UAA client dependency, optional
uaa("org.springframework.uaa:org.springframework.uaa.client:1.0.1.RELEASE") {
@@ -15,6 +15,8 @@
*/
package grails.util;
+import org.codehaus.groovy.grails.plugins.GrailsPluginUtils;
+
/**
* Static singleton holder for the BuildSettings instance. Should only
* be initialised once (in {@link org.codehaus.groovy.grails.cli.GrailsScriptRunner}.
@@ -29,6 +31,17 @@ public static BuildSettings getSettings() {
public static void setSettings(BuildSettings newSettings) {
settings = newSettings;
+ try {
+ // test if classpath has been initialized already
+ Class.forName("org.springframework.core.io.Resource");
+ if(settings != null) {
+ GrailsPluginUtils.getPluginBuildSettings(settings);
+ } else {
+ GrailsPluginUtils.setPluginBuildSettings(null);
+ }
+ } catch (ClassNotFoundException e) {
+ // ignore error that comes in Grails startup before the classpath has been initialized
+ }
}
private BuildSettingsHolder() {
@@ -31,6 +31,7 @@
import org.codehaus.groovy.grails.cli.ScriptExitException;
import org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener;
import org.codehaus.groovy.grails.io.support.*;
+import org.codehaus.groovy.grails.plugins.GrailsPluginUtils;
import org.codehaus.groovy.runtime.MethodClosure;
import java.beans.IntrospectionException;
@@ -87,7 +88,7 @@ public BaseSettingsApi(BuildSettings settings, GrailsBuildEventListener buildEve
metadataFile = metadata.getMetadataFile();
enableProfile = Boolean.valueOf(getPropertyValue("grails.script.profile", false).toString());
pluginsHome = buildSettings.getProjectPluginsDir().getPath();
- pluginSettings = new PluginBuildSettings(buildSettings);
+ pluginSettings = GrailsPluginUtils.getPluginBuildSettings(settings);
grailsAppName = metadata.getApplicationName();
isInteractive = interactive;
@@ -20,7 +20,8 @@ import grails.util.PluginBuildSettings
import jline.SimpleCompletor
import org.codehaus.groovy.grails.cli.support.BuildSettingsAware
import org.codehaus.groovy.grails.io.support.GrailsResourceUtils
-import org.codehaus.groovy.grails.io.support.Resource
+import org.codehaus.groovy.grails.plugins.GrailsPluginUtils;
+import org.springframework.core.io.Resource
/**
* A completor that completes
@@ -42,7 +43,7 @@ abstract class ClassNameCompletor extends SimpleCompletor implements BuildSettin
@Override
int complete(String buffer, int cursor, List clist) {
- PluginBuildSettings pluginSettings = new PluginBuildSettings(buildSettings)
+ PluginBuildSettings pluginSettings = GrailsPluginUtils.getPluginBuildSettings(buildSettings)
final resources = pluginSettings.getArtefactResourcesForOne(buildSettings.baseDir.absolutePath)
def classNames = []
@@ -18,6 +18,8 @@ package org.codehaus.groovy.grails.cli.maven
import org.codehaus.groovy.grails.cli.api.BaseSettingsApi
import grails.util.BuildSettings
import grails.util.Metadata
+
+import org.codehaus.groovy.grails.plugins.GrailsPluginUtils;
import org.codehaus.groovy.grails.resolve.EnhancedDefaultDependencyDescriptor
import org.apache.ivy.core.module.descriptor.DependencyDescriptor
import org.codehaus.groovy.grails.resolve.IvyDependencyManager
@@ -78,7 +80,7 @@ class MavenPomGenerator extends BaseSettingsApi{
private String readVersion(BuildSettings buildSettings, metadata) {
if(buildSettings.isPluginProject()) {
- def pluginSettings = new PluginBuildSettings(buildSettings)
+ def pluginSettings = GrailsPluginUtils.getPluginBuildSettings(buildSettings)
final info = pluginSettings.getPluginInfo(buildSettings.getBaseDir().absolutePath)
return info.version
}
@@ -14,6 +14,7 @@
*/
package org.codehaus.groovy.grails.plugins
+import grails.util.BuildSettings;
import grails.util.BuildSettingsHolder
import grails.util.PluginBuildSettings
import groovy.util.slurpersupport.GPathResult
@@ -109,17 +110,17 @@ class GrailsPluginUtils {
/**
* Returns a new PluginBuildSettings instance
*/
- static PluginBuildSettings newPluginBuildSettings() {
- new PluginBuildSettings(BuildSettingsHolder.settings)
+ static PluginBuildSettings newPluginBuildSettings(BuildSettings buildSettings = null) {
+ new PluginBuildSettings(buildSettings ?: BuildSettingsHolder.settings)
}
- private static INSTANCE
+ private static PluginBuildSettings INSTANCE
/**
* Returns a cached PluginBuildSettings instance.
*/
- static synchronized PluginBuildSettings getPluginBuildSettings() {
- if (INSTANCE == null) {
- INSTANCE = newPluginBuildSettings()
+ static synchronized PluginBuildSettings getPluginBuildSettings(BuildSettings buildSettings = null) {
+ if (INSTANCE == null || (buildSettings != null && !buildSettings.is(INSTANCE.buildSettings))) {
+ INSTANCE = newPluginBuildSettings(buildSettings)
}
return INSTANCE
}
@@ -163,7 +163,7 @@ public Object doCall() {
// dependencies needed at compile time
ModuleRevisionId[] groovyDependencies = {
- ModuleRevisionId.newInstance("org.codehaus.groovy", "groovy-all", "2.0.2")
+ ModuleRevisionId.newInstance("org.codehaus.groovy", "groovy-all", "2.0.4")
};
registerDependencies(dependencyManager, compileTimeDependenciesMethod, groovyDependencies, "jline");
@@ -75,7 +75,7 @@ class PluginInstallEngine {
protected PluginResolveEngine resolveEngine
PluginInstallEngine(BuildSettings settings) {
- this(settings, new PluginBuildSettings(settings), Metadata.current, new AntBuilder())
+ this(settings, GrailsPluginUtils.getPluginBuildSettings(settings), Metadata.current, new AntBuilder())
}
PluginInstallEngine(BuildSettings settings, PluginBuildSettings pbs) {
@@ -1398,6 +1398,20 @@ public static Mapping getMapping(Class<?> theClass) {
public static Mapping getMapping(GrailsDomainClass domainClass) {
return domainClass == null ? null : MAPPING_CACHE.get(domainClass.getClazz());
}
+
+ public static void clearMappingCache() {
+ MAPPING_CACHE.clear();
+ }
+
+ public static void clearMappingCache(Class<?> theClass) {
+ String className = theClass.getName();
+ for(Iterator<Map.Entry<Class<?>, Mapping>> it = MAPPING_CACHE.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<Class<?>, Mapping> entry = it.next();
+ if(className.equals(entry.getKey().getName())) {
+ it.remove();
+ }
+ }
+ }
/**
* Binds the specified persistant class to the runtime model based on the
@@ -29,7 +29,6 @@ import org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfigurati
import org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator
import org.codehaus.groovy.grails.commons.spring.RuntimeSpringConfiguration
import org.codehaus.groovy.grails.orm.hibernate.*
-import org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil
import org.codehaus.groovy.grails.orm.hibernate.events.PatchedDefaultFlushEventListener
@@ -39,35 +38,32 @@ import org.codehaus.groovy.grails.orm.hibernate.validation.HibernateConstraintsE
import org.codehaus.groovy.grails.orm.hibernate.validation.HibernateDomainClassValidator
import org.codehaus.groovy.grails.orm.hibernate.validation.PersistentConstraintFactory
import org.codehaus.groovy.grails.orm.hibernate.validation.UniqueConstraint
+import org.codehaus.groovy.grails.plugins.DomainClassGrailsPlugin
import org.codehaus.groovy.grails.validation.ConstrainedProperty
import org.codehaus.groovy.grails.validation.ConstraintsEvaluator
+import org.grails.datastore.mapping.core.Datastore
+import org.grails.datastore.mapping.model.MappingContext
+import org.grails.datastore.mapping.model.PersistentEntity
import org.hibernate.EmptyInterceptor
import org.hibernate.FlushMode
import org.hibernate.Session
import org.hibernate.SessionFactory
-import org.hibernate.cfg.Environment
import org.hibernate.cfg.ImprovedNamingStrategy
import org.hibernate.proxy.HibernateProxy
import org.springframework.beans.SimpleTypeConverter
import org.springframework.beans.TypeMismatchException
-import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinition
import org.springframework.beans.factory.config.PropertiesFactoryBean
import org.springframework.beans.factory.support.DefaultListableBeanFactory
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader
import org.springframework.context.ApplicationContext
import org.springframework.dao.DataAccessException
-import org.grails.datastore.mapping.model.MappingContext
-import org.grails.datastore.mapping.model.PersistentEntity
import org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor
import org.springframework.orm.hibernate3.HibernateAccessor
import org.springframework.orm.hibernate3.HibernateCallback
import org.springframework.orm.hibernate3.HibernateTemplate
-import org.springframework.orm.hibernate3.HibernateTransactionManager
-import org.springframework.validation.Validator
import org.springframework.transaction.PlatformTransactionManager
-import org.codehaus.groovy.grails.domain.GrailsDomainClassPersistentEntity
-import org.codehaus.groovy.grails.plugins.DomainClassGrailsPlugin
-import org.grails.datastore.mapping.core.Datastore
+import org.springframework.validation.Validator
/**
* Used by HibernateGrailsPlugin to implement the core parts of GORM.
@@ -221,6 +217,7 @@ Using Grails' default naming strategy: '${ImprovedNamingStrategy.name}'"""
}
hibProps.putAll(hibConfig.flatten().toProperties('hibernate'))
+ hibProps.remove('hibernate.reload')
// move net.sf.ehcache.configurationResourceName to "top level" if it exists
if (hibProps.'hibernate.net.sf.ehcache.configurationResourceName') {
@@ -341,33 +338,58 @@ Using Grails' default naming strategy: '${ImprovedNamingStrategy.name}'"""
static final onChange = { event ->
LOG.debug "onChange() started"
- def datasourceNames = [GrailsDomainClassProperty.DEFAULT_DATA_SOURCE]
+ def allDatasourceNames = [GrailsDomainClassProperty.DEFAULT_DATA_SOURCE] as Set
for (name in application.config.keySet()) {
if (name.startsWith('dataSource_')) {
- datasourceNames << name - 'dataSource_'
+ allDatasourceNames << name - 'dataSource_'
}
}
-
+
+ def datasourceNames
+ if(event.source instanceof Class) {
+ GrailsDomainClass dc = application.getDomainClass(event.source.name)
+ if(!dc.getMappingStrategy().equalsIgnoreCase(GrailsDomainClass.GORM)) {
+ return
+ }
+ GrailsDomainBinder.clearMappingCache(event.source)
+ def dcMappingDsNames = GrailsHibernateUtil.getDatasourceNames(dc) as Set
+ datasourceNames = [] as Set
+ for(name in allDatasourceNames) {
+ if(name in dcMappingDsNames || dcMappingDsNames.contains(GrailsDomainClassProperty.ALL_DATA_SOURCES)) {
+ datasourceNames << name
+ }
+ }
+ } else {
+ GrailsDomainBinder.clearMappingCache()
+ datasourceNames = allDatasourceNames
+ }
+
def beans = beans {
for (String datasourceName in datasourceNames) {
LOG.debug "processing DataSource $datasourceName"
boolean isDefault = datasourceName == GrailsDomainClassProperty.DEFAULT_DATA_SOURCE
String suffix = isDefault ? '' : '_' + datasourceName
-
- "${SessionFactoryHolder.BEAN_ID}$suffix"(SessionFactoryHolder) {
- sessionFactory = bean(ConfigurableLocalSessionFactoryBean) { bean ->
- bean.parent = ref("abstractSessionFactoryBeanConfig$suffix")
- proxyIfReloadEnabled = false
- }
- }
-
- GrailsDomainClass dc = application.getDomainClass(event.source.name)
- if (!dc.abstract && GrailsHibernateUtil.usesDatasource(dc, datasourceName)) {
- "${dc.fullName}Validator$suffix"(HibernateDomainClassValidator) {
- messageSource = ref("messageSource")
- domainClass = ref("${dc.fullName}DomainClass")
- sessionFactory = ref("sessionFactory$suffix")
- grailsApplication = ref("grailsApplication", true)
+ def hibConfig = application.config["hibernate$suffix"]
+ def sessionFactoryReload = hibConfig?.containsKey('reload') ? hibConfig.reload : true
+
+ if(sessionFactoryReload) {
+ "${SessionFactoryHolder.BEAN_ID}$suffix"(SessionFactoryHolder) {
+ sessionFactory = bean(ConfigurableLocalSessionFactoryBean) { bean ->
+ bean.parent = ref("abstractSessionFactoryBeanConfig$suffix")
+ proxyIfReloadEnabled = false
+ }
+ }
+
+ if(event.source instanceof Class) {
+ GrailsDomainClass dc = application.getDomainClass(event.source.name)
+ if (!dc.abstract && GrailsHibernateUtil.usesDatasource(dc, datasourceName)) {
+ "${dc.fullName}Validator$suffix"(HibernateDomainClassValidator) {
+ messageSource = ref("messageSource")
+ domainClass = ref("${dc.fullName}DomainClass")
+ sessionFactory = ref("sessionFactory$suffix")
+ grailsApplication = ref("grailsApplication", true)
+ }
+ }
}
}
}
@@ -27,6 +27,7 @@ import org.codehaus.groovy.grails.commons.GrailsTagLibClass
import org.codehaus.groovy.grails.commons.TagLibArtefactHandler
import org.codehaus.groovy.grails.commons.metaclass.MetaClassEnhancer
import org.codehaus.groovy.grails.plugins.GrailsPluginManager
+import org.codehaus.groovy.grails.plugins.GrailsPluginUtils;
import org.codehaus.groovy.grails.plugins.web.api.ControllerTagLibraryApi
import org.codehaus.groovy.grails.plugins.web.api.TagLibraryApi
import org.codehaus.groovy.grails.plugins.web.taglib.*
@@ -110,7 +111,7 @@ class GroovyPagesGrailsPlugin {
customResourceLoader=true
groovyPageResourceLoader(GroovyPageResourceLoader) {
baseResource = "file:${viewsDir}"
- pluginSettings = new PluginBuildSettings(BuildSettingsHolder.settings)
+ pluginSettings = GrailsPluginUtils.getPluginBuildSettings()
}
}
else {
@@ -121,7 +122,7 @@ class GroovyPagesGrailsPlugin {
BuildSettings settings = BuildSettingsHolder.settings
def location = settings?.baseDir ? GroovyPagesGrailsPlugin.transformToValidLocation(settings.baseDir.absolutePath) : '.'
baseResource = "file:$location"
- pluginSettings = new PluginBuildSettings(settings)
+ pluginSettings = GrailsPluginUtils.getPluginBuildSettings()
}
}
else {
@@ -130,7 +131,7 @@ class GroovyPagesGrailsPlugin {
groovyPageResourceLoader(GroovyPageResourceLoader) {
def location = GroovyPagesGrailsPlugin.transformToValidLocation(env.reloadLocation)
baseResource = "file:${location}"
- pluginSettings = new PluginBuildSettings(BuildSettingsHolder.settings)
+ pluginSettings = GrailsPluginUtils.getPluginBuildSettings()
}
}
}
@@ -2,6 +2,7 @@ package org.codehaus.groovy.grails.reload;
import org.codehaus.groovy.grails.orm.hibernate.AbstractGrailsHibernateTests
+import org.hibernate.SessionFactory;
/**
* Tests for auto-reloading of domain classes
@@ -30,6 +31,9 @@ class DomainReloadEye {
assert testDomain.respondsTo("getName")
assert !testDomain.respondsTo("getDescription")
assert !testDomain.respondsTo("addToEyes")
+
+ Map<String,Object> sessionFactoryBeans=ga.mainContext.getBeansOfType(SessionFactory.class);
+ assertEquals 1, sessionFactoryBeans.size()
def newGcl = new GroovyClassLoader()
def event = [source: newGcl.parseClass(domain1), ctx: appCtx, application: ga]
@@ -49,6 +53,9 @@ class DomainReloadEye {
assert newDomain.respondsTo("getDescription")
assert newDomain.respondsTo("save")
assert newDomain.respondsTo("addToEyes")
+
+ sessionFactoryBeans=ga.mainContext.getBeansOfType(SessionFactory.class);
+ assertEquals 1, sessionFactoryBeans.size()
}
void onSetUp() {
@@ -18,7 +18,6 @@ class GrailsPluginUtilsTests extends GroovyTestCase {
GrailsPluginUtils.clearCaches()
System.setProperty("disable.grails.plugin.transform","true")
settings = new BuildSettings(new File("."))
- BuildSettingsHolder.settings = settings
def resourceDir = "test/resources/grails-plugin-utils"
settings.projectPluginsDir = new File("$resourceDir/plugins")
settings.globalPluginsDir = new File("$resourceDir/global-plugins")
@@ -32,6 +31,7 @@ grails {
}
}
""")
+ BuildSettingsHolder.settings = settings
}
void tearDown() {
Oops, something went wrong.

0 comments on commit 08041fc

Please sign in to comment.