|
64 | 64 | */ |
65 | 65 | publicclassPlexusExtensionimplementsBeforeEachCallback, AfterEachCallback{ |
66 | 66 |
|
| 67 | +privatestaticclassPlexusClosableWrapperimplementsAutoCloseable{ |
| 68 | +privatefinalPlexusContainercontainer; |
| 69 | + |
| 70 | +PlexusClosableWrapper(PlexusContainercontainer){ |
| 71 | +this.container = container; |
| 72 | + } |
| 73 | + |
| 74 | +@Override |
| 75 | +publicvoidclose(){ |
| 76 | +container.dispose(); |
| 77 | + } |
| 78 | + |
| 79 | +publicPlexusContainerget(){ |
| 80 | +returncontainer; |
| 81 | + } |
| 82 | + } |
| 83 | + |
67 | 84 | privatestaticfinalExtensionContext.NamespacePLEXUS_EXTENSION = |
68 | 85 | ExtensionContext.Namespace.create("PlexusExtension"); |
69 | 86 |
|
@@ -140,7 +157,7 @@ private PlexusContainer setupContainer(ExtensionContext context){ |
140 | 157 | thrownewIllegalArgumentException("Failed to create plexus container.", e); |
141 | 158 | } |
142 | 159 | testInstanceCustomizeContainer(container, context); |
143 | | -context.getStore(PLEXUS_EXTENSION).put(PlexusContainer.class, container); |
| 160 | +context.getStore(PLEXUS_EXTENSION).put(PlexusClosableWrapper.class, newPlexusClosableWrapper(container)); |
144 | 161 |
|
145 | 162 | returncontainer; |
146 | 163 | } |
@@ -175,11 +192,7 @@ protected void customizeContext(Context context){} |
175 | 192 |
|
176 | 193 | @Override |
177 | 194 | publicvoidafterEach(ExtensionContextcontext) throwsException{ |
178 | | -PlexusContainercontainer = |
179 | | -context.getStore(PLEXUS_EXTENSION).remove(PlexusContainer.class, PlexusContainer.class); |
180 | | -if (container != null){ |
181 | | -container.dispose(); |
182 | | - } |
| 195 | +// empty method, not used |
183 | 196 | } |
184 | 197 |
|
185 | 198 | /** |
@@ -211,12 +224,12 @@ protected void setTestBasedir(String testBasedir, ExtensionContext context){ |
211 | 224 | } |
212 | 225 |
|
213 | 226 | publicPlexusContainergetContainer(ExtensionContextcontext){ |
214 | | -PlexusContainercontainer = |
215 | | -context.getStore(PLEXUS_EXTENSION).get(PlexusContainer.class, PlexusContainer.class); |
| 227 | +PlexusClosableWrappercontainer = |
| 228 | +context.getStore(PLEXUS_EXTENSION).get(PlexusClosableWrapper.class, PlexusClosableWrapper.class); |
216 | 229 | if (container == null){ |
217 | 230 | returnsetupContainer(context); |
218 | 231 | } |
219 | | -returncontainer; |
| 232 | +returncontainer.get(); |
220 | 233 | } |
221 | 234 |
|
222 | 235 | protectedStringgetCustomConfigurationName(){ |
|
0 commit comments