Skip to content

Commit

Permalink
Merge branch 'master' of github.com:grails/grails-core
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme Rocher authored and Graeme Rocher committed Sep 26, 2011
2 parents 94886a3 + 051a0b5 commit 49d9869
Show file tree
Hide file tree
Showing 33 changed files with 330 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class IvyDependencyManager extends AbstractIvyDependencyManager implements Depen
this.applicationVersion = applicationVersion
}

IvyDependencyManager createCopy() {
IvyDependencyManager copy = new IvyDependencyManager(applicationName, applicationVersion, buildSettings, metadata, ivySettings)
IvyDependencyManager createCopy(BuildSettings buildSettings) {
IvyDependencyManager copy = new IvyDependencyManager(applicationName, applicationVersion, buildSettings)
copy.offline = offline
copy.chainResolver = chainResolver
if (logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class PluginInstallEngine {
log "warn"
repositories {
def pluginResolver = new FileSystemResolver(name: "$name plugin install resolver")
pluginResolver.addArtifactPattern("${parentDir.absolutePath}/grails-[module]-[revision].[ext]")
pluginResolver.addArtifactPattern("${parentDir.absolutePath}/[module]-[revision].[ext]")
pluginResolver.settings = dependencyManager.ivySettings
pluginResolver.latestStrategy = new LatestTimeStrategy()
pluginResolver.changingPattern = ".*SNAPSHOT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class PluginResolveEngine {
}

IvyDependencyManager createFreshDependencyManager() {
dependencyManager.createCopy()
dependencyManager.createCopy(settings)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ public static boolean isDomainClass(Class clazz) {
// it's not a closure
if (clazz == null) return false;

if (clazz.getAnnotation(Entity.class) != null) {
return true;
}

if (Closure.class.isAssignableFrom(clazz)) {
return false;
}

if (GrailsClassUtils.isJdk5Enum(clazz)) return false;

if (clazz.getAnnotation(Entity.class) != null) {
return true;
}

Class testClass = clazz;
while (testClass != null && !testClass.equals(GroovyObject.class) && !testClass.equals(Object.class)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,10 +1094,16 @@ public static boolean isClassBelowPackage(Class<?> theClass, List<?> packageList
return false;
}

public static Object instantiateFromConfig(ConfigObject config, String configKey, String defaultClassName)
@SuppressWarnings("unchecked")
public static Object instantiateFromConfig(ConfigObject config, String configKey, String defaultClassName)
throws InstantiationException, IllegalAccessException, ClassNotFoundException, LinkageError {
return instantiateFromFlatConfig(config.flatten(), configKey, defaultClassName);
}

public static Object instantiateFromFlatConfig(Map<String, Object> flatConfig, String configKey, String defaultClassName)
throws InstantiationException, IllegalAccessException, ClassNotFoundException, LinkageError {
String className = defaultClassName;
Object configName = config.flatten().get(configKey);
Object configName = flatConfig.get(configKey);
if (configName instanceof CharSequence) {
className = configName.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -35,7 +36,7 @@
*/
public class ConstrainedPropertyBuilder extends BuilderSupport {

private Map<String, ConstrainedProperty> constrainedProperties = new HashMap<String, ConstrainedProperty>();
private Map<String, ConstrainedProperty> constrainedProperties = new LinkedHashMap<String, ConstrainedProperty>();
private Map<String, String> sharedConstraints = new HashMap<String, String>();
private int order = 1;
private Class<?> targetClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ public void validate(Object obj, Errors errors, boolean cascade) {
Map constrainedProperties = domainClass.getConstrainedProperties();
Set<String> constrainedPropertyNames = new HashSet(constrainedProperties.keySet());

for(Object key : constrainedProperties.keySet()) {
String propertyName = (String) key;
validatePropertyWithConstraint(propertyName, obj, errors, bean, constrainedProperties);
}

GrailsDomainClassProperty[] persistentProperties = domainClass.getPersistentProperties();

for (GrailsDomainClassProperty persistentProperty : persistentProperties) {
String propertyName = persistentProperty.getName();
if (constrainedProperties.containsKey(propertyName)) {
validatePropertyWithConstraint(propertyName, obj, errors, bean, constrainedProperties);
}

if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade) {
cascadeToAssociativeProperty(errors, bean, persistentProperty);
Expand Down
6 changes: 3 additions & 3 deletions grails-hibernate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
exclude group: 'org.grails', module:'grails-core'
exclude group: 'org.grails', module:'grails-test'
exclude group: 'org.slf4j', module:'jcl-over-slf4j'
exclude group: 'org.slf4j', module:'jcl-over-slf4j'
exclude group: 'org.slf4j', module:'jul-to-slf4j'
exclude group: 'org.slf4j', module:'slf4j-api'
exclude group: 'org.slf4j', module:'slf4j-simple'

Expand All @@ -31,12 +31,12 @@ dependencies {
exclude group: 'org.springframework', module:'spring-beans'
exclude group: 'org.springframework', module:'spring-tx'
exclude group: 'org.slf4j', module:'jcl-over-slf4j'
exclude group: 'org.slf4j', module:'jcl-over-slf4j'
exclude group: 'org.slf4j', module:'jul-to-slf4j'
exclude group: 'org.slf4j', module:'slf4j-api'
exclude group: 'org.slf4j', module:'slf4j-simple'
exclude group: 'org.grails', module:'grails-bootstrap'
exclude group: 'org.grails', module:'grails-core'
exclude group: 'commons-collection', module:'commons-collection'
exclude group: 'commons-collections', module:'commons-collections'
exclude group: 'commons-lang', module:'commons-lang'
exclude group: 'javassit', module:'javassist'
exclude group: 'java-persistence', module:'persistence-api'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,18 @@ private Datastore findDatastore(AbstractEvent hibernateEvent) {
SessionFactory sessionFactory = hibernateEvent.getSession().getSessionFactory();
if (!(sessionFactory instanceof SessionFactoryProxy)) {
// should always be the case
for (SessionFactory sf : getSessionFactories()) {
for (Map.Entry<SessionFactory, HibernateDatastore> entry : datastores.entrySet()) {
SessionFactory sf=entry.getKey();
if (sf instanceof SessionFactoryProxy) {
if (((SessionFactoryProxy)sf).getCurrentSessionFactory() == sessionFactory) {
sessionFactory = sf;
break;
return entry.getValue();
}
}
}
}
return datastores.get(sessionFactory);
}

private synchronized Collection<SessionFactory> getSessionFactories() {
if (sessionFactories == null) {
sessionFactories = ctx.getBeansOfType(SessionFactory.class).values();
}
return sessionFactories;
}

/*
* TODO: This is a horrible hack due to a bug in Hibernate's post-insert event processing (HHH-3904)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import org.codehaus.groovy.grails.support.PersistenceContextInterceptor
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
import org.codehaus.groovy.grails.web.sitemesh.GrailsContentBufferingResponse
import org.codehaus.groovy.grails.web.sitemesh.GroovyPageLayoutFinder
import org.codehaus.groovy.grails.web.sitemesh.GroovyPageLayoutRenderer
import org.codehaus.groovy.grails.web.sitemesh.SpringMVCViewDecorator
import org.codehaus.groovy.grails.web.util.WebUtils

import com.opensymphony.sitemesh.webapp.SiteMeshWebAppContext;

/**
* Wraps an AsyncContext providing additional logic to provide the appropriate context to a Grails application.
*
Expand Down Expand Up @@ -80,11 +82,8 @@ class GrailsAsyncContext implements AsyncContext {
if (content != null) {
def decorator = groovyPageLayoutFinder?.findLayout(request, content)
if (decorator) {
GroovyPageLayoutRenderer renderer = new GroovyPageLayoutRenderer(decorator,
originalWebRequest.attributes.pagesTemplateEngine, originalWebRequest.applicationContext)
renderer.render(content, request, targetResponse, request.servletContext)
}
else {
decorator.render(content, new SiteMeshWebAppContext(request, targetResponse, request.servletContext))
} else {
content.writeOriginal(targetResponse.getWriter())
}
}
Expand Down
6 changes: 3 additions & 3 deletions grails-plugin-domain-class/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
exclude group: 'org.grails', module:'grails-core'
exclude group: 'org.grails', module:'grails-test'
exclude group: 'org.slf4j', module:'jcl-over-slf4j'
exclude group: 'org.slf4j', module:'jcl-over-slf4j'
exclude group: 'org.slf4j', module:'jul-to-slf4j'
exclude group: 'org.slf4j', module:'slf4j-api'
exclude group: 'org.slf4j', module:'slf4j-simple'

Expand All @@ -21,12 +21,12 @@ dependencies {
exclude group: 'org.springframework', module:'spring-beans'
exclude group: 'org.springframework', module:'spring-tx'
exclude group: 'org.slf4j', module:'jcl-over-slf4j'
exclude group: 'org.slf4j', module:'jcl-over-slf4j'
exclude group: 'org.slf4j', module:'jul-to-slf4j'
exclude group: 'org.slf4j', module:'slf4j-api'
exclude group: 'org.slf4j', module:'slf4j-simple'
exclude group: 'org.grails', module:'grails-bootstrap'
exclude group: 'org.grails', module:'grails-core'
exclude group: 'commons-collection', module:'commons-collection'
exclude group: 'commons-collections', module:'commons-collections'
exclude group: 'commons-lang', module:'commons-lang'
exclude group: 'javassit', module:'javassist'
exclude group: 'java-persistence', module:'persistence-api'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ class GroovyPagesGrailsPlugin {
}

groovyPageLayoutFinder(GroovyPageLayoutFinder) {
groovyPageLocator = groovyPageLocator
gspReloadEnabled = enableReload
defaultDecoratorName = application.flatConfig['grails.sitemesh.default.layout'] ?: 'application'
viewResolver = ref('jspViewResolver')
}

// Setup the GroovyPagesUriService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
*/
package org.codehaus.groovy.grails.plugins.log4j

import java.util.Collection;
import java.util.Map;

import grails.util.BuildSettings
import grails.util.BuildSettingsHolder
import grails.util.Environment
import groovy.lang.Closure;

import org.apache.commons.beanutils.BeanUtils
import org.apache.log4j.Appender
import org.apache.log4j.ConsoleAppender
import org.apache.log4j.FileAppender
import org.apache.log4j.HTMLLayout
import org.apache.log4j.Level
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger
import org.apache.log4j.PatternLayout
import org.apache.log4j.RollingFileAppender
Expand Down Expand Up @@ -56,6 +61,27 @@ class Log4jConfig {
Log4jConfig(ConfigObject config) {
this.config = config
}

public static void initialize(ConfigObject config) {
if (config != null) {
LogManager.resetConfiguration();
Object o = config.get("log4j")
Log4jConfig log4jConfig = new Log4jConfig(config)
if (o instanceof Closure) {
log4jConfig.configure((Closure<?>)o);
}
else if (o instanceof Map) {
log4jConfig.configure((Map<?, ?>)o);
}
else if (o instanceof Collection) {
log4jConfig.configure((Collection<?>)o);
}
else {
// setup default logging
log4jConfig.configure();
}
}
}

def methodMissing(String name, args) {
if (APPENDERS.containsKey(name) && args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ class LoggingGrailsPlugin {
}

def onConfigChange = { event ->
def log4jConfig = event.source.log4j
if (log4jConfig instanceof Closure || log4jConfig instanceof Collection || log4jConfig instanceof Map) {
LogManager.resetConfiguration()
new Log4jConfig(event.application.config).configure(log4jConfig)
}
Log4jConfig.initialize(event.source)
}

def doWithWebDescriptor = { webXml ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,7 @@ public void contextInitialized(ServletContextEvent event) {
// create empty app to provide metadata
GrailsApplication application = new DefaultGrailsApplication();
co = application.getConfig();
if (co != null) {
Object o = co.get("log4j");
if (o instanceof Closure) {
new Log4jConfig(co).configure((Closure<?>)o);
}
else if (o instanceof Collection) {
new Log4jConfig(co).configure((Collection<?>)o);
}
else if (o instanceof Map) {
new Log4jConfig(co).configure((Map<?, ?>)o);
}
else {
new Log4jConfig(co).configure();
}
}
Log4jConfig.initialize(co);
}
}
catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package org.codehaus.groovy.grails.plugins.logging;

import groovy.lang.Closure;
import groovy.util.ConfigObject;
import org.apache.log4j.LogManager;

import org.codehaus.groovy.grails.plugins.log4j.Log4jConfig;

/**
Expand All @@ -29,13 +28,6 @@
public class LoggingInitializer {

public void initialize(ConfigObject config) {
LogManager.resetConfiguration();
Object log4j = config.get("log4j");
if (log4j instanceof Closure) {
new Log4jConfig(config).configure((Closure<?>)log4j);
} else {
// setup default logging
new Log4jConfig(config).configure();
}
Log4jConfig.initialize(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ private void processFilterChain(HttpServletRequest request, HttpServletResponse

protected void createStackTraceFilterer() {
try {
filterer = (StackTraceFilterer)GrailsClassUtils.instantiateFromConfig(
application.getConfig(), "grails.logging.stackTraceFiltererClass", DefaultStackTraceFilterer.class.getName());
filterer = (StackTraceFilterer)GrailsClassUtils.instantiateFromFlatConfig(
application.getFlatConfig(), "grails.logging.stackTraceFiltererClass", DefaultStackTraceFilterer.class.getName());
}
catch (Throwable t) {
logger.error("Problem instantiating StackTracePrinter class, using default: " + t.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ class ValidationFailureAuthor {
name(size:8..16)
}
}
class ValidationOrder {
Long id
Long version
String five
String four
String one
String six
String three
String two
static constraints = {
one blank: false
two blank: false
three blank: false
four blank: false
five blank: false
six blank: false
}
}
"""
}

Expand Down Expand Up @@ -61,4 +80,19 @@ class ValidationFailureAuthor {
a = authorClass.clazz.get(1)
assertEquals "123456789", a.name
}

void testOrderOfErrors() {
def orderClass = ga.getDomainClass('ValidationOrder')
def order = orderClass.newInstance()
assertFalse order.validate()
def errors = order.errors
assertNotNull errors
assertEquals 6, errors.errorCount
assertEquals 'one', errors.allErrors[0].field
assertEquals 'two', errors.allErrors[1].field
assertEquals 'three', errors.allErrors[2].field
assertEquals 'four', errors.allErrors[3].field
assertEquals 'five', errors.allErrors[4].field
assertEquals 'six', errors.allErrors[5].field
}
}

0 comments on commit 49d9869

Please sign in to comment.