16
16
package com .diffplug .spotless .maven ;
17
17
18
18
import static com .diffplug .common .base .Strings .isNullOrEmpty ;
19
- import static java .util .Arrays .asList ;
20
19
import static java .util .Arrays .stream ;
21
- import static java .util .Collections .emptyMap ;
22
20
import static java .util .Collections .singletonMap ;
23
21
import static java .util .stream .Collectors .toList ;
24
22
import static org .junit .jupiter .api .Assertions .fail ;
@@ -59,7 +57,6 @@ public class MavenIntegrationHarness extends ResourceHarness {
59
57
private static final String MODULES = "modules" ;
60
58
private static final String DEPENDENCIES = "dependencies" ;
61
59
private static final String MODULE_NAME = "name" ;
62
- private static final String CHILD_ID = "childId" ;
63
60
private static final int REMOTE_DEBUG_PORT = 5005 ;
64
61
65
62
private final MustacheFactory mustacheFactory = new DefaultMustacheFactory ();
@@ -190,10 +187,6 @@ protected MavenRunner mavenRunnerWithRemoteDebug() throws IOException {
190
187
return mavenRunner ().withRemoteDebug (REMOTE_DEBUG_PORT );
191
188
}
192
189
193
- protected MultiModuleProjectCreator multiModuleProject () {
194
- return new MultiModuleProjectCreator ();
195
- }
196
-
197
190
protected String createPomXmlContent (String pluginVersion , String [] executions , String [] configuration , String [] dependencies ) throws IOException {
198
191
return createPomXmlContent ("/pom-test.xml.mustache" , pluginVersion , executions , configuration , dependencies );
199
192
}
@@ -207,7 +200,7 @@ protected String createPomXmlContent(String pluginVersion, String[] executions,
207
200
return createPomXmlContent (pluginVersion , executions , configuration , null );
208
201
}
209
202
210
- private String createPomXmlContent (String pomTemplate , Map <String , Object > params ) throws IOException {
203
+ protected String createPomXmlContent (String pomTemplate , Map <String , Object > params ) throws IOException {
211
204
URL url = MavenIntegrationHarness .class .getResource (pomTemplate );
212
205
try (BufferedReader reader = Resources .asCharSource (url , StandardCharsets .UTF_8 ).openBufferedStream ()) {
213
206
Mustache mustache = mustacheFactory .compile (reader , "pom" );
@@ -217,7 +210,7 @@ private String createPomXmlContent(String pomTemplate, Map<String, Object> param
217
210
}
218
211
}
219
212
220
- private static Map <String , Object > buildPomXmlParams (String pluginVersion , String [] executions , String [] configuration , String [] modules , String [] dependencies ) {
213
+ protected static Map <String , Object > buildPomXmlParams (String pluginVersion , String [] executions , String [] configuration , String [] modules , String [] dependencies ) {
221
214
Map <String , Object > params = new HashMap <>();
222
215
params .put (SPOTLESS_MAVEN_PLUGIN_VERSION , pluginVersion == null ? getSystemProperty (SPOTLESS_MAVEN_PLUGIN_VERSION ) : pluginVersion );
223
216
@@ -276,86 +269,4 @@ private static String[] including(String... includes) {
276
269
private static String [] formats (String ... formats ) {
277
270
return groupWithSteps ("formats" , formats );
278
271
}
279
-
280
- protected class MultiModuleProjectCreator {
281
-
282
- private String configSubProject ;
283
- private SubProjectFile [] configSubProjectFiles ;
284
- private String [] configuration ;
285
- private final Map <String , List <SubProjectFile >> subProjects = new LinkedHashMap <>();
286
-
287
- protected MultiModuleProjectCreator withConfigSubProject (String name , SubProjectFile ... files ) {
288
- configSubProject = name ;
289
- configSubProjectFiles = files ;
290
- return this ;
291
- }
292
-
293
- protected MultiModuleProjectCreator withConfiguration (String ... lines ) {
294
- configuration = lines ;
295
- return this ;
296
- }
297
-
298
- protected MultiModuleProjectCreator addSubProject (String name , SubProjectFile ... files ) {
299
- subProjects .put (name , asList (files ));
300
- return this ;
301
- }
302
-
303
- protected void create () throws IOException {
304
- createRootPom ();
305
- createConfigSubProject ();
306
- createSubProjects ();
307
- }
308
-
309
- private void createRootPom () throws IOException {
310
- List <Object > modulesList = new ArrayList <>();
311
- modulesList .add (configSubProject );
312
- modulesList .addAll (subProjects .keySet ());
313
- String [] modules = modulesList .toArray (new String [0 ]);
314
-
315
- Map <String , Object > rootPomParams = buildPomXmlParams (null , null , configuration , modules , null );
316
- setFile ("pom.xml" ).toContent (createPomXmlContent ("/multi-module/pom-parent.xml.mustache" , rootPomParams ));
317
- }
318
-
319
- private void createConfigSubProject () throws IOException {
320
- if (configSubProject != null ) {
321
- String content = createPomXmlContent ("/multi-module/pom-config.xml.mustache" , emptyMap ());
322
- setFile (configSubProject + "/pom.xml" ).toContent (content );
323
-
324
- createSubProjectFiles (configSubProject , asList (configSubProjectFiles ));
325
- }
326
- }
327
-
328
- private void createSubProjects () throws IOException {
329
- for (Map .Entry <String , List <SubProjectFile >> entry : subProjects .entrySet ()) {
330
- String subProjectName = entry .getKey ();
331
- List <SubProjectFile > subProjectFiles = entry .getValue ();
332
-
333
- String content = createPomXmlContent ("/multi-module/pom-child.xml.mustache" , singletonMap (CHILD_ID , subProjectName ));
334
- setFile (subProjectName + "/pom.xml" ).toContent (content );
335
-
336
- createSubProjectFiles (subProjectName , subProjectFiles );
337
- }
338
- }
339
-
340
- private void createSubProjectFiles (String subProjectName , List <SubProjectFile > subProjectFiles ) throws IOException {
341
- for (SubProjectFile file : subProjectFiles ) {
342
- setFile (subProjectName + '/' + file .to ).toResource (file .from );
343
- }
344
- }
345
- }
346
-
347
- protected static class SubProjectFile {
348
-
349
- private final String from ;
350
- private final String to ;
351
-
352
- private SubProjectFile (String from , String to ) {
353
- this .from = from ;
354
- this .to = to ;
355
- }
356
-
357
- protected static SubProjectFile file (String from , String to ) {
358
- return new SubProjectFile (from , to );
359
- }
360
- }
361
272
}
0 commit comments