1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.commoncli.option.impl.about;
26
27 import static java.util.Arrays.asList;
28 import static java.util.Collections.unmodifiableSet;
29 import static java.util.logging.Level.FINE;
30 import static java.util.logging.Logger.getLogger;
31 import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
32 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
33 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.COMMAND_LINE_NULL_ERROR;
34 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.JAVA_PROGRAM_NULL_ERROR;
35 import static net.sourceforge.plantumldependency.commoncli.constants.log.FineConstants.OPTION_NOT_SPECIFIED_FINE;
36 import static net.sourceforge.plantumldependency.commoncli.option.status.OptionStatus.ACTIVE_OPTIONAL_OPTION_STATUS;
37
38 import java.util.Set;
39 import java.util.TreeSet;
40 import java.util.logging.Logger;
41
42 import net.sourceforge.plantumldependency.commoncli.command.CommandLine;
43 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
44 import net.sourceforge.plantumldependency.commoncli.option.AbstractOption;
45 import net.sourceforge.plantumldependency.commoncli.option.execution.ExecutableOption;
46 import net.sourceforge.plantumldependency.commoncli.option.execution.OptionExecution;
47 import net.sourceforge.plantumldependency.commoncli.option.status.OptionStatus;
48 import net.sourceforge.plantumldependency.commoncli.program.JavaProgram;
49
50
51
52
53
54
55
56
57
58 public class AboutOption extends AbstractOption implements ExecutableOption {
59
60
61 private static final long serialVersionUID = -89198534939353471L;
62
63
64 private static final transient Logger LOGGER = getLogger(AboutOption.class.getName());
65
66
67 public static final String OPTION_MAIN_SYNOPSIS = "-about";
68
69
70 public static final Set < String > OPTION_SYNOPSIS = unmodifiableSet(new TreeSet < String >(asList(new String[] {
71 "--author", "--authors"})));
72
73
74 private JavaProgram javaProgram;
75
76
77 private int priority;
78
79
80
81
82
83
84
85
86
87
88
89 public AboutOption(final JavaProgram program, final int optionPriority) {
90 this(new StringBuilder("To display information about " + program.getName() + ", its license and its authors."),
91 program, optionPriority, ACTIVE_OPTIONAL_OPTION_STATUS);
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 public AboutOption(final StringBuilder fullOptionDescription, final JavaProgram program, final int optionPriority,
111 final OptionStatus optionStatus) {
112 super(OPTION_MAIN_SYNOPSIS, OPTION_SYNOPSIS, fullOptionDescription, optionStatus);
113 setJavaProgram(program);
114 setPriority(optionPriority);
115 }
116
117
118
119
120
121
122 @Override
123 public AboutOption deepClone() {
124 final AboutOption a = (AboutOption) super.deepClone();
125 a.javaProgram = getJavaProgram().deepClone();
126 return a;
127 }
128
129
130
131
132
133
134 @Override
135 protected StringBuilder getFullUsageAdditions() {
136 return new StringBuilder();
137 }
138
139
140
141
142
143
144 @Override
145 protected StringBuilder getFullUsageDescriptionAdditions() {
146 return new StringBuilder();
147 }
148
149
150
151
152
153
154
155
156 private JavaProgram getJavaProgram() {
157 return javaProgram;
158 }
159
160
161
162
163
164
165 @Override
166 protected StringBuilder getMainUsageAdditions() {
167 return new StringBuilder();
168 }
169
170
171
172
173
174
175 @Override
176 public int getPriority() {
177 return priority;
178 }
179
180
181
182
183
184
185 @Override
186 public OptionExecution parseCommandLine(final CommandLine commandLine) throws CommandLineException {
187 checkNull(commandLine, COMMAND_LINE_NULL_ERROR);
188
189 OptionExecution optionExecution = null;
190
191 if (commandLine.isOptionActiveAndSpecified(this)) {
192 optionExecution = new AboutOptionExecution(getJavaProgram(), getPriority());
193 } else {
194 LOGGER.log(FINE, buildLogString(OPTION_NOT_SPECIFIED_FINE, getAllNames()));
195 }
196
197 return optionExecution;
198 }
199
200
201
202
203
204
205
206
207
208 private void setJavaProgram(final JavaProgram value) {
209 checkNull(value, JAVA_PROGRAM_NULL_ERROR);
210
211 javaProgram = value;
212 }
213
214
215
216
217
218
219
220
221
222 private void setPriority(final int value) {
223 priority = value;
224 }
225
226
227
228
229
230
231 @Override
232 public String toString() {
233 return getClass().getSimpleName() + " [" + super.toString() + ", javaProgram=" + javaProgram + ", priority="
234 + priority + "]";
235 }
236 }