Skip to content

Commit 9ce7c8e

Browse files
committed
Reinstate support for class-clone-pattern
1 parent 99f6154 commit 9ce7c8e

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public class QuarkusTestExtension extends AbstractJvmQuarkusTestExtension
122122
// needed for @Nested
123123
private static final Deque<Object> outerInstances = new ArrayDeque<>(1);
124124
private static RunningQuarkusApplication runningQuarkusApplication;
125-
private static Pattern clonePattern;
126125
private static Throwable firstException; //if this is set then it will be thrown from the very first test that is run, the rest are aborted
127126

128127
private static Class<?> quarkusTestMethodContextClass;

test-framework/junit5/src/main/java/io/quarkus/test/junit/internal/NewSerializingDeepClone.java

+38-32
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.UncheckedIOException;
66
import java.lang.reflect.Method;
77
import java.util.function.Supplier;
8+
import java.util.regex.Pattern;
89

910
import org.jboss.marshalling.cloner.ClassCloner;
1011
import org.jboss.marshalling.cloner.ClonerConfiguration;
@@ -19,6 +20,7 @@
1920
*/
2021
public final class NewSerializingDeepClone implements DeepClone {
2122
private final ObjectCloner cloner;
23+
private static Pattern clonePattern;
2224
private RunningQuarkusApplication runningQuarkusApplication;
2325

2426
public NewSerializingDeepClone(final ClassLoader sourceLoader, final ClassLoader targetLoader) {
@@ -49,45 +51,46 @@ public Class<?> cloneProxy(final Class<?> proxyClass) {
4951
theClassWeCareAbout = theClassWeCareAbout.getComponentType();
5052
}
5153

52-
// TODO } else if (clonePattern.matcher(theclass.getName()).matches()) {
53-
// cloneRequired = true;
54-
// }
55-
if (theClassWeCareAbout.isPrimitive()) {
56-
// avoid copying things that do not need to be copied
57-
return original;
58-
} else if (isUncloneable(theClassWeCareAbout)) {
59-
if (original instanceof Supplier<?> s) {
60-
// sneaky
61-
return (Supplier<?>) () -> clone(s.get());
62-
} else {
63-
return original;
64-
}
65-
} else if (original instanceof TestInfo info) {
66-
// copy the test info correctly
67-
return new TestInfoImpl(info.getDisplayName(), info.getTags(),
68-
info.getTestClass()
69-
.map(this::cloneClass),
70-
info.getTestMethod()
71-
.map(this::cloneMethod));
72-
} else {
73-
try {
74-
if (runningQuarkusApplication != null && runningQuarkusApplication.getClassLoader()
75-
.loadClass(theClassWeCareAbout.getName()) == theClassWeCareAbout) {
76-
// Don't clone things which are already loaded by the quarkus application's classloader side of the tree
77-
return original;
78-
}
79-
} catch (ClassNotFoundException e) {
54+
// Short-circuit the checks if we've been configured to clone this
55+
if (!clonePattern.matcher(theClassWeCareAbout.getName()).matches()) {
8056

57+
if (theClassWeCareAbout.isPrimitive()) {
58+
// avoid copying things that do not need to be copied
59+
return original;
60+
} else if (isUncloneable(theClassWeCareAbout)) {
8161
if (original instanceof Supplier<?> s) {
8262
// sneaky
8363
return (Supplier<?>) () -> clone(s.get());
8464
} else {
85-
throw e;
65+
return original;
66+
}
67+
} else if (original instanceof TestInfo info) {
68+
// copy the test info correctly
69+
return new TestInfoImpl(info.getDisplayName(), info.getTags(),
70+
info.getTestClass()
71+
.map(this::cloneClass),
72+
info.getTestMethod()
73+
.map(this::cloneMethod));
74+
} else {
75+
try {
76+
if (runningQuarkusApplication != null && runningQuarkusApplication.getClassLoader()
77+
.loadClass(theClassWeCareAbout.getName()) == theClassWeCareAbout) {
78+
// Don't clone things which are already loaded by the quarkus application's classloader side of the tree
79+
return original;
80+
}
81+
} catch (ClassNotFoundException e) {
82+
83+
if (original instanceof Supplier<?> s) {
84+
// sneaky
85+
return (Supplier<?>) () -> clone(s.get());
86+
} else {
87+
throw e;
88+
}
8689
}
87-
}
8890

89-
if (original == sourceLoader) {
90-
return targetLoader;
91+
if (original == sourceLoader) {
92+
return targetLoader;
93+
}
9194
}
9295
}
9396

@@ -133,6 +136,9 @@ public Object clone(final Object objectToClone) {
133136
@Override
134137
public void setRunningQuarkusApplication(RunningQuarkusApplication runningQuarkusApplication) {
135138
this.runningQuarkusApplication = runningQuarkusApplication;
139+
String patternString = runningQuarkusApplication.getConfigValue("quarkus.test.class-clone-pattern", String.class)
140+
.orElse("java\\..*");
141+
clonePattern = Pattern.compile(patternString);
136142
}
137143

138144
}

0 commit comments

Comments
 (0)