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