1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.release.phase;
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.List;
27
28 import org.apache.maven.project.MavenProject;
29 import org.apache.maven.scm.manager.NoSuchScmProviderException;
30 import org.apache.maven.scm.manager.ScmManager;
31 import org.apache.maven.scm.provider.ScmProvider;
32 import org.apache.maven.scm.repository.ScmRepositoryException;
33 import org.apache.maven.shared.release.ReleaseExecutionException;
34 import org.apache.maven.shared.release.ReleaseFailureException;
35 import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
36 import org.apache.maven.shared.release.config.ReleaseUtils;
37 import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
38 import org.apache.maven.shared.release.scm.DefaultScmRepositoryConfigurator;
39 import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
40 import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
41 import org.apache.maven.shared.release.stubs.ScmManagerStub;
42 import org.apache.maven.shared.release.transform.jdom2.JDomModelETLFactory;
43 import org.apache.maven.shared.release.util.ReleaseUtil;
44 import org.junit.Ignore;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
47 import org.junit.runners.Parameterized;
48 import org.junit.runners.Parameterized.Parameters;
49
50 import static org.junit.Assert.assertEquals;
51 import static org.junit.Assert.assertNull;
52 import static org.junit.Assert.assertTrue;
53 import static org.junit.Assert.fail;
54 import static org.mockito.Mockito.mock;
55 import static org.mockito.Mockito.verifyNoMoreInteractions;
56
57
58
59
60
61
62 @RunWith(Parameterized.class)
63 public abstract class AbstractRewritingReleasePhaseTestCase extends AbstractReleaseTestCase {
64 private final String modelETL;
65
66 @Parameters
67 public static Collection<Object[]> data() {
68 return Arrays.asList(new Object[][] {{JDomModelETLFactory.NAME}});
69 }
70
71 public AbstractRewritingReleasePhaseTestCase(String modelETL) {
72 this.modelETL = modelETL;
73 }
74
75 @Override
76 public void setUp() throws Exception {
77 super.setUp();
78 phase = lookup(ReleasePhase.class, getRoleHint());
79
80 if (phase instanceof AbstractRewritePomsPhase) {
81 ((AbstractRewritePomsPhase) phase).setModelETL(modelETL);
82 ((AbstractRewritePomsPhase) phase).setStartTime(0);
83 }
84 }
85
86 protected abstract String getRoleHint();
87
88 @Test
89 public void testRewriteBasicPom() throws Exception {
90 List<MavenProject> reactorProjects = createReactorProjects("basic-pom");
91 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom");
92 mapNextVersion(builder, "groupId:artifactId");
93
94 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
95
96 assertTrue(comparePomFiles(reactorProjects));
97 }
98
99 @Test
100 public void testRewriteBasicPomEntities() throws Exception {
101 List<MavenProject> reactorProjects = createReactorProjects("basic-pom-entities");
102 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom-entities");
103 mapNextVersion(builder, "groupId:artifactId");
104
105 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
106
107 assertTrue(comparePomFiles(reactorProjects));
108 }
109
110 @Test
111 public void testRewriteBasicPomNamespace() throws Exception {
112 List<MavenProject> reactorProjects = createReactorProjects("basic-pom-namespace");
113 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom-namespace");
114 mapNextVersion(builder, "groupId:artifactId");
115
116 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
117
118 assertTrue(comparePomFiles(reactorProjects));
119 }
120
121 @Test
122 public void testRewriteBasicPomWithEncoding() throws Exception {
123 List<MavenProject> reactorProjects = createReactorProjects("basic-pom-with-encoding");
124 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom-with-encoding");
125 mapNextVersion(builder, "groupId:artifactId");
126
127 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
128
129 assertTrue(comparePomFiles(reactorProjects));
130 }
131
132 @Test
133 public void testRewritePomWithParent() throws Exception {
134 List<MavenProject> reactorProjects = createReactorProjects("pom-with-parent");
135 ReleaseDescriptorBuilder builder =
136 createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "pom-with-parent");
137
138 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
139
140 assertTrue(comparePomFiles(reactorProjects));
141 }
142
143 @Test
144 public void testRewritePomWithUnmappedParent() throws Exception {
145
146 List<MavenProject> reactorProjects = createReactorProjects("pom-with-parent");
147 ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "pom-with-parent");
148
149
150 reactorProjects = new ArrayList<>(reactorProjects);
151 Collections.reverse(reactorProjects);
152
153 mapAlternateNextVersion(builder, "groupId:subproject1");
154
155 try {
156 phase.execute(
157 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
158
159 fail("Should have thrown an exception");
160 } catch (ReleaseFailureException e) {
161 assertTrue(true);
162 }
163 }
164
165 @Test
166 public void testRewritePomWithReleasedParent() throws Exception {
167
168 List<MavenProject> reactorProjects = createReactorProjects("pom-with-released-parent");
169 ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "pom-with-released-parent");
170
171 mapAlternateNextVersion(builder, "groupId:subproject1");
172 builder.addReleaseVersion("groupId:artifactId", "1");
173 builder.addDevelopmentVersion("groupId:artifactId", "1");
174
175 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
176
177 assertTrue(comparePomFiles(reactorProjects));
178 }
179
180 protected abstract void mapAlternateNextVersion(ReleaseDescriptorBuilder config, String projectId);
181
182 @Test
183 public void testRewritePomWithInheritedVersion() throws Exception {
184 List<MavenProject> reactorProjects = createReactorProjects("pom-with-inherited-version");
185 ReleaseDescriptorBuilder builder =
186 createConfigurationForWithParentNextVersion(reactorProjects, "pom-with-inherited-version");
187
188 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
189
190 assertTrue(comparePomFiles(reactorProjects));
191 }
192
193 @Test
194 public void testRewritePomWithChangedInheritedVersion() throws Exception {
195 List<MavenProject> reactorProjects = createReactorProjects("pom-with-inherited-version");
196 ReleaseDescriptorBuilder builder =
197 createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "pom-with-inherited-version");
198
199 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
200
201 MavenProject project = getProjectsAsMap(reactorProjects).get("groupId:subproject1");
202 comparePomFiles(project, "-version-changed");
203 }
204
205 protected abstract ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion(
206 List<MavenProject> reactorProjects, String workingDirectory) throws Exception;
207
208 @Test
209 public void testRewritePomDependencies() throws Exception {
210 List<MavenProject> reactorProjects = createReactorProjects("internal-snapshot-dependencies");
211 ReleaseDescriptorBuilder builder =
212 createDefaultConfiguration(reactorProjects, "internal-snapshot-dependencies");
213 mapNextVersion(builder, "groupId:subsubproject");
214
215 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
216
217 assertTrue(comparePomFiles(reactorProjects));
218 }
219
220 @Test
221 public void testRewritePomUnmappedDependencies() throws Exception {
222 List<MavenProject> reactorProjects = createReactorProjects("internal-snapshot-dependencies");
223 ReleaseDescriptorBuilder builder =
224 createUnmappedConfiguration(reactorProjects, "internal-snapshot-dependencies");
225
226 try {
227 phase.execute(
228 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
229
230 fail("Should have thrown an exception");
231 } catch (ReleaseFailureException e) {
232 assertTrue(true);
233 }
234 }
235
236 @Test
237 public void testRewritePomDependenciesDifferentVersion() throws Exception {
238 List<MavenProject> reactorProjects = createReactorProjects("internal-differing-snapshot-dependencies");
239 ReleaseDescriptorBuilder builder =
240 createDifferingVersionConfiguration(reactorProjects, "internal-differing-snapshot-dependencies");
241
242 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
243
244 assertTrue(comparePomFiles(reactorProjects));
245 }
246
247 @Test
248 public void testRewriteManagedPomDependencies() throws Exception {
249 List<MavenProject> reactorProjects = createReactorProjects("internal-managed-snapshot-dependency");
250 ReleaseDescriptorBuilder builder =
251 createMappedConfiguration(reactorProjects, "internal-managed-snapshot-dependency");
252
253 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
254
255 assertTrue(comparePomFiles(reactorProjects));
256 }
257
258 @Test
259 public void testRewriteManagedPomUnmappedDependencies() throws Exception {
260 List<MavenProject> reactorProjects = createReactorProjects("internal-managed-snapshot-dependency");
261 ReleaseDescriptorBuilder builder =
262 createUnmappedConfiguration(reactorProjects, "internal-managed-snapshot-dependency");
263
264 try {
265 phase.execute(
266 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
267
268 fail("Should have thrown an exception");
269 } catch (ReleaseFailureException e) {
270 assertTrue(true);
271 }
272 }
273
274 @Test
275 public void testRewritePomPlugins() throws Exception {
276 List<MavenProject> reactorProjects = createReactorProjects("internal-snapshot-plugins");
277 ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "internal-snapshot-plugins");
278
279 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
280
281 assertTrue(comparePomFiles(reactorProjects));
282 }
283
284 @Test
285 public void testRewritePomUnmappedPlugins() throws Exception {
286 List<MavenProject> reactorProjects = createReactorProjects("internal-snapshot-plugins");
287 ReleaseDescriptorBuilder builder = createUnmappedConfiguration(reactorProjects, "internal-snapshot-plugins");
288
289 try {
290 phase.execute(
291 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
292
293 fail("Should have thrown an exception");
294 } catch (ReleaseFailureException e) {
295 assertTrue(true);
296 }
297 }
298
299 @Test
300 public void testRewritePomPluginsDifferentVersion() throws Exception {
301 List<MavenProject> reactorProjects = createReactorProjects("internal-differing-snapshot-plugins");
302 ReleaseDescriptorBuilder builder =
303 createDifferingVersionConfiguration(reactorProjects, "internal-differing-snapshot-plugins");
304
305 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
306
307 assertTrue(comparePomFiles(reactorProjects));
308 }
309
310 @Test
311 public void testRewriteManagedPomPlugins() throws Exception {
312 List<MavenProject> reactorProjects = createReactorProjects("internal-managed-snapshot-plugin");
313 ReleaseDescriptorBuilder builder =
314 createMappedConfiguration(reactorProjects, "internal-managed-snapshot-plugin");
315
316 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
317
318 assertTrue(comparePomFiles(reactorProjects));
319 }
320
321 @Test
322 public void testRewriteManagedPomUnmappedPlugins() throws Exception {
323 List<MavenProject> reactorProjects = createReactorProjects("internal-managed-snapshot-plugin");
324 ReleaseDescriptorBuilder builder =
325 createUnmappedConfiguration(reactorProjects, "internal-managed-snapshot-plugin");
326
327 try {
328 phase.execute(
329 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
330
331 fail("Should have thrown an exception");
332 } catch (ReleaseFailureException e) {
333 assertTrue(true);
334 }
335 }
336
337 @Test
338 public void testRewritePomReportPlugins() throws Exception {
339 List<MavenProject> reactorProjects = createReactorProjects("internal-snapshot-report-plugins");
340 ReleaseDescriptorBuilder builder =
341 createDefaultConfiguration(reactorProjects, "internal-snapshot-report-plugins");
342
343 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
344
345 assertTrue(comparePomFiles(reactorProjects));
346 }
347
348 @Test
349 public void testRewritePomUnmappedReportPlugins() throws Exception {
350 List<MavenProject> reactorProjects = createReactorProjects("internal-snapshot-report-plugins");
351 ReleaseDescriptorBuilder builder =
352 createUnmappedConfiguration(reactorProjects, "internal-snapshot-report-plugins");
353
354 try {
355 phase.execute(
356 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
357
358 fail("Should have thrown an exception");
359 } catch (ReleaseFailureException e) {
360 assertTrue(true);
361 }
362 }
363
364 @Test
365 public void testRewritePomReportPluginsDifferentVersion() throws Exception {
366 List<MavenProject> reactorProjects = createReactorProjects("internal-differing-snapshot-report-plugins");
367 ReleaseDescriptorBuilder builder =
368 createDifferingVersionConfiguration(reactorProjects, "internal-differing-snapshot-report-plugins");
369
370 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
371
372 assertTrue(comparePomFiles(reactorProjects));
373 }
374
375 @Test
376 @Ignore("Extensions being part of reactor is not supported anymore")
377 public void testRewritePomExtension() throws Exception {
378 List<MavenProject> reactorProjects = createReactorProjects("internal-snapshot-extension");
379 ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "internal-snapshot-extension");
380
381 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
382
383 assertTrue(comparePomFiles(reactorProjects));
384 }
385
386 @Test
387 @Ignore("Extensions being part of reactor is not supported anymore")
388 public void testRewritePomUnmappedExtension() throws Exception {
389 List<MavenProject> reactorProjects = createReactorProjects("internal-snapshot-extension");
390 ReleaseDescriptorBuilder builder = createUnmappedConfiguration(reactorProjects, "internal-snapshot-extension");
391
392 try {
393 phase.execute(
394 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
395
396 fail("Should have thrown an exception");
397 } catch (ReleaseFailureException e) {
398 assertTrue(true);
399 }
400 }
401
402 @Test
403 @Ignore("Extensions being part of reactor is not supported anymore")
404 public void testRewritePomExtensionDifferentVersion() throws Exception {
405 List<MavenProject> reactorProjects = createReactorProjects("internal-differing-snapshot-extension");
406 ReleaseDescriptorBuilder builder =
407 createDifferingVersionConfiguration(reactorProjects, "internal-differing-snapshot-extension");
408
409 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
410
411 assertTrue(comparePomFiles(reactorProjects));
412 }
413
414 @Test
415 @Ignore("Extensions being part of reactor is not supported anymore")
416 public void testRewritePomExtensionUndefinedVersion() throws Exception {
417 List<MavenProject> reactorProjects = createReactorProjects("pom-without-extension-version");
418 ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "pom-without-extension-version");
419
420 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
421
422 assertTrue(comparePomFiles(reactorProjects));
423 }
424
425 @Test
426 public void testRewriteAddSchema() throws Exception {
427 boolean copyFiles = true;
428
429
430 for (int i = 0; i < 2; i++) {
431 String path = "basic-pom";
432 List<MavenProject> reactorProjects = prepareReactorProjects(path);
433 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom");
434 mapNextVersion(builder, "groupId:artifactId");
435 builder.setAddSchema(true);
436
437 phase.execute(
438 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
439
440 comparePomFiles(reactorProjects, "-with-schema");
441
442 copyFiles = false;
443
444 verifyReactorProjects(path, copyFiles);
445 }
446 }
447
448 @Test
449 public void testSimulateRewriteEditModeSkipped() throws Exception {
450
451 List<MavenProject> reactorProjects = createReactorProjects("basic-pom");
452 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom");
453 builder.setScmUseEditMode(true);
454 mapNextVersion(builder, "groupId:artifactId");
455
456 ScmProvider scmProviderMock = mock(ScmProvider.class);
457
458 ScmManagerStub scmManager = new ScmManagerStub();
459 DefaultScmRepositoryConfigurator configurator =
460 (DefaultScmRepositoryConfigurator) lookup(ScmRepositoryConfigurator.class);
461 configurator.setScmManager(scmManager);
462 scmManager.setScmProvider(scmProviderMock);
463
464
465 phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
466
467
468 verifyNoMoreInteractions(scmProviderMock);
469 }
470
471 @Test
472 public void testRewriteUnmappedPom() throws Exception {
473 List<MavenProject> reactorProjects = createReactorProjects("basic-pom");
474 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom");
475
476 try {
477 phase.execute(
478 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
479
480 fail("Should have thrown an exception");
481 } catch (ReleaseFailureException e) {
482 assertTrue(true);
483 }
484 }
485
486 @Test
487 public void testRewriteBasicPomWithScmRepoException() throws Exception {
488
489 List<MavenProject> reactorProjects = createReactorProjects("basic-pom");
490 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom");
491 builder.setScmUseEditMode(true);
492 builder.setScmSourceUrl("scm:svn:fail");
493 mapNextVersion(builder, "groupId:artifactId");
494
495 ScmManager scmManager = lookup(ScmManager.class);
496 if (scmManager instanceof ScmManagerStub) {
497 ((ScmManagerStub) scmManager).setException(new ScmRepositoryException("..."));
498 }
499
500 try {
501 phase.execute(
502 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
503
504 fail("Should have thrown an exception");
505 } catch (ReleaseScmRepositoryException e) {
506 assertNull("Check no additional cause", e.getCause());
507 }
508 }
509
510 @Test
511 public void testRewriteBasicPomWithNoSuchProviderException() throws Exception {
512
513 List<MavenProject> reactorProjects = createReactorProjects("basic-pom");
514 ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom");
515 builder.setScmUseEditMode(true);
516 builder.setScmSourceUrl("scm:fail:path");
517 mapNextVersion(builder, "groupId:artifactId");
518
519 ScmManager scmManager = (ScmManager) lookup(ScmManager.class);
520 if (scmManager instanceof ScmManagerStub) {
521 ((ScmManagerStub) scmManager).setException(new NoSuchScmProviderException("..."));
522 ;
523 }
524
525
526 try {
527 phase.execute(
528 ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
529
530 fail("Should have thrown an exception");
531 } catch (ReleaseExecutionException e) {
532
533 assertEquals(
534 "Check cause",
535 NoSuchScmProviderException.class,
536 e.getCause().getClass());
537 }
538 }
539
540 @Test
541 public void testRewriteWhitespaceAroundValues() throws Exception {
542 List<MavenProject> reactorProjects = createReactorProjects("whitespace-around-values");
543 ReleaseDescriptorBuilder builder =
544 createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "whitespace-around-values");
545 mapNextVersion(builder, "groupId:subproject2");
546
547 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
548
549 assertTrue(comparePomFiles(reactorProjects));
550 }
551
552 @Test
553 public void testRewriteCommentsAroundValues() throws Exception {
554 List<MavenProject> reactorProjects = createReactorProjects("comments-around-values");
555 ReleaseDescriptorBuilder builder =
556 createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "comments-around-values");
557 mapNextVersion(builder, "groupId:subproject2");
558
559 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
560
561 assertTrue(comparePomFiles(reactorProjects));
562 }
563
564 @Test
565 public void testRewriteCDataAroundValues() throws Exception {
566 List<MavenProject> reactorProjects = createReactorProjects("cdata-around-values");
567 ReleaseDescriptorBuilder builder =
568 createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "cdata-around-values");
569 mapNextVersion(builder, "groupId:subproject2");
570
571 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
572
573 assertTrue(comparePomFiles(reactorProjects));
574 }
575
576 @Test
577 public void testCleanNoProjects() throws Exception {
578
579 ((ResourceGenerator) phase).clean(Collections.<MavenProject>emptyList());
580 }
581
582 protected ReleaseDescriptorBuilder createUnmappedConfiguration(
583 List<MavenProject> reactorProjects, String workingDirectory) throws Exception {
584 ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory);
585
586 unmapNextVersion(builder, "groupId:subproject1");
587 mapNextVersion(builder, "groupId:subproject2");
588 mapNextVersion(builder, "groupId:subproject3");
589 mapNextVersion(builder, "groupId:artifactId");
590 return builder;
591 }
592
593 protected List<MavenProject> createReactorProjects(String path) throws Exception {
594 return prepareReactorProjects(path);
595 }
596
597 protected ReleaseDescriptorBuilder createDefaultConfiguration(
598 List<MavenProject> reactorProjects, String workingDirectory) throws Exception {
599 ReleaseDescriptorBuilder builder = createMappedConfiguration(reactorProjects, workingDirectory);
600
601 mapNextVersion(builder, "groupId:subproject4");
602 return builder;
603 }
604
605 protected ReleaseDescriptorBuilder createMappedConfiguration(
606 List<MavenProject> reactorProjects, String workingDirectory) throws Exception {
607 ReleaseDescriptorBuilder builder = createDifferingVersionConfiguration(reactorProjects, workingDirectory);
608
609 mapNextVersion(builder, "groupId:subproject3");
610 return builder;
611 }
612
613 private ReleaseDescriptorBuilder createDifferingVersionConfiguration(
614 List<MavenProject> reactorProjects, String workingDirectory) throws Exception {
615 ReleaseDescriptorBuilder builder =
616 createConfigurationForWithParentNextVersion(reactorProjects, workingDirectory);
617
618 mapNextVersion(builder, "groupId:subproject2");
619 return builder;
620 }
621
622 protected abstract ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion(
623 List<MavenProject> reactorProjects, String workingDirectory) throws Exception;
624
625 protected abstract void unmapNextVersion(ReleaseDescriptorBuilder config, String projectId);
626
627 protected abstract void mapNextVersion(ReleaseDescriptorBuilder config, String projectId);
628
629 protected ReleaseDescriptorBuilder createDescriptorFromBasicPom(
630 List<MavenProject> reactorProjects, String workingDirectory) throws Exception {
631 return createDescriptorFromProjects(reactorProjects, workingDirectory);
632 }
633
634 protected abstract String readTestProjectFile(String fileName) throws IOException;
635
636 @Test
637 public void testRewritePomDependenciesWithNamespace() throws Exception {
638 List<MavenProject> reactorProjects = createReactorProjects("pom-with-namespace");
639 ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "pom-with-namespace");
640
641 phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
642
643 assertTrue(comparePomFiles(reactorProjects));
644 }
645
646 protected abstract List<MavenProject> prepareReactorProjects(String path) throws Exception;
647
648 protected void verifyReactorProjects(String path, boolean copyFiles) throws Exception {}
649
650 protected ReleaseDescriptorBuilder createDescriptorFromProjects(
651 List<MavenProject> reactorProjects, String workingDirectory) {
652 ReleaseDescriptorBuilder builder =
653 createDescriptorFromProjects(new ReleaseDescriptorBuilder(), reactorProjects);
654 builder.setWorkingDirectory(getWorkingDirectory(workingDirectory).toString());
655 return builder;
656 }
657
658 private ReleaseDescriptorBuilder createDescriptorFromProjects(
659 ReleaseDescriptorBuilder builder, List<MavenProject> reactorProjects) {
660 MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects);
661
662 for (MavenProject project : reactorProjects) {
663 String key = project.getGroupId() + ':' + project.getArtifactId();
664 builder.putOriginalVersion(key, project.getVersion());
665 builder.addOriginalScmInfo(key, project.getScm());
666 }
667
668 if (rootProject.getScm() == null) {
669 builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo/trunk");
670 } else {
671 builder.setScmSourceUrl(rootProject.getScm().getConnection());
672 }
673
674 return builder;
675 }
676 }