@@ -65,7 +65,7 @@ public class WireMockContainer extends GenericContainer<WireMockContainer> {
6565 private final StringBuilder wireMockArgs ;
6666 private final Map <String , Stub > mappingStubs = new HashMap <>();
6767 private final Map <String , MountableFile > mappingFiles = new HashMap <>();
68- private final Map <String , Extension > extensions = new HashMap <>();
68+ private final Map <String , WireMockPlugin > plugins = new HashMap <>();
6969 private boolean isBannerDisabled = true ;
7070
7171 /**
@@ -169,28 +169,39 @@ public WireMockContainer withFileFromResource(String name, Class<?> resource, St
169169 }
170170
171171 /**
172- * Add extension that will be loaded from the specified JAR file .
173- * @param id Unique ID of the extension, for logging purposes
172+ * Add extension that will be loaded from the specified JAR files .
173+ * In the internal engine, it will be handled as a single plugin.
174174 * @param classNames Class names of the extension to be included
175175 * @param jars JARs to be included into the container
176176 * @return this instance
177177 */
178- public WireMockContainer withExtension (String id , Collection <String > classNames , Collection <File > jars ) {
179- final Extension extension = new Extension (id );
180- extension .extensionClassNames .addAll (classNames );
181- extension .jars .addAll (jars );
182- extensions .put (id , extension );
183- return this ;
178+ public WireMockContainer withExtensions (Collection <String > classNames , Collection <File > jars ) {
179+ return withExtensions (WireMockPlugin .guessPluginId (classNames , jars ), classNames , jars );
180+ }
181+
182+ /**
183+ * Add extension that will be loaded from the specified JAR files.
184+ * In the internal engine, it will be handled as a single plugin.
185+ * @param id Identifier top use
186+ * @param classNames Class names of the extension to be included
187+ * @param jars JARs to be included into the container
188+ * @return this instance
189+ */
190+ public WireMockContainer withExtensions (String id , Collection <String > classNames , Collection <File > jars ) {
191+ final WireMockPlugin extension = new WireMockPlugin (id )
192+ .withExtensions (classNames )
193+ .withJars (jars );
194+ return withPlugin (extension );
184195 }
185196
186197 /**
187198 * Add extension that will be loaded from the specified directory with JAR files.
188- * @param id Unique ID of the extension, for logging purposes
199+ * In the internal engine, it will be handled as a single plugin.
189200 * @param classNames Class names of the extension to be included
190201 * @param jarDirectory Directory that stores all JARs
191202 * @return this instance
192203 */
193- public WireMockContainer withExtension ( String id , Collection <String > classNames , File jarDirectory ) {
204+ public WireMockContainer withExtensions ( Collection <String > classNames , File jarDirectory ) {
194205 final List <File > jarsInTheDirectory ;
195206 try (Stream <Path > walk = Files .walk (jarDirectory .toPath ())) {
196207 jarsInTheDirectory = walk
@@ -202,19 +213,28 @@ public WireMockContainer withExtension(String id, Collection<String> classNames,
202213 throw new IllegalArgumentException ("Cannot list JARs in the directory " + jarDirectory , e );
203214 }
204215
205- return withExtension ( id , classNames , jarsInTheDirectory );
216+ return withExtensions ( classNames , jarsInTheDirectory );
206217 }
207218
208219 /**
209220 * Add extension that will be loaded from the classpath.
210221 * This method can be used if the extension is a part of the WireMock bundle,
211- * or a Jar is already added via {@link #withExtension(String, Collection, Collection)}}
212- * @param id Unique ID of the extension, for logging purposes
222+ * or a Jar is already added via {@link #withExtensions( Collection, Collection)}}.
223+ * In the internal engine, it will be handled as a single plugin.
213224 * @param className Class name of the extension
214225 * @return this instance
215226 */
216- public WireMockContainer withExtension (String id , String className ) {
217- return withExtension (id , Collections .singleton (className ), Collections .emptyList ());
227+ public WireMockContainer withExtension (String className ) {
228+ return withExtensions (Collections .singleton (className ), Collections .emptyList ());
229+ }
230+
231+ private WireMockContainer withPlugin (WireMockPlugin plugin ) {
232+ String pluginId = plugin .getPluginId ();
233+ if (plugins .containsKey (pluginId )) {
234+ throw new IllegalArgumentException ("The plugin is already included: " + pluginId );
235+ }
236+ plugins .put (pluginId , plugin );
237+ return this ;
218238 }
219239
220240 public String getBaseUrl () {
@@ -245,10 +265,10 @@ protected void configure() {
245265 }
246266
247267 final ArrayList <String > extensionClassNames = new ArrayList <>();
248- for (Map .Entry <String , Extension > entry : extensions .entrySet ()) {
249- final Extension ext = entry .getValue ();
250- extensionClassNames .addAll (ext .extensionClassNames );
251- for (File jar : ext .jars ) {
268+ for (Map .Entry <String , WireMockPlugin > entry : plugins .entrySet ()) {
269+ final WireMockPlugin ext = entry .getValue ();
270+ extensionClassNames .addAll (ext .getExtensionClassNames () );
271+ for (File jar : ext .getJars () ) {
252272 withCopyToContainer (MountableFile .forHostPath (jar .toPath ()), EXTENSIONS_DIR + jar .getName ());
253273 }
254274 }
@@ -275,13 +295,5 @@ public Stub(String name, String json) {
275295 }
276296 }
277297
278- private static final class Extension {
279- final String id ;
280- final List <File > jars = new ArrayList <>();
281- final List <String > extensionClassNames = new ArrayList <>();
282298
283- public Extension (String id ) {
284- this .id = id ;
285- }
286- }
287299}
0 commit comments