Skip to content

Commit

Permalink
Merge pull request #95 from microsphere-projects/dev-1.x
Browse files Browse the repository at this point in the history
Release 0.1.1
  • Loading branch information
mercyblitz authored Jan 11, 2025
2 parents 1960355 + 38ba5ff commit 9c2d842
Show file tree
Hide file tree
Showing 59 changed files with 828 additions and 353 deletions.
6 changes: 0 additions & 6 deletions microsphere-spring-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static io.microsphere.spring.beans.factory.BeanFactoryUtils.asConfigurableBeanFactory;
import static io.microsphere.spring.context.ApplicationContextUtils.asConfigurableApplicationContext;
import static io.microsphere.spring.context.ApplicationContextUtils.getApplicationContextAwareProcessor;
import static io.microsphere.util.ArrayUtils.isEmpty;
import static io.microsphere.util.ClassLoaderUtils.resolveClass;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
Expand All @@ -53,7 +54,7 @@
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
import static org.springframework.beans.factory.support.BeanDefinitionReaderUtils.generateBeanName;
import static org.springframework.util.ClassUtils.getUserClass;
import static org.springframework.util.ObjectUtils.isEmpty;
import static org.springframework.util.ClassUtils.resolveClassName;
import static org.springframework.util.StringUtils.hasText;

/**
Expand Down Expand Up @@ -207,7 +208,7 @@ public static Class<?> resolveBeanType(String beanClassName, ClassLoader classLo

Class<?> beanType = null;
try {
beanType = resolveClass(beanClassName, classLoader);
beanType = resolveClassName(beanClassName, classLoader);
beanType = getUserClass(beanType);
} catch (Exception e) {
if (logger.isErrorEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public abstract class BeanFactoryUtils extends BaseUtils {
* @return A bean if present , or <code>null</code>
*/
public static <T> T getOptionalBean(ListableBeanFactory beanFactory, String beanName, Class<T> beanType) {

if (!hasText(beanName)) {
return null;
}
Expand All @@ -77,6 +76,7 @@ public static <T> T getOptionalBean(ListableBeanFactory beanFactory, String bean
return isEmpty(beans) ? null : beans.get(0);
}


/**
* Gets name-matched Beans from {@link ListableBeanFactory BeanFactory}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
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;
Expand Down Expand Up @@ -53,6 +52,7 @@
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;
Expand Down Expand Up @@ -252,7 +252,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 @@ -45,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 Down Expand Up @@ -75,11 +74,15 @@
import static java.lang.Integer.getInteger;
import static java.util.Collections.singleton;
import static java.util.Collections.unmodifiableCollection;
import static org.springframework.beans.factory.annotation.InjectionMetadata.needsRefresh;
import static org.springframework.core.BridgeMethodResolver.findBridgedMethod;
import static org.springframework.core.BridgeMethodResolver.isVisibilityBridgeMethodPair;
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 @@ -305,27 +308,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 @@ -354,36 +354,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 @@ -424,10 +421,10 @@ private InjectionMetadata findInjectionMetadata(String beanName, Class<?> clazz,
String cacheKey = (hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
AnnotatedInjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
if (needsRefresh(metadata, clazz)) {
synchronized (this.injectionMetadataCache) {
metadata = this.injectionMetadataCache.get(cacheKey);
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
if (needsRefresh(metadata, clazz)) {
if (metadata != null) {
metadata.clear(pvs);
}
Expand Down Expand Up @@ -695,7 +692,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 @@ -769,7 +766,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 @@ -35,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 @@ -50,6 +49,7 @@
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 @@ -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 @@ -218,7 +218,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 9c2d842

Please sign in to comment.