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;
20
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.maven.api.annotations.Nonnull;
25 import org.apache.maven.api.cli.InvokerRequest;
26 import org.apache.maven.api.cli.mvnup.UpgradeOptions;
27 import org.apache.maven.cling.invoker.LookupContext;
28 import org.jline.reader.LineReader;
29 import org.jline.utils.AttributedString;
30 import org.jline.utils.AttributedStringBuilder;
31 import org.jline.utils.AttributedStyle;
32
33 import static org.apache.maven.cling.invoker.mvnup.goals.UpgradeConstants.Indentation;
34
35 @SuppressWarnings("VisibilityModifier")
36 public class UpgradeContext extends LookupContext {
37 public UpgradeContext(InvokerRequest invokerRequest, UpgradeOptions upgradeOptions) {
38 super(invokerRequest, true, upgradeOptions);
39 }
40
41 public Map<String, Goal> goals;
42
43 public List<AttributedString> header;
44 public AttributedStyle style;
45 public LineReader reader;
46
47
48 private int indentLevel = 0;
49 private String indentString = Indentation.DEFAULT;
50
51 public void addInHeader(String text) {
52 addInHeader(AttributedStyle.DEFAULT, text);
53 }
54
55 public void addInHeader(AttributedStyle style, String text) {
56 AttributedStringBuilder asb = new AttributedStringBuilder();
57 asb.style(style).append(text);
58 header.add(asb.toAttributedString());
59 }
60
61
62
63
64 public void indent() {
65 indentLevel++;
66 }
67
68
69
70
71 public void unindent() {
72 if (indentLevel > 0) {
73 indentLevel--;
74 }
75 }
76
77
78
79
80 public void setIndentString(String indentString) {
81 this.indentString = indentString != null ? indentString : Indentation.DEFAULT;
82 }
83
84
85
86
87 private String getCurrentIndent() {
88 if (indentLevel == 0) {
89 return "";
90 }
91 return indentString.repeat(indentLevel);
92 }
93
94
95
96
97 public void info(String message) {
98 logger.info(getCurrentIndent() + message);
99 }
100
101
102
103
104 public void debug(String message) {
105 logger.debug(getCurrentIndent() + message);
106 }
107
108
109
110
111 public void println() {
112 logger.info("");
113 }
114
115
116
117
118
119
120 public void success(String message) {
121 logger.info(getCurrentIndent() + "✓ " + message);
122 }
123
124
125
126
127 public void failure(String message) {
128 logger.error(getCurrentIndent() + "✗ " + message);
129 }
130
131
132
133
134 public void warning(String message) {
135 logger.warn(getCurrentIndent() + "⚠ " + message);
136 }
137
138
139
140
141 public void detail(String message) {
142 logger.info(getCurrentIndent() + "• " + message);
143 }
144
145
146
147
148 public void action(String message) {
149 logger.info(getCurrentIndent() + "→ " + message);
150 }
151
152
153
154
155
156
157
158 @Nonnull
159 public UpgradeOptions options() {
160 return (UpgradeOptions) super.options();
161 }
162 }