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.version;
26
27 import static java.util.logging.Level.INFO;
28 import static java.util.logging.Logger.getLogger;
29 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.LEFT_PARENTHESIS_CHAR;
30 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.LINE_CHAR;
31 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.RIGHT_PARENTHESIS_CHAR;
32 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.SPACE_CHAR;
33 import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
34 import static net.sourceforge.plantumldependency.common.utils.system.SystemUtils.getSystemPropertiesSetToDisplay;
35 import static net.sourceforge.plantumldependency.commoncli.constants.CommandLineConstants.IMPORTANT_SYSTEM_PROPERTIES;
36 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.JAVA_PROGRAM_NULL_ERROR;
37
38 import java.util.Set;
39 import java.util.logging.Logger;
40
41 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
42 import net.sourceforge.plantumldependency.commoncli.option.execution.AbstractOptionExecution;
43 import net.sourceforge.plantumldependency.commoncli.program.JavaProgram;
44
45
46
47
48
49
50
51
52
53 public class VersionOptionExecution extends AbstractOptionExecution {
54
55
56 private static final long serialVersionUID = 5663514744085994950L;
57
58
59 private static final transient Logger LOGGER = getLogger(VersionOptionExecution.class.getName());
60
61
62 private JavaProgram javaProgram;
63
64
65 private boolean verboseMode;
66
67
68
69
70
71
72
73
74
75
76
77
78 public VersionOptionExecution(final JavaProgram program, final boolean verboseModeActive, final int optionPriority) {
79 super(optionPriority);
80 setJavaProgram(program);
81 setVerboseMode(verboseModeActive);
82 }
83
84
85
86
87
88
89
90
91
92
93
94 public VersionOptionExecution(final JavaProgram program, final int optionPriority) {
95 this(program, true, optionPriority);
96 }
97
98
99
100
101
102
103 @Override
104 public VersionOptionExecution deepClone() {
105 final VersionOptionExecution a = (VersionOptionExecution) super.deepClone();
106 a.javaProgram = getJavaProgram().deepClone();
107 return a;
108 }
109
110
111
112
113
114
115 @Override
116 public void execute() throws CommandLineException {
117 final StringBuilder buffer = new StringBuilder(getJavaProgram().getName());
118 buffer.append(" version ");
119 buffer.append(getJavaProgram().getVersion().getFullVersionNumber());
120 buffer.append(SPACE_CHAR);
121 buffer.append(LEFT_PARENTHESIS_CHAR);
122 buffer.append(getJavaProgram().getVersion().getCompilationTime());
123 buffer.append(RIGHT_PARENTHESIS_CHAR);
124 buffer.append(SPACE_CHAR);
125
126 Set < String > systemPropertiesSetToDisplay = null;
127 if (isVerboseMode()) {
128 systemPropertiesSetToDisplay = getSystemPropertiesSetToDisplay();
129 } else {
130 systemPropertiesSetToDisplay = getSystemPropertiesSetToDisplay(IMPORTANT_SYSTEM_PROPERTIES);
131 }
132
133 for (final String propertyToDisplay : systemPropertiesSetToDisplay) {
134 buffer.append(LINE_CHAR);
135 buffer.append(propertyToDisplay);
136 }
137
138 final String bufferStr = buffer.toString();
139 System.out.println(bufferStr);
140 LOGGER.log(INFO, bufferStr);
141 }
142
143
144
145
146
147
148
149
150 private JavaProgram getJavaProgram() {
151 return javaProgram;
152 }
153
154
155
156
157
158
159
160
161 private boolean isVerboseMode() {
162 return verboseMode;
163 }
164
165
166
167
168
169
170
171
172
173 private void setJavaProgram(final JavaProgram value) {
174 checkNull(value, JAVA_PROGRAM_NULL_ERROR);
175
176 javaProgram = value;
177 }
178
179
180
181
182
183
184
185
186
187 private void setVerboseMode(final boolean value) {
188 verboseMode = value;
189 }
190
191
192
193
194
195
196 @Override
197 public String toString() {
198 return getClass().getSimpleName() + " [" + super.toString() + ", javaProgram=" + javaProgram + ", verboseMode="
199 + verboseMode + "]";
200 }
201 }