Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merged fix for GRAILS-8833

  • Loading branch information...
commit 342b7de7d793e54046e5d19197a2d2e444f13046 1 parent 5b3904c
@graemerocher graemerocher authored
View
2  grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/interactive/InteractiveMode.groovy
@@ -55,7 +55,7 @@ class InteractiveMode {
/** Options supported by the 'open' command. */
def openOptions
- private MetaClassRegistryCleaner registryCleaner = new MetaClassRegistryCleaner();
+ private MetaClassRegistryCleaner registryCleaner = MetaClassRegistryCleaner.createAndRegister()
InteractiveMode(BuildSettings settings, GrailsScriptRunner scriptRunner) {
this.scriptRunner = scriptRunner
View
28 grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/support/MetaClassRegistryCleaner.java
@@ -41,17 +41,37 @@
private Map<IdentityWeakReference, Object> alteredInstances = new ConcurrentHashMap<IdentityWeakReference, Object>();
private static final Object NO_CUSTOM_METACLASS = new Object();
private static boolean cleaning;
+ private static final MetaClassRegistryCleaner INSTANCE = new MetaClassRegistryCleaner();
+
+
+ private MetaClassRegistryCleaner() {
+ }
public static MetaClassRegistryCleaner createAndRegister() {
- MetaClassRegistryCleaner mcr = new MetaClassRegistryCleaner();
- GroovySystem.getMetaClassRegistry().addMetaClassRegistryChangeEventListener(mcr);
- return mcr;
+
+ MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
+ MetaClassRegistryChangeEventListener[] listeners = metaClassRegistry.getMetaClassRegistryChangeEventListeners();
+ boolean registered = false;
+ for (MetaClassRegistryChangeEventListener listener : listeners) {
+ if(listener == INSTANCE) {
+ registered = true;break;
+ }
+ }
+ if(!registered) {
+ GroovySystem.getMetaClassRegistry().addMetaClassRegistryChangeEventListener(INSTANCE);
+ }
+ return INSTANCE;
}
public static void cleanAndRemove(MetaClassRegistryCleaner cleaner) {
cleaner.clean();
GroovySystem.getMetaClassRegistry().removeMetaClassRegistryChangeEventListener(cleaner);
}
+
+
+ public static void addAlteredMetaClass(Class cls, MetaClass altered) {
+ INSTANCE.alteredClasses.put(cls, altered);
+ }
public void updateConstantMetaClass(MetaClassRegistryChangeEvent cmcu) {
if(!cleaning) {
@@ -81,7 +101,7 @@ private void updateMetaClassOfInstance(MetaClass oldMetaClass, Object instanceTo
private void updateMetaClassOfClass(MetaClass oldMetaClass, Class classToUpdate) {
if (oldMetaClass != null) {
Object current = alteredClasses.get(classToUpdate);
- if(current == null || current == NO_CUSTOM_METACLASS) {
+ if (current == null ) {
alteredClasses.put(classToUpdate, oldMetaClass);
}
}
View
9 grails-core/src/main/groovy/org/codehaus/groovy/grails/validation/ConstrainedProperty.java
@@ -234,6 +234,13 @@ public static void removeConstraint(String name, Class constraintClass) {
List<Object> objects = getOrInitializeConstraint(name);
objects.remove(constraintClass);
+ List<Object> toRemove = new ArrayList<Object>();
+ for (Object object : objects) {
+ if(constraintClass.isInstance(object)) {
+ toRemove.add(object);
+ }
+ }
+ objects.removeAll(toRemove);
}
public static void removeConstraint(String name) {
@@ -271,7 +278,7 @@ public static void registerNewConstraint(String name, ConstraintFactory factory)
}
public static boolean hasRegisteredConstraint(String constraintName) {
- return constraints.containsKey(constraintName);
+ return constraints.containsKey(constraintName) && constraints.get(constraintName).size()>0;
}
/**
View
10 grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/validation/UniqueConstraint.java
@@ -24,6 +24,8 @@
import org.codehaus.groovy.grails.commons.GrailsDomainClass;
import org.codehaus.groovy.grails.commons.GrailsDomainClassProperty;
import org.codehaus.groovy.grails.exceptions.GrailsRuntimeException;
+import org.codehaus.groovy.grails.lifecycle.ShutdownOperations;
+import org.codehaus.groovy.grails.validation.ConstrainedProperty;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.hibernate.Criteria;
import org.hibernate.FlushMode;
@@ -54,6 +56,14 @@
private boolean unique;
private List<String> uniquenessGroup = new ArrayList<String>();
+ public UniqueConstraint() {
+ ShutdownOperations.addOperation(new Runnable() {
+ public void run() {
+ ConstrainedProperty.removeConstraint(UNIQUE_CONSTRAINT, PersistentConstraintFactory.class);
+ }
+ });
+ }
+
/**
* @return Returns the unique.
*/
View
10 grails-plugin-testing/src/main/groovy/grails/test/GrailsUnitTestCase.groovy
@@ -42,7 +42,7 @@ class GrailsUnitTestCase extends GroovyTestCase {
Set loadedCodecs
def applicationContext
Map errorsMap
- private MetaClassRegistryCleaner registryCleaner = new MetaClassRegistryCleaner()
+ private MetaClassRegistryCleaner registryCleaner = MetaClassRegistryCleaner.createAndRegister()
/**
* Keeps track of the domain classes mocked within a single test so
@@ -100,6 +100,7 @@ class GrailsUnitTestCase extends GroovyTestCase {
*/
protected void registerMetaClass(Class clazz) {
// Create a new EMC for the class and attach it.
+ MetaClassRegistryCleaner.addAlteredMetaClass(clazz, GroovySystem.getMetaClassRegistry().getMetaClass(clazz))
def emc = new ExpandoMetaClass(clazz, true, true)
emc.initialize()
GroovySystem.metaClassRegistry.setMetaClass(clazz, emc)
@@ -142,7 +143,7 @@ class GrailsUnitTestCase extends GroovyTestCase {
def dc = MockUtils.mockDomain(domainClass, errorsMap, instances)
domainClassesInfo.addGrailsClass(dc)
- addConverters(domainClass)
+ addConverters(domainClass, false)
}
/**
@@ -223,8 +224,9 @@ class GrailsUnitTestCase extends GroovyTestCase {
Object.metaClass."decode$codecName" = { -> codec.decode(delegate) }
}
- protected void addConverters(Class clazz) {
- registerMetaClass(clazz)
+ protected void addConverters(Class clazz, boolean register = true) {
+ if(register)
+ registerMetaClass(clazz)
clazz.metaClass.asType = {Class asClass ->
if (ConverterUtil.isConverterClass(asClass)) {
return ConverterUtil.createConverter(asClass, delegate, applicationContext)
View
2  grails-plugin-testing/src/main/groovy/grails/test/mixin/support/GrailsUnitTestMixin.groovy
@@ -63,7 +63,7 @@ class GrailsUnitTestMixin {
static ConfigObject config
static MessageSource messageSource
- private static metaClassRegistryListener = new MetaClassRegistryCleaner()
+ private static metaClassRegistryListener = MetaClassRegistryCleaner.createAndRegister()
Map validationErrorsMap = new IdentityHashMap()
Set loadedCodecs = []
Please sign in to comment.
Something went wrong with that request. Please try again.