Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
TAKETODAY committed Apr 9, 2024
2 parents 9356c20 + 86b8b51 commit 65408a7
Show file tree
Hide file tree
Showing 124 changed files with 853 additions and 1,351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void testUserSpecifiedConfigName() throws Exception {
System.setProperty("loader.config.name", "foo");
this.launcher = new PropertiesLauncher();
assertThat(this.launcher.getMainClass()).isEqualTo("my.Application");
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[etc/]");
assertThat(getPaths()).hasToString("[etc/]");
}

@Test
Expand All @@ -158,14 +158,18 @@ void testRootOfClasspathFirst() throws Exception {
void testUserSpecifiedDotPath() {
System.setProperty("loader.path", ".");
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[.]");
assertThat(getPaths()).hasToString("[.]");
}

private Object getPaths() {
return ReflectionTestUtils.getField(this.launcher, "paths");
}

@Test
void testUserSpecifiedSlashPath() throws Exception {
System.setProperty("loader.path", "jars/");
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/]");
assertThat(getPaths()).hasToString("[jars/]");
List<Archive> archives = new ArrayList<>();
this.launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
assertThat(archives).areExactly(1, endingWith("app.jar"));
Expand All @@ -176,7 +180,7 @@ void testUserSpecifiedWildcardPath() throws Exception {
System.setProperty("loader.path", "jars/*");
System.setProperty("loader.main", "demo.Application");
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/]");
assertThat(getPaths()).hasToString("[jars/]");
this.launcher.launch(new String[0]);
waitFor("Hello World");
}
Expand All @@ -186,7 +190,7 @@ void testUserSpecifiedJarPath() throws Exception {
System.setProperty("loader.path", "jars/app.jar");
System.setProperty("loader.main", "demo.Application");
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
assertThat(getPaths()).hasToString("[jars/app.jar]");
this.launcher.launch(new String[0]);
waitFor("Hello World");
}
Expand All @@ -195,7 +199,7 @@ void testUserSpecifiedJarPath() throws Exception {
void testUserSpecifiedRootOfJarPath() throws Exception {
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars1/app.jar!/");
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths"))
assertThat(getPaths())
.hasToString("[jar:file:./src/test/resources/nested-jars1/app.jar!/]");
List<Archive> archives = new ArrayList<>();
this.launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
Expand Down Expand Up @@ -238,7 +242,7 @@ void testUserSpecifiedNestedJarPath() throws Exception {
System.setProperty("loader.path", "nested-jars1/nested-jar-app.jar!/BOOT-INF/classes/");
System.setProperty("loader.main", "demo.Application");
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths"))
assertThat(getPaths())
.hasToString("[nested-jars1/nested-jar-app.jar!/BOOT-INF/classes/]");
this.launcher.launch(new String[0]);
waitFor("Hello World");
Expand All @@ -258,7 +262,7 @@ void testUserSpecifiedJarPathWithDot() throws Exception {
System.setProperty("loader.path", "./jars/app.jar");
System.setProperty("loader.main", "demo.Application");
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
assertThat(getPaths()).hasToString("[jars/app.jar]");
this.launcher.launch(new String[0]);
waitFor("Hello World");
}
Expand All @@ -268,7 +272,7 @@ void testUserSpecifiedClassLoader() throws Exception {
System.setProperty("loader.path", "jars/app.jar");
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
assertThat(getPaths()).hasToString("[jars/app.jar]");
this.launcher.launch(new String[0]);
waitFor("Hello World");
}
Expand All @@ -278,7 +282,7 @@ void testUserSpecifiedClassPathOrder() throws Exception {
System.setProperty("loader.path", "more-jars/app.jar,jars/app.jar");
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
this.launcher = new PropertiesLauncher();
assertThat((Object) ReflectionTestUtils.getField(this.launcher, "paths"))
assertThat(getPaths())
.hasToString("[more-jars/app.jar, jars/app.jar]");
this.launcher.launch(new String[0]);
waitFor("Hello Other World");
Expand Down
4 changes: 2 additions & 2 deletions infra-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ dependencies {
api("com.google.code.findbugs:findbugs:3.0.1")
api("com.google.code.findbugs:jsr305:3.0.2")
api("com.google.code.gson:gson:2.10.1")
api("com.google.protobuf:protobuf-java-util:3.25.1")
api("com.google.protobuf:protobuf-java:3.25.1")
api("com.google.protobuf:protobuf-java-util:4.26.1")
api("com.google.protobuf:protobuf-java:4.26.1")
api("com.h2database:h2:1.4.199")
api("com.jayway.jsonpath:json-path:2.8.0")
api("com.rometools:rome:1.19.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public TargetInvocation(Method method, Class<?> targetClass, AdvisedSupport conf
this.method = method;
this.config = config;
this.targetClass = targetClass;
this.invoker = MethodInvoker.fromMethod(method, targetClass);
this.invoker = MethodInvoker.forMethod(method, targetClass);
}

public Method getMethod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public final PropertyAccessor obtainAccessor() {
protected PropertyAccessor createAccessor() {
Field field = getField();
if (field == null) {
return PropertyAccessor.fromMethod(readMethod, writeMethod);
return PropertyAccessor.forMethod(readMethod, writeMethod);
}
return PropertyAccessor.fromField(field, readMethod, writeMethod);
return PropertyAccessor.forField(field, readMethod, writeMethod);
}

public PropertyAccessor getPropertyAccessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class FieldBeanProperty extends BeanProperty {

@Override
protected PropertyAccessor createAccessor() {
return PropertyAccessor.fromField(field);
return PropertyAccessor.forField(field);
}

protected TypeDescriptor createDescriptor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static BeanInstantiator fromMethod(MethodAccessor accessor, Object obj) {
* @return MethodAccessorBeanInstantiator to construct target T
*/
public static BeanInstantiator fromMethod(Method method, Object obj) {
return fromMethod(MethodInvoker.fromMethod(method), obj);
return fromMethod(MethodInvoker.forMethod(method), obj);
}

/**
Expand All @@ -142,7 +142,7 @@ public static BeanInstantiator fromMethod(MethodAccessor accessor, Supplier<Obje
* @return MethodAccessorBeanInstantiator to construct target T
*/
public static BeanInstantiator fromMethod(Method method, Supplier<Object> obj) {
return fromMethod(MethodInvoker.fromMethod(method), obj);
return fromMethod(MethodInvoker.forMethod(method), obj);
}

/**
Expand All @@ -163,7 +163,7 @@ public static BeanInstantiator fromStaticMethod(MethodAccessor accessor) {
* @return StaticMethodAccessorBeanInstantiator to construct target T
*/
public static BeanInstantiator fromStaticMethod(Method method) {
return fromStaticMethod(MethodInvoker.fromMethod(method));
return fromStaticMethod(MethodInvoker.forMethod(method));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import cn.taketoday.beans.BeanProperty;
import cn.taketoday.beans.NoSuchPropertyException;
import cn.taketoday.beans.NotWritablePropertyException;
import cn.taketoday.core.Pair;
import cn.taketoday.lang.NonNull;
import cn.taketoday.lang.Nullable;
import cn.taketoday.reflect.SetterMethod;
import cn.taketoday.util.KeyValueHolder;
import cn.taketoday.util.ObjectUtils;

/**
Expand Down Expand Up @@ -78,10 +78,10 @@ public Set<Entry<String, Object>> entrySet() {
for (BeanProperty property : metadata) {
if (property.isReadable()) {
Object value = property.getValue(target);
entrySet.add(new KeyValueHolder<>(property.getName(), value));
entrySet.add(Pair.of(property.getName(), value));
}
else {
entrySet.add(new KeyValueHolder<>(property.getName(), null));
entrySet.add(Pair.of(property.getName(), null));
}
}
return entrySet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static <T> Constructor<T> newConstructorForSerialization(
reflectionFactory, type, constructor);
}
catch (Throwable e) {
Throwable throwable = ExceptionUtils.unwrapThrowable(e);
Throwable throwable = ExceptionUtils.unwrapIfNecessary(e);
throw new IllegalStateException(
"Serialization Constructor for '%s' created failed".formatted(type), throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public String test(String name) {
void testMethod() throws Throwable {

Method test = ReflectionUtils.findMethod(ITest.class, "test", String.class);
MethodAccessor methodAccessor = MethodInvoker.fromMethod(test);
MethodAccessor methodAccessor = MethodInvoker.forMethod(test);
test.setAccessible(true);
final ITest testBean = new MethodTestBean();

Expand Down Expand Up @@ -186,7 +186,7 @@ static class PropertyTestBean {
@Test
void testProperty() throws IllegalAccessException {
Field field = ReflectionUtils.findField(PropertyTestBean.class, "value");
PropertyAccessor propertyAccessor = PropertyAccessor.fromField(field);
PropertyAccessor propertyAccessor = PropertyAccessor.forField(field);

field.trySetAccessible();

Expand Down Expand Up @@ -272,10 +272,10 @@ void testReflect() throws Throwable {
void testMethodAccessor() throws Throwable {

MethodInvoker[] ma = new MethodInvoker[] {
MethodInvoker.fromMethod(Bench1.class.getDeclaredMethod("func0")),
MethodInvoker.fromMethod(Bench1.class.getDeclaredMethod("func1")),
MethodInvoker.fromMethod(Bench1.class.getDeclaredMethod("func2")),
MethodInvoker.fromMethod(Bench1.class.getDeclaredMethod("func3")),
MethodInvoker.forMethod(Bench1.class.getDeclaredMethod("func0")),
MethodInvoker.forMethod(Bench1.class.getDeclaredMethod("func1")),
MethodInvoker.forMethod(Bench1.class.getDeclaredMethod("func2")),
MethodInvoker.forMethod(Bench1.class.getDeclaredMethod("func3")),
};
Bench1 self = this;
long t = System.nanoTime();
Expand Down Expand Up @@ -331,7 +331,7 @@ void testReflect() throws Throwable {

void testMethodAccessor() throws Throwable {

MethodInvoker ma = MethodInvoker.fromMethod(Bench2.class.getDeclaredMethod("func0"));
MethodInvoker ma = MethodInvoker.forMethod(Bench2.class.getDeclaredMethod("func0"));

Bench2 self = this;
long t = System.nanoTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CodeGenerationException extends NestedRuntimeException {
public CodeGenerationException() { }

public CodeGenerationException(Throwable cause) {
super(ExceptionUtils.unwrapThrowable(cause).toString(), cause);
super(ExceptionUtils.unwrapIfNecessary(cause).toString(), cause);
}

public CodeGenerationException(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
*/
package cn.taketoday.bytecode.proxy;

import java.lang.reflect.UndeclaredThrowableException;
import java.util.List;

import cn.taketoday.bytecode.Opcodes;
import cn.taketoday.bytecode.Type;
import cn.taketoday.bytecode.commons.MethodSignature;
import cn.taketoday.bytecode.core.Block;
import cn.taketoday.bytecode.core.ClassEmitter;
import cn.taketoday.bytecode.core.CodeEmitter;
import cn.taketoday.bytecode.core.EmitUtils;
import cn.taketoday.bytecode.core.MethodInfo;
import cn.taketoday.bytecode.commons.MethodSignature;

/**
* @author TODAY <br>
Expand Down
13 changes: 12 additions & 1 deletion today-core/src/main/java/cn/taketoday/bytecode/proxy/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,19 @@ public static Class<?> getProxyClass(final ClassLoader loader, final Class<?>...
return enhancer.createClass();
}

/**
* Returns true if the given class is a proxy class.
*
* @param cl the class to test
* @return {@code true} if the class is a proxy class and
* {@code false} otherwise
* @throws NullPointerException if {@code cl} is {@code null}
* @implNote The reliability of this method is important for the ability
* to use it to make security decisions, so its implementation should
* not just test if the class in question extends {@code Proxy}.
*/
public static boolean isProxyClass(Class<?> cl) {
return cl.getSuperclass().equals(ProxyImpl.class);
return ProxyImpl.class.isAssignableFrom(cl);
}

/**
Expand Down

This file was deleted.

Loading

0 comments on commit 65408a7

Please sign in to comment.