Skip to content

Commit

Permalink
Merge pull request #64 from mercyblitz/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mercyblitz authored Jan 6, 2025
2 parents 47a0400 + 9bdf9b6 commit 87fdeca
Show file tree
Hide file tree
Showing 56 changed files with 237 additions and 255 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.microsphere.spring.beans;

import io.microsphere.logging.Logger;
import io.microsphere.logging.LoggerFactory;
import io.microsphere.util.BaseUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.Aware;
Expand Down Expand Up @@ -38,6 +37,7 @@
import java.util.List;
import java.util.Map;

import static io.microsphere.logging.LoggerFactory.getLogger;
import static io.microsphere.spring.beans.factory.BeanFactoryUtils.asBeanDefinitionRegistry;
import static io.microsphere.spring.beans.factory.BeanFactoryUtils.asConfigurableBeanFactory;
import static io.microsphere.spring.context.ApplicationContextUtils.asConfigurableApplicationContext;
Expand All @@ -63,7 +63,7 @@
*/
public abstract class BeanUtils extends BaseUtils {

private static final Logger logger = LoggerFactory.getLogger(BeanUtils.class);
private static final Logger logger = getLogger(BeanUtils.class);

/**
* Is Bean Present or not?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.microsphere.spring.beans.factory;

import io.microsphere.logging.Logger;
import io.microsphere.logging.LoggerFactory;
import io.microsphere.spring.beans.factory.filter.ResolvableDependencyTypeFilter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
Expand All @@ -36,6 +35,7 @@
import java.util.Set;
import java.util.function.Supplier;

import static io.microsphere.logging.LoggerFactory.getLogger;
import static io.microsphere.reflect.TypeUtils.asClass;
import static io.microsphere.reflect.TypeUtils.isParameterizedType;
import static io.microsphere.reflect.TypeUtils.resolveActualTypeArguments;
Expand All @@ -50,7 +50,7 @@
*/
public abstract class AbstractInjectionPointDependencyResolver implements InjectionPointDependencyResolver, BeanFactoryAware {

private final Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = getLogger(getClass());

private ResolvableDependencyTypeFilter resolvableDependencyTypeFilter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
*/
package io.microsphere.spring.beans.factory;

import io.microsphere.collection.CollectionUtils;
import io.microsphere.collection.SetUtils;
import io.microsphere.lang.function.ThrowableAction;
import io.microsphere.logging.Logger;
import io.microsphere.logging.LoggerFactory;
import io.microsphere.spring.beans.factory.filter.ResolvableDependencyTypeFilter;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
Expand Down Expand Up @@ -54,10 +52,12 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import static io.microsphere.collection.CollectionUtils.isNotEmpty;
import static io.microsphere.collection.ListUtils.newLinkedList;
import static io.microsphere.collection.MapUtils.newHashMap;
import static io.microsphere.collection.MapUtils.ofEntry;
import static io.microsphere.lang.function.ThrowableSupplier.execute;
import static io.microsphere.logging.LoggerFactory.getLogger;
import static io.microsphere.reflect.MemberUtils.isStatic;
import static io.microsphere.spring.beans.factory.BeanFactoryUtils.asDefaultListableBeanFactory;
import static io.microsphere.spring.beans.factory.config.BeanDefinitionUtils.resolveBeanType;
Expand All @@ -82,7 +82,7 @@
*/
public class DefaultBeanDependencyResolver implements BeanDependencyResolver {

private static final Logger logger = LoggerFactory.getLogger(DefaultBeanDependencyResolver.class);
private static final Logger logger = getLogger(DefaultBeanDependencyResolver.class);

private static final ThreadLocal<Set<Member>> resolvedBeanMembersHolder = withInitial(SetUtils::newLinkedHashSet);

Expand Down Expand Up @@ -250,7 +250,7 @@ private void flattenDependentBeanNamesMap(Map<String, Set<String>> dependentBean
Set<String> dependentBeanNames = entry.getValue();
for (String dependentBeanName : dependentBeanNames) {
Set<String> nestedDependentBeanNames = dependentBeanNamesMap.get(dependentBeanName);
if (CollectionUtils.isNotEmpty(nestedDependentBeanNames) && !dependentBeanNames.containsAll(nestedDependentBeanNames)) {
if (isNotEmpty(nestedDependentBeanNames) && !dependentBeanNames.containsAll(nestedDependentBeanNames)) {
nonRootBeanNames.add(beanName);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
*/
package io.microsphere.spring.beans.factory;

import io.microsphere.collection.CollectionUtils;
import io.microsphere.util.ArrayUtils;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

import static io.microsphere.collection.CollectionUtils.size;
import static io.microsphere.collection.ListUtils.newArrayList;
import static io.microsphere.collection.ListUtils.newLinkedList;
import static io.microsphere.util.ArrayUtils.length;
import static java.util.Collections.emptyList;
import static org.springframework.util.Assert.hasText;

Expand Down Expand Up @@ -149,7 +148,7 @@ public static Dependency create(String beanName, Dependency parent, String... de
}

private static List<Dependency> createList(Iterable<String> beanNames) {
int length = CollectionUtils.size(beanNames);
int length = size(beanNames);
if (length < 1) {
return emptyList();
}
Expand All @@ -163,7 +162,7 @@ private static List<Dependency> createList(Iterable<String> beanNames) {
}

private static List<Dependency> createList(String[] beanNames) {
int length = ArrayUtils.length(beanNames);
int length = length(beanNames);
if (length < 1) {
return emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
package io.microsphere.spring.beans.factory;

import io.microsphere.collection.CollectionUtils;

import java.util.Iterator;
import java.util.List;

import static io.microsphere.collection.CollectionUtils.isEmpty;

/**
* {@link Dependency} Tree Walker
*
Expand Down Expand Up @@ -54,7 +54,7 @@ private void removeIfDuplicated(Dependency dependency) {
}

private void walk(Dependency child, List<Dependency> siblings) {
if (CollectionUtils.isEmpty(siblings)) {
if (isEmpty(siblings)) {
return;
}
if (siblings.contains(child)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.microsphere.spring.beans.factory.annotation;

import io.microsphere.logging.Logger;
import io.microsphere.logging.LoggerFactory;
import io.microsphere.spring.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
Expand Down Expand Up @@ -46,7 +45,6 @@
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.ReflectionUtils;

import javax.annotation.Nullable;
import java.beans.PropertyDescriptor;
Expand All @@ -69,6 +67,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static io.microsphere.logging.LoggerFactory.getLogger;
import static io.microsphere.spring.beans.factory.BeanFactoryUtils.asConfigurableListableBeanFactory;
import static io.microsphere.spring.core.annotation.AnnotationUtils.getAnnotationAttributes;
import static java.util.Collections.singleton;
Expand All @@ -79,6 +78,9 @@
import static org.springframework.util.Assert.notEmpty;
import static org.springframework.util.ClassUtils.getMostSpecificMethod;
import static org.springframework.util.ClassUtils.getUserClass;
import static org.springframework.util.ReflectionUtils.doWithFields;
import static org.springframework.util.ReflectionUtils.doWithMethods;
import static org.springframework.util.ReflectionUtils.makeAccessible;
import static org.springframework.util.StringUtils.hasLength;

/**
Expand Down Expand Up @@ -110,7 +112,7 @@ public class AnnotatedInjectionBeanPostProcessor extends InstantiationAwareBeanP

private final static int CACHE_SIZE = Integer.getInteger("microsphere.spring.injection.metadata.cache.size", 32);

private final Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = getLogger(getClass());

private final Collection<Class<? extends Annotation>> annotationTypes;

Expand Down Expand Up @@ -304,27 +306,24 @@ private List<AnnotatedFieldElement> findFieldAnnotationMetadata(final Class<?> b

final List<AnnotatedFieldElement> elements = new LinkedList<AnnotatedFieldElement>();

ReflectionUtils.doWithFields(beanClass, new ReflectionUtils.FieldCallback() {
@Override
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
doWithFields(beanClass, field -> {

for (Class<? extends Annotation> annotationType : getAnnotationTypes()) {
for (Class<? extends Annotation> annotationType : getAnnotationTypes()) {

AnnotationAttributes attributes = doGetAnnotationAttributes(field, annotationType);
AnnotationAttributes attributes = doGetAnnotationAttributes(field, annotationType);

if (attributes != null) {
if (attributes != null) {

if (Modifier.isStatic(field.getModifiers())) {
if (logger.isWarnEnabled()) {
logger.warn("@" + annotationType.getName() + " is not supported on static fields: " + field);
}
return;
if (Modifier.isStatic(field.getModifiers())) {
if (logger.isWarnEnabled()) {
logger.warn("@" + annotationType.getName() + " is not supported on static fields: " + field);
}
return;
}

boolean required = determineRequiredStatus(attributes);
boolean required = determineRequiredStatus(attributes);

elements.add(new AnnotatedFieldElement(field, attributes, required));
}
elements.add(new AnnotatedFieldElement(field, attributes, required));
}
}
});
Expand Down Expand Up @@ -353,36 +352,33 @@ private List<AnnotatedMethodElement> findAnnotatedMethodMetadata(final Class<?>

final List<AnnotatedMethodElement> elements = new LinkedList<AnnotatedMethodElement>();

ReflectionUtils.doWithMethods(beanClass, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
doWithMethods(beanClass, method -> {

Method bridgedMethod = findBridgedMethod(method);
Method bridgedMethod = findBridgedMethod(method);

if (!isVisibilityBridgeMethodPair(method, bridgedMethod)) {
return;
}
if (!isVisibilityBridgeMethodPair(method, bridgedMethod)) {
return;
}

for (Class<? extends Annotation> annotationType : getAnnotationTypes()) {
for (Class<? extends Annotation> annotationType : getAnnotationTypes()) {

AnnotationAttributes attributes = doGetAnnotationAttributes(bridgedMethod, annotationType);
AnnotationAttributes attributes = doGetAnnotationAttributes(bridgedMethod, annotationType);

if (attributes != null && method.equals(getMostSpecificMethod(method, beanClass))) {
if (Modifier.isStatic(method.getModifiers())) {
if (logger.isWarnEnabled()) {
logger.warn("@" + annotationType.getName() + " annotation is not supported on static methods: " + method);
}
return;
if (attributes != null && method.equals(getMostSpecificMethod(method, beanClass))) {
if (Modifier.isStatic(method.getModifiers())) {
if (logger.isWarnEnabled()) {
logger.warn("@" + annotationType.getName() + " annotation is not supported on static methods: " + method);
}
if (method.getParameterTypes().length == 0) {
if (logger.isWarnEnabled()) {
logger.warn("@" + annotationType.getName() + " annotation should only be used on methods with parameters: " + method);
}
return;
}
if (method.getParameterTypes().length == 0) {
if (logger.isWarnEnabled()) {
logger.warn("@" + annotationType.getName() + " annotation should only be used on methods with parameters: " + method);
}
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, beanClass);
boolean required = determineRequiredStatus(attributes);
elements.add(new AnnotatedMethodElement(method, pd, attributes, required));
}
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, beanClass);
boolean required = determineRequiredStatus(attributes);
elements.add(new AnnotatedMethodElement(method, pd, attributes, required));
}
}
});
Expand Down Expand Up @@ -693,7 +689,7 @@ protected void inject(Object bean, @Nullable String beanName, @Nullable Property
value = resolveFieldValue(field, bean, beanName, pvs);
}
if (value != null) {
ReflectionUtils.makeAccessible(field);
makeAccessible(field);
field.set(bean, value);
}
}
Expand Down Expand Up @@ -767,7 +763,7 @@ protected void inject(Object bean, @Nullable String beanName, @Nullable Property
}
if (arguments != null) {
try {
ReflectionUtils.makeAccessible(method);
makeAccessible(method);
method.invoke(bean, arguments);
} catch (InvocationTargetException ex) {
throw ex.getTargetException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.microsphere.spring.beans.factory.annotation;

import io.microsphere.logging.Logger;
import io.microsphere.logging.LoggerFactory;
import io.microsphere.spring.context.annotation.ExposingClassPathBeanDefinitionScanner;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
Expand All @@ -36,7 +35,6 @@
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.util.ObjectUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
Expand All @@ -46,10 +44,12 @@
import java.util.Map;
import java.util.Set;

import static io.microsphere.logging.LoggerFactory.getLogger;
import static io.microsphere.spring.beans.factory.BeanFactoryUtils.asConfigurableListableBeanFactory;
import static io.microsphere.spring.context.annotation.AnnotatedBeanDefinitionRegistryUtils.resolveAnnotatedBeanNameGenerator;
import static io.microsphere.spring.core.annotation.AnnotationUtils.tryGetMergedAnnotation;
import static io.microsphere.spring.core.env.EnvironmentUtils.asConfigurableEnvironment;
import static io.microsphere.util.ArrayUtils.isNotEmpty;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableSet;
import static org.springframework.util.Assert.noNullElements;
Expand Down Expand Up @@ -81,7 +81,7 @@
public abstract class AnnotationBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor,
BeanFactoryAware, EnvironmentAware, ResourceLoaderAware, BeanClassLoaderAware {

protected final Logger logger = LoggerFactory.getLogger(getClass());
protected final Logger logger = getLogger(getClass());

private final Set<Class<? extends Annotation>> supportedAnnotationTypes;

Expand Down Expand Up @@ -144,7 +144,7 @@ public final void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry regis

String[] basePackages = resolveBasePackages(getPackagesToScan());

if (!ObjectUtils.isEmpty(basePackages)) {
if (isNotEmpty(basePackages)) {
registerBeanDefinitions(registry, basePackages);
} else {
if (logger.isWarnEnabled()) {
Expand Down Expand Up @@ -217,7 +217,7 @@ private void putPrimaryBeanDefinitions(Map<String, AnnotatedBeanDefinition> prim
private void putPrimaryBeanDefinition(Map<String, AnnotatedBeanDefinition> primaryBeanDefinitions,
AnnotatedBeanDefinition annotatedBeanDefinition,
String... keys) {
if (!ObjectUtils.isEmpty(keys)) {
if (isNotEmpty(keys)) {
for (String key : keys) {
primaryBeanDefinitions.put(key, annotatedBeanDefinition);
}
Expand Down
Loading

0 comments on commit 87fdeca

Please sign in to comment.