Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package grails.gorm.tests

import spock.lang.Ignore

import grails.persistence.Entity

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package grails.gorm.services

import spock.lang.Ignore

import grails.gorm.annotation.Entity
import grails.gorm.validation.PersistentEntityValidator
import grails.validation.ValidationException
import groovy.json.JsonOutput
import groovy.json.DefaultJsonGenerator
import groovy.json.JsonGenerator
import org.grails.datastore.gorm.validation.constraints.eval.DefaultConstraintEvaluator
import org.grails.datastore.gorm.validation.constraints.registry.DefaultConstraintRegistry
import org.grails.datastore.gorm.validation.constraints.registry.DefaultValidatorRegistry
Expand Down Expand Up @@ -309,27 +308,6 @@ class ServiceImplSpec extends Specification {

}

@Ignore('''
java.lang.StackOverflowError
at groovy.lang.Closure.call(Closure.java:435)
at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:319)
at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:40)
at org.grails.datastore.gorm.GormInstanceApi.isAttached(GormInstanceApi.groovy:227)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.isAttached(GormEntity.groovy:176)
at groovy.lang.MetaBeanProperty.getProperty(MetaBeanProperty.java:60)
at groovy.json.DefaultJsonGenerator.getObjectProperties(DefaultJsonGenerator.java:257)
at groovy.json.DefaultJsonGenerator.writeObject(DefaultJsonGenerator.java:234)
at groovy.json.DefaultJsonGenerator.writeMapEntry(DefaultJsonGenerator.java:401)
at groovy.json.DefaultJsonGenerator.writeMap(DefaultJsonGenerator.java:389)
at groovy.json.DefaultJsonGenerator.writeObject(DefaultJsonGenerator.java:204)
at groovy.json.DefaultJsonGenerator.writeMapEntry(DefaultJsonGenerator.java:401)
at groovy.json.DefaultJsonGenerator.writeMap(DefaultJsonGenerator.java:389)
at groovy.json.DefaultJsonGenerator.writeObject(DefaultJsonGenerator.java:235)
at groovy.json.DefaultJsonGenerator.writeMapEntry(DefaultJsonGenerator.java:401)
at groovy.json.DefaultJsonGenerator.writeMap(DefaultJsonGenerator.java:389)
at groovy.json.DefaultJsonGenerator.writeObject(DefaultJsonGenerator.java:235)
at groovy.json.DefaultJsonGenerator.writeMapEntry(DefaultJsonGenerator.java:401)
at groovy.json.DefaultJsonGenerator.writeMap(DefaultJsonGenerator.java:389)''')
void "test interface projection"() {
given:
ProductService productService = datastore.getService(ProductService)
Expand All @@ -341,7 +319,9 @@ class ServiceImplSpec extends Specification {

ProductInfo info = productService.findProductInfo("Pumpkin", "Vegetable")
List<ProductInfo> infos = productService.findProductInfos( "Vegetable")
def result = JsonOutput.toJson(info)

// groovy4 will include the generated methods in output of json, which recursively refer to themselves
def result = new DefaultJsonGenerator(new JsonGenerator.Options().excludeFieldsByName("\$target")).toJson(info)
then:
infos.size() == 2
infos.first().name == "Carrot"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.grails.datastore.gorm

import spock.lang.Ignore

import grails.gorm.tests.GormDatastoreSpec
import grails.persistence.Entity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.grails.datastore.gorm

import spock.lang.Ignore

import grails.gorm.tests.GormDatastoreSpec
import grails.persistence.Entity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.grails.datastore.gorm.validation

import spock.lang.Ignore

import grails.gorm.annotation.Entity
import grails.gorm.transactions.Transactional
import org.grails.datastore.gorm.validation.constraints.MappingContextAwareConstraintFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.springframework.asm.AnnotationVisitor;
import org.springframework.asm.SpringAsmInfo;
import org.springframework.core.annotation.AnnotationFilter;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
Expand All @@ -43,8 +44,8 @@ public class AnnotationMetadataReader implements MetadataReader {
* @param resource The resource
* @throws IOException
*/
AnnotationMetadataReader(Resource resource) throws IOException {
this.annotationMetadata = AnnotationMetadata.introspect(resource.getClass());
AnnotationMetadataReader(Resource resource, AnnotationFilter filter) throws IOException {
this.annotationMetadata = new FilteredAnnotationMetadata(resource.getClass(), filter);
// since AnnotationMetadata extends ClassMetadata
this.classMetadata = this.annotationMetadata;
this.resource = resource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright 2016 the original author or authors.
/*
* Copyright 2016-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,7 +67,7 @@ class ClasspathEntityScanner {
*/
Class[] scan(Package... packages) {
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false)
componentProvider.setMetadataReaderFactory(new AnnotationMetadataReaderFactory(classLoader))
componentProvider.setMetadataReaderFactory(new EntityAnnotationMetadataReaderFactory(classLoader))
for(ann in annotations) {
componentProvider.addIncludeFilter(new AnnotationTypeFilter(ann))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.grails.datastore.gorm.utils;

import org.springframework.core.annotation.AnnotationFilter;
import org.springframework.core.io.Resource;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
Expand All @@ -9,13 +10,13 @@
/**
* A {@link CachingMetadataReaderFactory} that only reads annotations and not the whole class body
*/
class AnnotationMetadataReaderFactory extends CachingMetadataReaderFactory {
public AnnotationMetadataReaderFactory(ClassLoader classLoader) {
class EntityAnnotationMetadataReaderFactory extends CachingMetadataReaderFactory {
public EntityAnnotationMetadataReaderFactory(ClassLoader classLoader) {
super(classLoader);
}

@Override
public MetadataReader getMetadataReader(Resource resource) throws IOException {
return new AnnotationMetadataReader(resource);
return new AnnotationMetadataReader(resource, AnnotationFilter.packages("grails.gorm.annotation", "grails.persistence", "jakarta.persistence"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.grails.datastore.gorm.utils;

import org.springframework.core.annotation.*;
import org.springframework.core.type.*;
import org.springframework.lang.Nullable;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/**
* {@link AnnotationMetadata} implementation that uses standard reflection
* to introspect a given {@link Class}.
*
* <p>Note: this class was ported to GORM 9 from Spring Framework 6.1 since the package filter can't be passed to the spring version.</p>
*
* @author Juergen Hoeller
* @author Mark Fisher
* @author Chris Beams
* @author Phillip Webb
* @author Sam Brannen
* @since 2.5
* @deprecated As of Spring Framework 6.1, this class does not allow specifying the annotation filter. An upstream pull request should be opened so this can be removed.
*/
@Deprecated
public class FilteredAnnotationMetadata extends StandardClassMetadata implements AnnotationMetadata {
private final MergedAnnotations mergedAnnotations;

@Nullable
private Set<String> annotationTypes;


/**
* Create a new {@code StandardAnnotationMetadata} wrapper for the given Class.
* @param introspectedClass the Class to introspect
*/
public FilteredAnnotationMetadata(Class<?> introspectedClass, AnnotationFilter filter) {
super(introspectedClass);
this.mergedAnnotations = MergedAnnotations.from(introspectedClass,
MergedAnnotations.SearchStrategy.INHERITED_ANNOTATIONS, RepeatableContainers.none(), filter);
}


@Override
public MergedAnnotations getAnnotations() {
return this.mergedAnnotations;
}

@Override
public Set<String> getAnnotationTypes() {
Set<String> annotationTypes = this.annotationTypes;
if (annotationTypes == null) {
annotationTypes = Collections.unmodifiableSet(AnnotationMetadata.super.getAnnotationTypes());
this.annotationTypes = annotationTypes;
}
return annotationTypes;
}

@Override
@Nullable
public Map<String, Object> getAnnotationAttributes(String annotationName, boolean classValuesAsString) {
return AnnotatedElementUtils.getMergedAnnotationAttributes(
getIntrospectedClass(), annotationName, classValuesAsString, false);
}

@Override
@Nullable
public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) {
return AnnotatedElementUtils.getAllAnnotationAttributes(
getIntrospectedClass(), annotationName, classValuesAsString, false);
}

@Override
public boolean hasAnnotatedMethods(String annotationName) {
if (AnnotationUtils.isCandidateClass(getIntrospectedClass(), annotationName)) {
try {
Method[] methods = org.springframework.util.ReflectionUtils.getDeclaredMethods(getIntrospectedClass());
for (Method method : methods) {
if (isAnnotatedMethod(method, annotationName)) {
return true;
}
}
}
catch (Throwable ex) {
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
}
}
return false;
}

@Override
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
Set<MethodMetadata> result = new LinkedHashSet<>(4);
if (AnnotationUtils.isCandidateClass(getIntrospectedClass(), annotationName)) {
org.springframework.util.ReflectionUtils.doWithLocalMethods(getIntrospectedClass(), method -> {
if (isAnnotatedMethod(method, annotationName)) {
result.add(new StandardMethodMetadata(method));
}
});
}
return result;
}

@Override
public Set<MethodMetadata> getDeclaredMethods() {
Set<MethodMetadata> result = new LinkedHashSet<>(16);
ReflectionUtils.doWithLocalMethods(getIntrospectedClass(), method ->
result.add(new StandardMethodMetadata(method)));
return result;
}


private static boolean isAnnotatedMethod(Method method, String annotationName) {
return !method.isBridge() && method.getAnnotations().length > 0 &&
AnnotatedElementUtils.isAnnotated(method, annotationName);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.grails.compiler.gorm

import spock.lang.Ignore

import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext
import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValuePersistentEntity
import org.grails.datastore.mapping.model.MappingContext
Expand Down Expand Up @@ -54,4 +52,4 @@ class HotWidgetSetting extends WidgetSetting {
entity.getPropertyByName("setting")
entity.getPropertyByName("setting").type.name == 'test.WidgetSetting'
}
}
}
Loading