1. 20 6月, 2015 2 次提交
    • S
      Polishing · 27d1ce84
      Sam Brannen 提交于
      27d1ce84
    • S
      Honor contract of @Repeatable in AnnotationUtils · fb83e83e
      Sam Brannen 提交于
      Prior to this commit, the implementation of getRepeatableAnnotation()
      in Spring's AnnotationUtils complied neither with the contract of
      getAnnotationsByType() nor with the contract of
      getDeclaredAnnotationsByType() as defined in AnnotatedElement in Java 8.
      
      Specifically, unexpected results can be encountered when using Spring's
      support for @Repeatable annotations: either annotations show up in the
      returned set in the wrong order, or annotations are returned in the set
      that should not even be found based on the semantics of @Repeatable.
      
      This commit remedies this problem by deprecating the existing
      getRepeatableAnnotation() methods and replacing them with new
      getRepeatableAnnotations() and getDeclaredRepeatableAnnotations()
      methods that comply with the contracts of Java's getAnnotationsByType()
      and getDeclaredAnnotationsByType(), respectively.
      
      Issue: SPR-13068
      fb83e83e
  2. 19 6月, 2015 1 次提交
    • S
      Synthesize annotation from map w/ minimal attributes · ece12f9d
      Sam Brannen 提交于
      The initial support for synthesizing an annotation from a Map (or
      AnnotationAttributes) introduced in SPR-13067 required that the map
      contain key-value pairs for every attribute defined by the supplied
      annotationType. However, there are use cases that would benefit from
      being able to supply a reduced set of attributes and still have the
      annotation synthesized properly.
      
      This commit refines the validation mechanism in
      MapAnnotationAttributeExtractor so that a reduced set of attributes may
      be supplied. Specifically, if an attribute is missing in the supplied
      map the attribute will be set either to value of its alias (if an alias
      value configured via @AliasFor exists) or to the value of the
      attribute's default value (if defined), and otherwise an exception will
      be thrown.
      
      Furthermore, TransactionalTestExecutionListener has been refactored to
      take advantage of this new feature by synthesizing an instance of
      @TransactionConfiguration solely from the default values of its
      declared attributes.
      
      Issue: SPR-13087
      ece12f9d
  3. 30 5月, 2015 1 次提交
  4. 29 5月, 2015 1 次提交
    • S
      Synthesize annotation from a map of attributes · e30c9b2e
      Sam Brannen 提交于
      Spring Framework 4.2 RC1 introduced support for synthesizing an
      annotation from an existing annotation in order to provide additional
      functionality above and beyond that provided by Java. Specifically,
      such synthesized annotations provide support for @AliasFor semantics.
      As luck would have it, the same principle can be used to synthesize an
      annotation from any map of attributes, and in particular, from an
      instance of AnnotationAttributes.
      
      The following highlight the major changes in this commit toward
      achieving this goal.
      
      - Introduced AnnotationAttributeExtractor abstraction and refactored
        SynthesizedAnnotationInvocationHandler to delegate to an
        AnnotationAttributeExtractor.
      
      - Extracted code from SynthesizedAnnotationInvocationHandler into new
        AbstractAliasAwareAnnotationAttributeExtractor and
        DefaultAnnotationAttributeExtractor implementation classes.
      
      - Introduced MapAnnotationAttributeExtractor for synthesizing an
        annotation that is backed by a map or AnnotationAttributes instance.
      
      - Introduced a variant of synthesizeAnnotation() in AnnotationUtils
        that accepts a map.
      
      - Introduced findAnnotation(*) methods in AnnotatedElementUtils that
        synthesize merged AnnotationAttributes back into an annotation of the
        target type.
      
      The following classes have been refactored to use the new support for
      synthesizing AnnotationAttributes back into an annotation.
      
      - ApplicationListenerMethodAdapter
      - TestAnnotationUtils
      - AbstractTestContextBootstrapper
      - ActiveProfilesUtils
      - ContextLoaderUtils
      - DefaultActiveProfilesResolver
      - DirtiesContextTestExecutionListener
      - TestPropertySourceAttributes
      - TestPropertySourceUtils
      - TransactionalTestExecutionListener
      - MetaAnnotationUtils
      - MvcUriComponentsBuilder
      - RequestMappingHandlerMapping
      
      In addition, this commit also includes changes to ensure that arrays
      returned by synthesized annotations are properly cloned first.
      
      Issue: SPR-13067
      e30c9b2e
  5. 27 5月, 2015 1 次提交
    • S
      Ensure synthesized nested annotation arrays retain correct type · f41de12c
      Sam Brannen 提交于
      Prior to this commit, when a nested array of annotations was
      synthesized while adapting values within an AnnotationAttributes map,
      the array was improperly replaced with an array of type Annotation[]
      instead of an array of the concrete annotation type, which can lead to
      unexpected run-time exceptions.
      
      This commit fixes this bug by replacing annotations in the existing
      array with synthesized versions of those annotations, thereby retaining
      the original array's component type.
      
      Issue: SPR-13077
      f41de12c
  6. 24 5月, 2015 3 次提交
  7. 22 5月, 2015 4 次提交
    • S
      Polish annotation utility tests · 73170224
      Sam Brannen 提交于
      73170224
    • S
      Verify that SynthesizedAnnotation must be public · e7ea9256
      Sam Brannen 提交于
      This commit introduces a test that will fail if SynthesizedAnnotation is
      not public as is required by the contract for getProxyClass() in
      java.lang.reflect.Proxy.
      
      Issue: SPR-13057
      e7ea9256
    • S
      Polish · 27c435c4
      Stephane Nicoll 提交于
      27c435c4
    • S
      Support annotation attribute aliases and overrides via @AliasFor · ca66e076
      Sam Brannen 提交于
      This commit introduces first-class support for aliases for annotation
      attributes. Specifically, this commit introduces a new @AliasFor
      annotation that can be used to declare a pair of aliased attributes
      within a single annotation or an alias from an attribute in a custom
      composed annotation to an attribute in a meta-annotation.
      
      To support @AliasFor within annotation instances, AnnotationUtils has
      been overhauled to "synthesize" any annotations returned by "get" and
      "find" searches. A SynthesizedAnnotation is an annotation that is
      wrapped in a JDK dynamic proxy which provides run-time support for
      @AliasFor semantics. SynthesizedAnnotationInvocationHandler is the
      actual handler behind the proxy.
      
      In addition, the contract for @AliasFor is fully validated, and an
      AnnotationConfigurationException is thrown in case invalid
      configuration is detected.
      
      For example, @ContextConfiguration from the spring-test module is now
      declared as follows:
      
          public @interface ContextConfiguration {
      
              @AliasFor(attribute = "locations")
              String[] value() default {};
      
              @AliasFor(attribute = "value")
              String[] locations() default {};
      
              // ...
          }
      
      The following annotations and their related support classes have been
      modified to use @AliasFor.
      
      - @ManagedResource
      - @ContextConfiguration
      - @ActiveProfiles
      - @TestExecutionListeners
      - @TestPropertySource
      - @Sql
      - @ControllerAdvice
      - @RequestMapping
      
      Similarly, support for AnnotationAttributes has been reworked to
      support @AliasFor as well. This allows for fine-grained control over
      exactly which attributes are overridden within an annotation hierarchy.
      In fact, it is now possible to declare an alias for the 'value'
      attribute of a meta-annotation.
      
      For example, given the revised declaration of @ContextConfiguration
      above, one can now develop a composed annotation with a custom
      attribute override as follows.
      
          @ContextConfiguration
          public @interface MyTestConfig {
      
              @AliasFor(
                 annotation = ContextConfiguration.class,
                 attribute = "locations"
              )
              String[] xmlFiles();
      
              // ...
          }
      
      Consequently, the following are functionally equivalent.
      
      - @MyTestConfig(xmlFiles = "test.xml")
      - @ContextConfiguration("test.xml")
      - @ContextConfiguration(locations = "test.xml").
      
      Issue: SPR-11512, SPR-11513
      ca66e076
  8. 13 5月, 2015 1 次提交
    • S
      Favor local, composed annotations in AnnotatedElementUtils · ebed52cc
      Sam Brannen 提交于
      This commit updates the "get semantics" search algorithm used in
      `AnnotatedElementUtils` so that locally declared 'composed annotations'
      are favored over inherited annotations.
      
      Specifically, the internal `searchWithGetSemantics()` method now
      searches locally declared annotations before searching inherited
      annotations.
      
      All TODOs in `AnnotatedElementUtilsTests` have been completed, and all
      ignored tests have been reinstated.
      
      Issue: SPR-11598
      ebed52cc
  9. 23 4月, 2015 1 次提交
  10. 22 4月, 2015 3 次提交
  11. 21 10月, 2014 1 次提交
  12. 26 2月, 2014 2 次提交
    • S
      Favor 'local' annotations over inherited ones · 1d30bf83
      Sam Brannen 提交于
      Prior to this commit, the implementations of findAnnotation() in
      AnnotationUtils and getAnnotationAttributes() in AnnotatedElementUtils
      favored inherited annotations and inherited composed annotations over
      composed annotations that are declared closer to the starting class
      passed to these methods.
      
      This commit addresses this issue as follows:
      
      - Refactored AnnotationUtils to use getDeclaredAnnotation() and
        getDeclaredAnnotations() instead of getAnnotation() and
        getAnnotations() where appropriate.
      
      - AnnotatedElementUtils.doProcess() supports a traverseClassHierarchy
        flag to control whether the class hierarchy should be traversed,
        using getDeclaredAnnotations() instead of getAnnotations() if the
        flag is true.
      
      - Overhauled Javadoc in AnnotatedElementUtils.
      
      Issue: SPR-11475
      1d30bf83
    • S
      Do not inspect meta-annotations on Java annotations · 979c4833
      Sam Brannen 提交于
      This commit introduces a new isInJavaLangAnnotationPackage(Annotation)
      method in AnnotationUtils. This method is now used in AnnotationUtils,
      AnnotatedElementUtils, and MetaAnnotationUtils to ensure that search
      algorithms do no search for meta-annotations on annotations in the
      "java.lang.annotation" package.
      
      The following are some empirical results from this change:
      
      - The number of times that the findAnnotation(Class,Class,Set) method in
        AnnotationUtils is recursively invoked while executing
        AnnotationUtilsTests drops from 51 to 29.
      
      - The number of times that the process(AnnotatedElement) method in
        AnnotationUtils.AnnotationCollector is recursively invoked while
        executing AnnotationUtilsTests.getRepeatableFromMethod() drops
        from 16 to 2.
      
      - The number of times that the doProcess() method in
        AnnotatedElementUtils is recursively invoked while executing the
        "getAnnotationAttributes() On MetaCycleAnnotatedClass with missing
        target meta-annotation" test in AnnotatedElementUtilsTests drops
        from 23 to 5.
      
      - The number of times that the findAnnotationDescriptor(Class,Set,Class)
        method in MetaAnnotationUtils is recursively invoked while executing
        the "findAnnotationDescriptor() on MetaCycleAnnotatedClass with
        missing target meta-annotation" test in MetaAnnotationUtilsTests drops
        from 16 to 8.
      
      Issue: SPR-11483
      979c4833
  13. 24 2月, 2014 1 次提交
  14. 20 2月, 2014 1 次提交
    • S
      Support nested meta-annotations in AnnotationUtils · 42a36349
      Sam Brannen 提交于
      Prior to this commit, AnnotationUtils.findAnnotation(Class, Class)
      claimed to recursively search through annotations; however, only one
      level of annotations was supported by the algorithm.
      
      This commit alters the search algorithm so that nested meta-annotations
      (i.e., meta-annotations on meta-annotations) are also supported.
      
      Issue: SPR-11448
      42a36349
  15. 19 2月, 2014 1 次提交
  16. 05 1月, 2014 1 次提交
  17. 21 11月, 2013 1 次提交
    • S
      Support non-public anno. attr. values in AnnoUtils · b830d736
      Sam Brannen 提交于
      Prior to this commit, the getValue(Annotation, String) method in
      AnnotationUtils failed to retrieve the value of the desired annotation
      attribute if the annotation itself was not public -- for example if the
      annotation was declared as package private.
      
      This commit addresses this issue by ensuring that getValue(Annotation,
      String) uses reflection to make the desired annotation attribute method
      accessible before attempting to invoke it to retrieve the value.
      
      Issue: SPR-11104
      b830d736
  18. 28 10月, 2013 1 次提交
    • S
      Provide meta-annotation support in the TCF · 5e7021f3
      Sam Brannen 提交于
      Spring 3.0 already allows component stereotypes to be used in a
      meta-annotation fashion, for example by creating a custom
      @TransactionalService stereotype annotation which combines
      @Transactional and @Service in a single, reusable, application-specific
      annotation. However, the Spring TestContext Framework (TCF) currently
      does not provide any support for test-related annotations to be used as
      meta-annotations.
      
      This commit overhauls the TCF with regard to how annotations are
      retrieved and adds explicit support for the following annotations to be
      used as meta-annotations in conjunction with the TCF.
      
      - @ContextConfiguration
      - @ContextHierarchy
      - @ActiveProfiles
      - @DirtiesContext
      - @IfProfileValue
      - @ProfileValueSourceConfiguration
      - @BeforeTransaction
      - @AfterTransaction
      - @TransactionConfiguration
      - @Rollback
      - @TestExecutionListeners
      - @Repeat
      - @Timed
      - @WebAppConfiguration
      
      Note that meta-annotation support for @Transactional was already
      available prior to this commit.
      
      The following is a summary of the major changes included in this commit.
      
      - Now using AnnotationUtils.getAnnotation() instead of
        Class.getAnnotation() where appropriate in the TestContext Framework.
      - Now using AnnotationUtils.findAnnotation() instead of
        Class.isAnnotationPresent() where appropriate in the TestContext
        Framework.
      - Introduced findAnnotationPrefersInteracesOverLocalMetaAnnotations() in
        AnnotationUtilsTests in order to verify the status quo.
      - AnnotationUtils.findAnnotationDeclaringClass() and
        AnnotationUtils.findAnnotationDeclaringClassForTypes() now support
        meta annotations.
      - Introduced MetaAnnotationUtils and AnnotationDescriptor in the
        spring-test module.
      - Introduced UntypedAnnotationDescriptor in MetaAnnotationUtils.
      - Introduced findAnnotationDescriptorForTypes() in MetaAnnotationUtils.
      - ContextLoaderUtils now uses MetaAnnotationUtils for looking up
        @ActiveProfiles as a potential meta-annotation.
      - TestContextManager now uses MetaAnnotationUtils for looking up
        @TestExecutionListeners as a potential meta-annotation.
      - DirtiesContextTestExecutionListener now uses AnnotationUtils for
        looking up @DirtiesContext as a potential meta-annotation.
      - Introduced DirtiesContextTestExecutionListenerTests.
      - ProfileValueUtils now uses AnnotationUtils for looking up
        @IfProfileValue and @ProfileValueSourceConfiguration as potential
        meta-annotations.
      - @BeforeTransaction and @AfterTransaction now support ANNOTATION_TYPE
        as a target, allowing them to be used as meta-annotations.
      - TransactionalTestExecutionListener now uses AnnotationUtils for
        looking up @BeforeTransaction, @AfterTransaction, @Rollback, and
        @TransactionConfiguration as potential meta-annotations.
      - Introduced TransactionalTestExecutionListenerTests.
      - @Repeat and @Timed now support ANNOTATION_TYPE as a target, allowing
        them to be used as meta-annotations.
      - SpringJUnit4ClassRunner now uses AnnotationUtils for looking up
        @Repeat and @Timed as potential meta-annotations.
      - Moved all remaining logic for building the MergedContextConfiguration
        from the DefaultTestContext constructor to
        ContextLoaderUtils.buildMergedContextConfiguration().
      - Verified meta-annotation support for @WebAppConfiguration and
        @ContextConfiguration.
      
      Issue: SPR-7827
      5e7021f3
  19. 23 10月, 2013 1 次提交
    • P
      Add @PropertySources and ignoreResourceNotFound · e95bd9e2
      Phillip Webb 提交于
      Support repeatable @PropertySource annotations in Java 8 and add
      @PropertySources container annotation for Java 6/7. Also add an
      ignoreResourceNotFound attribute to @PropertySource allowing missing
      property resources to be silently ignored.
      
      This commit also introduces some generally useful methods to
      AnnotationUtils for working with @Repeatable annotations.
      
      Issue: SPR-8371
      e95bd9e2
  20. 24 7月, 2013 1 次提交
  21. 07 3月, 2013 1 次提交
    • S
      Provide support for context hierarchies in the TCF · 98074e77
      Sam Brannen 提交于
      Prior to this commit the Spring TestContext Framework supported creating
      only flat, non-hierarchical contexts. There was no easy way to create
      contexts with parent-child relationships.
      
      This commit addresses this issue by introducing a new @ContextHierarchy
      annotation that can be used in conjunction with @ContextConfiguration
      for declaring hierarchies of application contexts, either within a
      single test class or within a test class hierarchy. In addition,
      @DirtiesContext now supports a new 'hierarchyMode' attribute for
      controlling context cache clearing for context hierarchies.
      
      - Introduced a new @ContextHierarchy annotation.
      - Introduced 'name' attribute in @ContextConfiguration.
      - Introduced 'name' property in ContextConfigurationAttributes.
      - TestContext is now aware of @ContextHierarchy in addition to
        @ContextConfiguration.
      - Introduced findAnnotationDeclaringClassForTypes() in AnnotationUtils.
      - Introduced resolveContextHierarchyAttributes() in ContextLoaderUtils.
      - Introduced buildContextHierarchyMap() in ContextLoaderUtils.
      - @ContextConfiguration and @ContextHierarchy may not be used as
        top-level, class-level annotations simultaneously.
      - Introduced reference to the parent configuration in
        MergedContextConfiguration and WebMergedContextConfiguration.
      - Introduced overloaded buildMergedContextConfiguration() methods in
        ContextLoaderUtils in order to handle context hierarchies separately
        from conventional, non-hierarchical contexts.
      - Introduced hashCode() and equals() in ContextConfigurationAttributes.
      - ContextLoaderUtils ensures uniqueness of @ContextConfiguration
        elements within a single @ContextHierarchy declaration.
      - Introduced CacheAwareContextLoaderDelegate that can be used for
        loading contexts with transparent support for interacting with the
        context cache -- for example, for retrieving the parent application
        context in a context hierarchy.
      - TestContext now delegates to CacheAwareContextLoaderDelegate for
        loading contexts.
      - Introduced getParentApplicationContext() in MergedContextConfiguration
      - The loadContext(MergedContextConfiguration) methods in
        AbstractGenericContextLoader and AbstractGenericWebContextLoader now
        set the parent context as appropriate.
      - Introduced 'hierarchyMode' attribute in @DirtiesContext with a
        corresponding HierarchyMode enum that defines EXHAUSTIVE and
        CURRENT_LEVEL cache removal modes.
      - ContextCache now internally tracks the relationships between contexts
        that make up a context hierarchy. Furthermore, when a context is
        removed, if it is part of a context hierarchy all corresponding
        contexts will be removed from the cache according to the supplied
        HierarchyMode.
      - AbstractGenericWebContextLoader will set a loaded context as the
        ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when
        context hierarchies are used if the context has no parent or if the
        context has a parent that is not a WAC.
      - Where appropriate, updated Javadoc to refer to the
        ServletTestExecutionListener, which was introduced in 3.2.0.
      - Updated Javadoc to avoid and/or suppress warnings in spring-test.
      - Suppressed remaining warnings in code in spring-test.
      
      Issue: SPR-5613, SPR-9863
      98074e77
  22. 29 12月, 2012 2 次提交
  23. 17 5月, 2012 1 次提交
    • P
      Fix annotation search ending too early · ef7e728b
      Petr Janecek 提交于
      In AnnotationUtils#findAnnotation(Method, Class), the search for a
      method annotation fails if:
      
       - the original method does not have the annotation
      
       - an abstract superclass does not have an equivalent method declared
      
       - an interface implemented by the superclass has the method and
         the annotation -> this should be found, but is not!
      
      This happens because the try-catch block in #findAnnotation is too wide:
      cl.getDeclaredMethod() can throw NoSuchMethodException and skip the
      '#searchOnInterfaces' call prematurely.
      
      The try-catch block was made narrower to allow #searchOnInterfaces to
      be called even if the abstract class does not have the method declared
      at all.
      
      Issue: SPR-9342
      ef7e728b
  24. 31 1月, 2012 1 次提交
    • C
      Rename modules {org.springframework.*=>spring-*} · 02a4473c
      Chris Beams 提交于
      This renaming more intuitively expresses the relationship between
      subprojects and the JAR artifacts they produce.
      
      Tracking history across these renames is possible, but it requires
      use of the --follow flag to `git log`, for example
      
          $ git log spring-aop/src/main/java/org/springframework/aop/Advisor.java
      
      will show history up until the renaming event, where
      
          $ git log --follow spring-aop/src/main/java/org/springframework/aop/Advisor.java
      
      will show history for all changes to the file, before and after the
      renaming.
      
      See http://chrisbeams.com/git-diff-across-renamed-directories
      02a4473c
  25. 29 11月, 2011 1 次提交
  26. 10 10月, 2011 1 次提交
    • C
      Refactor AnnotationUtils#findAllAnnotationAttributes · 6837111b
      Chris Beams 提交于
      Remove all convenience variants of #findAllAnnotationAttributes and
      refactor the remaining method to accept a MetadataReaderFactory
      instead of creating its own SimpleMetadataReaderFactory internally.
      This allows clients to use non-default class loaders as well as
      customize the particular MetadataReaderFactory to be used (e.g.
      'simple' vs 'caching', etc).
      
      Issue: SPR-8752
      6837111b
  27. 07 5月, 2011 1 次提交
    • C
      Process all meta and local @Import declarations · 89005a5b
      Chris Beams 提交于
      Includes the introduction of AnnotationUtils#findAllAnnotationAttributes
      to support iterating through all annotations declared on a given type
      and interrogating each for the presence of a meta-annotation. See tests
      for details.
      89005a5b
  28. 15 6月, 2010 3 次提交