Search in sources :

Example 1 with MergedAnnotations

use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.

the class OnAvailableEndpointCondition method getEndpointAnnotation.

protected MergedAnnotation<Endpoint> getEndpointAnnotation(Class<?> target) {
    MergedAnnotations annotations = MergedAnnotations.from(target, SearchStrategy.TYPE_HIERARCHY);
    MergedAnnotation<Endpoint> endpoint = annotations.get(Endpoint.class);
    if (endpoint.isPresent()) {
        return endpoint;
    }
    MergedAnnotation<EndpointExtension> extension = annotations.get(EndpointExtension.class);
    Assert.state(extension.isPresent(), "No endpoint is specified and the return type of the @Bean method is " + "neither an @Endpoint, nor an @EndpointExtension");
    return getEndpointAnnotation(extension.getClass("endpoint"));
}
Also used : EndpointExtension(org.springframework.boot.actuate.endpoint.annotation.EndpointExtension) ExposableEndpoint(org.springframework.boot.actuate.endpoint.ExposableEndpoint) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) MergedAnnotations(org.springframework.core.annotation.MergedAnnotations)

Example 2 with MergedAnnotations

use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.

the class OnBeanCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage matchMessage = ConditionMessage.empty();
    MergedAnnotations annotations = metadata.getAnnotations();
    if (annotations.isPresent(ConditionalOnBean.class)) {
        Spec<ConditionalOnBean> spec = new Spec<>(context, metadata, annotations, ConditionalOnBean.class);
        MatchResult matchResult = getMatchingBeans(context, spec);
        if (!matchResult.isAllMatched()) {
            String reason = createOnBeanNoMatchReason(matchResult);
            return ConditionOutcome.noMatch(spec.message().because(reason));
        }
        matchMessage = spec.message(matchMessage).found("bean", "beans").items(Style.QUOTE, matchResult.getNamesOfAllMatches());
    }
    if (metadata.isAnnotated(ConditionalOnSingleCandidate.class.getName())) {
        Spec<ConditionalOnSingleCandidate> spec = new SingleCandidateSpec(context, metadata, annotations);
        MatchResult matchResult = getMatchingBeans(context, spec);
        if (!matchResult.isAllMatched()) {
            return ConditionOutcome.noMatch(spec.message().didNotFind("any beans").atAll());
        } else if (!hasSingleAutowireCandidate(context.getBeanFactory(), matchResult.getNamesOfAllMatches(), spec.getStrategy() == SearchStrategy.ALL)) {
            return ConditionOutcome.noMatch(spec.message().didNotFind("a primary bean from beans").items(Style.QUOTE, matchResult.getNamesOfAllMatches()));
        }
        matchMessage = spec.message(matchMessage).found("a primary bean from beans").items(Style.QUOTE, matchResult.getNamesOfAllMatches());
    }
    if (metadata.isAnnotated(ConditionalOnMissingBean.class.getName())) {
        Spec<ConditionalOnMissingBean> spec = new Spec<>(context, metadata, annotations, ConditionalOnMissingBean.class);
        MatchResult matchResult = getMatchingBeans(context, spec);
        if (matchResult.isAnyMatched()) {
            String reason = createOnMissingBeanNoMatchReason(matchResult);
            return ConditionOutcome.noMatch(spec.message().because(reason));
        }
        matchMessage = spec.message(matchMessage).didNotFind("any beans").atAll();
    }
    return ConditionOutcome.match(matchMessage);
}
Also used : MergedAnnotations(org.springframework.core.annotation.MergedAnnotations)

Example 3 with MergedAnnotations

use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.

the class DefinitionsParser method parseElement.

private void parseElement(AnnotatedElement element, Class<?> source) {
    MergedAnnotations annotations = MergedAnnotations.from(element, SearchStrategy.SUPERCLASS);
    annotations.stream(MockBean.class).map(MergedAnnotation::synthesize).forEach((annotation) -> parseMockBeanAnnotation(annotation, element, source));
    annotations.stream(SpyBean.class).map(MergedAnnotation::synthesize).forEach((annotation) -> parseSpyBeanAnnotation(annotation, element, source));
}
Also used : MergedAnnotations(org.springframework.core.annotation.MergedAnnotations)

Example 4 with MergedAnnotations

use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.

the class ModifiedClassPathClassLoader method compute.

private static ModifiedClassPathClassLoader compute(Class<?> testClass) {
    ClassLoader classLoader = testClass.getClassLoader();
    MergedAnnotations annotations = MergedAnnotations.from(testClass, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY);
    if (annotations.isPresent(ForkedClassPath.class) && (annotations.isPresent(ClassPathOverrides.class) || annotations.isPresent(ClassPathExclusions.class))) {
        throw new IllegalStateException("@ForkedClassPath is redundant in combination with either " + "@ClassPathOverrides or @ClassPathExclusions");
    }
    return new ModifiedClassPathClassLoader(processUrls(extractUrls(classLoader), annotations), classLoader.getParent(), classLoader);
}
Also used : URLClassLoader(java.net.URLClassLoader) MergedAnnotations(org.springframework.core.annotation.MergedAnnotations)

Example 5 with MergedAnnotations

use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.

the class TimedAnnotations method findTimedAnnotations.

private static Set<Timed> findTimedAnnotations(AnnotatedElement element) {
    if (element == null) {
        return Collections.emptySet();
    }
    Set<Timed> result = cache.get(element);
    if (result != null) {
        return result;
    }
    MergedAnnotations annotations = MergedAnnotations.from(element);
    result = (!annotations.isPresent(Timed.class)) ? Collections.emptySet() : annotations.stream(Timed.class).collect(MergedAnnotationCollectors.toAnnotationSet());
    cache.put(element, result);
    return result;
}
Also used : Timed(io.micrometer.core.annotation.Timed) MergedAnnotations(org.springframework.core.annotation.MergedAnnotations)

Aggregations

MergedAnnotations (org.springframework.core.annotation.MergedAnnotations)7 Timed (io.micrometer.core.annotation.Timed)1 URLClassLoader (java.net.URLClassLoader)1 ExposableEndpoint (org.springframework.boot.actuate.endpoint.ExposableEndpoint)1 Endpoint (org.springframework.boot.actuate.endpoint.annotation.Endpoint)1 EndpointExtension (org.springframework.boot.actuate.endpoint.annotation.EndpointExtension)1