|
53 | 53 | abstract class AbstractExtensionContext<T extends TestDescriptor> implements ExtensionContextInternal, AutoCloseable {
|
54 | 54 |
|
55 | 55 | private static final Logger LOGGER = LoggerFactory.getLogger(AbstractExtensionContext.class);
|
| 56 | + private static final Namespace CLOSEABLE_RESOURCE_LOGGING_NAMESPACE = Namespace.create( |
| 57 | + AbstractExtensionContext.class, "CloseableResourceLogging"); |
56 | 58 |
|
57 | 59 | private final ExtensionContext parent;
|
58 | 60 | private final EngineExecutionListener engineExecutionListener;
|
@@ -85,42 +87,39 @@ abstract class AbstractExtensionContext<T extends TestDescriptor> implements Ext
|
85 | 87 | .collect(collectingAndThen(toCollection(LinkedHashSet::new), Collections::unmodifiableSet));
|
86 | 88 | // @formatter:on
|
87 | 89 |
|
88 |
| - this.valuesStore = createStore(parent, launcherStoreFacade, createCloseAction()); |
| 90 | + this.valuesStore = new NamespacedHierarchicalStore<>(getParentStore(parent), createCloseAction()); |
| 91 | + } |
| 92 | + |
| 93 | + private NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace> getParentStore( |
| 94 | + ExtensionContext parent) { |
| 95 | + return parent == null // |
| 96 | + ? this.launcherStoreFacade.getRequestLevelStore() // |
| 97 | + : ((AbstractExtensionContext<?>) parent).valuesStore; |
89 | 98 | }
|
90 | 99 |
|
91 | 100 | @SuppressWarnings("deprecation")
|
92 |
| - private NamespacedHierarchicalStore.CloseAction<org.junit.platform.engine.support.store.Namespace> createCloseAction() { |
| 101 | + private <N> NamespacedHierarchicalStore.CloseAction<N> createCloseAction() { |
| 102 | + Store store = this.launcherStoreFacade.getSessionLevelStore(CLOSEABLE_RESOURCE_LOGGING_NAMESPACE); |
93 | 103 | return (__, ___, value) -> {
|
94 | 104 | boolean isAutoCloseEnabled = this.configuration.isClosingStoredAutoCloseablesEnabled();
|
95 | 105 |
|
96 |
| - if (value instanceof AutoCloseable && isAutoCloseEnabled) { |
| 106 | + if (isAutoCloseEnabled && value instanceof AutoCloseable) { |
97 | 107 | ((AutoCloseable) value).close();
|
98 | 108 | return;
|
99 | 109 | }
|
100 | 110 |
|
101 | 111 | if (value instanceof Store.CloseableResource) {
|
102 | 112 | if (isAutoCloseEnabled) {
|
103 |
| - LOGGER.warn( |
104 |
| - () -> "Type implements CloseableResource but not AutoCloseable: " + value.getClass().getName()); |
| 113 | + store.getOrComputeIfAbsent(value.getClass(), type -> { |
| 114 | + LOGGER.warn(() -> "Type implements CloseableResource but not AutoCloseable: " + type.getName()); |
| 115 | + return true; |
| 116 | + }); |
105 | 117 | }
|
106 | 118 | ((Store.CloseableResource) value).close();
|
107 | 119 | }
|
108 | 120 | };
|
109 | 121 | }
|
110 | 122 |
|
111 |
| - private static NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace> createStore( |
112 |
| - ExtensionContext parent, LauncherStoreFacade launcherStoreFacade, |
113 |
| - NamespacedHierarchicalStore.CloseAction<org.junit.platform.engine.support.store.Namespace> closeAction) { |
114 |
| - NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace> parentStore; |
115 |
| - if (parent == null) { |
116 |
| - parentStore = launcherStoreFacade.getRequestLevelStore(); |
117 |
| - } |
118 |
| - else { |
119 |
| - parentStore = ((AbstractExtensionContext<?>) parent).valuesStore; |
120 |
| - } |
121 |
| - return new NamespacedHierarchicalStore<>(parentStore, closeAction); |
122 |
| - } |
123 |
| - |
124 | 123 | @Override
|
125 | 124 | public void close() {
|
126 | 125 | this.valuesStore.close();
|
|
0 commit comments