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.logging.Level.INFO;
28 import static java.util.logging.Logger.getLogger;
29 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.HYPHEN_CHAR;
30 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.LINE_CHAR;
31 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.SPACE_CHAR;
32 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.TAB_CHAR;
33 import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
34 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.JAVA_PROGRAM_NULL_ERROR;
35
36 import java.util.logging.Logger;
37
38 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
39 import net.sourceforge.plantumldependency.commoncli.option.execution.AbstractOptionExecution;
40 import net.sourceforge.plantumldependency.commoncli.program.JavaProgram;
41
42
43
44
45
46
47
48
49
50 public class AboutOptionExecution extends AbstractOptionExecution {
51
52
53 private static final long serialVersionUID = 5829000495584908599L;
54
55
56 private static final transient Logger LOGGER = getLogger(AboutOptionExecution.class.getName());
57
58
59 private JavaProgram javaProgram;
60
61
62
63
64
65
66
67
68
69
70
71 public AboutOptionExecution(final JavaProgram program, final int optionPriority) {
72 super(optionPriority);
73 setJavaProgram(program);
74 }
75
76
77
78
79
80
81 @Override
82 public AboutOptionExecution deepClone() {
83 final AboutOptionExecution a = (AboutOptionExecution) super.deepClone();
84 a.javaProgram = getJavaProgram().deepClone();
85 return a;
86 }
87
88
89
90
91
92
93 @Override
94 public void execute() throws CommandLineException {
95 final StringBuilder buffer = new StringBuilder(getJavaProgram().getName());
96 buffer.append(" authors :");
97 buffer.append(LINE_CHAR);
98
99 for (final String author : getJavaProgram().getAuthors()) {
100 buffer.append(LINE_CHAR);
101 buffer.append(TAB_CHAR);
102 buffer.append(HYPHEN_CHAR);
103 buffer.append(SPACE_CHAR);
104 buffer.append(author);
105 }
106
107 buffer.append(LINE_CHAR);
108 buffer.append(LINE_CHAR);
109 buffer.append(getJavaProgram().getName());
110 buffer.append(" licenses :");
111 buffer.append(LINE_CHAR);
112
113 for (final String license : getJavaProgram().getLicenseNames()) {
114 buffer.append(LINE_CHAR);
115 buffer.append(TAB_CHAR);
116 buffer.append(HYPHEN_CHAR);
117 buffer.append(SPACE_CHAR);
118 buffer.append(license);
119 }
120
121 final String bufferStr = buffer.toString();
122 System.out.println(bufferStr);
123 LOGGER.log(INFO, bufferStr);
124 }
125
126
127
128
129
130
131
132
133 private JavaProgram getJavaProgram() {
134 return javaProgram;
135 }
136
137
138
139
140
141
142
143
144
145 private void setJavaProgram(final JavaProgram value) {
146 checkNull(value, JAVA_PROGRAM_NULL_ERROR);
147
148 javaProgram = value;
149 }
150
151
152
153
154
155
156 @Override
157 public String toString() {
158 return getClass().getSimpleName() + " [" + super.toString() + ",javaProgram=" + javaProgram + "]";
159 }
160 }