|
5 | 5 | import java.io.UncheckedIOException;
|
6 | 6 | import java.lang.reflect.Method;
|
7 | 7 | import java.util.function.Supplier;
|
| 8 | +import java.util.regex.Pattern; |
8 | 9 |
|
9 | 10 | import org.jboss.marshalling.cloner.ClassCloner;
|
10 | 11 | import org.jboss.marshalling.cloner.ClonerConfiguration;
|
|
19 | 20 | */
|
20 | 21 | public final class NewSerializingDeepClone implements DeepClone {
|
21 | 22 | private final ObjectCloner cloner;
|
| 23 | + private static Pattern clonePattern; |
22 | 24 | private RunningQuarkusApplication runningQuarkusApplication;
|
23 | 25 |
|
24 | 26 | public NewSerializingDeepClone(final ClassLoader sourceLoader, final ClassLoader targetLoader) {
|
@@ -49,45 +51,46 @@ public Class<?> cloneProxy(final Class<?> proxyClass) {
|
49 | 51 | theClassWeCareAbout = theClassWeCareAbout.getComponentType();
|
50 | 52 | }
|
51 | 53 |
|
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()) { |
80 | 56 |
|
| 57 | + if (theClassWeCareAbout.isPrimitive()) { |
| 58 | + // avoid copying things that do not need to be copied |
| 59 | + return original; |
| 60 | + } else if (isUncloneable(theClassWeCareAbout)) { |
81 | 61 | if (original instanceof Supplier<?> s) {
|
82 | 62 | // sneaky
|
83 | 63 | return (Supplier<?>) () -> clone(s.get());
|
84 | 64 | } 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 | + } |
86 | 89 | }
|
87 |
| - } |
88 | 90 |
|
89 |
| - if (original == sourceLoader) { |
90 |
| - return targetLoader; |
| 91 | + if (original == sourceLoader) { |
| 92 | + return targetLoader; |
| 93 | + } |
91 | 94 | }
|
92 | 95 | }
|
93 | 96 |
|
@@ -133,6 +136,9 @@ public Object clone(final Object objectToClone) {
|
133 | 136 | @Override
|
134 | 137 | public void setRunningQuarkusApplication(RunningQuarkusApplication runningQuarkusApplication) {
|
135 | 138 | this.runningQuarkusApplication = runningQuarkusApplication;
|
| 139 | + String patternString = runningQuarkusApplication.getConfigValue("quarkus.test.class-clone-pattern", String.class) |
| 140 | + .orElse("java\\..*"); |
| 141 | + clonePattern = Pattern.compile(patternString); |
136 | 142 | }
|
137 | 143 |
|
138 | 144 | }
|
0 commit comments