1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.cling.invoker.mvnup.goals;
20
21 import java.nio.file.Path;
22 import java.util.Map;
23 import java.util.Set;
24
25 import org.apache.maven.api.cli.mvnup.UpgradeOptions;
26 import org.apache.maven.cling.invoker.mvnup.UpgradeContext;
27 import org.jdom2.Document;
28
29
30
31
32
33 public abstract class AbstractUpgradeStrategy implements UpgradeStrategy {
34
35
36
37
38
39 @Override
40 public final UpgradeResult apply(UpgradeContext context, Map<Path, Document> pomMap) {
41 context.info(getDescription());
42 context.indent();
43
44 try {
45 UpgradeResult result = doApply(context, pomMap);
46
47
48 logSummary(context, result);
49
50 return result;
51 } catch (Exception e) {
52 context.failure("Strategy execution failed: " + e.getMessage());
53 return UpgradeResult.failure(pomMap.keySet(), Set.of());
54 } finally {
55 context.unindent();
56 }
57 }
58
59
60
61
62
63
64
65
66 protected abstract UpgradeResult doApply(UpgradeContext context, Map<Path, Document> pomMap);
67
68
69
70
71
72
73
74 protected final UpgradeOptions getOptions(UpgradeContext context) {
75 return context.options();
76 }
77
78
79
80
81
82
83
84 protected void logSummary(UpgradeContext context, UpgradeResult result) {
85 context.println();
86 context.info(getDescription() + " Summary:");
87 context.indent();
88 context.info(result.modifiedCount() + " POM(s) modified");
89 context.info(result.unmodifiedCount() + " POM(s) needed no changes");
90 if (result.errorCount() > 0) {
91 context.info(result.errorCount() + " POM(s) had errors");
92 }
93 context.unindent();
94 }
95 }